implement config unload
[project/uci.git] / parse.c
diff --git a/parse.c b/parse.c
index 31756d9..4394bf6 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -77,9 +77,10 @@ static void uci_parse_cleanup(struct uci_context *ctx)
        if (!pctx)
                return;
 
+       ctx->pctx = NULL;
        if (pctx->cfg) {
                uci_list_del(&pctx->cfg->list);
-               uci_drop_file(pctx->cfg);
+               uci_drop_config(pctx->cfg);
        }
        if (pctx->buf)
                free(pctx->buf);
@@ -253,8 +254,6 @@ static void uci_parse_config(struct uci_context *ctx, char **str)
        type = next_arg(ctx, str, true);
        name = next_arg(ctx, str, false);
        assert_eol(ctx, str);
-
-       DPRINTF("Section<%s>: %s\n", type, name);
 }
 
 /*
@@ -270,8 +269,6 @@ static void uci_parse_option(struct uci_context *ctx, char **str)
        name = next_arg(ctx, str, true);
        value = next_arg(ctx, str, true);
        assert_eol(ctx, str);
-
-       DPRINTF("\tOption: %s=\"%s\"\n", name, value);
 }
 
 /*
@@ -317,6 +314,11 @@ int uci_load(struct uci_context *ctx, const char *name)
        UCI_HANDLE_ERR(ctx);
        UCI_ASSERT(ctx, name != NULL);
 
+       UCI_TRAP_SAVE(ctx, ignore);
+       uci_unload(ctx, name);
+       UCI_TRAP_RESTORE(ctx);
+
+ignore:
        /* make sure no memory from previous parse attempts is leaked */
        uci_parse_cleanup(ctx);
 
@@ -348,7 +350,7 @@ int uci_load(struct uci_context *ctx, const char *name)
        if (!pctx->file)
                UCI_THROW(ctx, UCI_ERR_IO);
 
-       pctx->cfg = uci_alloc_file(ctx, name);
+       pctx->cfg = uci_alloc_config(ctx, name);
 
        while (!feof(pctx->file)) {
                uci_getln(ctx);