src/cline.c

changeset 61
9c8d768f0244
parent 60
69be673a4fd0
child 62
7f5f9f43d0c0
equal deleted inserted replaced
60:69be673a4fd0 61:9c8d768f0244
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 -i - print out individual sums per file extension"
48 "\n (cannot be used together with -V)"
48 "\n -m - print information about matching files only" 49 "\n -m - print information about matching files only"
49 "\n -s <suffixes> - only count files with these suffixes (separated" 50 "\n -s <suffixes> - only count files with these suffixes (separated"
50 "\n by commas)" 51 "\n by commas)"
51 "\n -S <suffixes> - count any file except those with these suffixes" 52 "\n -S <suffixes> - count any file except those with these suffixes"
52 "\n (separated by commas)" 53 "\n (separated by commas)"
197 return exit_with_help(settings, 1); 198 return exit_with_help(settings, 1);
198 } 199 }
199 add_string(settings->regex->pattern_list, argv[t]); 200 add_string(settings->regex->pattern_list, argv[t]);
200 add_string(settings->regex->pattern_list, "$"); 201 add_string(settings->regex->pattern_list, "$");
201 } 202 }
203 /* i */
202 if ((argflags & 2048) > 0) { 204 if ((argflags & 2048) > 0) {
203 settings->individual_sums = true; 205 // cannot be used together with -V
206 if (registerArgument(&checked, 128)) {
207 return exit_with_help(settings, 1);
208 }
209 settings->individual_sums = true;
204 } 210 }
205 if (argflags == 0) { 211 if (argflags == 0) {
206 /* SHORTCUTS */ 212 /* SHORTCUTS */
207 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { 213 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) {
208 add_string(settings->regex->pattern_list, "\\s*//"); 214 add_string(settings->regex->pattern_list, "\\s*//");
224 parseCSL(includeSuffix, settings->includeSuffixes); 230 parseCSL(includeSuffix, settings->includeSuffixes);
225 parseCSL(excludeSuffix, settings->excludeSuffixes); 231 parseCSL(excludeSuffix, settings->excludeSuffixes);
226 232
227 /* Scan directories */ 233 /* Scan directories */
228 if (regex_compile_all(settings->regex)) { 234 if (regex_compile_all(settings->regex)) {
229 scanresult_t result; 235 scanresult_t* result = new_scanresult_t(settings);
230 /* Don't waste memory when only the total sum is needed */ 236 /* Don't waste memory when only the total sum is needed */
231 string_list_t *output = settings->verbose ? new_string_list_t() : NULL; 237 string_list_t *output = settings->verbose ? new_string_list_t() : NULL;
232 char *outbuf; 238 char *outbuf;
233 239
234 int total = 0; 240 int total = 0;
235 if (directories->count == 0) { 241 if (directories->count == 0) {
236 add_string(directories, "."); 242 add_string(directories, ".");
237 } 243 }
238 for (int t = 0 ; t < directories->count ; t++) { 244 for (int t = 0 ; t < directories->count ; t++) {
239 scanDirectory((scanner_t){directories->items[t], 0}, settings, 245 scanDirectory((scanner_t){directories->items[t], 0}, settings,
240 output, &result); 246 output, result);
241 total += result.directory; 247 total += result->lines;
242 if (directories->count > 1 ) { 248 if (directories->count > 1 ) {
243 outbuf = (char*) malloc(81); 249 outbuf = (char*) malloc(81);
244 memset(outbuf, '-', 79); 250 memset(outbuf, '-', 79);
245 outbuf[79] = '\n'; 251 outbuf[79] = '\n';
246 outbuf[80] = 0; 252 outbuf[80] = 0;
247 add_string(output, outbuf); 253 add_string(output, outbuf);
248 outbuf = (char*) malloc(81); 254 outbuf = (char*) malloc(81);
249 snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t], 255 snprintf(outbuf, 81, "%-63s%10d lines\n", directories->items[t],
250 result.directory); 256 result->lines);
251 add_string(output, outbuf); 257 add_string(output, outbuf);
252 outbuf = (char*) malloc(81); 258 outbuf = (char*) malloc(81);
253 memset(outbuf, '-', 79); 259 memset(outbuf, '-', 79);
254 outbuf[79] = '\n'; 260 outbuf[79] = '\n';
255 outbuf[80] = 0; 261 outbuf[80] = 0;
263 for (int i = 0 ; i < output->count ; i++) { 269 for (int i = 0 ; i < output->count ; i++) {
264 printf("%s", output->items[i]); 270 printf("%s", output->items[i]);
265 free(output->items[i]); 271 free(output->items[i]);
266 } 272 }
267 273
274 if (result->ext) {
275 if (result->ext->count > 0) {
276 for (int t = 0 ; t < 79 ; t++) {
277 printf("=");
278 }
279 printf("\nIndividual sums:\n");
280 for (int t = 0 ; t < result->ext->count ; t++) {
281 printf(" %-62s%10d lines\n",
282 result->ext->extensions[t],
283 result->ext->lines[t]);
284 }
285 }
286 }
287
268 for (int t = 0 ; t < 79 ; t++) { 288 for (int t = 0 ; t < 79 ; t++) {
269 printf("="); 289 printf("=");
270 } 290 }
271 printf("\n%73d lines\n", total); 291 printf("\n%73d lines\n", total);
272 292
278 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 298 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH);
279 } 299 }
280 } else { 300 } else {
281 printf("%d", total); 301 printf("%d", total);
282 } 302 }
303 destroy_scanresult_t(result);
283 destroy_string_list_t(output); 304 destroy_string_list_t(output);
284 destroy_settings_t(settings); 305 destroy_settings_t(settings);
285 } 306 }
286 307
287 fflush(stdout); 308 fflush(stdout);

mercurial