aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/posixregex.c
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2009-01-05 06:23:34 -0900
committerDavid M. Syzdek <david@syzdek.net>2009-01-05 06:23:34 -0900
commit9ba4880c2ef932080a5644d5c11e506bdcec2d3f (patch)
tree4ec51c477239bfc78207304bd29f063118341b41 /src/posixregex.c
parentff70a236d5a88a4b1e649829bd7d72c359ee5f19 (diff)
downloaddmstools-9ba4880c2ef932080a5644d5c11e506bdcec2d3f.tar.gz
dmstools-9ba4880c2ef932080a5644d5c11e506bdcec2d3f.tar.bz2
dmstools-9ba4880c2ef932080a5644d5c11e506bdcec2d3f.tar.xz
dmstools-9ba4880c2ef932080a5644d5c11e506bdcec2d3f.zip
Adding support for environment variables to posixregex.c
Diffstat (limited to 'src/posixregex.c')
-rw-r--r--src/posixregex.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/posixregex.c b/src/posixregex.c
index 33592df..db7deb6 100644
--- a/src/posixregex.c
+++ b/src/posixregex.c
@@ -81,6 +81,7 @@
81#include <stdio.h> 81#include <stdio.h>
82#include <getopt.h> 82#include <getopt.h>
83#include <string.h> 83#include <string.h>
84#include <stdlib.h>
84 85
85 86
86/////////////////// 87///////////////////
@@ -135,21 +136,21 @@ void my_version PARAMS((void));
135int main(int argc, char * argv[]) 136int main(int argc, char * argv[])
136{ 137{
137 /* declare local vars */ 138 /* declare local vars */
138 int c; 139 int c;
139 int x; 140 int x;
140 int y; 141 int y;
141 int err; 142 int err;
142 int code; 143 int code;
143 int strlen; 144 int strlen;
144 int quiet; 145 int quiet;
145 int verbosity; 146 int verbosity;
146 int opt_index; 147 int opt_index;
147 char arg[BUFFER_SIZE]; 148 char arg[BUFFER_SIZE];
148 char msg[BUFFER_SIZE]; 149 char msg[BUFFER_SIZE];
149 char str[BUFFER_SIZE]; 150 char str[BUFFER_SIZE];
150 char * restr; 151 regex_t regex;
151 regex_t regex; 152 regmatch_t matches[MAX_MATCHES];
152 regmatch_t matches[MAX_MATCHES]; 153 const char * restr;
153 154
154 /* getopt options */ 155 /* getopt options */
155 static char short_opt[] = "hpqr:vV"; 156 static char short_opt[] = "hpqr:vV";
@@ -166,7 +167,7 @@ int main(int argc, char * argv[])
166 167
167 /* initialize variables */ 168 /* initialize variables */
168 code = 0; 169 code = 0;
169 restr = ".*"; 170 restr = NULL;
170 quiet = 0; 171 quiet = 0;
171 verbosity = 0; 172 verbosity = 0;
172 opt_index = 0; 173 opt_index = 0;
@@ -209,7 +210,16 @@ int main(int argc, char * argv[])
209 }; 210 };
210 }; 211 };
211 212
212 /* compile regulare expression for later use */ 213 if (!(restr))
214 restr = getenv("POSIXREGEX");
215 if (!(restr))
216 {
217 fprintf(stderr, "%s: missing required argument `-- r'\n", PROGRAM_NAME);
218 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
219 return(1);
220 };
221
222 /* compile regular expression for later use */
213 if (!(quiet)) 223 if (!(quiet))
214 printf("regex: %s\n",restr); 224 printf("regex: %s\n",restr);
215 if ((err = regcomp(&regex, restr, REG_EXTENDED|REG_ICASE))) 225 if ((err = regcomp(&regex, restr, REG_EXTENDED|REG_ICASE)))
@@ -302,6 +312,8 @@ void my_usage(void)
302 printf(" -r regex regular expression to use for testing strings\n"); 312 printf(" -r regex regular expression to use for testing strings\n");
303 printf(" -v, --verbose print verbose messages\n"); 313 printf(" -v, --verbose print verbose messages\n");
304 printf(" -V, --version print version number and exit\n"); 314 printf(" -V, --version print version number and exit\n");
315 printf("Variables:\n");
316 printf(" POSIXREGEX default regular expression to use for testing strings\n");
305 printf("\n"); 317 printf("\n");
306#ifdef PACKAGE_BUGREPORT 318#ifdef PACKAGE_BUGREPORT
307 printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT); 319 printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);