added multi-directory support

Tue, 02 Oct 2012 10:49:25 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 02 Oct 2012 10:49:25 +0200
changeset 33
1a2d7298bc82
parent 32
51d6e45a7592
child 34
fa9bda32de17

added multi-directory support

fixed parser bug in directory parser locking argument number 1024

fixed freed memory access on settings structure

cline.c file | annotate | diff | comparison | revisions
     1.1 --- a/cline.c	Tue Aug 28 16:44:32 2012 +0200
     1.2 +++ b/cline.c	Tue Oct 02 10:49:25 2012 +0200
     1.3 @@ -15,10 +15,10 @@
     1.4  void printHelpText() {
     1.5    const char* helpText = 
     1.6      "\nUsage:"
     1.7 -    "\n      cline [Options] [Directory]"
     1.8 -    "\n      cline [Options] [Directory]"
     1.9 +    "\n      cline [Options] [Directories...]"
    1.10 +    "\n      cline [Options] [Directories...]"
    1.11      "\n\nCounts the line terminator characters (\\n) within all"
    1.12 -    " files in the specified\ndirectory."
    1.13 +    " files in the specified\ndirectories."
    1.14      "\n\nOptions:"
    1.15      "\n  -b <level>          - binary file heuristics level (default medium)"
    1.16      "\n                        One of: ignore low medium high"
    1.17 @@ -77,7 +77,11 @@
    1.18    }
    1.19  
    1.20    /* Get arguments */
    1.21 -  char* directory = "./";
    1.22 +  string_list_t *directories = new_string_list_t();
    1.23 +  if (directories == NULL) {
    1.24 +    fprintf(stderr, "Memory allocation failed.\n");
    1.25 +    return 1;
    1.26 +  }
    1.27    char* includeSuffix = NULL;
    1.28    char* excludeSuffix = NULL;
    1.29    int checked = 0;
    1.30 @@ -186,10 +190,9 @@
    1.31          add_string(settings->regex->pattern_list, "\\*/\\s*");
    1.32        }
    1.33        /* Path */
    1.34 -      else if (registerArgument(&checked, 1024)) {
    1.35 -        return exit_with_help(settings, 1);
    1.36 +      else {
    1.37 +        add_string(directories, argv[t]);
    1.38        }
    1.39 -      directory = argv[t];
    1.40      }
    1.41    }
    1.42  
    1.43 @@ -202,10 +205,22 @@
    1.44    parseCSL(includeSuffix, settings->includeSuffixes);
    1.45    parseCSL(excludeSuffix, settings->excludeSuffixes);
    1.46  
    1.47 -  /* Scan directory */
    1.48 +  /* Scan directories */
    1.49    if (regex_compile_all(settings->regex)) {
    1.50 -    int lines = scanDirectory((scanner_t){directory, 0}, settings);
    1.51 -    destroy_settings_t(settings);
    1.52 +    int lines = 0;
    1.53 +    if (directories->count == 0) {
    1.54 +        add_string(directories, ".");
    1.55 +    }
    1.56 +    for (int t = 0 ; t < directories->count ; t++) {
    1.57 +      if (t > 0) {
    1.58 +          for (int u = 0 ; u < 79 ; u++) {
    1.59 +              printf("-");
    1.60 +          }
    1.61 +          printf("\n");
    1.62 +      }
    1.63 +      lines += scanDirectory((scanner_t){directories->items[t], 0}, settings);
    1.64 +    }
    1.65 +    destroy_string_list_t(directories);
    1.66  
    1.67      /* Print double line and line count */
    1.68      for (int t = 0 ; t < 79 ; t++) {
    1.69 @@ -223,6 +238,7 @@
    1.70        reopen_stdout();
    1.71        printf("%d", lines);
    1.72      }
    1.73 +    destroy_settings_t(settings);
    1.74    }
    1.75  
    1.76    fflush(stdout);

mercurial