summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-01-17 22:53:12 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-01-17 22:53:12 +0000
commit0b41f0599f62ec9099197bbe6f4dd7144cebe0df (patch)
tree927f23ea1a943777baa0e7cf1f8070608c3847d7 /apps/plugins/lib
parent2fecb713ea07f06b5219a75c95909b986c2468a5 (diff)
downloadrockbox-0b41f0599f62ec9099197bbe6f4dd7144cebe0df.zip
rockbox-0b41f0599f62ec9099197bbe6f4dd7144cebe0df.tar.gz
rockbox-0b41f0599f62ec9099197bbe6f4dd7144cebe0df.tar.bz2
rockbox-0b41f0599f62ec9099197bbe6f4dd7144cebe0df.tar.xz
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
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/configfile.c25
-rw-r--r--apps/plugins/lib/configfile.h11
2 files changed, 25 insertions, 11 deletions
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c
index 419109f..063efdd 100644
--- a/apps/plugins/lib/configfile.c
+++ b/apps/plugins/lib/configfile.c
@@ -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;
diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h
index 0804a59..5dc3173 100644
--- a/apps/plugins/lib/configfile.h
+++ b/apps/plugins/lib/configfile.h
@@ -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