CSTRING_BUFFER_LENGTH = 1024 /* so it recurses less often */
+ grep.c
uses cstring_lineFromFile(), and doesn't ever say
Line is too long, anymore
{
char *cp;
long line = 0;
- char haystack[BUF_SIZE];
+ char *haystack;
int truth = !invertSearch;
- while (fgets(haystack, sizeof(haystack), fp)) {
+ while ((haystack = cstring_lineFromFile(fp))) {
line++;
cp = &haystack[strlen(haystack) - 1];
- if (*cp != '\n')
- fprintf(stderr, "%s: Line too long\n", fileName);
-
if (find_match(haystack, needle, ignoreCase) == truth) {
if (tellName == TRUE)
printf("%s:", fileName);
match = TRUE;
}
+ free(haystack);
}
}
{
char *cp;
long line = 0;
- char haystack[BUF_SIZE];
+ char *haystack;
int truth = !invertSearch;
- while (fgets(haystack, sizeof(haystack), fp)) {
+ while ((haystack = cstring_lineFromFile(fp))) {
line++;
cp = &haystack[strlen(haystack) - 1];
- if (*cp != '\n')
- fprintf(stderr, "%s: Line too long\n", fileName);
-
if (find_match(haystack, needle, ignoreCase) == truth) {
if (tellName == TRUE)
printf("%s:", fileName);
match = TRUE;
}
+ free(haystack);
}
}
}
#endif
-const unsigned int CSTRING_BUFFER_LENGTH = 128;
+const unsigned int CSTRING_BUFFER_LENGTH = 1024;
/* recursive parser that returns cstrings of arbitrary length
* from a FILE*
*/