Added line buffer (and warning message - there is no regexp parser, though)

Thu, 01 Dec 2011 17:04:30 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 01 Dec 2011 17:04:30 +0100
changeset 25
802c5382f499
parent 23
778388400f7b
child 26
853a1181884b

Added line buffer (and warning message - there is no regexp parser, though)

cline.c file | annotate | diff | comparison | revisions
scanner.c file | annotate | diff | comparison | revisions
settings.c file | annotate | diff | comparison | revisions
settings.h file | annotate | diff | comparison | revisions
--- a/cline.c	Fri Oct 21 15:09:26 2011 +0200
+++ b/cline.c	Thu Dec 01 17:04:30 2011 +0100
@@ -163,6 +163,13 @@
   }
   printf("\n%73d lines\n", lines);
 
+  if (settings->confusing_lnlen) {
+    /* TODO: display this only when the regexp parser is used */
+    printf("\nSome files contain too long lines.\n"
+      "The regexp parser currently supports a maximum line length of 2048."
+      "\nThe result might be wrong.\n");
+  }
+
   if (!settings->verbose) {
     reopen_stdout();
     printf("%d", lines);
--- a/scanner.c	Fri Oct 21 15:09:26 2011 +0200
+++ b/scanner.c	Thu Dec 01 17:04:30 2011 +0100
@@ -56,11 +56,14 @@
         continue;
       }
 
-      /* Count lines */
-      lines = 0;
-      bfile = false;
-      bfile_reset(settings->bfileHeuristics);
       if (testSuffix(filename, settings)) {
+        /* Count lines */
+        lines = 0;
+        bfile = false;
+        bfile_reset(settings->bfileHeuristics);
+        char line_buffer[2048];
+        int line_buffer_offset = 0;
+
         FILE *file = fopen(filename, "r");
         if (file == NULL) {
           printf(entryname);
@@ -74,7 +77,19 @@
           bfile = bfile_check(settings->bfileHeuristics, a);
 
           if (a == 10) {
+            line_buffer[line_buffer_offset] = 0;
+            /* TODO: do regex parsing */
+
+            line_buffer_offset = 0;
             lines++;
+          } else {
+            if (line_buffer_offset < 2048) {
+              line_buffer[line_buffer_offset] = a;
+              line_buffer_offset++;
+            } else {
+              line_buffer[line_buffer_offset-1] = 0;
+              settings->confusing_lnlen = true;
+            }
           }
         } while (!bfile && a != EOF);
         fclose(file);
--- a/settings.c	Fri Oct 21 15:09:26 2011 +0200
+++ b/settings.c	Thu Dec 01 17:04:30 2011 +0100
@@ -21,6 +21,7 @@
     settings->suffixList         = new_string_list_t();
     settings->verbose            = true;
     settings->bfileHeuristics    = new_bfile_heuristics_t();
+    settings->confusing_lnlen   = false;
   }
 
   return settings;
--- a/settings.h	Fri Oct 21 15:09:26 2011 +0200
+++ b/settings.h	Thu Dec 01 17:04:30 2011 +0100
@@ -20,6 +20,7 @@
   bool includeSuffixes;
   bool matchesOnly;
   bool verbose;
+  bool confusing_lnlen; /* this flag is set by the scanner */
 } settings_t;
 
 #ifdef _cplusplus

mercurial