scanner.c

changeset 25
802c5382f499
parent 23
778388400f7b
child 27
95a958e3de88
equal deleted inserted replaced
23:778388400f7b 25:802c5382f499
54 } else { 54 } else {
55 perror(" Error in stat call"); 55 perror(" Error in stat call");
56 continue; 56 continue;
57 } 57 }
58 58
59 /* Count lines */
60 lines = 0;
61 bfile = false;
62 bfile_reset(settings->bfileHeuristics);
63 if (testSuffix(filename, settings)) { 59 if (testSuffix(filename, settings)) {
60 /* Count lines */
61 lines = 0;
62 bfile = false;
63 bfile_reset(settings->bfileHeuristics);
64 char line_buffer[2048];
65 int line_buffer_offset = 0;
66
64 FILE *file = fopen(filename, "r"); 67 FILE *file = fopen(filename, "r");
65 if (file == NULL) { 68 if (file == NULL) {
66 printf(entryname); 69 printf(entryname);
67 perror(" File acces failed"); 70 perror(" File acces failed");
68 continue; 71 continue;
72 a = fgetc(file); 75 a = fgetc(file);
73 76
74 bfile = bfile_check(settings->bfileHeuristics, a); 77 bfile = bfile_check(settings->bfileHeuristics, a);
75 78
76 if (a == 10) { 79 if (a == 10) {
80 line_buffer[line_buffer_offset] = 0;
81 /* TODO: do regex parsing */
82
83 line_buffer_offset = 0;
77 lines++; 84 lines++;
85 } else {
86 if (line_buffer_offset < 2048) {
87 line_buffer[line_buffer_offset] = a;
88 line_buffer_offset++;
89 } else {
90 line_buffer[line_buffer_offset-1] = 0;
91 settings->confusing_lnlen = true;
92 }
78 } 93 }
79 } while (!bfile && a != EOF); 94 } while (!bfile && a != EOF);
80 fclose(file); 95 fclose(file);
81 96
82 /* Print and sum line count */ 97 /* Print and sum line count */

mercurial