1
0
Fork 0
forked from len0rd/rockbox

unify pointers to value for configfile, and add TYPE_BOOL type, used by

pictureflow

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19786 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andrew Mahone 2009-01-17 22:53:12 +00:00
parent 2fecb713ea
commit 0b41f0599f
16 changed files with 120 additions and 91 deletions

View file

@ -59,15 +59,21 @@ int configfile_save(const char *filename, struct configdata *cfg,
/* pre-allocate 10 bytes for INT */
rb->fdprintf(fd, "%s: %10d\n",
cfg[i].name,
*cfg[i].val);
*cfg[i].int_p);
break;
case TYPE_BOOL:
rb->fdprintf(fd, "%s: 10%d\n",
cfg[i].name,
(int)*cfg[i].bool_p);
break;
case TYPE_ENUM:
rb->fdprintf(fd, "%s: %s\n",
cfg[i].name,
cfg[i].values[*cfg[i].val]);
cfg[i].values[*cfg[i].int_p]);
break;
case TYPE_STRING:
rb->fdprintf(fd, "%s: %s\n",
cfg[i].name,
@ -116,17 +122,22 @@ int configfile_load(const char *filename, struct configdata *cfg,
tmp = rb->atoi(val);
/* Only set it if it's within range */
if(tmp >= cfg[i].min && tmp <= cfg[i].max)
*cfg[i].val = tmp;
*cfg[i].int_p = tmp;
break;
case TYPE_BOOL:
tmp = rb->atoi(val);
*cfg[i].bool_p = (bool)tmp;
break;
case TYPE_ENUM:
for(j = 0;j < cfg[i].max;j++) {
if(!rb->strcmp(cfg[i].values[j], val)) {
*cfg[i].val = j;
*cfg[i].int_p = j;
}
}
break;
case TYPE_STRING:
rb->strncpy(cfg[i].string, val, cfg[i].max);
break;

View file

@ -24,6 +24,7 @@
#define TYPE_INT 1
#define TYPE_ENUM 2
#define TYPE_STRING 3
#define TYPE_BOOL 4
struct configdata
{
@ -31,12 +32,14 @@ struct configdata
int min; /* Min value for integers, should be 0 for enums */
int max; /* Max value for enums and integers,
buffer size for strings */
int *val; /* Pointer to integer/enum value,
NULL if the item is a string */
union
{
int *int_p;
bool *bool_p;
char *string;
}; /* Pointer to value, a union of the possible types */
char *name; /* Pointer to the name of the item */
char **values; /* List of strings for enums, NULL if not enum */
char *string; /* Pointer to a string buffer if the item is a string,
NULL otherwise */
};
/* configfile_save - Given configdata entries this function will