From 8ed2a176d1dbefc541ad2cd9eb700f58d4719574 Mon Sep 17 00:00:00 2001 From: ticktock35 Date: Mon, 15 Dec 2008 00:10:01 -0500 Subject: opkg: fix option array handling git-svn-id: http://opkg.googlecode.com/svn/trunk@74 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libopkg/opkg.c b/libopkg/opkg.c index e254552..35aee1b 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -35,7 +35,7 @@ struct _opkg_t { args_t *args; opkg_conf_t *conf; - opkg_option_t *options[]; + opkg_option_t *options; }; /** Private Functions ***/ @@ -89,9 +89,14 @@ opkg_new () { opkg_t *opkg; opkg = malloc (sizeof (opkg_t)); + + opkg->args = malloc (sizeof (args_t)); args_init (opkg->args); + + opkg->conf = malloc (sizeof (opkg_conf_t)); opkg_conf_init (opkg->conf, opkg->args); - opkg_init_options_array (opkg->conf, opkg->options); + + opkg_init_options_array (opkg->conf, &opkg->options); return opkg; } @@ -106,7 +111,7 @@ void opkg_get_option (opkg_t *opkg, char *option, void **value) { int i = 0; - opkg_option_t **options = opkg->options; + opkg_option_t *options = opkg->options; /* can't store a value in a NULL pointer! */ if (!value) @@ -115,9 +120,9 @@ opkg_get_option (opkg_t *opkg, char *option, void **value) /* look up the option * TODO: this would be much better as a hash table */ - while (options[i]->name) + while (options[i].name) { - if (strcmp (options[i]->name, option) != 0) + if (strcmp (options[i].name, option) != 0) { i++; continue; @@ -125,18 +130,18 @@ opkg_get_option (opkg_t *opkg, char *option, void **value) } /* get the option */ - switch (options[i]->type) + switch (options[i].type) { case OPKG_OPT_TYPE_BOOL: - *((int *) value) = *((int *) options[i]->value); + *((int *) value) = *((int *) options[i].value); return; case OPKG_OPT_TYPE_INT: - *((int *) value) = *((int *) options[i]->value); + *((int *) value) = *((int *) options[i].value); return; case OPKG_OPT_TYPE_STRING: - *((char **)value) = strdup (options[i]->value); + *((char **)value) = strdup (options[i].value); return; } @@ -146,7 +151,7 @@ void opkg_set_option (opkg_t *opkg, char *option, void *value) { int i = 0; - opkg_option_t **options = opkg->options; + opkg_option_t *options = opkg->options; /* NULL values are not defined */ if (!value) @@ -155,31 +160,31 @@ opkg_set_option (opkg_t *opkg, char *option, void *value) /* look up the option * TODO: this would be much better as a hash table */ - while (options[i]->name) + while (options[i].name) { - if (strcmp (options[i]->name, option) != 0) + if (strcmp (options[i].name, option) == 0) { - i++; - continue; + break; } + i++; } /* set the option */ - switch (options[i]->type) + switch (options[i].type) { case OPKG_OPT_TYPE_BOOL: if (*((int *) value) == 0) - *((int *)options[i]->value) = 0; + *((int *)options[i].value) = 0; else - *((int *)options[i]->value) = 1; + *((int *)options[i].value) = 1; return; case OPKG_OPT_TYPE_INT: - *((int *) options[i]->value) = *((int *) value); + *((int *) options[i].value) = *((int *) value); return; case OPKG_OPT_TYPE_STRING: - *((char **)options[i]->value) = strdup (value); + *((char **)options[i].value) = strdup (value); return; } -- cgit v0.9.1