diff -r 95a958e3de88 -r 72a98cbcb9f1 cline.c --- a/cline.c Thu Jan 26 15:55:52 2012 +0100 +++ b/cline.c Thu Feb 02 14:17:35 2012 +0100 @@ -22,8 +22,9 @@ "\n\nOptions:" "\n -b - binary file heuristics level (default medium)" "\n One of: ignore low medium high" + "\n -E - Excludes any line matching the " "\n -e - Excludes lines between and " - "\n You may use this option multiple times" + "\n You may use these options multiple times" "\n -h, --help - this help text" "\n -m - print information about matching files only" "\n -s - only count files with these suffixes (separated" @@ -35,13 +36,18 @@ "\n -V - turn verbose output off, print the result only" "\n\n" "The default call without any options is:" - "\n cline ./\n" + "\n cline ./\n\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" - "\nIf you want to exclude comment lines, you may use the -e option." + "\nIf you want to exclude comment lines, you may use the -e/-E option." "\nAfter a line matches the regex pattern any following line is" - "\nnot counted unless a line matches the pattern."; + "\nnot counted unless a line matches the pattern. A line is still " + "\ncounted when it does not start or end with the respective patterns." + "\nPlease note, that cline does not remove whitespace characters as this" + "\nmight not be reasonable in some cases." + "\n\nExample (C comments):" + "\n cline -s .c,.h -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\""; printf(helpText); } @@ -74,7 +80,7 @@ for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRmvVbe"); + int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); /* s, S */ if ((argflags & 6) > 0) { @@ -138,6 +144,7 @@ return exit_with_help(settings, 1); } } + /* e */ if ((argflags & 512) > 0) { if (t + 2 >= argc) { return exit_with_help(settings, 1); @@ -145,6 +152,15 @@ t++; add_string(settings->regex->pattern_list, argv[t]); t++; add_string(settings->regex->pattern_list, argv[t]); } + /* E */ + if ((argflags & 1024) > 0) { + t++; + if (t >= argc) { + return exit_with_help(settings, 1); + } + add_string(settings->regex->pattern_list, argv[t]); + add_string(settings->regex->pattern_list, "$"); + } /* Path */ if (argflags == 0) { if (registerArgument(&checked, 1024)) { @@ -167,27 +183,29 @@ } /* Scan directory */ - regex_compile_all(settings->regex); - int lines = scanDirectory((scanner_t){directory, 0}, settings); - destroy_settings_t(settings); + if (regex_compile_all(settings->regex)) { + int lines = scanDirectory((scanner_t){directory, 0}, settings); + destroy_settings_t(settings); - /* Print double line and line count */ - for (int t = 0 ; t < 79 ; t++) { - printf("="); - } - printf("\n%73d lines\n", lines); + /* Print double line and line count */ + for (int t = 0 ; t < 79 ; t++) { + printf("="); + } + printf("\n%73d lines\n", lines); - if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { - printf("\nSome files contain too long lines.\n" - "The regex parser currently supports a maximum line length of %d." - "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); - } + if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { + printf("\nSome files contain too long lines.\n" + "The regex parser currently supports a maximum line length of %d." + "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); + } - if (!settings->verbose) { - reopen_stdout(); - printf("%d", lines); + if (!settings->verbose) { + reopen_stdout(); + printf("%d", lines); + } } fflush(stdout); + fflush(stderr); return 0; }