42 "\n One of: ignore low medium high" |
42 "\n One of: ignore low medium high" |
43 "\n -E <pattern> - Excludes any line matching the <pattern>" |
43 "\n -E <pattern> - Excludes any line matching the <pattern>" |
44 "\n -e <start> <end> - Excludes lines between <start> and <end>" |
44 "\n -e <start> <end> - Excludes lines between <start> and <end>" |
45 "\n You may use these options multiple times" |
45 "\n You may use these options multiple times" |
46 "\n -h, --help - this help text" |
46 "\n -h, --help - this help text" |
|
47 // "\n -i - print out individual sums per file extension" |
47 "\n -m - print information about matching files only" |
48 "\n -m - print information about matching files only" |
48 "\n -s <suffixes> - only count files with these suffixes (separated" |
49 "\n -s <suffixes> - only count files with these suffixes (separated" |
49 "\n by commas)" |
50 "\n by commas)" |
50 "\n -S <suffixes> - count any file except those with these suffixes" |
51 "\n -S <suffixes> - count any file except those with these suffixes" |
51 "\n (separated by commas)" |
52 "\n (separated by commas)" |
104 char* excludeSuffix = NULL; |
105 char* excludeSuffix = NULL; |
105 int checked = 0; |
106 int checked = 0; |
106 |
107 |
107 for (int t = 1 ; t < argc ; t++) { |
108 for (int t = 1 ; t < argc ; t++) { |
108 |
109 |
109 int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); |
110 int argflags = checkArgument(argv[t], "hsSrRmvVbeEi"); |
110 int paropt = 0; |
111 int paropt = 0; |
111 |
112 |
112 /* h */ |
113 /* h */ |
113 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
114 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
114 return exit_with_help(settings, 0); |
115 return exit_with_help(settings, 0); |
195 if (!checkParamOpt(&paropt) || t >= argc) { |
196 if (!checkParamOpt(&paropt) || t >= argc) { |
196 return exit_with_help(settings, 1); |
197 return exit_with_help(settings, 1); |
197 } |
198 } |
198 add_string(settings->regex->pattern_list, argv[t]); |
199 add_string(settings->regex->pattern_list, argv[t]); |
199 add_string(settings->regex->pattern_list, "$"); |
200 add_string(settings->regex->pattern_list, "$"); |
|
201 } |
|
202 if ((argflags & 2048) > 0) { |
|
203 settings->individual_sums = true; |
200 } |
204 } |
201 if (argflags == 0) { |
205 if (argflags == 0) { |
202 /* SHORTCUTS */ |
206 /* SHORTCUTS */ |
203 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { |
207 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { |
204 add_string(settings->regex->pattern_list, "\\s*//"); |
208 add_string(settings->regex->pattern_list, "\\s*//"); |
220 parseCSL(includeSuffix, settings->includeSuffixes); |
224 parseCSL(includeSuffix, settings->includeSuffixes); |
221 parseCSL(excludeSuffix, settings->excludeSuffixes); |
225 parseCSL(excludeSuffix, settings->excludeSuffixes); |
222 |
226 |
223 /* Scan directories */ |
227 /* Scan directories */ |
224 if (regex_compile_all(settings->regex)) { |
228 if (regex_compile_all(settings->regex)) { |
|
229 scanresult_t result; |
225 /* Don't waste memory when only the total sum is needed */ |
230 /* Don't waste memory when only the total sum is needed */ |
226 string_list_t *output = settings->verbose ? new_string_list_t() : NULL; |
231 string_list_t *output = settings->verbose ? new_string_list_t() : NULL; |
227 char *outbuf; |
232 char *outbuf; |
228 |
233 |
229 int lineSum = 0, lines; |
234 int total = 0; |
230 if (directories->count == 0) { |
235 if (directories->count == 0) { |
231 add_string(directories, "."); |
236 add_string(directories, "."); |
232 } |
237 } |
233 for (int t = 0 ; t < directories->count ; t++) { |
238 for (int t = 0 ; t < directories->count ; t++) { |
234 lines = scanDirectory((scanner_t){directories->items[t], 0}, settings, |
239 scanDirectory((scanner_t){directories->items[t], 0}, settings, |
235 output); |
240 output, &result); |
236 lineSum += lines; |
241 total += result.directory; |
237 if (directories->count > 1 ) { |
242 if (directories->count > 1 ) { |
238 outbuf = (char*) malloc(81); |
243 outbuf = (char*) malloc(81); |
239 memset(outbuf, '-', 79); |
244 memset(outbuf, '-', 79); |
240 outbuf[79] = '\n'; |
245 outbuf[79] = '\n'; |
241 outbuf[80] = 0; |
246 outbuf[80] = 0; |
242 add_string(output, outbuf); |
247 add_string(output, outbuf); |
243 outbuf = (char*) malloc(81); |
248 outbuf = (char*) malloc(81); |
244 snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], lines); |
249 snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], |
|
250 result.directory); |
245 add_string(output, outbuf); |
251 add_string(output, outbuf); |
246 outbuf = (char*) malloc(81); |
252 outbuf = (char*) malloc(81); |
247 memset(outbuf, '-', 79); |
253 memset(outbuf, '-', 79); |
248 outbuf[79] = '\n'; |
254 outbuf[79] = '\n'; |
249 outbuf[80] = 0; |
255 outbuf[80] = 0; |
260 } |
266 } |
261 |
267 |
262 for (int t = 0 ; t < 79 ; t++) { |
268 for (int t = 0 ; t < 79 ; t++) { |
263 printf("="); |
269 printf("="); |
264 } |
270 } |
265 printf("\n%73d lines\n", lineSum); |
271 printf("\n%73d lines\n", total); |
266 |
272 |
267 if (settings->confusing_lnlen && |
273 if (settings->confusing_lnlen && |
268 settings->regex->pattern_list->count > 0) { |
274 settings->regex->pattern_list->count > 0) { |
269 |
275 |
270 printf("\nSome files contain too long lines.\n" |
276 printf("\nSome files contain too long lines.\n" |
271 "The regex parser currently supports a maximum line length of %d." |
277 "The regex parser currently supports a maximum line length of %d." |
272 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); |
278 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); |
273 } |
279 } |
274 } else { |
280 } else { |
275 printf("%d", lineSum); |
281 printf("%d", total); |
276 } |
282 } |
277 destroy_string_list_t(output); |
283 destroy_string_list_t(output); |
278 destroy_settings_t(settings); |
284 destroy_settings_t(settings); |
279 } |
285 } |
280 |
286 |