Sat, 25 Jul 2020 18:28:01 +0200
preparing changes for individual sum feature
src/cline.c | file | annotate | diff | comparison | revisions | |
src/scanner.c | file | annotate | diff | comparison | revisions | |
src/scanner.h | file | annotate | diff | comparison | revisions | |
src/settings.c | file | annotate | diff | comparison | revisions | |
src/settings.h | file | annotate | diff | comparison | revisions |
1.1 --- a/src/cline.c Sat Jul 25 17:53:54 2020 +0200 1.2 +++ b/src/cline.c Sat Jul 25 18:28:01 2020 +0200 1.3 @@ -44,6 +44,7 @@ 1.4 "\n -e <start> <end> - Excludes lines between <start> and <end>" 1.5 "\n You may use these options multiple times" 1.6 "\n -h, --help - this help text" 1.7 +// "\n -i - print out individual sums per file extension" 1.8 "\n -m - print information about matching files only" 1.9 "\n -s <suffixes> - only count files with these suffixes (separated" 1.10 "\n by commas)" 1.11 @@ -106,7 +107,7 @@ 1.12 1.13 for (int t = 1 ; t < argc ; t++) { 1.14 1.15 - int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 1.16 + int argflags = checkArgument(argv[t], "hsSrRmvVbeEi"); 1.17 int paropt = 0; 1.18 1.19 /* h */ 1.20 @@ -198,6 +199,9 @@ 1.21 add_string(settings->regex->pattern_list, argv[t]); 1.22 add_string(settings->regex->pattern_list, "$"); 1.23 } 1.24 + if ((argflags & 2048) > 0) { 1.25 + settings->individual_sums = true; 1.26 + } 1.27 if (argflags == 0) { 1.28 /* SHORTCUTS */ 1.29 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { 1.30 @@ -222,18 +226,19 @@ 1.31 1.32 /* Scan directories */ 1.33 if (regex_compile_all(settings->regex)) { 1.34 + scanresult_t result; 1.35 /* Don't waste memory when only the total sum is needed */ 1.36 string_list_t *output = settings->verbose ? new_string_list_t() : NULL; 1.37 char *outbuf; 1.38 1.39 - int lineSum = 0, lines; 1.40 + int total = 0; 1.41 if (directories->count == 0) { 1.42 add_string(directories, "."); 1.43 } 1.44 for (int t = 0 ; t < directories->count ; t++) { 1.45 - lines = scanDirectory((scanner_t){directories->items[t], 0}, settings, 1.46 - output); 1.47 - lineSum += lines; 1.48 + scanDirectory((scanner_t){directories->items[t], 0}, settings, 1.49 + output, &result); 1.50 + total += result.directory; 1.51 if (directories->count > 1 ) { 1.52 outbuf = (char*) malloc(81); 1.53 memset(outbuf, '-', 79); 1.54 @@ -241,7 +246,8 @@ 1.55 outbuf[80] = 0; 1.56 add_string(output, outbuf); 1.57 outbuf = (char*) malloc(81); 1.58 - snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], lines); 1.59 + snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], 1.60 + result.directory); 1.61 add_string(output, outbuf); 1.62 outbuf = (char*) malloc(81); 1.63 memset(outbuf, '-', 79); 1.64 @@ -262,7 +268,7 @@ 1.65 for (int t = 0 ; t < 79 ; t++) { 1.66 printf("="); 1.67 } 1.68 - printf("\n%73d lines\n", lineSum); 1.69 + printf("\n%73d lines\n", total); 1.70 1.71 if (settings->confusing_lnlen && 1.72 settings->regex->pattern_list->count > 0) { 1.73 @@ -272,7 +278,7 @@ 1.74 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 1.75 } 1.76 } else { 1.77 - printf("%d", lineSum); 1.78 + printf("%d", total); 1.79 } 1.80 destroy_string_list_t(output); 1.81 destroy_settings_t(settings);
2.1 --- a/src/scanner.c Sat Jul 25 17:53:54 2020 +0200 2.2 +++ b/src/scanner.c Sat Jul 25 18:28:01 2020 +0200 2.3 @@ -112,11 +112,11 @@ 2.4 return list; 2.5 } 2.6 2.7 -int scanDirectory(scanner_t scanner, settings_t* settings, 2.8 - string_list_t* output) { 2.9 +void scanDirectory(scanner_t scanner, settings_t* settings, 2.10 + string_list_t* output, scanresult_t* result) { 2.11 2.12 - int lines, a; 2.13 - int lineSum = 0; 2.14 + result->directory = 0; 2.15 + int a; 2.16 bool bfile; 2.17 char *outbuf; 2.18 2.19 @@ -128,15 +128,17 @@ 2.20 if (!S_ISREG(filelist->st_mode)) { 2.21 if (settings->recursive && S_ISDIR(filelist->st_mode)) { 2.22 string_list_t *recoutput = new_string_list_t(); 2.23 - lines = scanDirectory( 2.24 + scanresult_t recresult; 2.25 + scanDirectory( 2.26 (scanner_t) {filelist->filename, scanner.spaces+1}, 2.27 - settings, recoutput); 2.28 - lineSum += lines; 2.29 + settings, recoutput, &recresult); 2.30 + result->directory += recresult.directory; 2.31 if (!settings->matchesOnly || recoutput->count > 0) { 2.32 outbuf = (char*) malloc(81); 2.33 snprintf(outbuf, 81, "%*s/%*s%13d lines\n", 2.34 filelist->displayname_len+scanner.spaces, filelist->displayname, 2.35 - 60-filelist->displayname_len-scanner.spaces-1, "", lines); 2.36 + 60-filelist->displayname_len-scanner.spaces-1, "", 2.37 + recresult.directory); 2.38 add_string(output, outbuf); 2.39 for (int i = 0 ; i < recoutput->count ; i++) { 2.40 add_string(output, recoutput->items[i]); 2.41 @@ -155,7 +157,7 @@ 2.42 && !testSuffix(filelist->displayname, settings->excludeSuffixes)) { 2.43 2.44 /* Count lines */ 2.45 - lines = 0; 2.46 + int lines = 0; 2.47 bfile = false; 2.48 bfile_reset(settings->bfileHeuristics); 2.49 regex_parser_reset(settings->regex); 2.50 @@ -209,7 +211,7 @@ 2.51 add_string(output, outbuf); 2.52 } 2.53 } else { 2.54 - lineSum += lines; 2.55 + result->directory += lines; 2.56 outbuf = (char*) malloc(81); 2.57 snprintf(outbuf, 81, "%*s%*s%13d lines\n", 2.58 filelist->displayname_len+scanner.spaces, filelist->displayname, 2.59 @@ -235,6 +237,4 @@ 2.60 filelist = filelist->next; 2.61 free(freethis); 2.62 } 2.63 - 2.64 - return lineSum; 2.65 }
3.1 --- a/src/scanner.h Sat Jul 25 17:53:54 2020 +0200 3.2 +++ b/src/scanner.h Sat Jul 25 18:28:01 2020 +0200 3.3 @@ -36,12 +36,16 @@ 3.4 int spaces; 3.5 } scanner_t; 3.6 3.7 +typedef struct { 3.8 + int directory; 3.9 +} scanresult_t; 3.10 + 3.11 #ifdef _cplusplus 3.12 extern "C" { 3.13 #endif 3.14 3.15 -int scanDirectory(scanner_t scanner, settings_t* settings, 3.16 - string_list_t* output); 3.17 +void scanDirectory(scanner_t scanner, settings_t* settings, 3.18 + string_list_t* output, scanresult_t* result); 3.19 3.20 #ifdef _cplusplus 3.21 }
4.1 --- a/src/settings.c Sat Jul 25 17:53:54 2020 +0200 4.2 +++ b/src/settings.c Sat Jul 25 18:28:01 2020 +0200 4.3 @@ -36,12 +36,13 @@ 4.4 #endif /* _WIN32 */ 4.5 settings->recursive = false; 4.6 settings->matchesOnly = false; 4.7 - settings->includeSuffixes = new_string_list_t(); 4.8 + settings->includeSuffixes = new_string_list_t(); 4.9 settings->excludeSuffixes = new_string_list_t(); 4.10 settings->verbose = true; 4.11 settings->bfileHeuristics = new_bfile_heuristics_t(); 4.12 settings->confusing_lnlen = false; 4.13 settings->regex = new_regex_parser_t(); 4.14 + settings->individual_sums = false; 4.15 } 4.16 4.17 return settings;
5.1 --- a/src/settings.h Sat Jul 25 17:53:54 2020 +0200 5.2 +++ b/src/settings.h Sat Jul 25 18:28:01 2020 +0200 5.3 @@ -42,6 +42,7 @@ 5.4 bool matchesOnly; 5.5 bool verbose; 5.6 bool confusing_lnlen; /* this flag is set by the scanner */ 5.7 + bool individual_sums; 5.8 } settings_t; 5.9 5.10 #ifdef _cplusplus