/*
* parse the 'package' uci command (next config package)
*/
-static void uci_parse_package(struct uci_context *ctx, char **str)
+static void uci_parse_package(struct uci_context *ctx, char **str, bool single)
{
char *name = NULL;
name = next_arg(ctx, str, true);
assert_eol(ctx, str);
+ if (single)
+ return;
+
ctx->pctx->name = name;
uci_switch_config(ctx);
}
/*
* parse a complete input line, split up combined commands by ';'
*/
-static void uci_parse_line(struct uci_context *ctx)
+static void uci_parse_line(struct uci_context *ctx, bool single)
{
struct uci_parse_context *pctx = ctx->pctx;
char *word, *brk = NULL;
switch(word[0]) {
case 'p':
if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
- uci_parse_package(ctx, &word);
+ uci_parse_package(ctx, &word, single);
break;
case 'c':
if ((word[1] == 0) || !strcmp(word + 1, "onfig"))
return 0;
}
-int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct uci_package **package)
+int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct uci_package **package, bool single)
{
struct uci_parse_context *pctx;
while (!feof(pctx->file)) {
uci_getln(ctx, 0);
if (pctx->buf[0])
- uci_parse_line(ctx);
+ uci_parse_line(ctx, single);
}
if (package)
ctx->errno = 0;
UCI_TRAP_SAVE(ctx, done);
- uci_import(ctx, file, name, package);
+ uci_import(ctx, file, name, package, true);
UCI_TRAP_RESTORE(ctx);
if (*package) {
* @stream: file stream to import from
* @name: (optional) assume the config has the given name
* @package: (optional) store the last parsed config package in this variable
+ * @single: ignore the 'package' keyword and parse everything into a single package
*
* the name parameter is for config files that don't explicitly use the 'package <...>' keyword
*/
-extern int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct uci_package **package);
+extern int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct uci_package **package, bool single);
/**
* uci_export: Export one or all uci config packages