static int package_cmd(int cmd, char *tuple)
{
- struct uci_element *e = NULL;
struct uci_ptr ptr;
int ret = 1;
return 1;
}
- e = ptr.last;
switch(cmd) {
case CMD_CHANGES:
uci_show_changes(ptr.p);
cli_perror();
goto out;
}
- switch(e->type) {
- case UCI_TYPE_PACKAGE:
- uci_show_package(ptr.p);
- break;
- case UCI_TYPE_SECTION:
- uci_show_section(ptr.s);
- break;
- case UCI_TYPE_OPTION:
- uci_show_option(ptr.o, true);
- break;
- default:
- /* should not happen */
- goto out;
- }
+ if (ptr.o)
+ uci_show_option(ptr.o, true);
+ else if (ptr.s)
+ uci_show_section(ptr.s);
+ else if (ptr.p)
+ uci_show_package(ptr.p);
+ else
+ goto out; /* should not happen */
break;
}
static int uci_do_section_cmd(int cmd, int argc, char **argv)
{
- struct uci_element *e;
struct uci_ptr ptr;
int ret = UCI_OK;
int dummy;
(cmd != CMD_RENAME) && (cmd != CMD_REORDER))
return 1;
- e = ptr.last;
switch(cmd) {
case CMD_GET:
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
cli_perror();
return 1;
}
- switch(e->type) {
- case UCI_TYPE_SECTION:
- printf("%s\n", ptr.s->type);
- break;
- case UCI_TYPE_OPTION:
+ if (ptr.o)
uci_show_value(ptr.o, false);
- break;
- default:
- break;
- }
- /* throw the value to stdout */
+ else if (ptr.s)
+ printf("%s\n", ptr.s->type);
break;
case CMD_RENAME:
ret = uci_rename(ctx, &ptr);
static void uci_parse_delta_line(struct uci_context *ctx, struct uci_package *p)
{
- struct uci_element *e = NULL;
struct uci_ptr ptr;
int cmd;
UCI_INTERNAL(uci_del_list, ctx, &ptr);
break;
case UCI_CMD_ADD:
+ UCI_INTERNAL(uci_set, ctx, &ptr);
+ if (!ptr.option && ptr.s)
+ ptr.s->anonymous = true;
+ break;
case UCI_CMD_CHANGE:
UCI_INTERNAL(uci_set, ctx, &ptr);
- e = ptr.last;
- if (!ptr.option && e && (cmd == UCI_CMD_ADD))
- uci_to_section(e)->anonymous = true;
+ break;
+ default:
break;
}
return;
UCI_TRAP_SAVE(ctx, error);
ptr->o = uci_alloc_list(ptr->s, ptr->option, NULL);
UCI_TRAP_RESTORE(ctx);
- ptr->last = &ptr->o->e;
} else if (ptr->o->type == UCI_TYPE_STRING) {
/* create new list and add old string value as item to list */
struct uci_option *old = ptr->o;
if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
uci_free_option(old);
- ptr->last = &ptr->o->e;
}
/* add new item to list */
return uci_delete(ctx, ptr);
} else if (!ptr->o && ptr->option) { /* new option */
ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, NULL);
- ptr->last = &ptr->o->e;
} else if (!ptr->s && ptr->section) { /* new section */
ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section, NULL);
- ptr->last = &ptr->s->e;
} else if (ptr->o && ptr->option) { /* update option */
if (ptr->o->type == UCI_TYPE_STRING && !strcmp(ptr->o->v.string, ptr->value))
return 0;
if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
uci_free_option(old);
- ptr->last = &ptr->o->e;
}
} else if (ptr->s && ptr->section) { /* update section */
if (!strcmp(ptr->s->type, ptr->value))
ptr->section = ptr->s->e.name;
uci_free_section(old);
ptr->s->package->n_section--;
- ptr->last = &ptr->s->e;
}
} else {
UCI_THROW(ctx, UCI_ERR_INVAL);
uci_lua_get_any(lua_State *L, bool all)
{
struct uci_context *ctx;
- struct uci_element *e = NULL;
struct uci_ptr ptr;
int offset = 0;
int nret = 1;
char *s = NULL;
- int err = UCI_ERR_NOTFOUND;
ctx = find_context(L, &offset);
if (lookup_args(L, ctx, offset, &ptr, &s))
goto error;
- lookup_ptr(ctx, &ptr, NULL, true);
if (!all && !ptr.s) {
ctx->err = UCI_ERR_INVAL;
goto error;
goto error;
}
- err = UCI_OK;
- e = ptr.last;
- switch(e->type) {
- case UCI_TYPE_PACKAGE:
- uci_push_package(L, ptr.p);
- break;
- case UCI_TYPE_SECTION:
- if (all) {
- uci_push_section(L, ptr.s, -1);
- }
- else {
- lua_pushstring(L, ptr.s->type);
- lua_pushstring(L, ptr.s->e.name);
- nret++;
- }
- break;
- case UCI_TYPE_OPTION:
- uci_push_option(L, ptr.o);
- break;
- default:
- ctx->err = UCI_ERR_INVAL;
- goto error;
+ if (ptr.o) {
+ uci_push_option(L, ptr.o);
+ } else if (ptr.s) {
+ if (all) {
+ uci_push_section(L, ptr.s, -1);
+ }
+ else {
+ lua_pushstring(L, ptr.s->type);
+ lua_pushstring(L, ptr.s->e.name);
+ nret++;
+ }
+ } else {
+ uci_push_package(L, ptr.p);
}
+
if (s)
free(s);
- if (!err)
- return nret;
+ return nret;
error:
if (s)