From 333ef9e09be5ac9c191625cca4efcebdbfc22073 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 3 Feb 2008 00:25:50 +0100 Subject: [PATCH] add flag for naming unnamed sections --- cli.c | 12 ++++++++++-- file.c | 2 +- uci.h | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cli.c b/cli.c index 0c68d08..bedef6d 100644 --- a/cli.c +++ b/cli.c @@ -50,8 +50,10 @@ static void uci_usage(int argc, char **argv) "Options:\n" "\t-f use as input instead of stdin\n" "\t-m when importing, merge data into an existing package\n" - "\t-s force strict mode (stop on parser errors)\n" + "\t-s force strict mode (stop on parser errors, default)\n" "\t-S disable strict mode\n" + "\t-n name unnamed sections on export (default)\n" + "\t-N don't name unnamed sections\n" "\n", argv[0] ); @@ -299,7 +301,7 @@ int main(int argc, char **argv) return 1; } - while((c = getopt(argc, argv, "mf:sS")) != -1) { + while((c = getopt(argc, argv, "mf:sSnN")) != -1) { switch(c) { case 'f': input = fopen(optarg, "r"); @@ -318,6 +320,12 @@ int main(int argc, char **argv) ctx->flags &= ~UCI_FLAG_STRICT; ctx->flags |= UCI_FLAG_PERROR; break; + case 'n': + ctx->flags |= UCI_FLAG_EXPORT_NAME; + break; + case 'N': + ctx->flags &= ~UCI_FLAG_EXPORT_NAME; + break; default: uci_usage(argc, argv); break; diff --git a/file.c b/file.c index 95469c5..ae58fbc 100644 --- a/file.c +++ b/file.c @@ -523,7 +523,7 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header) uci_foreach_element(&p->sections, s) { struct uci_section *sec = uci_to_section(s); fprintf(stream, "\nconfig '%s'", uci_escape(ctx, sec->type)); - if (!sec->anonymous) + if (!sec->anonymous || (ctx->flags & UCI_FLAG_EXPORT_NAME)) fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name)); fprintf(stream, "\n"); uci_foreach_element(&sec->options, o) { diff --git a/uci.h b/uci.h index 574a384..e921269 100644 --- a/uci.h +++ b/uci.h @@ -237,8 +237,9 @@ enum uci_type { }; enum uci_flags { - UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */ - UCI_FLAG_PERROR = (1 << 1), /* print error messages to stderr */ + UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */ + UCI_FLAG_PERROR = (1 << 1), /* print parser error messages */ + UCI_FLAG_EXPORT_NAME = (1 << 2), /* when exporting, name unnamed sections */ }; struct uci_element -- 2.11.0