Sat, 04 Jul 2026 12:28:16 +0200
fix inconsistent naming of symbols
relates to #917
| src/arguments.c | file | annotate | diff | comparison | revisions | |
| src/arguments.h | file | annotate | diff | comparison | revisions | |
| src/cline.c | file | annotate | diff | comparison | revisions | |
| src/scanner.c | file | annotate | diff | comparison | revisions | |
| src/scanner.h | file | annotate | diff | comparison | revisions | |
| src/settings.c | file | annotate | diff | comparison | revisions | |
| src/settings.h | file | annotate | diff | comparison | revisions | |
| src/string_list.c | file | annotate | diff | comparison | revisions |
--- a/src/arguments.c Sat Jul 04 12:09:37 2026 +0200 +++ b/src/arguments.c Sat Jul 04 12:28:16 2026 +0200 @@ -26,7 +26,7 @@ #include "arguments.h" -int checkArgument(const char *arg, const char *expected) { +int argument_check(const char *arg, const char *expected) { size_t len = strlen(expected); int ret = 0; @@ -41,19 +41,13 @@ return ret; } -bool registerArgument(int *reg, int mask) { +bool argument_register(int *reg, int mask) { bool ret = (*reg & mask) > 0; *reg |= mask; return ret; } -bool checkParamOpt(int *paropt) { - bool ret = *paropt == 0; - *paropt = 1; - return ret; -} - -void parseCSL(const char *csl, string_list *list) { +void parse_csl(const char *csl, string_list *list) { if (csl != NULL) { char *buf = strdup(csl); char *finder = strtok(buf, ",");
--- a/src/arguments.h Sat Jul 04 12:09:37 2026 +0200 +++ b/src/arguments.h Sat Jul 04 12:28:16 2026 +0200 @@ -34,10 +34,9 @@ extern "C" { #endif -int checkArgument(const char*, const char*); -bool checkParamOpt(int*); -bool registerArgument(int*, int); -void parseCSL(const char*, string_list*); +int argument_check(const char*, const char*); +bool argument_register(int*, int); +void parse_csl(const char*, string_list*); #ifdef _cplusplus }
--- a/src/cline.c Sat Jul 04 12:09:37 2026 +0200 +++ b/src/cline.c Sat Jul 04 12:28:16 2026 +0200 @@ -34,7 +34,7 @@ #include "arguments.h" #include "regex_parser.h" -static void printHelpText() { +static void print_help() { printf( "\nUsage:" "\n cline [Options] [Directories...]" @@ -89,36 +89,36 @@ static int exit_with_help(settings *settings, int code) { printf("cline - Version: " VERSION "\n"); - printHelpText(); + print_help(); destroy_settings(settings); return code; } static void normalize_excluded_dirs(settings *settings) { /* normalize all paths */ - for (size_t i = 0 ; i < settings->excludeDirs->count ; i++) { - char *arg = strdup(settings->excludeDirs->items[i]); + for (size_t i = 0 ; i < settings->exclude_dirs->count ; i++) { + char *arg = strdup(settings->exclude_dirs->items[i]); if (strpbrk(arg, "/\\") == NULL) { /* do not normalize names */ - settings->excludeDirs->items[i] = arg; + settings->exclude_dirs->items[i] = arg; } else { size_t arglen = strlen(arg); /* fix file separators */ - char fs = settings->fileSeparator; - char badfs = settings->fileSeparator == '/' ? '\\' : '/'; + char fs = FILE_SEPARATOR; + char badfs = FILE_SEPARATOR == '/' ? '\\' : '/'; for (size_t j = 0 ; j < arglen ; j++) { if (arg[j] == badfs) { arg[j] = fs; } } /* make path absolute */ - settings->excludeDirs->items[i] = make_path_absolute(arg); + settings->exclude_dirs->items[i] = make_path_absolute(arg); free(arg); } } /* tell the string list to free the items */ - settings->excludeDirs->free_item = free; + settings->exclude_dirs->free_item = free; } static const char *sepline_double = "===============================================================================\n"; @@ -145,8 +145,8 @@ for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRmvVbeEicdD"); - int paropt = 0; + int argflags = argument_check(argv[t], "hsSrRmvVbeEicdD"); + int paropt = 0; /* checks if no more than one opt with arg is combined */ /* h */ if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { @@ -154,7 +154,7 @@ } /* s */ if ((argflags & 2) > 0) { - if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { + if (paropt++ || argument_register(&checked, 2)) { return exit_with_help(settings, 1); } t++; @@ -165,7 +165,7 @@ } /* S */ if ((argflags & 4) > 0) { - if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { + if (paropt++ || argument_register(&checked, 4)) { return exit_with_help(settings, 1); } t++; @@ -176,17 +176,17 @@ } /* r, R */ if ((argflags & 24) > 0) { - if (registerArgument(&checked, 24)) { + if (argument_register(&checked, 24)) { return exit_with_help(settings, 1); } settings->recursive = true; } /* m */ if ((argflags & 32) > 0) { - if (registerArgument(&checked, 32)) { + if (argument_register(&checked, 32)) { return exit_with_help(settings, 1); } - settings->matchesOnly = true; + settings->matches_only = true; } /* v */ if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { @@ -194,14 +194,14 @@ } /* V */ if ((argflags & 128) > 0) { - if (registerArgument(&checked, 128)) { + if (argument_register(&checked, 128)) { return exit_with_help(settings, 1); } settings->verbose = false; } /* b */ if ((argflags & 256) > 0) { - if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { + if (paropt++ || argument_register(&checked, 256)) { return exit_with_help(settings, 1); } t++; @@ -209,20 +209,20 @@ return exit_with_help(settings, 1); } if (strcasecmp(argv[t], "ignore") == 0) { - settings->bfileHeuristics->level = BFILE_IGNORE; + settings->bfile->level = BFILE_IGNORE; } else if (strcasecmp(argv[t], "low") == 0) { - settings->bfileHeuristics->level = BFILE_LOW_ACCURACY; + settings->bfile->level = BFILE_LOW_ACCURACY; } else if (strcasecmp(argv[t], "medium") == 0) { - settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY; + settings->bfile->level = BFILE_MEDIUM_ACCURACY; } else if (strcasecmp(argv[t], "high") == 0) { - settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY; + settings->bfile->level = BFILE_HIGH_ACCURACY; } else { return exit_with_help(settings, 1); } } /* e */ if ((argflags & 512) > 0) { - if (!checkParamOpt(&paropt) || t + 2 >= argc) { + if (paropt++ || t + 2 >= argc) { return exit_with_help(settings, 1); } t++; add_string(settings->regex->pattern_list, argv[t]); @@ -231,7 +231,7 @@ /* E */ if ((argflags & 1024) > 0) { t++; - if (!checkParamOpt(&paropt) || t >= argc) { + if (paropt++ || t >= argc) { return exit_with_help(settings, 1); } add_string(settings->regex->pattern_list, argv[t]); @@ -247,7 +247,7 @@ } /* c */ if ((argflags & 4096) > 0) { - if (registerArgument(&checked, 4096)) { + if (argument_register(&checked, 4096)) { return exit_with_help(settings, 1); } settings->count_chars = true; @@ -255,21 +255,21 @@ } /* d */ if ((argflags & 8192) > 0) { - if (registerArgument(&checked, 8192)) { + if (argument_register(&checked, 8192)) { return exit_with_help(settings, 1); } /* ignored together with -V */ if ((checked & 128) == 0) { - settings->dirsOnly = true; + settings->dirs_only = true; } } /* D */ if ((argflags & 16384) > 0) { t++; - if (!checkParamOpt(&paropt) || t >= argc) { + if (paropt++ || t >= argc) { return exit_with_help(settings, 1); } - add_string(settings->excludeDirs, argv[t]); + add_string(settings->exclude_dirs, argv[t]); } if (argflags == 0) { /* SHORTCUTS */ @@ -295,8 +295,8 @@ } /* Find tokens */ - parseCSL(includeSuffix, settings->includeSuffixes); - parseCSL(excludeSuffix, settings->excludeSuffixes); + parse_csl(includeSuffix, settings->include_suffixes); + parse_csl(excludeSuffix, settings->exclude_suffixes); /* Compiler regular expressions, if any specified */ if (!regex_compile_all(settings->regex)) { @@ -323,7 +323,7 @@ output = new_string_list(); output->free_item = free; } - scanDirectory((scanner){directories->items[t], 0}, + scan_dir((scanner){directories->items[t], 0}, settings, output, result); total += result->result; if (settings->verbose) {
--- a/src/scanner.c Sat Jul 04 12:09:37 2026 +0200 +++ b/src/scanner.c Sat Jul 04 12:28:16 2026 +0200 @@ -88,7 +88,7 @@ struct filelist *next; }; -static bool testSuffix(const char *filename, string_list *list) { +static bool test_suffix(const char *filename, string_list *list) { bool ret = false; size_t tokenlen, fnamelen = strlen(filename); for (size_t t = 0 ; t < list->count ; t++) { @@ -104,8 +104,8 @@ return ret; } -static void addResultPerExtension(scanresult_ext *result, - const char *ext, unsigned value) { +static void add_result_per_ext(scanresult_ext *result, + const char *ext, unsigned value) { if (!result) return; if (!ext) ext = "w/o"; @@ -157,7 +157,7 @@ free(result); } -static struct filelist *buildFileList(scanner scanner, settings *settings) { +static struct filelist *filelist_create(scanner scanner) { struct filelist *list = NULL; DIR *dirf; @@ -188,8 +188,8 @@ size_t dirnamelen = strlen(scanner.dir); char *filename = malloc(2 + dirnamelen + newentry->displayname_len); memcpy(filename, scanner.dir, dirnamelen); - if (filename[dirnamelen - 1] != settings->fileSeparator) { - filename[dirnamelen++] = settings->fileSeparator; + if (filename[dirnamelen - 1] != FILE_SEPARATOR) { + filename[dirnamelen++] = FILE_SEPARATOR; } memcpy(filename+dirnamelen, entry->d_name, newentry->displayname_len); filename[dirnamelen+newentry->displayname_len] = 0; @@ -234,13 +234,13 @@ } static bool is_dir_excluded(settings *settings, const char *dir) { - const string_list * const list = settings->excludeDirs; + const string_list * const list = settings->exclude_dirs; for (size_t i = 0 ; i < list->count ; i++) { /* determine if the list item is a path or a name */ - if (strchr(list->items[i], settings->fileSeparator) == NULL) { + if (strchr(list->items[i], FILE_SEPARATOR) == NULL) { /* compare only the name */ - const char *dirpart = strrchr(dir, settings->fileSeparator); + const char *dirpart = strrchr(dir, FILE_SEPARATOR); if (dirpart == NULL) { dirpart = dir; } else { @@ -262,7 +262,7 @@ return false; } -void scanDirectory(scanner scnr, settings *settings, +void scan_dir(scanner scnr, settings *settings, string_list *output, scanresult *result) { result->result = 0; @@ -270,7 +270,7 @@ char *outbuf; const char *result_type = settings->count_chars ? "chars" : "lines"; - struct filelist *filelist = buildFileList(scnr, settings); + struct filelist *filelist = filelist_create(scnr); while (filelist != NULL) { @@ -279,7 +279,7 @@ if (S_ISDIR(filelist->st_mode)) { if (settings->recursive) { if (is_dir_excluded(settings, filelist->filename)) { - if (!settings->matchesOnly && settings->verbose) { + if (!settings->matches_only && settings->verbose) { /* Print hint */ outbuf = malloc(81); snprintf(outbuf, 81, "%*s%*s%19s\n", @@ -296,12 +296,12 @@ if (settings->verbose) { recoutput = new_string_list(); } - scanDirectory( + scan_dir( (scanner) {filelist->filename, scnr.spaces+1}, settings, recoutput, &recresult); result->result += recresult.result; if (settings->verbose && - (!settings->matchesOnly || recresult.result > 0)) { + (!settings->matches_only || recresult.result > 0)) { outbuf = malloc(81); snprintf(outbuf, 81, "%*s/%*s%13u %s\n", filelist->displayname_len+scnr.spaces, filelist->displayname, @@ -315,7 +315,7 @@ destroy_string_list(recoutput); } } - } else if (!settings->matchesOnly && settings->verbose) { + } else if (!settings->matches_only && settings->verbose) { outbuf = malloc(81); snprintf(outbuf, 81, "%*s\n", filelist->displayname_len+scnr.spaces, @@ -323,14 +323,14 @@ add_string(output, outbuf); } } else { - if ((settings->includeSuffixes->count == 0 - || testSuffix(filelist->displayname, settings->includeSuffixes)) - && !testSuffix(filelist->displayname, settings->excludeSuffixes)) { + if ((settings->include_suffixes->count == 0 + || test_suffix(filelist->displayname, settings->include_suffixes)) + && !test_suffix(filelist->displayname, settings->exclude_suffixes)) { /* Count */ unsigned res_value = 0; bfile = false; - bfile_reset(settings->bfileHeuristics); + bfile_reset(settings->bfile); regex_parser_reset(settings->regex); char line_buffer[MAX_LINELENGTH + 1]; unsigned line_buffer_pos = 0; @@ -344,7 +344,7 @@ do { a = fgetc(file); - bfile = bfile_check(settings->bfileHeuristics, a); + bfile = bfile_check(settings->bfile, a); /* ignore carriage return completely */ if (a == 13) continue; @@ -381,7 +381,7 @@ /* Print and sum line count */ if (bfile) { if (settings->verbose && - !settings->matchesOnly && !settings->dirsOnly) { + !settings->matches_only && !settings->dirs_only) { outbuf = malloc(81); snprintf(outbuf, 81, "%*s%*s%19s\n", filelist->displayname_len+scnr.spaces, @@ -390,9 +390,9 @@ add_string(output, outbuf); } } else { - addResultPerExtension(result->ext, filelist->ext, res_value); + add_result_per_ext(result->ext, filelist->ext, res_value); result->result += res_value; - if (settings->verbose && !settings->dirsOnly) { + if (settings->verbose && !settings->dirs_only) { outbuf = malloc(81); snprintf(outbuf, 81, "%*s%*s%13u %s\n", filelist->displayname_len+scnr.spaces, @@ -408,7 +408,7 @@ } } else { if (settings->verbose && - !settings->matchesOnly && !settings->dirsOnly) { + !settings->matches_only && !settings->dirs_only) { /* Print hint */ outbuf = malloc(81); snprintf(outbuf, 81, "%*s%*s%19s\n", @@ -430,11 +430,7 @@ char *make_path_absolute(const char *path) { static const char *cwd = NULL; static size_t cwdlen = 0; -#ifdef _WIN32 - static char fs = '\\'; -#else - static char fs = '/'; -#endif /* _WIN32 */ + static const char fs = FILE_SEPARATOR; char *abspath; if (path_is_relative(path)) { if (cwdlen == 0) {
--- a/src/scanner.h Sat Jul 04 12:09:37 2026 +0200 +++ b/src/scanner.h Sat Jul 04 12:28:16 2026 +0200 @@ -51,7 +51,7 @@ extern "C" { #endif -void scanDirectory(scanner scanner, settings *settings, +void scan_dir(scanner scanner, settings *settings, string_list *output, scanresult *result); scanresult *new_scanresult(settings *settings);
--- a/src/settings.c Sat Jul 04 12:09:37 2026 +0200 +++ b/src/settings.c Sat Jul 04 12:28:16 2026 +0200 @@ -29,23 +29,18 @@ settings *new_settings() { settings *s = malloc(sizeof(settings)); if (s != NULL) { - #ifdef _WIN32 - s->fileSeparator = '\\'; - #else - s->fileSeparator = '/'; - #endif /* _WIN32 */ s->recursive = false; - s->matchesOnly = false; - s->includeSuffixes = new_string_list(); - s->excludeSuffixes = new_string_list(); - s->excludeDirs = new_string_list(); + s->matches_only = false; + s->include_suffixes = new_string_list(); + s->exclude_suffixes = new_string_list(); + s->exclude_dirs = new_string_list(); s->verbose = true; - s->bfileHeuristics = new_bfile_heuristics(); + s->bfile = new_bfile_heuristics(); s->confusing_lnlen = false; s->regex = new_regex_parser(); s->individual_sums = false; s->count_chars = false; - s->dirsOnly = false; + s->dirs_only = false; } return s; @@ -53,9 +48,9 @@ void destroy_settings(settings *settings) { destroy_regex_parser(settings->regex); - destroy_string_list(settings->includeSuffixes); - destroy_string_list(settings->excludeSuffixes); - destroy_string_list(settings->excludeDirs); - destroy_bfile_heuristics(settings->bfileHeuristics); + destroy_string_list(settings->include_suffixes); + destroy_string_list(settings->exclude_suffixes); + destroy_string_list(settings->exclude_dirs); + destroy_bfile_heuristics(settings->bfile); free(settings); }
--- a/src/settings.h Sat Jul 04 12:09:37 2026 +0200 +++ b/src/settings.h Sat Jul 04 12:28:16 2026 +0200 @@ -27,27 +27,31 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ -#include "stdinc.h" #include "string_list.h" #include "bfile_heuristics.h" #include "regex_parser.h" typedef struct { - string_list *includeSuffixes; - string_list *excludeSuffixes; - string_list *excludeDirs; + string_list *include_suffixes; + string_list *exclude_suffixes; + string_list *exclude_dirs; regex_parser *regex; - bfile_heuristics *bfileHeuristics; - char fileSeparator; + bfile_heuristics *bfile; bool recursive; - bool matchesOnly; + bool matches_only; bool verbose; bool confusing_lnlen; /* this flag is set by the scanner */ bool individual_sums; bool count_chars; - bool dirsOnly; + bool dirs_only; } settings; +#ifdef _WIN32 +#define FILE_SEPARATOR '\\' +#else +#define FILE_SEPARATOR '/' +#endif /* _WIN32 */ + #ifdef _cplusplus extern "C" { #endif
--- a/src/string_list.c Sat Jul 04 12:09:37 2026 +0200 +++ b/src/string_list.c Sat Jul 04 12:28:16 2026 +0200 @@ -33,13 +33,13 @@ } string_list *new_string_list() { - string_list *stringList = malloc(sizeof(string_list)); - stringList->count = 0; - stringList->capacity = 32; - stringList->items = calloc(stringList->capacity, sizeof(char*)); - stringList->free_item = do_not_free; + string_list *list = malloc(sizeof(string_list)); + list->count = 0; + list->capacity = 32; + list->items = calloc(list->capacity, sizeof(char*)); + list->free_item = do_not_free; - return stringList; + return list; } void destroy_string_list(string_list *list) { @@ -60,11 +60,11 @@ list->items[list->count++] = item; return; } - size_t newCapacity = list->capacity * 2; + size_t new_cap = list->capacity * 2; char **reallocated_list = - realloc(list->items, sizeof(char*) * newCapacity); + realloc(list->items, sizeof(char*) * new_cap); assert(reallocated_list != NULL); - list->capacity = newCapacity; + list->capacity = new_cap; list->items = reallocated_list; list->items[list->count++] = item; }