Cleanup config.h

This commit is contained in:
Alexander Batalov 2022-06-18 16:02:36 +03:00
parent 2c5f3c1337
commit fac4d57b3d
2 changed files with 15 additions and 16 deletions

View File

@ -11,10 +11,20 @@
#include <stdlib.h>
#include <string.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)
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;

View File

@ -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);