Avoid confusion with edb. Fix null string item problem.

SVN revision: 13882
This commit is contained in:
Kim Woelders 2005-03-24 08:37:27 +00:00
parent 5cdc4733a5
commit 63a4832d3d
1 changed files with 24 additions and 26 deletions

View File

@ -44,7 +44,7 @@ typedef struct
#define E_DB_File ECfgFile #define E_DB_File ECfgFile
static ECfgFile * static ECfgFile *
e_db_open(const char *name) e16_db_open(const char *name)
{ {
ECfgFile *ecf; ECfgFile *ecf;
FILE *fs; FILE *fs;
@ -66,7 +66,7 @@ e_db_open(const char *name)
} }
static ECfgFile * static ECfgFile *
e_db_open_read(const char *name) e16_db_open_read(const char *name)
{ {
ECfgFile *ecf; ECfgFile *ecf;
FILE *fs; FILE *fs;
@ -111,7 +111,7 @@ e_db_open_read(const char *name)
} }
static void static void
e_db_close(ECfgFile * ecf) e16_db_close(ECfgFile * ecf)
{ {
int i; int i;
@ -130,7 +130,7 @@ e_db_close(ECfgFile * ecf)
} }
static void static void
e_db_flush(void) e16_db_flush(void)
{ {
} }
@ -147,7 +147,7 @@ ECfgFileFindValue(ECfgFile * ecf, const char *key)
} }
static int static int
e_db_int_get(ECfgFile * ecf, const char *key, int *pint) e16_db_int_get(ECfgFile * ecf, const char *key, int *pint)
{ {
const char *value; const char *value;
@ -162,7 +162,7 @@ e_db_int_get(ECfgFile * ecf, const char *key, int *pint)
} }
static int static int
e_db_float_get(ECfgFile * ecf, const char *key, float *pflt) e16_db_float_get(ECfgFile * ecf, const char *key, float *pflt)
{ {
const char *value; const char *value;
@ -177,7 +177,7 @@ e_db_float_get(ECfgFile * ecf, const char *key, float *pflt)
} }
static char * static char *
e_db_str_get(ECfgFile * ecf, const char *key) e16_db_str_get(ECfgFile * ecf, const char *key)
{ {
const char *value; const char *value;
@ -189,21 +189,21 @@ e_db_str_get(ECfgFile * ecf, const char *key)
} }
static void static void
e_db_int_set(ECfgFile * ecf, const char *key, int value) e16_db_int_set(ECfgFile * ecf, const char *key, int value)
{ {
fprintf(ecf->fs, "%s = %d\n", key, value); fprintf(ecf->fs, "%s = %d\n", key, value);
} }
static void static void
e_db_float_set(ECfgFile * ecf, const char *key, float value) e16_db_float_set(ECfgFile * ecf, const char *key, float value)
{ {
fprintf(ecf->fs, "%s = %f\n", key, value); fprintf(ecf->fs, "%s = %f\n", key, value);
} }
static void static void
e_db_str_set(ECfgFile * ecf, const char *key, const char *value) e16_db_str_set(ECfgFile * ecf, const char *key, const char *value)
{ {
fprintf(ecf->fs, "%s = %s\n", key, value); fprintf(ecf->fs, "%s = %s\n", key, (value) ? value : "");
} }
/* /*
@ -233,22 +233,22 @@ CfgItemLoad(E_DB_File * edf, const char *prefix, const CfgItem * ci)
switch (ci->type) switch (ci->type)
{ {
case ITEM_TYPE_BOOL: case ITEM_TYPE_BOOL:
if (!edf || !e_db_int_get(edf, name, &my_int)) if (!edf || !e16_db_int_get(edf, name, &my_int))
my_int = (ci->dflt) ? 1 : 0; my_int = (ci->dflt) ? 1 : 0;
*((char *)ci->ptr) = my_int; *((char *)ci->ptr) = my_int;
break; break;
case ITEM_TYPE_INT: case ITEM_TYPE_INT:
if (!edf || !e_db_int_get(edf, name, &my_int)) if (!edf || !e16_db_int_get(edf, name, &my_int))
my_int = ci->dflt; my_int = ci->dflt;
*((int *)ci->ptr) = my_int; *((int *)ci->ptr) = my_int;
break; break;
case ITEM_TYPE_FLOAT: case ITEM_TYPE_FLOAT:
if (!edf || !e_db_float_get(edf, name, &my_float)) if (!edf || !e16_db_float_get(edf, name, &my_float))
my_float = ci->dflt; my_float = ci->dflt;
*((float *)ci->ptr) = my_float; *((float *)ci->ptr) = my_float;
break; break;
case ITEM_TYPE_STRING: case ITEM_TYPE_STRING:
s = (edf) ? e_db_str_get(edf, name) : NULL; s = (edf) ? e16_db_str_get(edf, name) : NULL;
*((char **)ci->ptr) = s; *((char **)ci->ptr) = s;
break; break;
} }
@ -275,19 +275,17 @@ CfgItemSave(E_DB_File * edf, const char *prefix, const CfgItem * ci)
switch (ci->type) switch (ci->type)
{ {
case ITEM_TYPE_BOOL: case ITEM_TYPE_BOOL:
e_db_int_set(edf, name, *((char *)ci->ptr)); e16_db_int_set(edf, name, *((char *)ci->ptr));
break; break;
case ITEM_TYPE_INT: case ITEM_TYPE_INT:
e_db_int_set(edf, name, *((int *)ci->ptr)); e16_db_int_set(edf, name, *((int *)ci->ptr));
break; break;
case ITEM_TYPE_FLOAT: case ITEM_TYPE_FLOAT:
e_db_float_set(edf, name, *((float *)ci->ptr)); e16_db_float_set(edf, name, *((float *)ci->ptr));
break; break;
case ITEM_TYPE_STRING: case ITEM_TYPE_STRING:
s = *(char **)(ci->ptr); s = *(char **)(ci->ptr);
if (!s) e16_db_str_set(edf, name, s);
break;
e_db_str_set(edf, name, s);
break; break;
} }
} }
@ -310,7 +308,7 @@ ConfigurationLoad(void)
memset(&Conf, 0, sizeof(EConf)); memset(&Conf, 0, sizeof(EConf));
edf = e_db_open_read(ConfigurationGetFile(buf, sizeof(buf))); edf = e16_db_open_read(ConfigurationGetFile(buf, sizeof(buf)));
/* NB! We have to assign the defaults even if it doesn't exist */ /* NB! We have to assign the defaults even if it doesn't exist */
/* Load module configs */ /* Load module configs */
@ -326,7 +324,7 @@ ConfigurationLoad(void)
ModuleListFree(pml); ModuleListFree(pml);
if (edf) if (edf)
e_db_close(edf); e16_db_close(edf);
} }
void void
@ -338,7 +336,7 @@ ConfigurationSave(void)
char buf[4096]; char buf[4096];
E_DB_File *edf; E_DB_File *edf;
edf = e_db_open(ConfigurationGetFile(buf, sizeof(buf))); edf = e16_db_open(ConfigurationGetFile(buf, sizeof(buf)));
if (edf == NULL) if (edf == NULL)
return; return;
@ -354,8 +352,8 @@ ConfigurationSave(void)
} }
ModuleListFree(pml); ModuleListFree(pml);
e_db_close(edf); e16_db_close(edf);
e_db_flush(); e16_db_flush();
} }
const CfgItem * const CfgItem *