diff options
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -65,16 +65,13 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName, | |||
65 | { | 65 | { |
66 | char *cp; | 66 | char *cp; |
67 | long line = 0; | 67 | long line = 0; |
68 | char haystack[BUF_SIZE]; | 68 | char *haystack; |
69 | int truth = !invertSearch; | 69 | int truth = !invertSearch; |
70 | 70 | ||
71 | while (fgets(haystack, sizeof(haystack), fp)) { | 71 | while ((haystack = cstring_lineFromFile(fp))) { |
72 | line++; | 72 | line++; |
73 | cp = &haystack[strlen(haystack) - 1]; | 73 | cp = &haystack[strlen(haystack) - 1]; |
74 | 74 | ||
75 | if (*cp != '\n') | ||
76 | fprintf(stderr, "%s: Line too long\n", fileName); | ||
77 | |||
78 | if (find_match(haystack, needle, ignoreCase) == truth) { | 75 | if (find_match(haystack, needle, ignoreCase) == truth) { |
79 | if (tellName == TRUE) | 76 | if (tellName == TRUE) |
80 | printf("%s:", fileName); | 77 | printf("%s:", fileName); |
@@ -87,6 +84,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName, | |||
87 | 84 | ||
88 | match = TRUE; | 85 | match = TRUE; |
89 | } | 86 | } |
87 | free(haystack); | ||
90 | } | 88 | } |
91 | } | 89 | } |
92 | 90 | ||