13 #include "regex_parser.h" |
13 #include "regex_parser.h" |
14 |
14 |
15 void printHelpText() { |
15 void printHelpText() { |
16 const char* helpText = |
16 const char* helpText = |
17 "\nUsage:" |
17 "\nUsage:" |
18 "\n cline [Options] [Directory]" |
18 "\n cline [Options] [Directories...]" |
19 "\n cline [Options] [Directory]" |
19 "\n cline [Options] [Directories...]" |
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\ndirectories." |
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 <pattern> - Excludes any line matching the <pattern>" |
26 "\n -e <start> <end> - Excludes lines between <start> and <end>" |
26 "\n -e <start> <end> - Excludes lines between <start> and <end>" |
75 fprintf(stderr, "Memory allocation failed.\n"); |
75 fprintf(stderr, "Memory allocation failed.\n"); |
76 return 1; |
76 return 1; |
77 } |
77 } |
78 |
78 |
79 /* Get arguments */ |
79 /* Get arguments */ |
80 char* directory = "./"; |
80 string_list_t *directories = new_string_list_t(); |
|
81 if (directories == NULL) { |
|
82 fprintf(stderr, "Memory allocation failed.\n"); |
|
83 return 1; |
|
84 } |
81 char* includeSuffix = NULL; |
85 char* includeSuffix = NULL; |
82 char* excludeSuffix = NULL; |
86 char* excludeSuffix = NULL; |
83 int checked = 0; |
87 int checked = 0; |
84 |
88 |
85 for (int t = 1 ; t < argc ; t++) { |
89 for (int t = 1 ; t < argc ; t++) { |
184 add_string(settings->regex->pattern_list, "$"); |
188 add_string(settings->regex->pattern_list, "$"); |
185 add_string(settings->regex->pattern_list, "\\s*/\\*"); |
189 add_string(settings->regex->pattern_list, "\\s*/\\*"); |
186 add_string(settings->regex->pattern_list, "\\*/\\s*"); |
190 add_string(settings->regex->pattern_list, "\\*/\\s*"); |
187 } |
191 } |
188 /* Path */ |
192 /* Path */ |
189 else if (registerArgument(&checked, 1024)) { |
193 else { |
190 return exit_with_help(settings, 1); |
194 add_string(directories, argv[t]); |
191 } |
195 } |
192 directory = argv[t]; |
|
193 } |
196 } |
194 } |
197 } |
195 |
198 |
196 /* Configure output */ |
199 /* Configure output */ |
197 if (!settings->verbose) { |
200 if (!settings->verbose) { |
200 |
203 |
201 /* Find tokens */ |
204 /* Find tokens */ |
202 parseCSL(includeSuffix, settings->includeSuffixes); |
205 parseCSL(includeSuffix, settings->includeSuffixes); |
203 parseCSL(excludeSuffix, settings->excludeSuffixes); |
206 parseCSL(excludeSuffix, settings->excludeSuffixes); |
204 |
207 |
205 /* Scan directory */ |
208 /* Scan directories */ |
206 if (regex_compile_all(settings->regex)) { |
209 if (regex_compile_all(settings->regex)) { |
207 int lines = scanDirectory((scanner_t){directory, 0}, settings); |
210 int lines = 0; |
208 destroy_settings_t(settings); |
211 if (directories->count == 0) { |
|
212 add_string(directories, "."); |
|
213 } |
|
214 for (int t = 0 ; t < directories->count ; t++) { |
|
215 if (t > 0) { |
|
216 for (int u = 0 ; u < 79 ; u++) { |
|
217 printf("-"); |
|
218 } |
|
219 printf("\n"); |
|
220 } |
|
221 lines += scanDirectory((scanner_t){directories->items[t], 0}, settings); |
|
222 } |
|
223 destroy_string_list_t(directories); |
209 |
224 |
210 /* Print double line and line count */ |
225 /* Print double line and line count */ |
211 for (int t = 0 ; t < 79 ; t++) { |
226 for (int t = 0 ; t < 79 ; t++) { |
212 printf("="); |
227 printf("="); |
213 } |
228 } |