cline.c

changeset 28
72a98cbcb9f1
parent 27
95a958e3de88
child 30
d642fdb6745e
equal deleted inserted replaced
27:95a958e3de88 28:72a98cbcb9f1
20 "\n\nCounts the line terminator characters (\\n) within all" 20 "\n\nCounts the line terminator characters (\\n) within all"
21 " files in the specified\ndirectory." 21 " files in the specified\ndirectory."
22 "\n\nOptions:" 22 "\n\nOptions:"
23 "\n -b <level> - binary file heuristics level (default medium)" 23 "\n -b <level> - binary file heuristics level (default medium)"
24 "\n One of: ignore low medium high" 24 "\n One of: ignore low medium high"
25 "\n -E <pattern> - Excludes any line matching the <pattern>"
25 "\n -e <start> <end> - Excludes lines between <start> and <end>" 26 "\n -e <start> <end> - Excludes lines between <start> and <end>"
26 "\n You may use this option multiple times" 27 "\n You may use these options multiple times"
27 "\n -h, --help - this help text" 28 "\n -h, --help - this help text"
28 "\n -m - print information about matching files only" 29 "\n -m - print information about matching files only"
29 "\n -s <suffixes> - only count files with these suffixes (separated" 30 "\n -s <suffixes> - only count files with these suffixes (separated"
30 "\n by commas)" 31 "\n by commas)"
31 "\n -S <suffixes> - count any file except those with these suffixes" 32 "\n -S <suffixes> - count any file except those with these suffixes"
33 "\n -r, -R - includes subdirectories" 34 "\n -r, -R - includes subdirectories"
34 "\n -v, --version - print out version information" 35 "\n -v, --version - print out version information"
35 "\n -V - turn verbose output off, print the result only" 36 "\n -V - turn verbose output off, print the result only"
36 "\n\n" 37 "\n\n"
37 "The default call without any options is:" 38 "The default call without any options is:"
38 "\n cline ./\n" 39 "\n cline ./\n\n"
39 "So each file in the working directory is counted. If you want to count C" 40 "So each file in the working directory is counted. If you want to count C"
40 "\nsource code in your working directory and its subdirectories, type:" 41 "\nsource code in your working directory and its subdirectories, type:"
41 "\n cline -rs .c\n" 42 "\n cline -rs .c\n"
42 "\nIf you want to exclude comment lines, you may use the -e option." 43 "\nIf you want to exclude comment lines, you may use the -e/-E option."
43 "\nAfter a line matches the regex pattern <start> any following line is" 44 "\nAfter a line matches the regex pattern <start> any following line is"
44 "\nnot counted unless a line matches the <end> pattern."; 45 "\nnot counted unless a line matches the <end> pattern. A line is still "
46 "\ncounted when it does not start or end with the respective patterns."
47 "\nPlease note, that cline does not remove whitespace characters as this"
48 "\nmight not be reasonable in some cases."
49 "\n\nExample (C comments):"
50 "\n cline -s .c,.h -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\"";
45 51
46 printf(helpText); 52 printf(helpText);
47 } 53 }
48 54
49 int exit_with_version(settings_t* settings) { 55 int exit_with_version(settings_t* settings) {
72 char* suffix = " "; 78 char* suffix = " ";
73 int checked = 0; 79 int checked = 0;
74 80
75 for (int t = 1 ; t < argc ; t++) { 81 for (int t = 1 ; t < argc ; t++) {
76 82
77 int argflags = checkArgument(argv[t], "hsSrRmvVbe"); 83 int argflags = checkArgument(argv[t], "hsSrRmvVbeE");
78 84
79 /* s, S */ 85 /* s, S */
80 if ((argflags & 6) > 0) { 86 if ((argflags & 6) > 0) {
81 if (registerArgument(&checked, 6)) { 87 if (registerArgument(&checked, 6)) {
82 return exit_with_help(settings, 1); 88 return exit_with_help(settings, 1);
136 settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY; 142 settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
137 } else { 143 } else {
138 return exit_with_help(settings, 1); 144 return exit_with_help(settings, 1);
139 } 145 }
140 } 146 }
147 /* e */
141 if ((argflags & 512) > 0) { 148 if ((argflags & 512) > 0) {
142 if (t + 2 >= argc) { 149 if (t + 2 >= argc) {
143 return exit_with_help(settings, 1); 150 return exit_with_help(settings, 1);
144 } 151 }
145 t++; add_string(settings->regex->pattern_list, argv[t]); 152 t++; add_string(settings->regex->pattern_list, argv[t]);
146 t++; add_string(settings->regex->pattern_list, argv[t]); 153 t++; add_string(settings->regex->pattern_list, argv[t]);
154 }
155 /* E */
156 if ((argflags & 1024) > 0) {
157 t++;
158 if (t >= argc) {
159 return exit_with_help(settings, 1);
160 }
161 add_string(settings->regex->pattern_list, argv[t]);
162 add_string(settings->regex->pattern_list, "$");
147 } 163 }
148 /* Path */ 164 /* Path */
149 if (argflags == 0) { 165 if (argflags == 0) {
150 if (registerArgument(&checked, 1024)) { 166 if (registerArgument(&checked, 1024)) {
151 return exit_with_help(settings, 1); 167 return exit_with_help(settings, 1);
165 add_string(settings->suffixList, finder); 181 add_string(settings->suffixList, finder);
166 finder = strtok(NULL, ","); 182 finder = strtok(NULL, ",");
167 } 183 }
168 184
169 /* Scan directory */ 185 /* Scan directory */
170 regex_compile_all(settings->regex); 186 if (regex_compile_all(settings->regex)) {
171 int lines = scanDirectory((scanner_t){directory, 0}, settings); 187 int lines = scanDirectory((scanner_t){directory, 0}, settings);
172 destroy_settings_t(settings); 188 destroy_settings_t(settings);
173 189
174 /* Print double line and line count */ 190 /* Print double line and line count */
175 for (int t = 0 ; t < 79 ; t++) { 191 for (int t = 0 ; t < 79 ; t++) {
176 printf("="); 192 printf("=");
177 } 193 }
178 printf("\n%73d lines\n", lines); 194 printf("\n%73d lines\n", lines);
179 195
180 if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { 196 if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) {
181 printf("\nSome files contain too long lines.\n" 197 printf("\nSome files contain too long lines.\n"
182 "The regex parser currently supports a maximum line length of %d." 198 "The regex parser currently supports a maximum line length of %d."
183 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 199 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH);
184 } 200 }
185 201
186 if (!settings->verbose) { 202 if (!settings->verbose) {
187 reopen_stdout(); 203 reopen_stdout();
188 printf("%d", lines); 204 printf("%d", lines);
205 }
189 } 206 }
190 207
191 fflush(stdout); 208 fflush(stdout);
209 fflush(stderr);
192 return 0; 210 return 0;
193 } 211 }

mercurial