+ utility.c
CSTRING_BUFFER_LENGTH = 1024 /* so it recurses less often */ + grep.c uses cstring_lineFromFile(), and doesn't ever say Line is too long, anymore
This commit is contained in:
parent
9f16d61408
commit
c7ccfc99fc
@ -65,16 +65,13 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
|||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
long line = 0;
|
long line = 0;
|
||||||
char haystack[BUF_SIZE];
|
char *haystack;
|
||||||
int truth = !invertSearch;
|
int truth = !invertSearch;
|
||||||
|
|
||||||
while (fgets(haystack, sizeof(haystack), fp)) {
|
while ((haystack = cstring_lineFromFile(fp))) {
|
||||||
line++;
|
line++;
|
||||||
cp = &haystack[strlen(haystack) - 1];
|
cp = &haystack[strlen(haystack) - 1];
|
||||||
|
|
||||||
if (*cp != '\n')
|
|
||||||
fprintf(stderr, "%s: Line too long\n", fileName);
|
|
||||||
|
|
||||||
if (find_match(haystack, needle, ignoreCase) == truth) {
|
if (find_match(haystack, needle, ignoreCase) == truth) {
|
||||||
if (tellName == TRUE)
|
if (tellName == TRUE)
|
||||||
printf("%s:", fileName);
|
printf("%s:", fileName);
|
||||||
@ -87,6 +84,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
|||||||
|
|
||||||
match = TRUE;
|
match = TRUE;
|
||||||
}
|
}
|
||||||
|
free(haystack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
grep.c
8
grep.c
@ -65,16 +65,13 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
|||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
long line = 0;
|
long line = 0;
|
||||||
char haystack[BUF_SIZE];
|
char *haystack;
|
||||||
int truth = !invertSearch;
|
int truth = !invertSearch;
|
||||||
|
|
||||||
while (fgets(haystack, sizeof(haystack), fp)) {
|
while ((haystack = cstring_lineFromFile(fp))) {
|
||||||
line++;
|
line++;
|
||||||
cp = &haystack[strlen(haystack) - 1];
|
cp = &haystack[strlen(haystack) - 1];
|
||||||
|
|
||||||
if (*cp != '\n')
|
|
||||||
fprintf(stderr, "%s: Line too long\n", fileName);
|
|
||||||
|
|
||||||
if (find_match(haystack, needle, ignoreCase) == truth) {
|
if (find_match(haystack, needle, ignoreCase) == truth) {
|
||||||
if (tellName == TRUE)
|
if (tellName == TRUE)
|
||||||
printf("%s:", fileName);
|
printf("%s:", fileName);
|
||||||
@ -87,6 +84,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
|||||||
|
|
||||||
match = TRUE;
|
match = TRUE;
|
||||||
}
|
}
|
||||||
|
free(haystack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1573,7 +1573,7 @@ extern int find_real_root_device_name(char* name)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const unsigned int CSTRING_BUFFER_LENGTH = 128;
|
const unsigned int CSTRING_BUFFER_LENGTH = 1024;
|
||||||
/* recursive parser that returns cstrings of arbitrary length
|
/* recursive parser that returns cstrings of arbitrary length
|
||||||
* from a FILE*
|
* from a FILE*
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user