} while (**str && !isspace(**str));
done:
- /*
+ /*
* if the string was unquoted and we've stopped at a whitespace
* character, skip to the next one, because the whitespace will
* be overwritten by a null byte here
uci_parse_error(ctx, *str, "too many arguments");
}
-/*
+/*
* switch to a different config, either triggered by uci_load, or by a
* 'package <...>' statement in the import file
*/
if (!name)
return;
- /*
+ /*
* if an older config under the same name exists, unload it
* ignore errors here, e.g. if the config was not found
*/
struct uci_parse_context *pctx;
UCI_HANDLE_ERR(ctx);
+ pctx = NULL;
/* make sure no memory from previous parse attempts is leaked */
uci_cleanup(ctx);
uci_alloc_parse_context(ctx);
pctx = ctx->pctx;
- pctx->file = stream;
- if (*package && single) {
- pctx->package = *package;
- pctx->merge = true;
- }
-
- /*
- * If 'name' was supplied, assume that the supplied stream does not contain
- * the appropriate 'package <name>' string to specify the config name
- * NB: the config file can still override the package name
- */
- if (name) {
- UCI_ASSERT(ctx, uci_validate_package(name));
- pctx->name = name;
- }
+ if (pctx != NULL) {
+ pctx->file = stream;
+ if (*package && single) {
+ pctx->package = *package;
+ pctx->merge = true;
+ }
+ /*
+ * If 'name' was supplied, assume that the supplied stream does not contain
+ * the appropriate 'package <name>' string to specify the config name
+ * NB: the config file can still override the package name
+ */
+ if (name) {
+ UCI_ASSERT(ctx, uci_validate_package(name));
+ pctx->name = name;
+ }
- while (!feof(pctx->file)) {
- uci_getln(ctx, 0);
- UCI_TRAP_SAVE(ctx, error);
- if (pctx->buf[0])
- uci_parse_line(ctx, single);
- UCI_TRAP_RESTORE(ctx);
- continue;
+ while (!feof(pctx->file)) {
+ uci_getln(ctx, 0);
+ UCI_TRAP_SAVE(ctx, error);
+ if (pctx->buf[0])
+ uci_parse_line(ctx, single);
+ UCI_TRAP_RESTORE(ctx);
+ continue;
error:
- if (ctx->flags & UCI_FLAG_PERROR)
- uci_perror(ctx, NULL);
- if ((ctx->err != UCI_ERR_PARSE) ||
- (ctx->flags & UCI_FLAG_STRICT))
- UCI_THROW(ctx, ctx->err);
- }
+ if (ctx->flags & UCI_FLAG_PERROR)
+ uci_perror(ctx, NULL);
+ if ((ctx->err != UCI_ERR_PARSE) ||
+ (ctx->flags & UCI_FLAG_STRICT))
+ UCI_THROW(ctx, ctx->err);
+ }
- uci_fixup_section(ctx, ctx->pctx->section);
- if (!pctx->package && name)
- uci_switch_config(ctx);
- if (package)
- *package = pctx->package;
- if (pctx->merge)
- pctx->package = NULL;
+ uci_fixup_section(ctx, ctx->pctx->section);
+ if (!pctx->package && name)
+ uci_switch_config(ctx);
+ if (package)
+ *package = pctx->package;
+ if (pctx->merge)
+ pctx->package = NULL;
- pctx->name = NULL;
+ pctx->name = NULL;
+ }
uci_switch_config(ctx);
/* no error happened, we can get rid of the parser context now */
if (!uci_list_empty(&p->delta))
UCI_INTERNAL(uci_save, ctx, p);
- /*
- * other processes might have modified the config
- * as well. dump and reload
+ /*
+ * other processes might have modified the config
+ * as well. dump and reload
*/
uci_free_package(&p);
uci_cleanup(ctx);
}
-/*
+/*
* This function returns the filename by returning the string
* after the last '/' character. By checking for a non-'\0'
* character afterwards, directories are ignored (glob marks