diff options
| author | Mark Whitley <markw@lineo.com> | 2000-06-28 22:15:26 +0000 |
|---|---|---|
| committer | Mark Whitley <markw@lineo.com> | 2000-06-28 22:15:26 +0000 |
| commit | 1ca41775bbdc07cf67be79aebc566754c9c02855 (patch) | |
| tree | 0ac134f0a80036aec272b04c3a057ea2ae055b20 /findutils | |
| parent | d37218941c37795cc8e96ddb3312d83fb2269d5a (diff) | |
| download | busybox-w32-1ca41775bbdc07cf67be79aebc566754c9c02855.tar.gz busybox-w32-1ca41775bbdc07cf67be79aebc566754c9c02855.tar.bz2 busybox-w32-1ca41775bbdc07cf67be79aebc566754c9c02855.zip | |
Yanked out the cstring_alloc() and cstring_lineFromFile() functions from
utility.c and replaced them with get_line_from_file() from the new grep.c.
Also changed declaration in internal.h and replaced instances of
cstring_lineFromFile() in dc.c and sort.c with get_line_from_file(). Tested
them and they worked fine.
Diffstat (limited to 'findutils')
| -rw-r--r-- | findutils/grep.c | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index aca469e2f..a374e114d 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
| @@ -46,8 +46,6 @@ static const char grep_usage[] = | |||
| 46 | #endif | 46 | #endif |
| 47 | ; | 47 | ; |
| 48 | 48 | ||
| 49 | static const int GROWBY = 80; /* how large we will grow strings by */ | ||
| 50 | |||
| 51 | /* options */ | 49 | /* options */ |
| 52 | static int ignore_case = 0; | 50 | static int ignore_case = 0; |
| 53 | static int print_filename = 0; | 51 | static int print_filename = 0; |
| @@ -62,35 +60,6 @@ static int nmatches = 0; /* keeps track of the number of matches */ | |||
| 62 | static char *cur_file = NULL; /* the current file we are reading */ | 60 | static char *cur_file = NULL; /* the current file we are reading */ |
| 63 | 61 | ||
| 64 | 62 | ||
| 65 | /* This returns a malloc'ed char * which must be stored and free'ed */ | ||
| 66 | /* XXX: This function should probably go in a 'common'/'util'/'misc' file | ||
| 67 | * somewhere so it can be used by other folks. */ | ||
| 68 | static char *get_line_from_file(FILE *file) | ||
| 69 | { | ||
| 70 | int ch; | ||
| 71 | int idx = 0; | ||
| 72 | char *linebuf = NULL; | ||
| 73 | int linebufsz = 0; | ||
| 74 | |||
| 75 | while (1) { | ||
| 76 | ch = fgetc(file); | ||
| 77 | if (ch == EOF) | ||
| 78 | break; | ||
| 79 | /* grow the line buffer as necessary */ | ||
| 80 | if (idx > linebufsz-1) | ||
| 81 | linebuf = realloc(linebuf, linebufsz += GROWBY); | ||
| 82 | linebuf[idx++] = (char)ch; | ||
| 83 | if ((char)ch == '\n') | ||
| 84 | break; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (idx == 0) | ||
| 88 | return NULL; | ||
| 89 | |||
| 90 | linebuf[idx] = 0; | ||
| 91 | return linebuf; | ||
| 92 | } | ||
| 93 | |||
| 94 | static void print_matched_line(char *line, int linenum) | 63 | static void print_matched_line(char *line, int linenum) |
| 95 | { | 64 | { |
| 96 | if (print_filename) | 65 | if (print_filename) |
