add flag for naming unnamed sections
authorFelix Fietkau <nbd@openwrt.org>
Sat, 2 Feb 2008 23:25:50 +0000 (00:25 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 2 Feb 2008 23:25:50 +0000 (00:25 +0100)
cli.c
file.c
uci.h

diff --git a/cli.c b/cli.c
index 0c68d0836c6149deae7db4be43aa349ac2a67074..bedef6dbbed012490ead5622e8ec09ea94a6faf8 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -50,8 +50,10 @@ static void uci_usage(int argc, char **argv)
                "Options:\n"
                "\t-f <file>  use <file> 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 95469c5f64e7b221621ee27b29fc2e45fb549bba..ae58fbc6ed9982c495aa84e8fa3f7260b60782dd 100644 (file)
--- 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 574a3849f44ea828e4fcc7021bbf5a35e8303994..e921269872a114f43611907bbea44983aba0bb51 100644 (file)
--- 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