aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /findutils/grep.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index cc2b697e8..b4a25923e 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -88,8 +88,7 @@ static void grep_file(FILE *file)
88 int idx = 0; /* used for iteration through the circular buffer */ 88 int idx = 0; /* used for iteration through the circular buffer */
89#endif /* CONFIG_FEATURE_GREP_CONTEXT */ 89#endif /* CONFIG_FEATURE_GREP_CONTEXT */
90 90
91 while ((line = get_line_from_file(file)) != NULL) { 91 while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
92 chomp(line);
93 linenum++; 92 linenum++;
94 93
95 for (i = 0; i < nregexes; i++) { 94 for (i = 0; i < nregexes; i++) {
@@ -154,7 +153,7 @@ static void grep_file(FILE *file)
154 /* Add the line to the circular 'before' buffer */ 153 /* Add the line to the circular 'before' buffer */
155 if(lines_before) { 154 if(lines_before) {
156 free(before_buf[curpos]); 155 free(before_buf[curpos]);
157 before_buf[curpos] = xstrdup(line); 156 before_buf[curpos] = bb_xstrdup(line);
158 curpos = (curpos + 1) % lines_before; 157 curpos = (curpos + 1) % lines_before;
159 } 158 }
160 } 159 }
@@ -205,9 +204,8 @@ static void add_regex(const char *restr)
205static void load_regexes_from_file(const char *filename) 204static void load_regexes_from_file(const char *filename)
206{ 205{
207 char *line; 206 char *line;
208 FILE *f = xfopen(filename, "r"); 207 FILE *f = bb_xfopen(filename, "r");
209 while ((line = get_line_from_file(f)) != NULL) { 208 while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
210 chomp(line);
211 add_regex(line); 209 add_regex(line);
212 free(line); 210 free(line);
213 } 211 }
@@ -242,7 +240,7 @@ extern int grep_main(int argc, char **argv)
242#endif 240#endif
243 241
244#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS 242#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS
245 if (strcmp(get_last_path_component(argv[0]), "egrep") == 0) 243 if (strcmp(bb_get_last_path_component(argv[0]), "egrep") == 0)
246 reflags |= REG_EXTENDED; 244 reflags |= REG_EXTENDED;
247#endif 245#endif
248 246
@@ -298,23 +296,23 @@ extern int grep_main(int argc, char **argv)
298 case 'A': 296 case 'A':
299 lines_after = strtoul(optarg, &junk, 10); 297 lines_after = strtoul(optarg, &junk, 10);
300 if(*junk != '\0') 298 if(*junk != '\0')
301 error_msg_and_die("invalid context length argument"); 299 bb_error_msg_and_die("invalid context length argument");
302 break; 300 break;
303 case 'B': 301 case 'B':
304 lines_before = strtoul(optarg, &junk, 10); 302 lines_before = strtoul(optarg, &junk, 10);
305 if(*junk != '\0') 303 if(*junk != '\0')
306 error_msg_and_die("invalid context length argument"); 304 bb_error_msg_and_die("invalid context length argument");
307 before_buf = (char **)xcalloc(lines_before, sizeof(char *)); 305 before_buf = (char **)xcalloc(lines_before, sizeof(char *));
308 break; 306 break;
309 case 'C': 307 case 'C':
310 lines_after = lines_before = strtoul(optarg, &junk, 10); 308 lines_after = lines_before = strtoul(optarg, &junk, 10);
311 if(*junk != '\0') 309 if(*junk != '\0')
312 error_msg_and_die("invalid context length argument"); 310 bb_error_msg_and_die("invalid context length argument");
313 before_buf = (char **)xcalloc(lines_before, sizeof(char *)); 311 before_buf = (char **)xcalloc(lines_before, sizeof(char *));
314 break; 312 break;
315#endif /* CONFIG_FEATURE_GREP_CONTEXT */ 313#endif /* CONFIG_FEATURE_GREP_CONTEXT */
316 default: 314 default:
317 show_usage(); 315 bb_show_usage();
318 } 316 }
319 } 317 }
320 318
@@ -322,7 +320,7 @@ extern int grep_main(int argc, char **argv)
322 * argv[optind] should be the pattern. no pattern, no worky */ 320 * argv[optind] should be the pattern. no pattern, no worky */
323 if (nregexes == 0) { 321 if (nregexes == 0) {
324 if (argv[optind] == NULL) 322 if (argv[optind] == NULL)
325 show_usage(); 323 bb_show_usage();
326 else { 324 else {
327 add_regex(argv[optind]); 325 add_regex(argv[optind]);
328 optind++; 326 optind++;
@@ -356,7 +354,7 @@ extern int grep_main(int argc, char **argv)
356 file = fopen(cur_file, "r"); 354 file = fopen(cur_file, "r");
357 if (file == NULL) { 355 if (file == NULL) {
358 if (!suppress_err_msgs) 356 if (!suppress_err_msgs)
359 perror_msg("%s", cur_file); 357 bb_perror_msg("%s", cur_file);
360 } 358 }
361 else { 359 else {
362 grep_file(file); 360 grep_file(file);