src/cline.c

changeset 61
9c8d768f0244
parent 60
69be673a4fd0
child 62
7f5f9f43d0c0
     1.1 --- a/src/cline.c	Sat Jul 25 18:28:01 2020 +0200
     1.2 +++ b/src/cline.c	Mon Jul 27 17:19:56 2020 +0200
     1.3 @@ -44,7 +44,8 @@
     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  -i                  - print out individual sums per file extension"
     1.9 +    "\n                        (cannot be used together with -V)"
    1.10      "\n  -m                  - print information about matching files only"
    1.11      "\n  -s <suffixes>       - only count files with these suffixes (separated"
    1.12      "\n                        by commas)"
    1.13 @@ -199,8 +200,13 @@
    1.14        add_string(settings->regex->pattern_list, argv[t]);
    1.15        add_string(settings->regex->pattern_list, "$");
    1.16      }
    1.17 +    /* i */
    1.18      if ((argflags & 2048) > 0) {
    1.19 -        settings->individual_sums = true;
    1.20 +      // cannot be used together with -V
    1.21 +      if (registerArgument(&checked, 128)) {
    1.22 +        return exit_with_help(settings, 1);
    1.23 +      }
    1.24 +      settings->individual_sums = true;
    1.25      }
    1.26      if (argflags == 0) {
    1.27        /* SHORTCUTS */
    1.28 @@ -226,7 +232,7 @@
    1.29  
    1.30    /* Scan directories */
    1.31    if (regex_compile_all(settings->regex)) {
    1.32 -    scanresult_t result;
    1.33 +    scanresult_t* result = new_scanresult_t(settings);
    1.34      /* Don't waste memory when only the total sum is needed */
    1.35      string_list_t *output = settings->verbose ? new_string_list_t() : NULL;
    1.36      char *outbuf;
    1.37 @@ -237,8 +243,8 @@
    1.38      }
    1.39      for (int t = 0 ; t < directories->count ; t++) {
    1.40        scanDirectory((scanner_t){directories->items[t], 0}, settings,
    1.41 -          output, &result);
    1.42 -      total += result.directory;
    1.43 +          output, result);
    1.44 +      total += result->lines;
    1.45        if (directories->count > 1 ) {
    1.46          outbuf = (char*) malloc(81);
    1.47          memset(outbuf, '-', 79);
    1.48 @@ -247,7 +253,7 @@
    1.49          add_string(output, outbuf);
    1.50          outbuf = (char*) malloc(81);
    1.51          snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t],
    1.52 -                result.directory);
    1.53 +                result->lines);
    1.54          add_string(output, outbuf);
    1.55          outbuf = (char*) malloc(81);
    1.56          memset(outbuf, '-', 79);
    1.57 @@ -265,6 +271,20 @@
    1.58          free(output->items[i]);
    1.59        }
    1.60        
    1.61 +      if (result->ext) {
    1.62 +        if (result->ext->count > 0) {
    1.63 +          for (int t = 0 ; t < 79 ; t++) {
    1.64 +            printf("=");
    1.65 +          }
    1.66 +          printf("\nIndividual sums:\n");
    1.67 +          for (int t = 0 ; t < result->ext->count ; t++) {
    1.68 +            printf(" %-62s%10d lines\n",
    1.69 +                    result->ext->extensions[t],
    1.70 +                    result->ext->lines[t]);
    1.71 +          }
    1.72 +        }
    1.73 +      }
    1.74 +      
    1.75        for (int t = 0 ; t < 79 ; t++) {
    1.76          printf("=");
    1.77        }
    1.78 @@ -280,6 +300,7 @@
    1.79      } else {
    1.80        printf("%d", total);
    1.81      }
    1.82 +    destroy_scanresult_t(result);
    1.83      destroy_string_list_t(output);
    1.84      destroy_settings_t(settings);
    1.85    }

mercurial