--- a/cline.c Thu Dec 01 17:06:27 2011 +0100 +++ b/cline.c Thu Jan 26 15:55:52 2012 +0100 @@ -10,17 +10,20 @@ #include "settings.h" #include "arguments.h" #include "stream.h" +#include "regex_parser.h" void printHelpText() { const char* helpText = "\nUsage:" - "\n cline [-hrmvV][-s suffix][-b level][<directory>]" - "\n cline [-hrmvV][-S suffix][-b level][<directory>]" + "\n cline [Options] [Directory]" + "\n cline [Options] [Directory]" "\n\nCounts the line terminator characters (\\n) within all" " files in the specified\ndirectory." "\n\nOptions:" "\n -b <level> - binary file heuristics level (default medium)" "\n One of: ignore low medium high" + "\n -e <start> <end> - Excludes lines between <start> and <end>" + "\n You may use this option multiple times" "\n -h, --help - this help text" "\n -m - print information about matching files only" "\n -s <suffixes> - only count files with these suffixes (separated" @@ -35,7 +38,10 @@ "\n cline ./\n" "So each file in the working directory is counted. If you want to count C" "\nsource code in your working directory and its subdirectories, type:" - "\n cline -rs .c\n"; + "\n cline -rs .c\n" + "\nIf you want to exclude comment lines, you may use the -e option." + "\nAfter a line matches the regex pattern <start> any following line is" + "\nnot counted unless a line matches the <end> pattern."; printf(helpText); } @@ -68,7 +74,7 @@ for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRmvVb"); + int argflags = checkArgument(argv[t], "hsSrRmvVbe"); /* s, S */ if ((argflags & 6) > 0) { @@ -132,6 +138,13 @@ return exit_with_help(settings, 1); } } + if ((argflags & 512) > 0) { + if (t + 2 >= argc) { + return exit_with_help(settings, 1); + } + t++; add_string(settings->regex->pattern_list, argv[t]); + t++; add_string(settings->regex->pattern_list, argv[t]); + } /* Path */ if (argflags == 0) { if (registerArgument(&checked, 1024)) { @@ -154,6 +167,7 @@ } /* Scan directory */ + regex_compile_all(settings->regex); int lines = scanDirectory((scanner_t){directory, 0}, settings); destroy_settings_t(settings); @@ -163,11 +177,10 @@ } printf("\n%73d lines\n", lines); - if (settings->confusing_lnlen) { - /* TODO: display this only when the regexp parser is used */ + if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { printf("\nSome files contain too long lines.\n" - "The regexp parser currently supports a maximum line length of 2048." - "\nThe result might be wrong.\n"); + "The regex parser currently supports a maximum line length of %d." + "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); } if (!settings->verbose) {