r4363 - trunk/src/target/opkg/libopkg

thomas at sita.openmoko.org thomas at sita.openmoko.org
Tue Apr 15 18:31:34 CEST 2008


Author: thomas
Date: 2008-04-15 18:31:30 +0200 (Tue, 15 Apr 2008)
New Revision: 4363

Modified:
   trunk/src/target/opkg/libopkg/opkg.c
   trunk/src/target/opkg/libopkg/opkg.h
   trunk/src/target/opkg/libopkg/opkg_conf.c
   trunk/src/target/opkg/libopkg/opkg_conf.h
Log:
opkg: implement opkg_set_option() and opkg_get_option()


Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-04-15 14:34:05 UTC (rev 4362)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-04-15 16:31:30 UTC (rev 4363)
@@ -29,6 +29,7 @@
 {
   args_t *args;
   opkg_conf_t *conf;
+  opkg_option_t *options[];
 };
 
 /** Private Functions ***/
@@ -84,6 +85,7 @@
   opkg = malloc (sizeof (opkg_t));
   args_init (opkg->args);
   opkg_conf_init (opkg->conf, opkg->args);
+  opkg_init_options_array (opkg->conf, opkg->options);
   return opkg;
 }
 
@@ -97,11 +99,84 @@
 void
 opkg_get_option (opkg_t *opkg, char *option, void **value)
 {
+  int i = 0;
+  opkg_option_t **options = opkg->options;
+
+  /* can't store a value in a NULL pointer! */
+  if (!value)
+    return;
+
+  /* look up the option
+   * TODO: this would be much better as a hash table
+   */
+  while (options[i]->name)
+  {
+    if (strcmp(options[i]->name, option) != 0)
+    {
+      i++;
+      continue;
+    }
+  }
+
+  /* get the option */
+  switch (options[i]->type)
+  {
+    case OPKG_OPT_TYPE_BOOL:
+      *((int *) value) = *((int *) options[i]->value);
+      return;
+
+    case OPKG_OPT_TYPE_INT:
+      *((int *) value) = *((int *) options[i]->value);
+      return;
+
+    case OPKG_OPT_TYPE_STRING:
+      *((char **)value) = strdup (options[i]->value);
+      return;
+   }
+
 }
 
 void
 opkg_set_option (opkg_t *opkg, char *option, void *value)
 {
+  int i = 0;
+  opkg_option_t **options = opkg->options;
+
+  /* NULL values are not defined */
+  if (!value)
+    return;
+
+  /* look up the option
+   * TODO: this would be much better as a hash table
+   */
+  while (options[i]->name)
+  {
+    if (strcmp(options[i]->name, option) != 0)
+    {
+      i++;
+      continue;
+    }
+  }
+
+  /* set the option */
+  switch (options[i]->type)
+  {
+    case OPKG_OPT_TYPE_BOOL:
+      if (*((int *) value) == 0)
+        *((int *)options[i]->value) = 0;
+      else
+        *((int *)options[i]->value) = 1;
+      return;
+
+    case OPKG_OPT_TYPE_INT:
+      *((int *) options[i]->value) = *((int *) value);
+      return;
+
+    case OPKG_OPT_TYPE_STRING:
+      *((char **)options[i]->value) = strdup(value);
+      return;
+   }
+
 }
 
 int

Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h	2008-04-15 14:34:05 UTC (rev 4362)
+++ trunk/src/target/opkg/libopkg/opkg.h	2008-04-15 16:31:30 UTC (rev 4363)
@@ -19,6 +19,9 @@
 
 opkg_t* opkg_new ();
 void opkg_free (opkg_t *opkg);
+void opkg_get_option (opkg_t *opkg, char *option, void **value);
+void opkg_set_option (opkg_t *opkg, char *option, void *value);
+
 int opkg_install_package (opkg_t *opkg, char *package_name);
 int opkg_remove_package (opkg_t *opkg, char *package_name);
 int opkg_upgrade_package (opkg_t *opkg, char *package_name);

Modified: trunk/src/target/opkg/libopkg/opkg_conf.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.c	2008-04-15 14:34:05 UTC (rev 4362)
+++ trunk/src/target/opkg/libopkg/opkg_conf.c	2008-04-15 16:31:30 UTC (rev 4363)
@@ -33,7 +33,6 @@
 				pkg_src_list_t *pkg_src_list,
 				nv_pair_list_t *tmp_dest_nv_pair_list,
 				char **tmp_lists_dir);
-static int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options);
 static int opkg_conf_set_option(const opkg_option_t *options,
 				const char *name, const char *value);
 static int opkg_conf_set_default_dest(opkg_conf_t *conf,

Modified: trunk/src/target/opkg/libopkg/opkg_conf.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.h	2008-04-15 14:34:05 UTC (rev 4362)
+++ trunk/src/target/opkg/libopkg/opkg_conf.h	2008-04-15 16:31:30 UTC (rev 4363)
@@ -104,4 +104,7 @@
 int opkg_conf_write_status_files(opkg_conf_t *conf);
 char *root_filename_alloc(opkg_conf_t *conf, char *filename);
 
+
+int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options);
+
 #endif





More information about the commitlog mailing list