Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line number in error message #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions paraconf/src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ PC_status_t PC_len( const PC_tree_t tree, int *res )
*res = tree.node->data.scalar.length;
} break;
default: {
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE, "Unknown yaml node type: #%d", tree.node->type), err0);
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE, "In line %zu: Unknown yaml node type: #%d",
tree.node->start_mark.line + 1,
tree.node->type), err0);
} break;
}

Expand All @@ -253,13 +255,17 @@ PC_status_t PC_int( const PC_tree_t tree, long *res )
}

if ( tree.node->type != YAML_SCALAR_NODE ) {
return PC_make_err(PC_INVALID_NODE_TYPE, "Expected a scalar, found %s\n", nodetype[tree.node->type]);
return PC_make_err(PC_INVALID_NODE_TYPE, "In line %zu: Expected a scalar, found %s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type]);
}

char *endptr; long result = strtol((char*)tree.node->data.scalar.value, &endptr, 0);
if ( *endptr ) {
char *content; PC_handle_err(PC_string(tree, &content), err0);
status = PC_make_err(PC_INVALID_NODE_TYPE, "Expected integer, found `%s'\n", content);
status = PC_make_err(PC_INVALID_NODE_TYPE, "In line %zu: Expected integer, found `%s'\n",
tree.node->start_mark.line + 1,
content);
free(content);
PC_handle_err(status, err0);
}
Expand All @@ -285,13 +291,14 @@ PC_status_t PC_double( const PC_tree_t tree, double* value )

if ( tree.node->type != YAML_SCALAR_NODE ) {
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE,
"Expected a scalar, found %s\n",
"In line %zu: Expected a scalar, found %s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type]), err0);
}
char *endptr; *value = strtod((char*)tree.node->data.scalar.value, &endptr);
if ( *endptr ) {
char *content = NULL; PC_handle_err(PC_string(tree, &content), err0);
status = PC_make_err(PC_INVALID_PARAMETER, "Expected floating point, found `%s'\n", content);
status = PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Expected floating point, found `%s'\n", content);
free(content);
PC_handle_err(status, err0);
}
Expand All @@ -316,7 +323,8 @@ PC_status_t PC_string( const PC_tree_t tree, char** value )

if ( tree.node->type != YAML_SCALAR_NODE ) {
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE,
"Expected a scalar, found %s\n",
"In line %zu: Expected a scalar, found %s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type]), err0);
}

Expand Down Expand Up @@ -346,7 +354,9 @@ PC_status_t PC_bool( const PC_tree_t tree, int *res )

if ( tree.node->type != YAML_SCALAR_NODE ) {
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE,
"Expected a scalar, found %s\n", nodetype[tree.node->type]), err0);
"In line %zu: Expected a scalar, found %s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type]), err0);
}

char *value = (char*)tree.node->data.scalar.value;
Expand All @@ -371,7 +381,9 @@ PC_status_t PC_bool( const PC_tree_t tree, int *res )
*res = 0;
} else {
char *content = NULL; PC_handle_err(PC_string(tree, &content), err0);
status = PC_make_err(PC_INVALID_PARAMETER, "Expected logical expression, found `%s'\n", content);
status = PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Expected logical expression, found `%s'\n",
tree.node->start_mark.line + 1,
content);
free(content);
PC_handle_err(status, err0);
}
Expand Down
48 changes: 32 additions & 16 deletions paraconf/src/ypath.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static PC_tree_t get_seq_idx( const PC_tree_t tree, const char **req_index, cons

// read '['
if ( *index != '[' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "Expected opening square bracket at char #%ld of `%.*s'\n",
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Expected opening square bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -60,7 +61,8 @@ static PC_tree_t get_seq_idx( const PC_tree_t tree, const char **req_index, cons
long seq_idx = strtol(index, &post_index, 0);
if ( post_index == index ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected integer at char #%ld of `%.*s'\n",
"In line %zu: Expected integer at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -69,7 +71,8 @@ static PC_tree_t get_seq_idx( const PC_tree_t tree, const char **req_index, cons
// read ']'
if ( *index != ']' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected closing square bracket at char #%ld of `%.*s'\n",
"In line %zu: Expected closing square bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -78,7 +81,8 @@ static PC_tree_t get_seq_idx( const PC_tree_t tree, const char **req_index, cons
// check type
if ( tree.node->type != YAML_SEQUENCE_NODE ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_NODE_TYPE,
"Expected sequence, found %s (ROOT)%.*s\n",
"In line %zu: Expected sequence, found %s (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type],
(int)(*req_index-full_index),
full_index), err0);
Expand All @@ -87,7 +91,8 @@ static PC_tree_t get_seq_idx( const PC_tree_t tree, const char **req_index, cons
// handle index
if ( seq_idx < 0 || seq_idx >= (tree.node->data.sequence.items.top - tree.node->data.sequence.items.start) ) {
PC_handle_err_tree(PC_make_err(PC_NODE_NOT_FOUND,
"Index %ld out of range [0...%ld[ in (ROOT)%.*s\n",
"In line %zu: Index %ld out of range [0...%ld] in (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
seq_idx,
(long)(tree.node->data.sequence.items.top - tree.node->data.sequence.items.start),
(int)(*req_index-full_index),
Expand All @@ -112,7 +117,8 @@ static PC_tree_t get_map_key_val( const PC_tree_t tree, const char **req_index,

// read '.'
if ( *index != '.' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "Expected dot at char #%ld of `%.*s'\n",
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Expected dot at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -126,7 +132,8 @@ static PC_tree_t get_map_key_val( const PC_tree_t tree, const char **req_index,

// check type
if ( tree.node->type != YAML_MAPPING_NODE ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_NODE_TYPE, "Expected mapping, found %s (ROOT)%.*s\n",
PC_handle_err_tree(PC_make_err(PC_INVALID_NODE_TYPE, "In line %zu: Expected mapping, found %s (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type],
(int)(*req_index-full_index),
full_index), err0);
Expand All @@ -145,7 +152,8 @@ static PC_tree_t get_map_key_val( const PC_tree_t tree, const char **req_index,
if ( !cmp ) break;
}
if ( pair == tree.node->data.mapping.pairs.top ) {
PC_handle_err_tree(PC_make_err(PC_NODE_NOT_FOUND, "Key `%.*s' not found in (ROOT)%.*s\n",
PC_handle_err_tree(PC_make_err(PC_NODE_NOT_FOUND, "In line %zu: Key `%.*s' not found in (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
key_len,
key,
(int)(*req_index-full_index),
Expand All @@ -172,23 +180,26 @@ static PC_status_t get_map_idx_pair( const PC_tree_t tree, const char **req_inde
char *post_index;
long map_idx = strtol(index, &post_index, 0);
if ( post_index == index ) {
PC_handle_err(PC_make_err(PC_INVALID_PARAMETER, "Expected integer at char #%ld of `%.*s'\n",
PC_handle_err(PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Expected integer at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
index = post_index;

// check type
if ( tree.node->type != YAML_MAPPING_NODE ) {
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE, "Expected mapping, found %s (ROOT)%.*s\n",
PC_handle_err(PC_make_err(PC_INVALID_NODE_TYPE, "In line %zu: Expected mapping, found %s (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
nodetype[tree.node->type],
(int)(*req_index-full_index),
full_index), err0);
}

// handle index
if ( map_idx < 0 || map_idx >= (tree.node->data.mapping.pairs.top - tree.node->data.mapping.pairs.start) ) {
PC_handle_err(PC_make_err(PC_NODE_NOT_FOUND, "Index %ld out of range [0...%ld] in (ROOT)%.*s\n",
PC_handle_err(PC_make_err(PC_NODE_NOT_FOUND, "In line %zu: Index %ld out of range [0...%ld] in (ROOT)%.*s\n",
tree.node->start_mark.line + 1,
map_idx,
(long)(tree.node->data.mapping.pairs.top - tree.node->data.mapping.pairs.start),
(int)(*req_index-full_index-1),
Expand All @@ -214,7 +225,8 @@ static PC_tree_t get_map_idx_key( const PC_tree_t tree, const char **req_index,
// read '{'
if ( *index != '{' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected opening curly bracket at char #%ld of `%.*s'\n",
"In line %zu: Expected opening curly bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -227,7 +239,8 @@ static PC_tree_t get_map_idx_key( const PC_tree_t tree, const char **req_index,
// read '}'
if ( *index != '}' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected closing curly bracket at char #%ld of `%.*s'\n",
"In line %zu: Expected closing curly bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -254,7 +267,8 @@ static PC_tree_t get_map_idx_val( const PC_tree_t tree, const char **req_index,
// read '<'
if ( *index != '<' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected opening angle bracket at char #%ld of `%.*s'\n",
"In line %zu: Expected opening angle bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand All @@ -267,7 +281,8 @@ static PC_tree_t get_map_idx_val( const PC_tree_t tree, const char **req_index,
// read '>'
if ( *index != '>' ) {
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER,
"Expected closing angle bracket at char #%ld of `%.*s'\n",
"In line %zu: Expected closing angle bracket at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand Down Expand Up @@ -316,7 +331,8 @@ PC_tree_t PC_sget( const PC_tree_t tree, const char *index )
assert(restree.node);
goto err0;
default:
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "Invalid character at char #%ld of `%.*s'\n",
PC_handle_err_tree(PC_make_err(PC_INVALID_PARAMETER, "In line %zu: Invalid character at char #%ld of `%.*s'\n",
tree.node->start_mark.line + 1,
(long int)(index-full_index),
full_index), err0);
}
Expand Down