LCOV - code coverage report
Current view: top level - src - init_config.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 38 38
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "precizer.h"
       2              : 
       3              : #if 0
       4              : #include <locale.h>
       5              : #endif
       6              : 
       7              : /**
       8              :  *
       9              :  * The structure Config where all runtime settings will be stored.
      10              :  * Initialization the structure elements by zero.
      11              :  *
      12              :  */
      13          204 : void init_config(void)
      14              : {
      15              : 
      16              :         // Fill out with zeroes
      17          204 :         memset(config,0,sizeof(Config));
      18              : 
      19              :         // Max available size of a path
      20          204 :         config->running_dir_size = 0;
      21              : 
      22              :         // Absolute path name of the working directory
      23              :         // A directory where the program was executed
      24          204 :         config->running_dir = NULL;
      25              : 
      26              :         // Show progress bar
      27          204 :         config->progress = false;
      28              : 
      29              :         // Force update of the database
      30          204 :         config->force = false;
      31              : 
      32              :         // Additional output for debugging
      33          204 :         config->verbose = false;
      34              : 
      35              :         // Force update of the database with new,
      36              :         // changed or deleted files. This is special
      37              :         // protection against accidental deletion of
      38              :         // information from the database.
      39          204 :         config->update = false;
      40              : 
      41              :         // Parameter to compare database
      42          204 :         config->compare = false;
      43              : 
      44              :         // An array of paths to traverse
      45          204 :         config->paths = NULL;
      46              : 
      47              :         // The pointer to the primary database
      48          204 :         config->db = NULL;
      49              : 
      50              :         /// The flags parameter to sqlite3_open_v2()
      51              :         /// must include, at a minimum, one of the
      52              :         /// following flag combinations:
      53              :         ///   - SQLITE_OPEN_READONLY
      54              :         ///   - SQLITE_OPEN_READWRITE
      55              :         ///   - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
      56              :         /// Default value: RO
      57          204 :         config->sqlite_open_flag = SQLITE_OPEN_READONLY;
      58              : 
      59              :         // The path of DB file
      60          204 :         config->db_primary_file_path = NULL;
      61              : 
      62              :         // The name of DB file
      63          204 :         config->db_file_name = NULL;
      64              : 
      65              :         // Pointers to the array with database paths
      66          204 :         config->db_file_paths = NULL;
      67              : 
      68              :         // Pointers to the array with database file names
      69          204 :         config->db_file_names = NULL;
      70              : 
      71              :         /// Allow or disallow database table
      72              :         /// initialization. True by default
      73          204 :         config->db_initialize_tables = true;
      74              : 
      75              :         /// Flag indicating whether the primary database file exists
      76          204 :         config->db_primary_file_exists = false;
      77              : 
      78              :         // The flag means that the DB already exists
      79              :         // and not empty
      80          204 :         config->db_contains_data = false;
      81              : 
      82              :         // Must be specified additionally in order
      83              :         // to remove from the database mention of
      84              :         // files that matches the regular expression
      85              :         // passed through the ignore option(s)
      86              :         // This is special protection against accidental
      87              :         // deletion of information from the database.
      88          204 :         config->db_clean_ignored = false;
      89              : 
      90              :         /// Select database validation level: 'quick' for basic
      91              :         /// structure check, 'full' (default) for comprehensive
      92              :         /// integrity verification
      93          204 :         config->db_check_level = FULL;
      94              : 
      95              :         // Flag that reflects the presence of any changes
      96              :         // since the last research
      97          204 :         config->db_primary_file_modified = false;
      98              : 
      99              :         /// The "Warning about using the update option has already been shown"
     100              :         /// option prevents duplicate notifications from being displayed
     101          204 :         config->the_update_warning_has_already_been_shown = false;
     102              : 
     103              :         // Recursion depth limit. The depth of the traversal,
     104              :         // numbered from 0 to N, where a file could be found.
     105              :         // Representing the maximum of the starting
     106              :         // point (from root) of the traversal.
     107              :         // The root itself is numbered 0
     108          204 :         config->maxdepth = -1;
     109              : 
     110              :         // Ignore those relative paths
     111              :         // The string array of PCRE2 regular expressions
     112          204 :         config->ignore = NULL;
     113              : 
     114              :         // Include those relative paths even if
     115              :         // they were excluded via the --ignore option
     116              :         // The string array of PCRE2 regular expressions
     117          204 :         config->include = NULL;
     118              : 
     119              :         // Relative paths whose checksums must never be recalculated
     120              :         // after the initial write. PCRE2 regular expressions.
     121          204 :         config->lock_checksum = NULL;
     122              : 
     123              :         // Force a full rehash for checksum-locked entries
     124          204 :         config->rehash_locked = false;
     125              : 
     126              :         // Perform a trial run with no changes made
     127          204 :         config->dry_run = false;
     128              : 
     129              :         // Define the comparison string
     130          204 :         const char *compare_string = "true";
     131              : 
     132              :         // Retrieve the value of the "TESTING" environment variable,
     133              :         // Validate if the environment variable TESTING exists
     134              :         // and if it match to "true" display ONLY testing
     135              :         // messages for System Testing purposes.
     136          204 :         const char *env_var = getenv("TESTING");
     137              : 
     138              :         // Check if it exists and compare it to "true"
     139          204 :         if(env_var != NULL && strncasecmp(env_var,compare_string,strlen(compare_string)) == 0)
     140              :         {
     141              :                 // Global variable
     142          164 :                 rational_logger_mode = TESTING;
     143              :         } else {
     144              :                 // Global variable, default value
     145           40 :                 rational_logger_mode = REGULAR;
     146              :         }
     147              : 
     148              :         /// This option prevents directory traversal from descending into
     149              :         /// directories that have a different device number than the file
     150              :         /// from  which the descent began
     151          204 :         config->start_device_only = false;
     152              : 
     153              :         /// Track both file metadata (created/modified dates) and size changes
     154              :         /// for change detection. Out of the box, only size changes trigger
     155              :         /// a rescan. When enabled, any update to timestamps or file size
     156              :         /// will force a rescan and update the checksum in the database.
     157          204 :         config->watch_timestamps = false;
     158              : 
     159              : #if 0
     160              :         if(NULL != setlocale(LC_ALL,""))
     161              :         {
     162              :                 slog(TRACE,"Enable locale support\n");
     163              :         } else {
     164              :                 slog(TRACE,"Failed to set locale\n");
     165              :         }
     166              : #endif
     167              : 
     168          204 :         slog(TRACE,"Configuration initialized\n");
     169          204 : }
        

Generated by: LCOV version 2.0-1