add initial work for option datatype abstraction
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 19c6b07..4098e59 100644 (file)
--- a/file.c
+++ b/file.c
@@ -186,19 +186,27 @@ static void uci_parse_line(struct uci_context *ctx, bool single)
                        case 'p':
                                if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
                                        uci_parse_package(ctx, &word, single);
+                               else
+                                       goto invalid;
                                break;
                        case 'c':
                                if ((word[1] == 0) || !strcmp(word + 1, "onfig"))
                                        uci_parse_config(ctx, &word);
+                               else
+                                       goto invalid;
                                break;
                        case 'o':
                                if ((word[1] == 0) || !strcmp(word + 1, "ption"))
                                        uci_parse_option(ctx, &word);
+                               else
+                                       goto invalid;
                                break;
                        default:
-                               uci_parse_error(ctx, word, "unterminated command");
-                               break;
+                               goto invalid;
                }
+               continue;
+invalid:
+               uci_parse_error(ctx, word, "invalid command");
        } while (1);
 }
 
@@ -267,8 +275,15 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header)
                fprintf(stream, "\n");
                uci_foreach_element(&sec->options, o) {
                        struct uci_option *opt = uci_to_option(o);
-                       fprintf(stream, "\toption '%s'", uci_escape(ctx, opt->e.name));
-                       fprintf(stream, " '%s'\n", uci_escape(ctx, opt->value));
+                       switch(o->type) {
+                       case UCI_TYPE_STRING:
+                               fprintf(stream, "\toption '%s'", uci_escape(ctx, opt->e.name));
+                               fprintf(stream, " '%s'\n", uci_escape(ctx, opt->v.string));
+                               break;
+                       default:
+                               fprintf(stream, "\t# unknown type for option '%s'\n", uci_escape(ctx, opt->e.name));
+                               break;
+                       }
                }
        }
        fprintf(stream, "\n");