scanner.c

changeset 21
91e0890464b0
parent 20
43725438ac50
child 22
4508da679ffb
equal deleted inserted replaced
20:43725438ac50 21:91e0890464b0
6 */ 6 */
7 7
8 8
9 #include "scanner.h" 9 #include "scanner.h"
10 #include "suffix_fnc.h" 10 #include "suffix_fnc.h"
11 #include "bfile_heuristics.h"
11 12
12 int scanDirectory(DIR *dir, const int spaces, 13 int scanDirectory(DIR *dir, const int spaces,
13 char* currdir, settings_t* settings) { 14 char* currdir, settings_t* settings) {
14 DIR *subdir; 15 DIR *subdir;
15 struct dirent *entry; 16 struct dirent *entry;
16 int lines, a; 17 int lines, a;
17 int lineSum = 0; 18 int lineSum = 0;
19 bool bfile;
18 20
19 while ((entry = readdir(dir)) != NULL) { 21 while ((entry = readdir(dir)) != NULL) {
20 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 22 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
21 // Print occurence 23 // Print occurence
22 char entryname[strlen(entry->d_name)+spaces]; 24 char entryname[strlen(entry->d_name)+spaces];
41 continue; 43 continue;
42 } 44 }
43 45
44 // Count lines 46 // Count lines
45 lines = 0; 47 lines = 0;
48 bfile = false;
46 if (testSuffix(filename, settings)) { 49 if (testSuffix(filename, settings)) {
47 FILE *file = fopen(filename, "r"); 50 FILE *file = fopen(filename, "r");
48 if (file == NULL) { 51 if (file == NULL) {
49 perror(" File acces failed"); 52 perror(" File acces failed");
50 continue; 53 continue;
51 } 54 }
52 55
53 do { 56 do {
54 a = fgetc(file); 57 a = fgetc(file);
55 58
59 bfile = bfile_check(settings->bfileHeuristics, a);
60
56 if (a == 10) { 61 if (a == 10) {
57 lines++; 62 lines++;
58 } 63 }
59 } while (a != EOF); 64 } while (!bfile && a != EOF);
60 fclose(file); 65 fclose(file);
61 66
62 // Print line count 67 // Print line count
63 #ifdef _WIN32 68 if (bfile) {
69 printf("%-60s%19s\n", entryname, "binary");
70 } else {
64 printf("%-60s%13d lines\n", entryname, lines); 71 printf("%-60s%13d lines\n", entryname, lines);
65 #else 72 }
66 printf("%-60s%14d lines\n", entryname, lines);
67 #endif /* _WIN32 */
68
69 lineSum += lines; 73 lineSum += lines;
70 } else { 74 } else {
71 if (!settings->matchesOnly) { 75 if (!settings->matchesOnly) {
72 // Print hint 76 // Print hint
73 #ifdef _WIN32 77 printf("%-60s%19s\n", entryname, "no match");
74 printf("%-60s%19s\n", entryname, "no match");
75 #else
76 printf("%-60s%20s\n", entryname, "no match");
77 #endif /* _WIN32 */
78 } 78 }
79 } 79 }
80 } 80 }
81 } 81 }
82 return lineSum; 82 return lineSum;

mercurial