scanner.c

changeset 22
4508da679ffb
parent 21
91e0890464b0
child 23
778388400f7b
equal deleted inserted replaced
21:91e0890464b0 22:4508da679ffb
18 int lineSum = 0; 18 int lineSum = 0;
19 bool bfile; 19 bool bfile;
20 20
21 while ((entry = readdir(dir)) != NULL) { 21 while ((entry = readdir(dir)) != NULL) {
22 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 22 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
23 // Print occurence 23 /* Print occurence */
24 char entryname[strlen(entry->d_name)+spaces]; 24 char entryname[strlen(entry->d_name)+spaces];
25 for (int t = 0 ; t < spaces ; t++) { 25 for (int t = 0 ; t < spaces ; t++) {
26 entryname[t]=' '; 26 entryname[t]=' ';
27 } 27 }
28 entryname[spaces] = 0; 28 entryname[spaces] = 0;
31 char filename[(1+strlen(currdir)+strlen(entry->d_name))]; 31 char filename[(1+strlen(currdir)+strlen(entry->d_name))];
32 strcpy(filename, currdir); 32 strcpy(filename, currdir);
33 strncat(filename, &settings->fileSeparator, 1); 33 strncat(filename, &settings->fileSeparator, 1);
34 strcat(filename, entry->d_name); 34 strcat(filename, entry->d_name);
35 35
36 // Check for subdirectory 36 /* Check for subdirectory */
37 if ((subdir = opendir(filename)) != NULL) { 37 if ((subdir = opendir(filename)) != NULL) {
38 printf("%-60s\n", entryname); 38 printf("%-60s\n", entryname);
39 if (settings->recursive) { 39 if (settings->recursive) {
40 lineSum += scanDirectory(subdir, spaces+1, filename, settings); 40 lineSum += scanDirectory(subdir, spaces+1, filename, settings);
41 } 41 }
42 closedir(subdir); 42 closedir(subdir);
43 continue; 43 continue;
44 } 44 }
45 45
46 // Count lines 46 /* Count lines */
47 lines = 0; 47 lines = 0;
48 bfile = false; 48 bfile = false;
49 bfile_reset(settings->bfileHeuristics);
49 if (testSuffix(filename, settings)) { 50 if (testSuffix(filename, settings)) {
50 FILE *file = fopen(filename, "r"); 51 FILE *file = fopen(filename, "r");
51 if (file == NULL) { 52 if (file == NULL) {
52 perror(" File acces failed"); 53 perror(" File acces failed");
53 continue; 54 continue;
62 lines++; 63 lines++;
63 } 64 }
64 } while (!bfile && a != EOF); 65 } while (!bfile && a != EOF);
65 fclose(file); 66 fclose(file);
66 67
67 // Print line count 68 /* Print and sum line count */
68 if (bfile) { 69 if (bfile) {
69 printf("%-60s%19s\n", entryname, "binary"); 70 if (!settings->matchesOnly) {
71 printf("%-60s%19s\n", entryname, "binary");
72 }
70 } else { 73 } else {
74 lineSum += lines;
71 printf("%-60s%13d lines\n", entryname, lines); 75 printf("%-60s%13d lines\n", entryname, lines);
72 } 76 }
73 lineSum += lines;
74 } else { 77 } else {
75 if (!settings->matchesOnly) { 78 if (!settings->matchesOnly) {
76 // Print hint 79 /* Print hint */
77 printf("%-60s%19s\n", entryname, "no match"); 80 printf("%-60s%19s\n", entryname, "no match");
78 } 81 }
79 } 82 }
80 } 83 }
81 } 84 }

mercurial