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);