diff options
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 31 |
1 files changed, 0 insertions, 31 deletions
@@ -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) |