FILE *fp;
char const *filename;
int lineno;
+ char *line; //!< where the current line started
int braces; //!< how many levels deep we are in a { ... }
bool saw_semicolon; //!< whether we saw a semicolon
redo:
state->lineno++;
+ state->line = state->ptr;
+
if (!fgets(state->ptr, (state->buffer + state->bufsize) - state->ptr, state->fp)) {
if (feof(state->fp)) {
state->eof = true;
if (rcode == 0) {
if (!state->allow_eof) {
- fr_strerror_printf("Failed reading %s line %d: Unexpected EOF",
- state->filename, state->lineno);
+ fr_strerror_printf("Unexpected EOF");
return -1;
}
state->token_len = p - state->token;
if (state->token_len >= 256) {
- fr_strerror_printf("Token too large");
+ fr_strerror_printf("token too large");
return -1;
}
*/
if (hint == T_LCBRACE) {
if (*state->token != '{') {
- fr_strerror_printf("Failed reading %s line %d - Missing '{'",
- state->filename, lineno);
+ fr_strerror_printf("missing '{'");
return -1;
}
if (hint == T_RCBRACE) {
if (*state->token != '}') {
- fr_strerror_printf("Failed reading %s line %d - Missing '}'",
- state->filename, lineno);
+ fr_strerror_printf("missing '}'");
return -1;
}
*/
if (*state->token == '}') {
if (!allow_rcbrace) {
- fr_strerror_printf("Failed reading %s line %d - Unexpected '}'",
- state->filename, lineno);
+ fr_strerror_printf("unexpected '}'");
return -1;
}
*/
if ((hint == T_BARE_WORD) || (hint == T_DOUBLE_QUOTED_STRING)) {
if (*state->token == '{') {
- fr_strerror_printf("Failed reading %s line %d - Unexpected '{'",
- state->filename, lineno);
+ fr_strerror_printf("unexpected '{'");
return -1;
}
}
/*
* Remember the next command.
*/
- next = cmd;
+ next = q = cmd;
while (*next && !isspace((int) *next) && (*next != ',')) next++;
if (!*next) semicolon = YES_SEMICOLON;
- q = cmd;
-
/*
* Matching an in-line word.
*/
if (islower((int) *q)) {
- char const *start = q;
-
rcode = read_token(state, T_BARE_WORD, semicolon, false);
- if (rcode <= 0) return rcode;
+ if (rcode <= 0) return -1;
/*
* Look for a verbatim word.
for (p = state->token; p < (state->token + state->token_len); p++, q++) {
if (*p != *q) {
fail:
- fr_strerror_printf("Expected '%s', not '%.*s'",
- start, state->token_len, state->token);
+ fr_strerror_printf("Expected '%.*s', got unknown text '%.*s'",
+ state->token_len, state->token,
+ (int) (next - cmd), cmd);
return -1;
}
}
type = fr_str2int(fr_value_box_type_names, type_name, -1);
if (type < 0) {
- fr_strerror_printf("Unknown data type '%s'", cmd);
- return -1;
+ fr_strerror_printf("unknown data type '%.*s'",
+ (int) (next - cmd), cmd);
+ return -1; /* internal error */
}
redo_multi:
* list. i.e. as if the file was included in-place.
*/
rcode = read_file(info->parent, name, state->debug);
-
if (rcode < 0) return rcode;
/*
state.braces = 0;
state.ptr = buffer;
+ state.token = NULL;
state.debug = debug;
state.allow_eof = true;
rcode = read_token(&state, T_BARE_WORD, true, false);
if (rcode < 0) {
fail:
+ if (!state.token) {
+ fr_strerror_printf("Failed reading %s:[%d] - %s",
+ filename, state.lineno,
+ fr_strerror());
+ } else {
+ fr_strerror_printf("Failed reading %s:[%d] offset %d - %s",
+ filename, state.lineno,
+ (int) (state.token - state.line),
+ fr_strerror());
+ }
fclose(fp);
return rcode;
}