diff options
| author | David M. Syzdek <syzdek@bindlebinaries.com> | 2012-06-04 13:08:37 -0800 |
|---|---|---|
| committer | David M. Syzdek <syzdek@bindlebinaries.com> | 2012-06-04 13:08:37 -0800 |
| commit | fddf0d97c1ee060ea1646a2ade5d2bedbae20130 (patch) | |
| tree | e25465363ce984e89e80514c89dec084cfb6e054 /src | |
| parent | a1130b343428463f53414bea37776a16a045fba3 (diff) | |
| download | dmstools-fddf0d97c1ee060ea1646a2ade5d2bedbae20130.tar.gz dmstools-fddf0d97c1ee060ea1646a2ade5d2bedbae20130.tar.bz2 dmstools-fddf0d97c1ee060ea1646a2ade5d2bedbae20130.tar.xz dmstools-fddf0d97c1ee060ea1646a2ade5d2bedbae20130.zip | |
Updating comment style in posixregex.
Diffstat (limited to 'src')
| -rw-r--r-- | src/posixregex.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/src/posixregex.c b/src/posixregex.c index 652d7c3..d2ca1ee 100644 --- a/src/posixregex.c +++ b/src/posixregex.c | |||
| @@ -57,22 +57,21 @@ | |||
| 57 | // // | 57 | // // |
| 58 | ///////////// | 58 | ///////////// |
| 59 | 59 | ||
| 60 | /* | 60 | // |
| 61 | * POSIX ASCII Description | 61 | // POSIX ASCII Description |
| 62 | * [:alnum:] [A-Za-z0-9] Alphanumeric characters | 62 | // [:alnum:] [A-Za-z0-9] Alphanumeric characters |
| 63 | * [:alpha:] [A-Za-z] Alphabetic characters | 63 | // [:alpha:] [A-Za-z] Alphabetic characters |
| 64 | * [:blank:] [ \t] Space and tab | 64 | // [:blank:] [ \t] Space and tab |
| 65 | * [:cntrl:] [\x00-\x1F\x7F] Control characters | 65 | // [:cntrl:] [\x00-\x1F\x7F] Control characters |
| 66 | * [:digit:] [0-9] Digits | 66 | // [:digit:] [0-9] Digits |
| 67 | * [:graph:] [\x21-\x7E] Visible characters | 67 | // [:graph:] [\x21-\x7E] Visible characters |
| 68 | * [:lower:] [a-z] Lowercase letters | 68 | // [:lower:] [a-z] Lowercase letters |
| 69 | * [:print:] [\x20-\x7E] Visible characters and spaces | 69 | // [:print:] [\x20-\x7E] Visible characters and spaces |
| 70 | * [:space:] [ \t\r\n\v\f] Whitespace characters | 70 | // [:space:] [ \t\r\n\v\f] Whitespace characters |
| 71 | * [:upper:] [A-Z] Uppercase letters | 71 | // [:upper:] [A-Z] Uppercase letters |
| 72 | * [:xdigit:] [A-Fa-f0-9] Hexadecimal digits | 72 | // [:xdigit:] [A-Fa-f0-9] Hexadecimal digits |
| 73 | * [:punct:] [-!"#$%&'()*+,./:;<=>?@[\\\]_`{|}~] Punctuation characters | 73 | // [:punct:] [-!"#$%&'()*+,./:;<=>?@[\\\]_`{|}~] Punctuation characters |
| 74 | */ | 74 | // |
| 75 | |||
| 76 | // Example Uses: | 75 | // Example Uses: |
| 77 | // posixregex '^([[:alpha:]]+)://(([[:alnum:]]+)(:([[:alnum:]]+)){0,1}@){0,1}([-.a-z]+)(:([[:digit:]]+))*/([-/[:alnum:]]*)(\?(.*)){0,1}$' http://jdoe:password@www.foo.org:123/path/to/file?query_string | 76 | // posixregex '^([[:alpha:]]+)://(([[:alnum:]]+)(:([[:alnum:]]+)){0,1}@){0,1}([-.a-z]+)(:([[:digit:]]+))*/([-/[:alnum:]]*)(\?(.*)){0,1}$' http://jdoe:password@www.foo.org:123/path/to/file?query_string |
| 78 | // posixregex '\$([[:digit:]]+)\.([[:digit:]]{2,2})' 'Your change is $7.45.' | 77 | // posixregex '\$([[:digit:]]+)\.([[:digit:]]{2,2})' 'Your change is $7.45.' |
| @@ -155,16 +154,16 @@ | |||
| 155 | // // | 154 | // // |
| 156 | ////////////////// | 155 | ////////////////// |
| 157 | 156 | ||
| 158 | /* main statement */ | 157 | // main statement |
| 159 | int main PARAMS((int, char **)); | 158 | int main PARAMS((int, char **)); |
| 160 | 159 | ||
| 161 | /* displays POSIX regular expressions */ | 160 | // displays POSIX regular expressions |
| 162 | void my_posixregex PARAMS((void)); | 161 | void my_posixregex PARAMS((void)); |
| 163 | 162 | ||
| 164 | /* displays usage */ | 163 | // displays usage |
| 165 | void my_usage PARAMS((void)); | 164 | void my_usage PARAMS((void)); |
| 166 | 165 | ||
| 167 | /* displays usage */ | 166 | // displays usage |
| 168 | void my_version PARAMS((void)); | 167 | void my_version PARAMS((void)); |
| 169 | 168 | ||
| 170 | 169 | ||
| @@ -179,7 +178,7 @@ void my_version PARAMS((void)); | |||
| 179 | /// @param[in] argv array of arguments | 178 | /// @param[in] argv array of arguments |
| 180 | int main(int argc, char * argv[]) | 179 | int main(int argc, char * argv[]) |
| 181 | { | 180 | { |
| 182 | /* declare local vars */ | 181 | // declare local vars |
| 183 | int c; | 182 | int c; |
| 184 | int x; | 183 | int x; |
| 185 | int y; | 184 | int y; |
| @@ -196,7 +195,7 @@ int main(int argc, char * argv[]) | |||
| 196 | regmatch_t matches[MAX_MATCHES]; | 195 | regmatch_t matches[MAX_MATCHES]; |
| 197 | const char * restr; | 196 | const char * restr; |
| 198 | 197 | ||
| 199 | /* getopt options */ | 198 | // getopt options |
| 200 | static char short_opt[] = "hpqr:vV"; | 199 | static char short_opt[] = "hpqr:vV"; |
| 201 | static struct option long_opt[] = | 200 | static struct option long_opt[] = |
| 202 | { | 201 | { |
| @@ -209,20 +208,20 @@ int main(int argc, char * argv[]) | |||
| 209 | {NULL, 0, 0, 0 } | 208 | {NULL, 0, 0, 0 } |
| 210 | }; | 209 | }; |
| 211 | 210 | ||
| 212 | /* initialize variables */ | 211 | // initialize variables |
| 213 | code = 0; | 212 | code = 0; |
| 214 | restr = NULL; | 213 | restr = NULL; |
| 215 | quiet = 0; | 214 | quiet = 0; |
| 216 | verbosity = 0; | 215 | verbosity = 0; |
| 217 | opt_index = 0; | 216 | opt_index = 0; |
| 218 | 217 | ||
| 219 | /* loops through arguments */ | 218 | // loops through arguments |
| 220 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | 219 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) |
| 221 | { | 220 | { |
| 222 | switch(c) | 221 | switch(c) |
| 223 | { | 222 | { |
| 224 | case -1: /* no more arguments */ | 223 | case -1: // no more arguments |
| 225 | case 0: /* long options toggles */ | 224 | case 0: // long options toggles |
| 226 | break; | 225 | break; |
| 227 | case 'h': | 226 | case 'h': |
| 228 | my_usage(); | 227 | my_usage(); |
| @@ -267,7 +266,7 @@ int main(int argc, char * argv[]) | |||
| 267 | return(1); | 266 | return(1); |
| 268 | }; | 267 | }; |
| 269 | 268 | ||
| 270 | /* compile regular expression for later use */ | 269 | // compile regular expression for later use |
| 271 | if (!(quiet)) | 270 | if (!(quiet)) |
| 272 | printf("regex: %s\n",restr); | 271 | printf("regex: %s\n",restr); |
| 273 | if ((err = regcomp(®ex, restr, REG_EXTENDED|REG_ICASE))) | 272 | if ((err = regcomp(®ex, restr, REG_EXTENDED|REG_ICASE))) |
| @@ -277,18 +276,16 @@ int main(int argc, char * argv[]) | |||
| 277 | return(1); | 276 | return(1); |
| 278 | }; | 277 | }; |
| 279 | 278 | ||
| 280 | /* | 279 | // Loops through command line arguments and tests the compiled expressions |
| 281 | * Loops through command line arguments and tests the compiled expressions | 280 | // against each argument. |
| 282 | * against each argument. | ||
| 283 | */ | ||
| 284 | for (x = optind; x < argc; x++) | 281 | for (x = optind; x < argc; x++) |
| 285 | { | 282 | { |
| 286 | /* copies string into buffer and prints to screen */ | 283 | // copies string into buffer and prints to screen |
| 287 | strncpy(arg, argv[x], (size_t)BUFFER_SIZE-1); | 284 | strncpy(arg, argv[x], (size_t)BUFFER_SIZE-1); |
| 288 | if (!(quiet)) | 285 | if (!(quiet)) |
| 289 | printf("%3i: %s ==> ", x-optind+1, arg); | 286 | printf("%3i: %s ==> ", x-optind+1, arg); |
| 290 | 287 | ||
| 291 | /* tests the buffer against the regular expression */ | 288 | // tests the buffer against the regular expression |
| 292 | if ((regexec(®ex, arg, (size_t)MAX_MATCHES, matches, 0))) | 289 | if ((regexec(®ex, arg, (size_t)MAX_MATCHES, matches, 0))) |
| 293 | { | 290 | { |
| 294 | if (!(quiet)) | 291 | if (!(quiet)) |
| @@ -300,7 +297,7 @@ int main(int argc, char * argv[]) | |||
| 300 | if (!(quiet)) | 297 | if (!(quiet)) |
| 301 | printf(" found\n"); | 298 | printf(" found\n"); |
| 302 | 299 | ||
| 303 | /* copies sub matches in buffer string */ | 300 | // copies sub matches in buffer string |
| 304 | if (verbosity) | 301 | if (verbosity) |
| 305 | { | 302 | { |
| 306 | for(y = 0; ((y < MAX_MATCHES) && (matches[y].rm_eo > -1)); y++) | 303 | for(y = 0; ((y < MAX_MATCHES) && (matches[y].rm_eo > -1)); y++) |
| @@ -319,10 +316,10 @@ int main(int argc, char * argv[]) | |||
| 319 | }; | 316 | }; |
| 320 | }; | 317 | }; |
| 321 | 318 | ||
| 322 | /* free regular expression */ | 319 | // free regular expression |
| 323 | regfree(®ex); | 320 | regfree(®ex); |
| 324 | 321 | ||
| 325 | /* end function */ | 322 | // end function |
| 326 | return(code); | 323 | return(code); |
| 327 | } | 324 | } |
| 328 | 325 | ||
