X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=file.c;h=c2b0e721da417cbbf000252cca3c0d2d83e4e992;hp=33ba93c84e5d402d407f6dde3a19ca76462da6fc;hb=d3722382bdd467d1c705911450120be75426406f;hpb=6ce771b1095c220f849e70cdcbf23bd09f7fe7d5 diff --git a/file.c b/file.c index 33ba93c..c2b0e72 100644 --- a/file.c +++ b/file.c @@ -9,7 +9,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU Lesser General Public License for more details. */ /* @@ -266,7 +266,7 @@ int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char * } static int -uci_fill_ptr(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_element *e, bool complete) +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); @@ -296,8 +296,6 @@ fill_package: ptr->package = ptr->p->e.name; ptr->flags |= UCI_LOOKUP_DONE; - if (complete) - ptr->flags |= UCI_LOOKUP_COMPLETE; return 0; } @@ -400,11 +398,11 @@ static void uci_parse_config(struct uci_context *ctx, char **str) name = next_arg(ctx, str, false, true); assert_eol(ctx, str); - if (!name) { + if (!name || !name[0]) { ctx->internal = !pctx->merge; UCI_NESTED(uci_add_section, ctx, pctx->package, type, &pctx->section); } else { - uci_fill_ptr(ctx, &ptr, &pctx->package->e, false); + uci_fill_ptr(ctx, &ptr, &pctx->package->e); e = uci_lookup_list(&pctx->package->sections, name); if (e) ptr.s = uci_to_section(e); @@ -438,7 +436,7 @@ static void uci_parse_option(struct uci_context *ctx, char **str, bool list) value = next_arg(ctx, str, false, false); assert_eol(ctx, str); - uci_fill_ptr(ctx, &ptr, &pctx->section->e, false); + uci_fill_ptr(ctx, &ptr, &pctx->section->e); e = uci_lookup_list(&pctx->section->options, name); if (e) ptr.o = uci_to_option(e); @@ -510,7 +508,7 @@ invalid: /* * escape an uci string for export */ -static char *uci_escape(struct uci_context *ctx, const char *str) +static const char *uci_escape(struct uci_context *ctx, const char *str) { const char *end; int ofs = 0; @@ -518,6 +516,9 @@ static char *uci_escape(struct uci_context *ctx, const char *str) if (!ctx->buf) { ctx->bufsz = LINEBUF; ctx->buf = malloc(LINEBUF); + + if (!ctx->buf) + return str; } while (1) { @@ -560,10 +561,10 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header) struct uci_element *s, *o, *i; if (header) - fprintf(stream, "package '%s'\n", uci_escape(ctx, p->e.name)); + fprintf(stream, "package %s\n", uci_escape(ctx, p->e.name)); uci_foreach_element(&p->sections, s) { struct uci_section *sec = uci_to_section(s); - fprintf(stream, "\nconfig '%s'", uci_escape(ctx, sec->type)); + fprintf(stream, "\nconfig %s", uci_escape(ctx, sec->type)); if (!sec->anonymous || (ctx->flags & UCI_FLAG_EXPORT_NAME)) fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name)); fprintf(stream, "\n"); @@ -571,12 +572,12 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header) struct uci_option *opt = uci_to_option(o); switch(opt->type) { case UCI_TYPE_STRING: - fprintf(stream, "\toption '%s'", uci_escape(ctx, opt->e.name)); + fprintf(stream, "\toption %s", uci_escape(ctx, opt->e.name)); fprintf(stream, " '%s'\n", uci_escape(ctx, opt->v.string)); break; case UCI_TYPE_LIST: uci_foreach_element(&opt->v.list, i) { - fprintf(stream, "\tlist '%s'", uci_escape(ctx, opt->e.name)); + fprintf(stream, "\tlist %s", uci_escape(ctx, opt->e.name)); fprintf(stream, " '%s'\n", uci_escape(ctx, i->name)); } break; @@ -618,7 +619,7 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u uci_alloc_parse_context(ctx); pctx = ctx->pctx; pctx->file = stream; - if (*package && single) { + if (package && *package && single) { pctx->package = *package; pctx->merge = true; } @@ -677,7 +678,7 @@ static char *uci_config_path(struct uci_context *ctx, const char *name) return filename; } -void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool overwrite) +static void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool overwrite) { struct uci_package *p = *package; FILE *f = NULL; @@ -694,14 +695,14 @@ void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool /* open the config file for writing now, so that it is locked */ f = uci_open_stream(ctx, p->path, SEEK_SET, true, true); - /* flush unsaved changes and reload from history file */ + /* flush unsaved changes and reload from delta file */ UCI_TRAP_SAVE(ctx, done); - if (p->has_history) { + if (p->has_delta) { if (!overwrite) { name = uci_strdup(ctx, p->e.name); path = uci_strdup(ctx, p->path); - /* dump our own changes to the history file */ - if (!uci_list_empty(&p->history)) + /* dump our own changes to the delta file */ + if (!uci_list_empty(&p->delta)) UCI_INTERNAL(uci_save, ctx, p); /* @@ -713,15 +714,15 @@ void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool UCI_INTERNAL(uci_import, ctx, f, name, &p, true); p->path = path; - p->has_history = true; + p->has_delta = true; *package = p; /* freed together with the uci_package */ path = NULL; } - /* flush history */ - if (!uci_load_history(ctx, p, true)) + /* flush delta */ + if (!uci_load_delta(ctx, p, true)) goto done; } @@ -841,8 +842,8 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na if (package) { package->path = filename; - package->has_history = confdir; - uci_load_history(ctx, package, false); + package->has_delta = confdir; + uci_load_delta(ctx, package, false); } done: