opkg: fix option array handling
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:10:01 +0000 (05:10 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:10:01 +0000 (05:10 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@74 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg.c

index e2545527a735084130c5bb65c7bc10d2a8d86c3a..35aee1becd1cc16a8f4b424c11395e9c391e3ad4 100644 (file)
@@ -35,7 +35,7 @@ struct _opkg_t
 {
   args_t *args;
   opkg_conf_t *conf;
 {
   args_t *args;
   opkg_conf_t *conf;
-  opkg_option_t *options[];
+  opkg_option_t *options;
 };
 
 /** Private Functions ***/
 };
 
 /** Private Functions ***/
@@ -89,9 +89,14 @@ opkg_new ()
 {
   opkg_t *opkg;
   opkg = malloc (sizeof (opkg_t));
 {
   opkg_t *opkg;
   opkg = malloc (sizeof (opkg_t));
+
+  opkg->args = malloc (sizeof (args_t));
   args_init (opkg->args);
   args_init (opkg->args);
+
+  opkg->conf = malloc (sizeof (opkg_conf_t));
   opkg_conf_init (opkg->conf, opkg->args);
   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;
 }
 
   return opkg;
 }
 
@@ -106,7 +111,7 @@ void
 opkg_get_option (opkg_t *opkg, char *option, void **value)
 {
   int i = 0;
 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)
 
   /* 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
    */
   /* 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;
     {
       i++;
       continue;
@@ -125,18 +130,18 @@ opkg_get_option (opkg_t *opkg, char *option, void **value)
   }
 
   /* get the option */
   }
 
   /* get the option */
-  switch (options[i]->type)
+  switch (options[i].type)
   {
   case OPKG_OPT_TYPE_BOOL:
   {
   case OPKG_OPT_TYPE_BOOL:
-    *((int *) value) = *((int *) options[i]->value);
+    *((int *) value) = *((int *) options[i].value);
     return;
 
   case OPKG_OPT_TYPE_INT:
     return;
 
   case OPKG_OPT_TYPE_INT:
-    *((int *) value) = *((int *) options[i]->value);
+    *((int *) value) = *((int *) options[i].value);
     return;
 
   case OPKG_OPT_TYPE_STRING:
     return;
 
   case OPKG_OPT_TYPE_STRING:
-    *((char **)value) = strdup (options[i]->value);
+    *((char **)value) = strdup (options[i].value);
     return;
   }
 
     return;
   }
 
@@ -146,7 +151,7 @@ void
 opkg_set_option (opkg_t *opkg, char *option, void *value)
 {
   int i = 0;
 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)
 
   /* 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
    */
   /* 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 */
   }
 
   /* set the option */
-  switch (options[i]->type)
+  switch (options[i].type)
   {
   case OPKG_OPT_TYPE_BOOL:
     if (*((int *) value) == 0)
   {
   case OPKG_OPT_TYPE_BOOL:
     if (*((int *) value) == 0)
-      *((int *)options[i]->value) = 0;
+      *((int *)options[i].value) = 0;
     else
     else
-      *((int *)options[i]->value) = 1;
+      *((int *)options[i].value) = 1;
     return;
 
   case OPKG_OPT_TYPE_INT:
     return;
 
   case OPKG_OPT_TYPE_INT:
-    *((int *) options[i]->value) = *((int *) value);
+    *((int *) options[i].value) = *((int *) value);
     return;
 
   case OPKG_OPT_TYPE_STRING:
     return;
 
   case OPKG_OPT_TYPE_STRING:
-    *((char **)options[i]->value) = strdup (value);
+    *((char **)options[i].value) = strdup (value);
     return;
   }
 
     return;
   }