aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-10-24 05:00:29 +0000
committerEric Andersen <andersen@codepoet.org>2001-10-24 05:00:29 +0000
commitbdfd0d78bc44e73d693510e70087857785b3b521 (patch)
tree153a573095afac8d8d0ea857759ecabd77fb28b7 /findutils/grep.c
parent9260fc5552a3ee52eb95823aa6689d52a1ffd33c (diff)
downloadbusybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.tar.gz
busybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.tar.bz2
busybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.zip
Major rework of the directory structure and the entire build system.
-Erik
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index eff7c3ff5..a97a8bbb7 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Mini grep implementation for busybox using libc regex. 2 * Mini grep implementation for busybox using libc regex.
3 * 3 *
4 * Copyright (C) 1999,2000,2001 by Lineo, inc. 4 * Copyright (C) 1999,2000,2001 by Lineo, inc. and Mark Whitley
5 * Written by Mark Whitley <markw@lineo.com>, <markw@codepoet.org> 5 * Copyright (C) 1999,2000,2001 by Mark Whitley <markw@codepoet.org>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -42,13 +42,13 @@ static int invert_search = 0;
42static int suppress_err_msgs = 0; 42static int suppress_err_msgs = 0;
43static int print_files_with_matches = 0; 43static int print_files_with_matches = 0;
44 44
45#ifdef BB_FEATURE_GREP_CONTEXT 45#ifdef CONFIG_FEATURE_GREP_CONTEXT
46extern char *optarg; /* in getopt.h */ 46extern char *optarg; /* in getopt.h */
47static int lines_before = 0; 47static int lines_before = 0;
48static int lines_after = 0; 48static int lines_after = 0;
49static char **before_buf = NULL; 49static char **before_buf = NULL;
50static int last_line_printed = 0; 50static int last_line_printed = 0;
51#endif /* BB_FEATURE_GREP_CONTEXT */ 51#endif /* CONFIG_FEATURE_GREP_CONTEXT */
52 52
53/* globals used internally */ 53/* globals used internally */
54static regex_t *regexes = NULL; /* growable array of compiled regular expressions */ 54static regex_t *regexes = NULL; /* growable array of compiled regular expressions */
@@ -59,7 +59,7 @@ static char *cur_file = NULL; /* the current file we are reading */
59 59
60static void print_line(const char *line, int linenum, char decoration) 60static void print_line(const char *line, int linenum, char decoration)
61{ 61{
62#ifdef BB_FEATURE_GREP_CONTEXT 62#ifdef CONFIG_FEATURE_GREP_CONTEXT
63 /* possibly print the little '--' seperator */ 63 /* possibly print the little '--' seperator */
64 if ((lines_before || lines_after) && last_line_printed && 64 if ((lines_before || lines_after) && last_line_printed &&
65 last_line_printed < linenum - 1) { 65 last_line_printed < linenum - 1) {
@@ -82,11 +82,11 @@ static void grep_file(FILE *file)
82 int linenum = 0; 82 int linenum = 0;
83 int nmatches = 0; 83 int nmatches = 0;
84 int i; 84 int i;
85#ifdef BB_FEATURE_GREP_CONTEXT 85#ifdef CONFIG_FEATURE_GREP_CONTEXT
86 int print_n_lines_after = 0; 86 int print_n_lines_after = 0;
87 int curpos = 0; /* track where we are in the circular 'before' buffer */ 87 int curpos = 0; /* track where we are in the circular 'before' buffer */
88 int idx = 0; /* used for iteration through the circular buffer */ 88 int idx = 0; /* used for iteration through the circular buffer */
89#endif /* BB_FEATURE_GREP_CONTEXT */ 89#endif /* CONFIG_FEATURE_GREP_CONTEXT */
90 90
91 while ((line = get_line_from_file(file)) != NULL) { 91 while ((line = get_line_from_file(file)) != NULL) {
92 chomp(line); 92 chomp(line);
@@ -116,7 +116,7 @@ static void grep_file(FILE *file)
116 116
117 /* print the matched line */ 117 /* print the matched line */
118 if (print_match_counts == 0) { 118 if (print_match_counts == 0) {
119#ifdef BB_FEATURE_GREP_CONTEXT 119#ifdef CONFIG_FEATURE_GREP_CONTEXT
120 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1; 120 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
121 121
122 /* if we were told to print 'before' lines and there is at least 122 /* if we were told to print 'before' lines and there is at least
@@ -145,11 +145,11 @@ static void grep_file(FILE *file)
145 145
146 /* make a note that we need to print 'after' lines */ 146 /* make a note that we need to print 'after' lines */
147 print_n_lines_after = lines_after; 147 print_n_lines_after = lines_after;
148#endif /* BB_FEATURE_GREP_CONTEXT */ 148#endif /* CONFIG_FEATURE_GREP_CONTEXT */
149 print_line(line, linenum, ':'); 149 print_line(line, linenum, ':');
150 } 150 }
151 } 151 }
152#ifdef BB_FEATURE_GREP_CONTEXT 152#ifdef CONFIG_FEATURE_GREP_CONTEXT
153 else { /* no match */ 153 else { /* no match */
154 /* Add the line to the circular 'before' buffer */ 154 /* Add the line to the circular 'before' buffer */
155 if(lines_before) { 155 if(lines_before) {
@@ -165,7 +165,7 @@ static void grep_file(FILE *file)
165 print_line(line, linenum, '-'); 165 print_line(line, linenum, '-');
166 print_n_lines_after--; 166 print_n_lines_after--;
167 } 167 }
168#endif /* BB_FEATURE_GREP_CONTEXT */ 168#endif /* CONFIG_FEATURE_GREP_CONTEXT */
169 } /* for */ 169 } /* for */
170 free(line); 170 free(line);
171 } 171 }
@@ -215,7 +215,7 @@ static void load_regexes_from_file(const char *filename)
215} 215}
216 216
217 217
218#ifdef BB_FEATURE_CLEAN_UP 218#ifdef CONFIG_FEATURE_CLEAN_UP
219static void destroy_regexes() 219static void destroy_regexes()
220{ 220{
221 if (regexes == NULL) 221 if (regexes == NULL)
@@ -233,11 +233,11 @@ static void destroy_regexes()
233extern int grep_main(int argc, char **argv) 233extern int grep_main(int argc, char **argv)
234{ 234{
235 int opt; 235 int opt;
236#ifdef BB_FEATURE_GREP_CONTEXT 236#ifdef CONFIG_FEATURE_GREP_CONTEXT
237 char *junk; 237 char *junk;
238#endif 238#endif
239 239
240#ifdef BB_FEATURE_CLEAN_UP 240#ifdef CONFIG_FEATURE_CLEAN_UP
241 /* destroy command strings on exit */ 241 /* destroy command strings on exit */
242 if (atexit(destroy_regexes) == -1) 242 if (atexit(destroy_regexes) == -1)
243 perror_msg_and_die("atexit"); 243 perror_msg_and_die("atexit");
@@ -245,7 +245,7 @@ extern int grep_main(int argc, char **argv)
245 245
246 /* do normal option parsing */ 246 /* do normal option parsing */
247 while ((opt = getopt(argc, argv, "iHhlnqvsce:f:" 247 while ((opt = getopt(argc, argv, "iHhlnqvsce:f:"
248#ifdef BB_FEATURE_GREP_CONTEXT 248#ifdef CONFIG_FEATURE_GREP_CONTEXT
249"A:B:C:" 249"A:B:C:"
250#endif 250#endif
251)) > 0) { 251)) > 0) {
@@ -283,7 +283,7 @@ extern int grep_main(int argc, char **argv)
283 case 'f': 283 case 'f':
284 load_regexes_from_file(optarg); 284 load_regexes_from_file(optarg);
285 break; 285 break;
286#ifdef BB_FEATURE_GREP_CONTEXT 286#ifdef CONFIG_FEATURE_GREP_CONTEXT
287 case 'A': 287 case 'A':
288 lines_after = strtoul(optarg, &junk, 10); 288 lines_after = strtoul(optarg, &junk, 10);
289 if(*junk != '\0') 289 if(*junk != '\0')
@@ -301,7 +301,7 @@ extern int grep_main(int argc, char **argv)
301 error_msg_and_die("invalid context length argument"); 301 error_msg_and_die("invalid context length argument");
302 before_buf = (char **)calloc(lines_before, sizeof(char *)); 302 before_buf = (char **)calloc(lines_before, sizeof(char *));
303 break; 303 break;
304#endif /* BB_FEATURE_GREP_CONTEXT */ 304#endif /* CONFIG_FEATURE_GREP_CONTEXT */
305 default: 305 default:
306 show_usage(); 306 show_usage();
307 } 307 }
@@ -321,7 +321,7 @@ extern int grep_main(int argc, char **argv)
321 /* sanity checks */ 321 /* sanity checks */
322 if (print_match_counts || be_quiet || print_files_with_matches) { 322 if (print_match_counts || be_quiet || print_files_with_matches) {
323 print_line_num = 0; 323 print_line_num = 0;
324#ifdef BB_FEATURE_GREP_CONTEXT 324#ifdef CONFIG_FEATURE_GREP_CONTEXT
325 lines_before = 0; 325 lines_before = 0;
326 lines_after = 0; 326 lines_after = 0;
327#endif 327#endif