--- a/src/cline.c Sat Jul 25 18:28:01 2020 +0200 +++ b/src/cline.c Mon Jul 27 17:19:56 2020 +0200 @@ -44,7 +44,8 @@ "\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 -i - print out individual sums per file extension" + "\n (cannot be used together with -V)" "\n -m - print information about matching files only" "\n -s <suffixes> - only count files with these suffixes (separated" "\n by commas)" @@ -199,8 +200,13 @@ add_string(settings->regex->pattern_list, argv[t]); add_string(settings->regex->pattern_list, "$"); } + /* i */ if ((argflags & 2048) > 0) { - settings->individual_sums = true; + // cannot be used together with -V + if (registerArgument(&checked, 128)) { + return exit_with_help(settings, 1); + } + settings->individual_sums = true; } if (argflags == 0) { /* SHORTCUTS */ @@ -226,7 +232,7 @@ /* Scan directories */ if (regex_compile_all(settings->regex)) { - scanresult_t result; + scanresult_t* result = new_scanresult_t(settings); /* Don't waste memory when only the total sum is needed */ string_list_t *output = settings->verbose ? new_string_list_t() : NULL; char *outbuf; @@ -237,8 +243,8 @@ } for (int t = 0 ; t < directories->count ; t++) { scanDirectory((scanner_t){directories->items[t], 0}, settings, - output, &result); - total += result.directory; + output, result); + total += result->lines; if (directories->count > 1 ) { outbuf = (char*) malloc(81); memset(outbuf, '-', 79); @@ -247,7 +253,7 @@ add_string(output, outbuf); outbuf = (char*) malloc(81); snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], - result.directory); + result->lines); add_string(output, outbuf); outbuf = (char*) malloc(81); memset(outbuf, '-', 79); @@ -265,6 +271,20 @@ free(output->items[i]); } + if (result->ext) { + if (result->ext->count > 0) { + for (int t = 0 ; t < 79 ; t++) { + printf("="); + } + printf("\nIndividual sums:\n"); + for (int t = 0 ; t < result->ext->count ; t++) { + printf(" %-62s%10d lines\n", + result->ext->extensions[t], + result->ext->lines[t]); + } + } + } + for (int t = 0 ; t < 79 ; t++) { printf("="); } @@ -280,6 +300,7 @@ } else { printf("%d", total); } + destroy_scanresult_t(result); destroy_string_list_t(output); destroy_settings_t(settings); }