r4373 - trunk/src/target/opkg/libopkg

thomas at sita.openmoko.org thomas at sita.openmoko.org
Thu Apr 17 16:51:26 CEST 2008


Author: thomas
Date: 2008-04-17 16:51:25 +0200 (Thu, 17 Apr 2008)
New Revision: 4373

Modified:
   trunk/src/target/opkg/libopkg/opkg.c
Log:
opkg: fix option array handling


Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-04-17 11:14:37 UTC (rev 4372)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-04-17 14:51:25 UTC (rev 4373)
@@ -35,7 +35,7 @@
 {
   args_t *args;
   opkg_conf_t *conf;
-  opkg_option_t *options[];
+  opkg_option_t *options;
 };
 
 /** Private Functions ***/
@@ -89,9 +89,14 @@
 {
   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 @@
 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 @@
   /* 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 @@
   }
 
   /* 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 @@
 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 @@
   /* 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;
   }
 





More information about the commitlog mailing list