+ utility.c
authorJohn Beppu <beppu@lbox.org>
Mon, 12 Jun 2000 23:39:04 +0000 (23:39 -0000)
committerJohn Beppu <beppu@lbox.org>
Mon, 12 Jun 2000 23:39:04 +0000 (23:39 -0000)
  CSTRING_BUFFER_LENGTH = 1024 /* so it recurses less often */
+ grep.c
  uses cstring_lineFromFile(), and doesn't ever say
  Line is too long, anymore

findutils/grep.c
grep.c
utility.c

index 6872ac271018987890685ca8a5d92eb3efcc7cde..bb1a1462242617667028c0945e00b53c003d9b05 100644 (file)
@@ -65,16 +65,13 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
 {
        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);
@@ -87,6 +84,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
 
                        match = TRUE;
                }
+               free(haystack);
        }
 }
 
diff --git a/grep.c b/grep.c
index 6872ac271018987890685ca8a5d92eb3efcc7cde..bb1a1462242617667028c0945e00b53c003d9b05 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -65,16 +65,13 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
 {
        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);
@@ -87,6 +84,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
 
                        match = TRUE;
                }
+               free(haystack);
        }
 }
 
index 48aaeb85dad9f7c48487fce032f9ba8b7d4da24d..b9c7a76cd30c4ab65c4b040a9bf375b33cdbd195 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -1573,7 +1573,7 @@ extern int find_real_root_device_name(char* name)
 }
 #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* 
  */