{
args_t *args;
opkg_conf_t *conf;
- opkg_option_t *options[];
+ opkg_option_t *options;
};
/** Private Functions ***/
{
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;
}
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)
/* 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;
}
/* 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;
}
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)
/* 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;
}