diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-29 21:04:12 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-29 21:04:12 +0000 |
commit | 6c30db8bd37da1466dc71bf3c8c20851d8f46c43 (patch) | |
tree | 7585fdac678edd30f1b46a0cb999619cb0b981cf | |
parent | 51937534fb6ae25b4197ac03635bb09a405957ba (diff) | |
download | busybox-w32-6c30db8bd37da1466dc71bf3c8c20851d8f46c43.tar.gz busybox-w32-6c30db8bd37da1466dc71bf3c8c20851d8f46c43.tar.bz2 busybox-w32-6c30db8bd37da1466dc71bf3c8c20851d8f46c43.zip |
grep: add help text; fix style
-rw-r--r-- | findutils/grep.c | 50 | ||||
-rw-r--r-- | include/usage.h | 3 |
2 files changed, 27 insertions, 26 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index f301b535d..e02fc8d10 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -140,7 +140,7 @@ static int grep_file(FILE *file) | |||
140 | * match (regexec returns failure (REG_NOMATCH) and the user specified | 140 | * match (regexec returns failure (REG_NOMATCH) and the user specified |
141 | * invert search) | 141 | * invert search) |
142 | */ | 142 | */ |
143 | if(!(gl->flg_mem_alocated_compiled & COMPILED)) { | 143 | if (!(gl->flg_mem_alocated_compiled & COMPILED)) { |
144 | gl->flg_mem_alocated_compiled |= COMPILED; | 144 | gl->flg_mem_alocated_compiled |= COMPILED; |
145 | xregcomp(&(gl->preg), gl->pattern, reflags); | 145 | xregcomp(&(gl->preg), gl->pattern, reflags); |
146 | } | 146 | } |
@@ -210,7 +210,7 @@ static int grep_file(FILE *file) | |||
210 | #if ENABLE_FEATURE_GREP_CONTEXT | 210 | #if ENABLE_FEATURE_GREP_CONTEXT |
211 | else { /* no match */ | 211 | else { /* no match */ |
212 | /* Add the line to the circular 'before' buffer */ | 212 | /* Add the line to the circular 'before' buffer */ |
213 | if(lines_before) { | 213 | if (lines_before) { |
214 | free(before_buf[curpos]); | 214 | free(before_buf[curpos]); |
215 | before_buf[curpos] = xstrdup(line); | 215 | before_buf[curpos] = xstrdup(line); |
216 | curpos = (curpos + 1) % lines_before; | 216 | curpos = (curpos + 1) % lines_before; |
@@ -273,7 +273,7 @@ static void load_regexes_from_file(llist_t *fopt) | |||
273 | char *line; | 273 | char *line; |
274 | FILE *f; | 274 | FILE *f; |
275 | 275 | ||
276 | while(fopt) { | 276 | while (fopt) { |
277 | llist_t *cur = fopt; | 277 | llist_t *cur = fopt; |
278 | char *ffile = cur->data; | 278 | char *ffile = cur->data; |
279 | 279 | ||
@@ -308,23 +308,23 @@ int grep_main(int argc, char **argv) | |||
308 | &pattern_head, &fopt, | 308 | &pattern_head, &fopt, |
309 | &slines_after, &slines_before, &Copt); | 309 | &slines_after, &slines_before, &Copt); |
310 | 310 | ||
311 | if(opt & GREP_OPT_C) { | 311 | if (opt & GREP_OPT_C) { |
312 | /* C option unseted A and B options, but next -A or -B | 312 | /* C option unseted A and B options, but next -A or -B |
313 | may be ovewrite own option */ | 313 | may be ovewrite own option */ |
314 | if(!(opt & GREP_OPT_A)) /* not overwtited */ | 314 | if (!(opt & GREP_OPT_A)) /* not overwtited */ |
315 | slines_after = Copt; | 315 | slines_after = Copt; |
316 | if(!(opt & GREP_OPT_B)) /* not overwtited */ | 316 | if (!(opt & GREP_OPT_B)) /* not overwtited */ |
317 | slines_before = Copt; | 317 | slines_before = Copt; |
318 | opt |= GREP_OPT_A|GREP_OPT_B; /* set for parse now */ | 318 | opt |= GREP_OPT_A|GREP_OPT_B; /* set for parse now */ |
319 | } | 319 | } |
320 | if(opt & GREP_OPT_A) { | 320 | if (opt & GREP_OPT_A) { |
321 | lines_after = strtoul(slines_after, &junk, 10); | 321 | lines_after = strtoul(slines_after, &junk, 10); |
322 | if(*junk != '\0') | 322 | if (*junk != '\0') |
323 | bb_error_msg_and_die(bb_msg_invalid_arg, slines_after, "-A"); | 323 | bb_error_msg_and_die(bb_msg_invalid_arg, slines_after, "-A"); |
324 | } | 324 | } |
325 | if(opt & GREP_OPT_B) { | 325 | if (opt & GREP_OPT_B) { |
326 | lines_before = strtoul(slines_before, &junk, 10); | 326 | lines_before = strtoul(slines_before, &junk, 10); |
327 | if(*junk != '\0') | 327 | if (*junk != '\0') |
328 | bb_error_msg_and_die(bb_msg_invalid_arg, slines_before, "-B"); | 328 | bb_error_msg_and_die(bb_msg_invalid_arg, slines_before, "-B"); |
329 | } | 329 | } |
330 | /* sanity checks after parse may be invalid numbers ;-) */ | 330 | /* sanity checks after parse may be invalid numbers ;-) */ |
@@ -332,7 +332,7 @@ int grep_main(int argc, char **argv) | |||
332 | opt &= ~GREP_OPT_n; | 332 | opt &= ~GREP_OPT_n; |
333 | lines_before = 0; | 333 | lines_before = 0; |
334 | lines_after = 0; | 334 | lines_after = 0; |
335 | } else if(lines_before > 0) | 335 | } else if (lines_before > 0) |
336 | before_buf = (char **)xzalloc(lines_before * sizeof(char *)); | 336 | before_buf = (char **)xzalloc(lines_before * sizeof(char *)); |
337 | #else | 337 | #else |
338 | /* with auto sanity checks */ | 338 | /* with auto sanity checks */ |
@@ -342,31 +342,31 @@ int grep_main(int argc, char **argv) | |||
342 | #endif | 342 | #endif |
343 | invert_search = (opt & GREP_OPT_v) != 0; /* 0 | 1 */ | 343 | invert_search = (opt & GREP_OPT_v) != 0; /* 0 | 1 */ |
344 | 344 | ||
345 | if(opt & GREP_OPT_H) | 345 | if (opt & GREP_OPT_H) |
346 | print_filename++; | 346 | print_filename++; |
347 | if(opt & GREP_OPT_h) | 347 | if (opt & GREP_OPT_h) |
348 | print_filename--; | 348 | print_filename--; |
349 | if (pattern_head != NULL) { | 349 | if (pattern_head != NULL) { |
350 | /* convert char *argv[] to grep_list_data_t */ | 350 | /* convert char *argv[] to grep_list_data_t */ |
351 | llist_t *cur; | 351 | llist_t *cur; |
352 | 352 | ||
353 | for(cur = pattern_head; cur; cur = cur->link) | 353 | for (cur = pattern_head; cur; cur = cur->link) |
354 | cur->data = new_grep_list_data(cur->data, 0); | 354 | cur->data = new_grep_list_data(cur->data, 0); |
355 | } | 355 | } |
356 | if(opt & GREP_OPT_f) | 356 | if (opt & GREP_OPT_f) |
357 | load_regexes_from_file(fopt); | 357 | load_regexes_from_file(fopt); |
358 | 358 | ||
359 | if(ENABLE_FEATURE_GREP_FGREP_ALIAS && bb_applet_name[0] == 'f') | 359 | if (ENABLE_FEATURE_GREP_FGREP_ALIAS && bb_applet_name[0] == 'f') |
360 | opt |= GREP_OPT_F; | 360 | opt |= GREP_OPT_F; |
361 | 361 | ||
362 | if(!(opt & GREP_OPT_o)) | 362 | if (!(opt & GREP_OPT_o)) |
363 | reflags = REG_NOSUB; | 363 | reflags = REG_NOSUB; |
364 | 364 | ||
365 | if(ENABLE_FEATURE_GREP_EGREP_ALIAS && | 365 | if (ENABLE_FEATURE_GREP_EGREP_ALIAS && |
366 | (bb_applet_name[0] == 'e' || (opt & GREP_OPT_E))) | 366 | (bb_applet_name[0] == 'e' || (opt & GREP_OPT_E))) |
367 | reflags |= REG_EXTENDED; | 367 | reflags |= REG_EXTENDED; |
368 | 368 | ||
369 | if(opt & GREP_OPT_i) | 369 | if (opt & GREP_OPT_i) |
370 | reflags |= REG_ICASE; | 370 | reflags |= REG_ICASE; |
371 | 371 | ||
372 | argv += optind; | 372 | argv += optind; |
@@ -398,7 +398,7 @@ int grep_main(int argc, char **argv) | |||
398 | matched = 0; | 398 | matched = 0; |
399 | while (argc--) { | 399 | while (argc--) { |
400 | cur_file = *argv++; | 400 | cur_file = *argv++; |
401 | if(!cur_file || (*cur_file == '-' && !cur_file[1])) { | 401 | if (!cur_file || (*cur_file == '-' && !cur_file[1])) { |
402 | cur_file = "(standard input)"; | 402 | cur_file = "(standard input)"; |
403 | file = stdin; | 403 | file = stdin; |
404 | } else { | 404 | } else { |
@@ -410,7 +410,7 @@ int grep_main(int argc, char **argv) | |||
410 | error_open_count++; | 410 | error_open_count++; |
411 | } else { | 411 | } else { |
412 | matched += grep_file(file); | 412 | matched += grep_file(file); |
413 | if(matched < 0) { | 413 | if (matched < 0) { |
414 | /* we found a match but were told to be quiet, stop here and | 414 | /* we found a match but were told to be quiet, stop here and |
415 | * return success */ | 415 | * return success */ |
416 | break; | 416 | break; |
@@ -427,9 +427,9 @@ int grep_main(int argc, char **argv) | |||
427 | (grep_list_data_t *)pattern_head_ptr->data; | 427 | (grep_list_data_t *)pattern_head_ptr->data; |
428 | 428 | ||
429 | pattern_head = pattern_head->link; | 429 | pattern_head = pattern_head->link; |
430 | if((gl->flg_mem_alocated_compiled & PATTERN_MEM_A)) | 430 | if ((gl->flg_mem_alocated_compiled & PATTERN_MEM_A)) |
431 | free(gl->pattern); | 431 | free(gl->pattern); |
432 | if((gl->flg_mem_alocated_compiled & COMPILED)) | 432 | if ((gl->flg_mem_alocated_compiled & COMPILED)) |
433 | regfree(&(gl->preg)); | 433 | regfree(&(gl->preg)); |
434 | free(pattern_head_ptr); | 434 | free(pattern_head_ptr); |
435 | } | 435 | } |
@@ -437,9 +437,9 @@ int grep_main(int argc, char **argv) | |||
437 | /* 0 = success, 1 = failed, 2 = error */ | 437 | /* 0 = success, 1 = failed, 2 = error */ |
438 | /* If the -q option is specified, the exit status shall be zero | 438 | /* If the -q option is specified, the exit status shall be zero |
439 | * if an input line is selected, even if an error was detected. */ | 439 | * if an input line is selected, even if an error was detected. */ |
440 | if(BE_QUIET && matched) | 440 | if (BE_QUIET && matched) |
441 | return 0; | 441 | return 0; |
442 | if(error_open_count) | 442 | if (error_open_count) |
443 | return 2; | 443 | return 2; |
444 | return !matched; /* invert return value 0 = success, 1 = failed */ | 444 | return !matched; /* invert return value 0 = success, 1 = failed */ |
445 | } | 445 | } |
diff --git a/include/usage.h b/include/usage.h index bb814f1f8..543befca3 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -927,7 +927,7 @@ USE_FEATURE_DATE_ISOFMT( \ | |||
927 | "\t-H login_host\tLog login_host into the utmp file as the hostname" | 927 | "\t-H login_host\tLog login_host into the utmp file as the hostname" |
928 | 928 | ||
929 | #define grep_trivial_usage \ | 929 | #define grep_trivial_usage \ |
930 | "[-ihHnqvs" \ | 930 | "[-ihHnqvso" \ |
931 | USE_FEATURE_GREP_EGREP_ALIAS("E") \ | 931 | USE_FEATURE_GREP_EGREP_ALIAS("E") \ |
932 | USE_FEATURE_GREP_CONTEXT("ABC") \ | 932 | USE_FEATURE_GREP_CONTEXT("ABC") \ |
933 | "] PATTERN [FILEs...]" | 933 | "] PATTERN [FILEs...]" |
@@ -945,6 +945,7 @@ USE_FEATURE_DATE_ISOFMT( \ | |||
945 | "\t-s\tsuppress file open/read error messages\n" \ | 945 | "\t-s\tsuppress file open/read error messages\n" \ |
946 | "\t-c\tonly print count of matching lines\n" \ | 946 | "\t-c\tonly print count of matching lines\n" \ |
947 | "\t-f\tread PATTERN from file\n" \ | 947 | "\t-f\tread PATTERN from file\n" \ |
948 | "\t-o\tshow only the part of a line that matches PATTERN\n" \ | ||
948 | "\t-e\tPATTERN is a regular expression\n" \ | 949 | "\t-e\tPATTERN is a regular expression\n" \ |
949 | "\t-F\tPATTERN is a set of newline-separated strings" \ | 950 | "\t-F\tPATTERN is a set of newline-separated strings" \ |
950 | USE_FEATURE_GREP_EGREP_ALIAS("\n\t-E\tPATTERN is an extended regular expression") \ | 951 | USE_FEATURE_GREP_EGREP_ALIAS("\n\t-E\tPATTERN is an extended regular expression") \ |