Sfoglia il codice sorgente

Add reference to item array parameter

Some config items may refer to other config items values for
transformations.
master
parent
commit
bff1ce5f8a
4 ha cambiato i file con 13 aggiunte e 13 eliminazioni
  1. +2
    -2
      source/ini-config.c
  2. +2
    -2
      source/ini-config.h
  3. +7
    -7
      source/types/int.c
  4. +2
    -2
      source/types/string.c

+ 2
- 2
source/ini-config.c Vedi File

@@ -28,7 +28,7 @@ void INI_ConfigLoad(INI_ConfigItem item[], const char* config_path) {
if (!item[i].type.load) {
continue;
}
item[i].type.load(&item[i], config_path);
item[i].type.load(&item[i], config_path, item);
}
}

@@ -36,7 +36,7 @@ INI_ConfigSaveResult INI_ConfigSave(INI_ConfigItem item[], const char* config_pa
uint8_t i;
int32_t problems = 0;
for (i = 0; item[i].type.size > 0; i += 1) {
int32_t result = item[i].type.save ? item[i].type.save(&item[i], config_path) : 0;
int32_t result = item[i].type.save ? item[i].type.save(&item[i], config_path, item) : 0;

if (result < 0) {
problems |= (1 << (int32_t) i);


+ 2
- 2
source/ini-config.h Vedi File

@@ -29,7 +29,7 @@ struct INI_ConfigItem;
/**
* Function for loading a config item value from file to memory.
*/
typedef void INI_ConfigTypeLoad(struct INI_ConfigItem*, const char*);
typedef void INI_ConfigTypeLoad(struct INI_ConfigItem*, const char*, void*);

/**
* Result enum for saving config items.
@@ -49,7 +49,7 @@ typedef enum {
/**
* Function for saving a config item value from memory to file.
*/
typedef INI_ConfigSaveItemResult INI_ConfigTypeSave(struct INI_ConfigItem*, const char*);
typedef INI_ConfigSaveItemResult INI_ConfigTypeSave(struct INI_ConfigItem*, const char*, void*);

/**
* Function for retrieving a config item value from the command-line to memory.


+ 7
- 7
source/types/int.c Vedi File

@@ -3,9 +3,9 @@
#define INI_CONFIG_IMPLEMENT_INT_TYPE(ID, T) \
typedef bool INI_ConfigValidate##ID(T); \
\
typedef T INI_ConfigDeserialize##ID(const char*); \
typedef T INI_ConfigDeserialize##ID(const char*, void*); \
\
typedef void INI_ConfigSerialize##ID(T, const char[128]); \
typedef void INI_ConfigSerialize##ID(T, const char[128], void*); \
\
void INI_ConfigEnsureValid##ID(INI_ConfigItem* item, T raw_value, T default_value) { \
T* dest = item->dest; \
@@ -21,7 +21,7 @@ void INI_ConfigEnsureValid##ID(INI_ConfigItem* item, T raw_value, T default_valu
*dest = raw_value; \
} \
\
void INI_ConfigLoad##ID(INI_ConfigItem* item, const char* config_path) { \
void INI_ConfigLoad##ID(INI_ConfigItem* item, const char* config_path, void* item_array) { \
static T raw_value; \
static T default_value; \
default_value = *((T*) item->default_value); \
@@ -30,18 +30,18 @@ void INI_ConfigLoad##ID(INI_ConfigItem* item, const char* config_path) { \
INI_ConfigSerialize##ID* serialize = item->transformer.serialize; \
const char serialized_default_value[128]; \
if (default_value) { \
serialize(default_value, serialized_default_value); \
serialize(default_value, serialized_default_value, item_array); \
} \
char buffer[128]; \
ini_gets(item->section, item->key, serialized_default_value, buffer, 128, config_path); \
raw_value = deserialize(buffer); \
raw_value = deserialize(buffer, item_array); \
} else { \
raw_value = ini_getl(item->section, item->key, default_value, config_path); \
} \
INI_ConfigEnsureValid##ID(item, raw_value, default_value); \
} \
\
INI_ConfigSaveItemResult INI_ConfigSave##ID(INI_ConfigItem* item, const char* config_path) { \
INI_ConfigSaveItemResult INI_ConfigSave##ID(INI_ConfigItem* item, const char* config_path, void* item_array) { \
T dest = *((T*) item->dest); \
if (item->validator) { \
INI_ConfigValidate##ID* validate = item->validator; \
@@ -53,7 +53,7 @@ INI_ConfigSaveItemResult INI_ConfigSave##ID(INI_ConfigItem* item, const char* co
if (item->transformer.deserialize && item->transformer.serialize) { \
INI_ConfigSerialize##ID* serialize = item->transformer.serialize; \
const char serialized_value[128]; \
serialize(dest, serialized_value); \
serialize(dest, serialized_value, item_array); \
if (!ini_puts(item->section, item->key, serialized_value, config_path)) { \
return -1; \
} \


+ 2
- 2
source/types/string.c Vedi File

@@ -15,13 +15,13 @@ void INI_ConfigEnsureValidString(INI_ConfigItem* item, const char* buffer) {
memcpy(item->dest, buffer, item->type.size);
}

void INI_ConfigLoadString(INI_ConfigItem* item, const char* config_path) {
void INI_ConfigLoadString(INI_ConfigItem* item, const char* config_path, void* item_array) {
char buffer[item->type.size];
ini_gets(item->section, item->key, item->default_value, buffer, (int32_t) item->type.size, config_path);
INI_ConfigEnsureValidString(item, buffer);
}

INI_ConfigSaveItemResult INI_ConfigSaveString(INI_ConfigItem* item, const char* config_path) {
INI_ConfigSaveItemResult INI_ConfigSaveString(INI_ConfigItem* item, const char* config_path, void* item_array) {
const char* dest = (const char*) item->dest;
if (item->validator) {
INI_ConfigLoadParamsStringValidator* validator = item->validator;


Caricamento…
Annulla
Salva