--- a/src/cline.c Sat Jul 25 17:53:54 2020 +0200 +++ b/src/cline.c Sat Jul 25 18:28:01 2020 +0200 @@ -44,6 +44,7 @@ "\n -e <start> <end> - Excludes lines between <start> and <end>" "\n You may use these options multiple times" "\n -h, --help - this help text" +// "\n -i - print out individual sums per file extension" "\n -m - print information about matching files only" "\n -s <suffixes> - only count files with these suffixes (separated" "\n by commas)" @@ -106,7 +107,7 @@ for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); + int argflags = checkArgument(argv[t], "hsSrRmvVbeEi"); int paropt = 0; /* h */ @@ -198,6 +199,9 @@ add_string(settings->regex->pattern_list, argv[t]); add_string(settings->regex->pattern_list, "$"); } + if ((argflags & 2048) > 0) { + settings->individual_sums = true; + } if (argflags == 0) { /* SHORTCUTS */ if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { @@ -222,18 +226,19 @@ /* Scan directories */ if (regex_compile_all(settings->regex)) { + scanresult_t result; /* Don't waste memory when only the total sum is needed */ string_list_t *output = settings->verbose ? new_string_list_t() : NULL; char *outbuf; - int lineSum = 0, lines; + int total = 0; if (directories->count == 0) { add_string(directories, "."); } for (int t = 0 ; t < directories->count ; t++) { - lines = scanDirectory((scanner_t){directories->items[t], 0}, settings, - output); - lineSum += lines; + scanDirectory((scanner_t){directories->items[t], 0}, settings, + output, &result); + total += result.directory; if (directories->count > 1 ) { outbuf = (char*) malloc(81); memset(outbuf, '-', 79); @@ -241,7 +246,8 @@ outbuf[80] = 0; add_string(output, outbuf); outbuf = (char*) malloc(81); - snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], lines); + snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], + result.directory); add_string(output, outbuf); outbuf = (char*) malloc(81); memset(outbuf, '-', 79); @@ -262,7 +268,7 @@ for (int t = 0 ; t < 79 ; t++) { printf("="); } - printf("\n%73d lines\n", lineSum); + printf("\n%73d lines\n", total); if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { @@ -272,7 +278,7 @@ "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); } } else { - printf("%d", lineSum); + printf("%d", total); } destroy_string_list_t(output); destroy_settings_t(settings);