Thu, 09 Feb 2012 15:56:18 +0100
allow parallel use of -s and -S
arguments.c | file | annotate | diff | comparison | revisions | |
arguments.h | file | annotate | diff | comparison | revisions | |
cline.c | file | annotate | diff | comparison | revisions | |
scanner.c | file | annotate | diff | comparison | revisions | |
settings.c | file | annotate | diff | comparison | revisions | |
settings.h | file | annotate | diff | comparison | revisions | |
suffix_fnc.c | file | annotate | diff | comparison | revisions | |
suffix_fnc.h | file | annotate | diff | comparison | revisions |
1.1 --- a/arguments.c Thu Feb 02 16:55:51 2012 +0100 1.2 +++ b/arguments.c Thu Feb 09 15:56:18 2012 +0100 1.3 @@ -27,3 +27,19 @@ 1.4 *reg |= mask; 1.5 return ret; 1.6 } 1.7 + 1.8 +bool checkParamOpt(int* paropt) { 1.9 + bool ret = *paropt == 0; 1.10 + *paropt = 1; 1.11 + return ret; 1.12 +} 1.13 + 1.14 +void parseCSL(char* csl, string_list_t* list) { 1.15 + if (csl != NULL) { 1.16 + char* finder = strtok(csl, ","); 1.17 + while (finder != NULL) { 1.18 + add_string(list, finder); 1.19 + finder = strtok(NULL, ","); 1.20 + } 1.21 + } 1.22 +}
2.1 --- a/arguments.h Thu Feb 02 16:55:51 2012 +0100 2.2 +++ b/arguments.h Thu Feb 09 15:56:18 2012 +0100 2.3 @@ -9,13 +9,16 @@ 2.4 #define ARGUMENTS_H_ 2.5 2.6 #include "stdinc.h" 2.7 +#include "string_list.h" 2.8 2.9 #ifdef _cplusplus 2.10 extern "C" { 2.11 #endif 2.12 2.13 int checkArgument(const char*, const char*); 2.14 +bool checkParamOpt(int*); 2.15 bool registerArgument(int*, int); 2.16 +void parseCSL(char*, string_list_t*); 2.17 2.18 #ifdef _cplusplus 2.19 }
3.1 --- a/cline.c Thu Feb 02 16:55:51 2012 +0100 3.2 +++ b/cline.c Thu Feb 09 15:56:18 2012 +0100 3.3 @@ -75,24 +75,36 @@ 3.4 3.5 /* Get arguments */ 3.6 char* directory = "./"; 3.7 - char* suffix = " "; 3.8 + char* includeSuffix = NULL; 3.9 + char* excludeSuffix = NULL; 3.10 int checked = 0; 3.11 3.12 for (int t = 1 ; t < argc ; t++) { 3.13 3.14 int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 3.15 + int paropt = 0; 3.16 3.17 - /* s, S */ 3.18 - if ((argflags & 6) > 0) { 3.19 - if (registerArgument(&checked, 6)) { 3.20 + /* s */ 3.21 + if ((argflags & 2) > 0) { 3.22 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { 3.23 return exit_with_help(settings, 1); 3.24 } 3.25 - settings->includeSuffixes = (argflags & 2) > 0; 3.26 t++; 3.27 if (t >= argc) { 3.28 return exit_with_help(settings, 1); 3.29 } 3.30 - suffix = argv[t]; 3.31 + includeSuffix = argv[t]; 3.32 + } 3.33 + /* S */ 3.34 + if ((argflags & 4) > 0) { 3.35 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { 3.36 + return exit_with_help(settings, 1); 3.37 + } 3.38 + t++; 3.39 + if (t >= argc) { 3.40 + return exit_with_help(settings, 1); 3.41 + } 3.42 + excludeSuffix = argv[t]; 3.43 } 3.44 /* h */ 3.45 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 3.46 @@ -125,7 +137,7 @@ 3.47 } 3.48 /* b */ 3.49 if ((argflags & 256) > 0) { 3.50 - if (registerArgument(&checked, 256)) { 3.51 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { 3.52 return exit_with_help(settings, 1); 3.53 } 3.54 t++; 3.55 @@ -146,7 +158,7 @@ 3.56 } 3.57 /* e */ 3.58 if ((argflags & 512) > 0) { 3.59 - if (t + 2 >= argc) { 3.60 + if (!checkParamOpt(&paropt) || t + 2 >= argc) { 3.61 return exit_with_help(settings, 1); 3.62 } 3.63 t++; add_string(settings->regex->pattern_list, argv[t]); 3.64 @@ -155,7 +167,7 @@ 3.65 /* E */ 3.66 if ((argflags & 1024) > 0) { 3.67 t++; 3.68 - if (t >= argc) { 3.69 + if (!checkParamOpt(&paropt) || t >= argc) { 3.70 return exit_with_help(settings, 1); 3.71 } 3.72 add_string(settings->regex->pattern_list, argv[t]); 3.73 @@ -176,11 +188,8 @@ 3.74 } 3.75 3.76 /* Find tokens */ 3.77 - char* finder = strtok(suffix, ","); 3.78 - while (finder != NULL) { 3.79 - add_string(settings->suffixList, finder); 3.80 - finder = strtok(NULL, ","); 3.81 - } 3.82 + parseCSL(includeSuffix, settings->includeSuffixes); 3.83 + parseCSL(excludeSuffix, settings->excludeSuffixes); 3.84 3.85 /* Scan directory */ 3.86 if (regex_compile_all(settings->regex)) {
4.1 --- a/scanner.c Thu Feb 02 16:55:51 2012 +0100 4.2 +++ b/scanner.c Thu Feb 09 15:56:18 2012 +0100 4.3 @@ -57,7 +57,9 @@ 4.4 continue; 4.5 } 4.6 4.7 - if (testSuffix(filename, settings)) { 4.8 + if ((settings->includeSuffixes->count == 0 4.9 + || testSuffix(filename, settings->includeSuffixes)) 4.10 + && !testSuffix(filename, settings->excludeSuffixes)) { 4.11 /* Count lines */ 4.12 lines = 0; 4.13 bfile = false;
5.1 --- a/settings.c Thu Feb 02 16:55:51 2012 +0100 5.2 +++ b/settings.c Thu Feb 09 15:56:18 2012 +0100 5.3 @@ -16,9 +16,9 @@ 5.4 settings->fileSeparator = '/'; 5.5 #endif /* _WIN32 */ 5.6 settings->recursive = false; 5.7 - settings->includeSuffixes = false; 5.8 settings->matchesOnly = false; 5.9 - settings->suffixList = new_string_list_t(); 5.10 + settings->includeSuffixes = new_string_list_t(); 5.11 + settings->excludeSuffixes = new_string_list_t(); 5.12 settings->verbose = true; 5.13 settings->bfileHeuristics = new_bfile_heuristics_t(); 5.14 settings->confusing_lnlen = false; 5.15 @@ -30,7 +30,8 @@ 5.16 5.17 void destroy_settings_t(settings_t* settings) { 5.18 destroy_regex_parser_t(settings->regex); 5.19 - destroy_string_list_t(settings->suffixList); 5.20 + destroy_string_list_t(settings->includeSuffixes); 5.21 + destroy_string_list_t(settings->excludeSuffixes); 5.22 destroy_bfile_heuristics_t(settings->bfileHeuristics); 5.23 free(settings); 5.24 }
6.1 --- a/settings.h Thu Feb 02 16:55:51 2012 +0100 6.2 +++ b/settings.h Thu Feb 09 15:56:18 2012 +0100 6.3 @@ -14,12 +14,12 @@ 6.4 #include "regex_parser.h" 6.5 6.6 typedef struct _settings { 6.7 - string_list_t* suffixList; 6.8 + string_list_t* includeSuffixes; 6.9 + string_list_t* excludeSuffixes; 6.10 regex_parser_t* regex; 6.11 bfile_heuristics_t* bfileHeuristics; 6.12 char fileSeparator; 6.13 bool recursive; 6.14 - bool includeSuffixes; 6.15 bool matchesOnly; 6.16 bool verbose; 6.17 bool confusing_lnlen; /* this flag is set by the scanner */
7.1 --- a/suffix_fnc.c Thu Feb 02 16:55:51 2012 +0100 7.2 +++ b/suffix_fnc.c Thu Feb 09 15:56:18 2012 +0100 7.3 @@ -7,19 +7,19 @@ 7.4 7.5 #include "suffix_fnc.h" 7.6 7.7 -bool testSuffix(char* filename, settings_t* settings) { 7.8 +bool testSuffix(char* filename, string_list_t* list) { 7.9 bool ret = false; 7.10 int tokenlen, fnamelen = strlen(filename); 7.11 - for (int t = 0 ; t < settings->suffixList->count ; t++) { 7.12 - tokenlen = strlen(settings->suffixList->items[t]); 7.13 + for (int t = 0 ; t < list->count ; t++) { 7.14 + tokenlen = strlen(list->items[t]); 7.15 if (fnamelen >= tokenlen && tokenlen > 0) { 7.16 if (strncmp(filename+fnamelen-tokenlen, 7.17 - settings->suffixList->items[t], tokenlen) == 0) { 7.18 + list->items[t], tokenlen) == 0) { 7.19 ret = true; 7.20 break; 7.21 } 7.22 } 7.23 } 7.24 - return ret ^ !settings->includeSuffixes; 7.25 + return ret; 7.26 } 7.27
8.1 --- a/suffix_fnc.h Thu Feb 02 16:55:51 2012 +0100 8.2 +++ b/suffix_fnc.h Thu Feb 09 15:56:18 2012 +0100 8.3 @@ -9,8 +9,8 @@ 8.4 #define SUFFIX_FNC_H_ 8.5 8.6 #include "stdinc.h" 8.7 -#include "settings.h" 8.8 +#include "string_list.h" 8.9 8.10 -bool testSuffix(char*, settings_t*); 8.11 +bool testSuffix(char*, string_list_t*); 8.12 8.13 #endif /* SUFFIX_FNC_H_ */