From fac4d57b3d20104709b9e24c0130e7bf4ea79f71 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 18 Jun 2022 16:02:36 +0300 Subject: [PATCH] Cleanup config.h --- src/config.cc | 20 +++++++++++++++----- src/config.h | 11 ----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/config.cc b/src/config.cc index e741417..04ccf4f 100644 --- a/src/config.cc +++ b/src/config.cc @@ -11,10 +11,20 @@ #include #include +#define CONFIG_FILE_MAX_LINE_LENGTH (256) + +// The initial number of sections (or key-value) pairs in the config. +#define CONFIG_INITIAL_CAPACITY (10) + +static bool configParseLine(Config* config, char* string); +static bool configParseKeyValue(char* string, char* key, char* value); +static bool configEnsureSectionExists(Config* config, const char* sectionKey); +static bool configTrimString(char* string); + // Last section key read from .INI file. // // 0x518224 -char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH] = "unknown"; +static char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH] = "unknown"; // 0x42BD90 bool configInit(Config* config) @@ -361,7 +371,7 @@ bool configWrite(Config* config, const char* filePath, bool isDb) // added to the config, or `false` otherwise. // // 0x42C4BC -bool configParseLine(Config* config, char* string) +static bool configParseLine(Config* config, char* string) { char* pch; @@ -411,7 +421,7 @@ bool configParseLine(Config* config, char* string) // Both key and value are trimmed. // // 0x42C594 -bool configParseKeyValue(char* string, char* key, char* value) +static bool configParseKeyValue(char* string, char* key, char* value) { if (string == NULL || key == NULL || value == NULL) { return false; @@ -446,7 +456,7 @@ bool configParseKeyValue(char* string, char* key, char* value) // otherwise. // // 0x42C638 -bool configEnsureSectionExists(Config* config, const char* sectionKey) +static bool configEnsureSectionExists(Config* config, const char* sectionKey) { if (config == NULL || sectionKey == NULL) { return false; @@ -472,7 +482,7 @@ bool configEnsureSectionExists(Config* config, const char* sectionKey) // Removes leading and trailing whitespace from the specified string. // // 0x42C698 -bool configTrimString(char* string) +static bool configTrimString(char* string) { if (string == NULL) { return false; diff --git a/src/config.h b/src/config.h index 4a509b4..f07880d 100644 --- a/src/config.h +++ b/src/config.h @@ -3,11 +3,6 @@ #include "dictionary.h" -#define CONFIG_FILE_MAX_LINE_LENGTH (256) - -// The initial number of sections (or key-value) pairs in the config. -#define CONFIG_INITIAL_CAPACITY (10) - // A representation of .INI file. // // It's implemented as a [Dictionary] whos keys are section names of .INI file, @@ -20,8 +15,6 @@ typedef Dictionary Config; // key-pair values, and it's values are pointers to strings (char**). typedef Dictionary ConfigSection; -extern char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH]; - bool configInit(Config* config); void configFree(Config* config); bool configParseCommandLineArguments(Config* config, int argc, char** argv); @@ -32,10 +25,6 @@ bool configGetIntList(Config* config, const char* section, const char* key, int* bool configSetInt(Config* config, const char* sectionKey, const char* key, int value); bool configRead(Config* config, const char* filePath, bool isDb); bool configWrite(Config* config, const char* filePath, bool isDb); -bool configParseLine(Config* config, char* string); -bool configParseKeyValue(char* string, char* key, char* value); -bool configEnsureSectionExists(Config* config, const char* sectionKey); -bool configTrimString(char* string); bool configGetDouble(Config* config, const char* sectionKey, const char* key, double* valuePtr); bool configSetDouble(Config* config, const char* sectionKey, const char* key, double value);