scanner.c

changeset 21
91e0890464b0
parent 20
43725438ac50
child 22
4508da679ffb
--- a/scanner.c	Thu Oct 20 14:13:56 2011 +0200
+++ b/scanner.c	Thu Oct 20 15:21:53 2011 +0200
@@ -8,6 +8,7 @@
 
 #include "scanner.h"
 #include "suffix_fnc.h"
+#include "bfile_heuristics.h"
 
 int scanDirectory(DIR *dir, const int spaces,
                   char* currdir, settings_t* settings) {
@@ -15,6 +16,7 @@
   struct dirent *entry;
   int lines, a;
   int lineSum = 0;
+  bool bfile;
 
   while ((entry = readdir(dir)) != NULL) {
     if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
@@ -43,6 +45,7 @@
 
       // Count lines
       lines = 0;
+      bfile = false;
       if (testSuffix(filename, settings)) {
         FILE *file = fopen(filename, "r");
         if (file == NULL) {
@@ -53,28 +56,25 @@
         do {
           a = fgetc(file);
 
+          bfile = bfile_check(settings->bfileHeuristics, a);
+
           if (a == 10) {
             lines++;
           }
-        } while (a != EOF);
+        } while (!bfile && a != EOF);
         fclose(file);
 
         // Print line count
-        #ifdef _WIN32
+        if (bfile) {
+          printf("%-60s%19s\n", entryname, "binary");
+        } else {
           printf("%-60s%13d lines\n", entryname, lines);
-        #else
-          printf("%-60s%14d lines\n", entryname, lines);
-        #endif /* _WIN32 */
-
+        }
         lineSum += lines;
       } else {
         if (!settings->matchesOnly) {
           // Print hint
-          #ifdef _WIN32
-            printf("%-60s%19s\n", entryname, "no match");
-          #else
-            printf("%-60s%20s\n", entryname, "no match");
-          #endif /* _WIN32 */
+          printf("%-60s%19s\n", entryname, "no match");
         }
       }
     }

mercurial