Cleanup config.h
This commit is contained in:
parent
2c5f3c1337
commit
fac4d57b3d
|
@ -11,10 +11,20 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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.
|
// Last section key read from .INI file.
|
||||||
//
|
//
|
||||||
// 0x518224
|
// 0x518224
|
||||||
char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH] = "unknown";
|
static char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH] = "unknown";
|
||||||
|
|
||||||
// 0x42BD90
|
// 0x42BD90
|
||||||
bool configInit(Config* config)
|
bool configInit(Config* config)
|
||||||
|
@ -361,7 +371,7 @@ bool configWrite(Config* config, const char* filePath, bool isDb)
|
||||||
// added to the config, or `false` otherwise.
|
// added to the config, or `false` otherwise.
|
||||||
//
|
//
|
||||||
// 0x42C4BC
|
// 0x42C4BC
|
||||||
bool configParseLine(Config* config, char* string)
|
static bool configParseLine(Config* config, char* string)
|
||||||
{
|
{
|
||||||
char* pch;
|
char* pch;
|
||||||
|
|
||||||
|
@ -411,7 +421,7 @@ bool configParseLine(Config* config, char* string)
|
||||||
// Both key and value are trimmed.
|
// Both key and value are trimmed.
|
||||||
//
|
//
|
||||||
// 0x42C594
|
// 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) {
|
if (string == NULL || key == NULL || value == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -446,7 +456,7 @@ bool configParseKeyValue(char* string, char* key, char* value)
|
||||||
// otherwise.
|
// otherwise.
|
||||||
//
|
//
|
||||||
// 0x42C638
|
// 0x42C638
|
||||||
bool configEnsureSectionExists(Config* config, const char* sectionKey)
|
static bool configEnsureSectionExists(Config* config, const char* sectionKey)
|
||||||
{
|
{
|
||||||
if (config == NULL || sectionKey == NULL) {
|
if (config == NULL || sectionKey == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -472,7 +482,7 @@ bool configEnsureSectionExists(Config* config, const char* sectionKey)
|
||||||
// Removes leading and trailing whitespace from the specified string.
|
// Removes leading and trailing whitespace from the specified string.
|
||||||
//
|
//
|
||||||
// 0x42C698
|
// 0x42C698
|
||||||
bool configTrimString(char* string)
|
static bool configTrimString(char* string)
|
||||||
{
|
{
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
|
11
src/config.h
11
src/config.h
|
@ -3,11 +3,6 @@
|
||||||
|
|
||||||
#include "dictionary.h"
|
#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.
|
// A representation of .INI file.
|
||||||
//
|
//
|
||||||
// It's implemented as a [Dictionary] whos keys are section names 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**).
|
// key-pair values, and it's values are pointers to strings (char**).
|
||||||
typedef Dictionary ConfigSection;
|
typedef Dictionary ConfigSection;
|
||||||
|
|
||||||
extern char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH];
|
|
||||||
|
|
||||||
bool configInit(Config* config);
|
bool configInit(Config* config);
|
||||||
void configFree(Config* config);
|
void configFree(Config* config);
|
||||||
bool configParseCommandLineArguments(Config* config, int argc, char** argv);
|
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 configSetInt(Config* config, const char* sectionKey, const char* key, int value);
|
||||||
bool configRead(Config* config, const char* filePath, bool isDb);
|
bool configRead(Config* config, const char* filePath, bool isDb);
|
||||||
bool configWrite(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 configGetDouble(Config* config, const char* sectionKey, const char* key, double* valuePtr);
|
||||||
bool configSetDouble(Config* config, const char* sectionKey, const char* key, double value);
|
bool configSetDouble(Config* config, const char* sectionKey, const char* key, double value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue