switch (err) {
case UCI_ERR_PARSE:
if (ctx->pctx) {
- fprintf(stderr, "%s: %s at line %d, byte %d\n", str, uci_errstr[err], ctx->pctx->line, ctx->pctx->byte);
+ fprintf(stderr, "%s: %s (%s) at line %d, byte %d\n", str, uci_errstr[err], (ctx->pctx->reason ? ctx->pctx->reason : "unknown"), ctx->pctx->line, ctx->pctx->byte);
break;
}
/* fall through */
}
if (pctx->bufsz > LINEBUF_MAX/2) {
+ pctx->reason = "line too long";
pctx->byte = LINEBUF_MAX;
UCI_THROW(ctx, UCI_ERR_PARSE);
}
break;
}
}
+ ctx->pctx->reason = "unterminated \"";
ctx->pctx->byte = *str - ctx->pctx->buf;
UCI_THROW(ctx, UCI_ERR_PARSE);
}
addc(target, str);
}
}
+ ctx->pctx->reason = "unterminated '";
ctx->pctx->byte = *str - ctx->pctx->buf;
UCI_THROW(ctx, UCI_ERR_PARSE);
}
skip_whitespace(str);
parse_str(ctx, str, &ptr);
if (required && !*val) {
+ ctx->pctx->reason = "insufficient arguments";
ctx->pctx->byte = *str - ctx->pctx->buf;
UCI_THROW(ctx, UCI_ERR_PARSE);
}
tmp = next_arg(ctx, str, false);
if (tmp && *tmp) {
+ ctx->pctx->reason = "too many arguments";
ctx->pctx->byte = tmp - ctx->pctx->buf;
UCI_THROW(ctx, UCI_ERR_PARSE);
}
{
char *type, *name;
+ /* command string null-terminated by strtok */
*str += strlen(*str) + 1;
- if (!*str) {
- ctx->pctx->byte = *str - ctx->pctx->buf;
- UCI_THROW(ctx, UCI_ERR_PARSE);
- }
-
type = next_arg(ctx, str, true);
name = next_arg(ctx, str, false);
assert_eol(ctx, str);
+
+ DPRINTF("Section<%s>: %s\n", type, name);
}
/*
{
char *name, *value;
+ /* command string null-terminated by strtok */
*str += strlen(*str) + 1;
name = next_arg(ctx, str, true);
uci_parse_option(ctx, &word);
break;
default:
+ pctx->reason = "unterminated command";
pctx->byte = word - pctx->buf;
UCI_THROW(ctx, UCI_ERR_PARSE);
break;