src/scanner.c

changeset 103
31fa205db85a
parent 102
665b60727a89
--- 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) {

mercurial