+int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char **result)
+{
+ int ofs_result;
+
+ UCI_HANDLE_ERR(ctx);
+ UCI_ASSERT(ctx, str != NULL);
+ UCI_ASSERT(ctx, result != NULL);
+
+ if (ctx->pctx && (ctx->pctx->file != stream))
+ uci_cleanup(ctx);
+
+ if (!ctx->pctx)
+ uci_alloc_parse_context(ctx);
+
+ ctx->pctx->file = stream;
+ if (!*str) {
+ ctx->pctx->pos = 0;
+ uci_getln(ctx, 0);
+ }
+
+ ofs_result = next_arg(ctx, false, false, false);
+ *result = pctx_str(ctx->pctx, ofs_result);
+ *str = pctx_cur_str(ctx->pctx);
+
+ return 0;
+}
+
+/*
+ * Fixup sections functions does the fixup of all sections for given package.
+ * It is used as a preprocessing step for fixing up existing anonymous sections
+ * from configurations.
+ *
+ * It uses uci_fixup_section() from list.c and then adds delta changes.
+ */
+static void
+uci_fixup_sections(struct uci_context *ctx, struct uci_package *p)
+{
+ struct uci_element *e;
+ struct uci_section *s;
+
+ uci_foreach_element(&p->sections, e) {
+ s = uci_to_section(e);
+ s->package->name_index++;
+ uci_fixup_section(ctx, s);
+ s->anonymous = false;
+ }
+}
+
+static int
+uci_fill_ptr(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_element *e)
+{
+ UCI_ASSERT(ctx, ptr != NULL);
+ UCI_ASSERT(ctx, e != NULL);
+
+ memset(ptr, 0, sizeof(struct uci_ptr));
+ switch(e->type) {
+ case UCI_TYPE_OPTION:
+ ptr->o = uci_to_option(e);
+ goto fill_option;
+ case UCI_TYPE_SECTION:
+ ptr->s = uci_to_section(e);
+ goto fill_section;
+ case UCI_TYPE_PACKAGE:
+ ptr->p = uci_to_package(e);
+ goto fill_package;
+ default:
+ UCI_THROW(ctx, UCI_ERR_INVAL);
+ }
+
+fill_option:
+ ptr->option = ptr->o->e.name;
+ ptr->s = ptr->o->section;
+fill_section:
+ ptr->section = ptr->s->e.name;
+ ptr->p = ptr->s->package;
+fill_package:
+ ptr->package = ptr->p->e.name;
+
+ ptr->flags |= UCI_LOOKUP_DONE;
+
+ return 0;
+}
+
+
+