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 |
--- a/arguments.c Thu Feb 02 16:55:51 2012 +0100 +++ b/arguments.c Thu Feb 09 15:56:18 2012 +0100 @@ -27,3 +27,19 @@ *reg |= mask; return ret; } + +bool checkParamOpt(int* paropt) { + bool ret = *paropt == 0; + *paropt = 1; + return ret; +} + +void parseCSL(char* csl, string_list_t* list) { + if (csl != NULL) { + char* finder = strtok(csl, ","); + while (finder != NULL) { + add_string(list, finder); + finder = strtok(NULL, ","); + } + } +}
--- a/arguments.h Thu Feb 02 16:55:51 2012 +0100 +++ b/arguments.h Thu Feb 09 15:56:18 2012 +0100 @@ -9,13 +9,16 @@ #define ARGUMENTS_H_ #include "stdinc.h" +#include "string_list.h" #ifdef _cplusplus extern "C" { #endif int checkArgument(const char*, const char*); +bool checkParamOpt(int*); bool registerArgument(int*, int); +void parseCSL(char*, string_list_t*); #ifdef _cplusplus }
--- a/cline.c Thu Feb 02 16:55:51 2012 +0100 +++ b/cline.c Thu Feb 09 15:56:18 2012 +0100 @@ -75,24 +75,36 @@ /* Get arguments */ char* directory = "./"; - char* suffix = " "; + char* includeSuffix = NULL; + char* excludeSuffix = NULL; int checked = 0; for (int t = 1 ; t < argc ; t++) { int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); + int paropt = 0; - /* s, S */ - if ((argflags & 6) > 0) { - if (registerArgument(&checked, 6)) { + /* s */ + if ((argflags & 2) > 0) { + if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { return exit_with_help(settings, 1); } - settings->includeSuffixes = (argflags & 2) > 0; t++; if (t >= argc) { return exit_with_help(settings, 1); } - suffix = argv[t]; + includeSuffix = argv[t]; + } + /* S */ + if ((argflags & 4) > 0) { + if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { + return exit_with_help(settings, 1); + } + t++; + if (t >= argc) { + return exit_with_help(settings, 1); + } + excludeSuffix = argv[t]; } /* h */ if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { @@ -125,7 +137,7 @@ } /* b */ if ((argflags & 256) > 0) { - if (registerArgument(&checked, 256)) { + if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { return exit_with_help(settings, 1); } t++; @@ -146,7 +158,7 @@ } /* e */ if ((argflags & 512) > 0) { - if (t + 2 >= argc) { + if (!checkParamOpt(&paropt) || t + 2 >= argc) { return exit_with_help(settings, 1); } t++; add_string(settings->regex->pattern_list, argv[t]); @@ -155,7 +167,7 @@ /* E */ if ((argflags & 1024) > 0) { t++; - if (t >= argc) { + if (!checkParamOpt(&paropt) || t >= argc) { return exit_with_help(settings, 1); } add_string(settings->regex->pattern_list, argv[t]); @@ -176,11 +188,8 @@ } /* Find tokens */ - char* finder = strtok(suffix, ","); - while (finder != NULL) { - add_string(settings->suffixList, finder); - finder = strtok(NULL, ","); - } + parseCSL(includeSuffix, settings->includeSuffixes); + parseCSL(excludeSuffix, settings->excludeSuffixes); /* Scan directory */ if (regex_compile_all(settings->regex)) {
--- a/scanner.c Thu Feb 02 16:55:51 2012 +0100 +++ b/scanner.c Thu Feb 09 15:56:18 2012 +0100 @@ -57,7 +57,9 @@ continue; } - if (testSuffix(filename, settings)) { + if ((settings->includeSuffixes->count == 0 + || testSuffix(filename, settings->includeSuffixes)) + && !testSuffix(filename, settings->excludeSuffixes)) { /* Count lines */ lines = 0; bfile = false;
--- a/settings.c Thu Feb 02 16:55:51 2012 +0100 +++ b/settings.c Thu Feb 09 15:56:18 2012 +0100 @@ -16,9 +16,9 @@ settings->fileSeparator = '/'; #endif /* _WIN32 */ settings->recursive = false; - settings->includeSuffixes = false; settings->matchesOnly = false; - settings->suffixList = new_string_list_t(); + settings->includeSuffixes = new_string_list_t(); + settings->excludeSuffixes = new_string_list_t(); settings->verbose = true; settings->bfileHeuristics = new_bfile_heuristics_t(); settings->confusing_lnlen = false; @@ -30,7 +30,8 @@ void destroy_settings_t(settings_t* settings) { destroy_regex_parser_t(settings->regex); - destroy_string_list_t(settings->suffixList); + destroy_string_list_t(settings->includeSuffixes); + destroy_string_list_t(settings->excludeSuffixes); destroy_bfile_heuristics_t(settings->bfileHeuristics); free(settings); }
--- a/settings.h Thu Feb 02 16:55:51 2012 +0100 +++ b/settings.h Thu Feb 09 15:56:18 2012 +0100 @@ -14,12 +14,12 @@ #include "regex_parser.h" typedef struct _settings { - string_list_t* suffixList; + string_list_t* includeSuffixes; + string_list_t* excludeSuffixes; regex_parser_t* regex; bfile_heuristics_t* bfileHeuristics; char fileSeparator; bool recursive; - bool includeSuffixes; bool matchesOnly; bool verbose; bool confusing_lnlen; /* this flag is set by the scanner */
--- a/suffix_fnc.c Thu Feb 02 16:55:51 2012 +0100 +++ b/suffix_fnc.c Thu Feb 09 15:56:18 2012 +0100 @@ -7,19 +7,19 @@ #include "suffix_fnc.h" -bool testSuffix(char* filename, settings_t* settings) { +bool testSuffix(char* filename, string_list_t* list) { bool ret = false; int tokenlen, fnamelen = strlen(filename); - for (int t = 0 ; t < settings->suffixList->count ; t++) { - tokenlen = strlen(settings->suffixList->items[t]); + for (int t = 0 ; t < list->count ; t++) { + tokenlen = strlen(list->items[t]); if (fnamelen >= tokenlen && tokenlen > 0) { if (strncmp(filename+fnamelen-tokenlen, - settings->suffixList->items[t], tokenlen) == 0) { + list->items[t], tokenlen) == 0) { ret = true; break; } } } - return ret ^ !settings->includeSuffixes; + return ret; }
--- a/suffix_fnc.h Thu Feb 02 16:55:51 2012 +0100 +++ b/suffix_fnc.h Thu Feb 09 15:56:18 2012 +0100 @@ -9,8 +9,8 @@ #define SUFFIX_FNC_H_ #include "stdinc.h" -#include "settings.h" +#include "string_list.h" -bool testSuffix(char*, settings_t*); +bool testSuffix(char*, string_list_t*); #endif /* SUFFIX_FNC_H_ */