cline.c

changeset 27
95a958e3de88
parent 26
853a1181884b
child 28
72a98cbcb9f1
     1.1 --- a/cline.c	Thu Dec 01 17:06:27 2011 +0100
     1.2 +++ b/cline.c	Thu Jan 26 15:55:52 2012 +0100
     1.3 @@ -10,17 +10,20 @@
     1.4  #include "settings.h"
     1.5  #include "arguments.h"
     1.6  #include "stream.h"
     1.7 +#include "regex_parser.h"
     1.8  
     1.9  void printHelpText() {
    1.10    const char* helpText = 
    1.11      "\nUsage:"
    1.12 -    "\n      cline [-hrmvV][-s suffix][-b level][<directory>]"
    1.13 -    "\n      cline [-hrmvV][-S suffix][-b level][<directory>]"
    1.14 +    "\n      cline [Options] [Directory]"
    1.15 +    "\n      cline [Options] [Directory]"
    1.16      "\n\nCounts the line terminator characters (\\n) within all"
    1.17      " files in the specified\ndirectory."
    1.18      "\n\nOptions:"
    1.19      "\n  -b <level>          - binary file heuristics level (default medium)"
    1.20      "\n                        One of: ignore low medium high"
    1.21 +    "\n  -e <start> <end>    - Excludes lines between <start> and <end>"
    1.22 +    "\n                        You may use this option multiple times"
    1.23      "\n  -h, --help          - this help text"
    1.24      "\n  -m                  - print information about matching files only"
    1.25      "\n  -s <suffixes>       - only count files with these suffixes (separated"
    1.26 @@ -35,7 +38,10 @@
    1.27      "\n  cline ./\n"
    1.28      "So each file in the working directory is counted. If you want to count C"
    1.29      "\nsource code in your working directory and its subdirectories, type:"
    1.30 -    "\n  cline -rs .c\n";
    1.31 +    "\n  cline -rs .c\n"
    1.32 +    "\nIf you want to exclude comment lines, you may use the -e option."
    1.33 +    "\nAfter a line matches the regex pattern <start> any following line is"
    1.34 +    "\nnot counted unless a line matches the <end> pattern.";
    1.35      
    1.36    printf(helpText);
    1.37  }
    1.38 @@ -68,7 +74,7 @@
    1.39  
    1.40    for (int t = 1 ; t < argc ; t++) {
    1.41  
    1.42 -    int argflags = checkArgument(argv[t], "hsSrRmvVb");
    1.43 +    int argflags = checkArgument(argv[t], "hsSrRmvVbe");
    1.44  
    1.45      /* s, S */
    1.46      if ((argflags & 6) > 0) {
    1.47 @@ -132,6 +138,13 @@
    1.48          return exit_with_help(settings, 1);
    1.49        }
    1.50      }
    1.51 +    if ((argflags & 512) > 0) {
    1.52 +      if (t + 2 >= argc) {
    1.53 +        return exit_with_help(settings, 1);
    1.54 +      }
    1.55 +      t++; add_string(settings->regex->pattern_list, argv[t]);
    1.56 +      t++; add_string(settings->regex->pattern_list, argv[t]);
    1.57 +    }
    1.58      /* Path */
    1.59      if (argflags == 0) {
    1.60        if (registerArgument(&checked, 1024)) {
    1.61 @@ -154,6 +167,7 @@
    1.62    }
    1.63  
    1.64    /* Scan directory */
    1.65 +  regex_compile_all(settings->regex);
    1.66    int lines = scanDirectory((scanner_t){directory, 0}, settings);
    1.67    destroy_settings_t(settings);
    1.68  
    1.69 @@ -163,11 +177,10 @@
    1.70    }
    1.71    printf("\n%73d lines\n", lines);
    1.72  
    1.73 -  if (settings->confusing_lnlen) {
    1.74 -    /* TODO: display this only when the regexp parser is used */
    1.75 +  if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) {
    1.76      printf("\nSome files contain too long lines.\n"
    1.77 -      "The regexp parser currently supports a maximum line length of 2048."
    1.78 -      "\nThe result might be wrong.\n");
    1.79 +      "The regex parser currently supports a maximum line length of %d."
    1.80 +      "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH);
    1.81    }
    1.82  
    1.83    if (!settings->verbose) {

mercurial