1.1 --- a/cline.c Thu Jan 26 15:55:52 2012 +0100 1.2 +++ b/cline.c Thu Feb 02 14:17:35 2012 +0100 1.3 @@ -22,8 +22,9 @@ 1.4 "\n\nOptions:" 1.5 "\n -b <level> - binary file heuristics level (default medium)" 1.6 "\n One of: ignore low medium high" 1.7 + "\n -E <pattern> - Excludes any line matching the <pattern>" 1.8 "\n -e <start> <end> - Excludes lines between <start> and <end>" 1.9 - "\n You may use this option multiple times" 1.10 + "\n You may use these options multiple times" 1.11 "\n -h, --help - this help text" 1.12 "\n -m - print information about matching files only" 1.13 "\n -s <suffixes> - only count files with these suffixes (separated" 1.14 @@ -35,13 +36,18 @@ 1.15 "\n -V - turn verbose output off, print the result only" 1.16 "\n\n" 1.17 "The default call without any options is:" 1.18 - "\n cline ./\n" 1.19 + "\n cline ./\n\n" 1.20 "So each file in the working directory is counted. If you want to count C" 1.21 "\nsource code in your working directory and its subdirectories, type:" 1.22 "\n cline -rs .c\n" 1.23 - "\nIf you want to exclude comment lines, you may use the -e option." 1.24 + "\nIf you want to exclude comment lines, you may use the -e/-E option." 1.25 "\nAfter a line matches the regex pattern <start> any following line is" 1.26 - "\nnot counted unless a line matches the <end> pattern."; 1.27 + "\nnot counted unless a line matches the <end> pattern. A line is still " 1.28 + "\ncounted when it does not start or end with the respective patterns." 1.29 + "\nPlease note, that cline does not remove whitespace characters as this" 1.30 + "\nmight not be reasonable in some cases." 1.31 + "\n\nExample (C comments):" 1.32 + "\n cline -s .c,.h -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\""; 1.33 1.34 printf(helpText); 1.35 } 1.36 @@ -74,7 +80,7 @@ 1.37 1.38 for (int t = 1 ; t < argc ; t++) { 1.39 1.40 - int argflags = checkArgument(argv[t], "hsSrRmvVbe"); 1.41 + int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 1.42 1.43 /* s, S */ 1.44 if ((argflags & 6) > 0) { 1.45 @@ -138,6 +144,7 @@ 1.46 return exit_with_help(settings, 1); 1.47 } 1.48 } 1.49 + /* e */ 1.50 if ((argflags & 512) > 0) { 1.51 if (t + 2 >= argc) { 1.52 return exit_with_help(settings, 1); 1.53 @@ -145,6 +152,15 @@ 1.54 t++; add_string(settings->regex->pattern_list, argv[t]); 1.55 t++; add_string(settings->regex->pattern_list, argv[t]); 1.56 } 1.57 + /* E */ 1.58 + if ((argflags & 1024) > 0) { 1.59 + t++; 1.60 + if (t >= argc) { 1.61 + return exit_with_help(settings, 1); 1.62 + } 1.63 + add_string(settings->regex->pattern_list, argv[t]); 1.64 + add_string(settings->regex->pattern_list, "$"); 1.65 + } 1.66 /* Path */ 1.67 if (argflags == 0) { 1.68 if (registerArgument(&checked, 1024)) { 1.69 @@ -167,27 +183,29 @@ 1.70 } 1.71 1.72 /* Scan directory */ 1.73 - regex_compile_all(settings->regex); 1.74 - int lines = scanDirectory((scanner_t){directory, 0}, settings); 1.75 - destroy_settings_t(settings); 1.76 + if (regex_compile_all(settings->regex)) { 1.77 + int lines = scanDirectory((scanner_t){directory, 0}, settings); 1.78 + destroy_settings_t(settings); 1.79 1.80 - /* Print double line and line count */ 1.81 - for (int t = 0 ; t < 79 ; t++) { 1.82 - printf("="); 1.83 - } 1.84 - printf("\n%73d lines\n", lines); 1.85 + /* Print double line and line count */ 1.86 + for (int t = 0 ; t < 79 ; t++) { 1.87 + printf("="); 1.88 + } 1.89 + printf("\n%73d lines\n", lines); 1.90 1.91 - if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { 1.92 - printf("\nSome files contain too long lines.\n" 1.93 - "The regex parser currently supports a maximum line length of %d." 1.94 - "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 1.95 - } 1.96 + if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { 1.97 + printf("\nSome files contain too long lines.\n" 1.98 + "The regex parser currently supports a maximum line length of %d." 1.99 + "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 1.100 + } 1.101 1.102 - if (!settings->verbose) { 1.103 - reopen_stdout(); 1.104 - printf("%d", lines); 1.105 + if (!settings->verbose) { 1.106 + reopen_stdout(); 1.107 + printf("%d", lines); 1.108 + } 1.109 } 1.110 1.111 fflush(stdout); 1.112 + fflush(stderr); 1.113 return 0; 1.114 }