aboutsummaryrefslogtreecommitdiff
path: root/src/lookup.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 15:18:29 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 21:23:42 +0300
commit440771ca0056eb20396e24f03d349a75ee1c9d22 (patch)
tree3ec58a85e96d21a855ad3dcefaa8adc51039fc38 /src/lookup.c
parent4c1959a4848c30206de3be4b16bdf04b650daae8 (diff)
downloadgrecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.gz
grecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.bz2
Keep track of columns in the node and value locations. Improve error diagnostics.
* src/grecs.h (grecs_locus_point): New struct. (grecs_locus_point_advance_line): New macro. (grecs_locus_t): Redesign. (grecs_value) <locus>: New member. (grecs_node) <idloc>: New member. (grecs_print_diag_fun): Change signature. (grecs_warning,grecs_error): Change signature. (grecs_parse_line_directive) (grecs_parse_line_directive_cpp) (grecs_string_convert): Change signature. (grecs_current_locus): Remove. (grecs_current_locus_point): New extern. * src/grecs-locus.h: New file. * src/Make.am (noinst_HEADERS): Add grecs-locus.h. * src/join.c (reset_locus): Rewrite. * src/lookup.c: Initialize new members of grecs_value and grecs_node. (split_cfg_path): Return wrdse error code. (grecs_node_from_path_locus): Take two grecs_locus_t arguments. Make sure all created nodes have their locus members properly initialized. * src/parser.c (grecs_parse): Initialize grecs_current_locus_point. * src/tree.c (grecs_node_create_points): New function. (string_to_bool,string_to_host,string_to_sockaddr) (grecs_string_convert): Change signatures. Be more precise in what locus to report. * src/diag.c (default_print_diag): Use YY_LOCATION_PRINT to output locus. (grecs_print_diag_fun): Change signature. (grecs_warning,grecs_error): Change signature. * src/format.c (grecs_format_locus): Rewrite. (grecs_format_node): Be more precise in what locus is being output. * src/bind-gram.y: Keep track of locations. Turn on error-verbose mode. * src/grecs-gram.y: Likewise. * src/meta1-gram.y: Likewise. * src/bind-lex.l: Keep track of locations. * src/git-parser.c: Likewise. * src/grecs-lex.l: Likewise. * src/meta1-lex.l: Likewise. * src/path-parser.c: Likewise. * src/preproc.c: Likewise. * tests/gcf1.conf: Untabify. * tests/format01.at: Reflect changes in the output. * tests/join.at: Likewise. * tests/set.at: Likewise. * tests/locus-bind.at: New testcase. * tests/locus-git.at: New testcase. * tests/locus-meta1.at: New testcase. * tests/locus00.at: New testcase. * tests/locus01.at: New testcase. * tests/locus02.at: New testcase. * tests/path-locus.at: New testcase.
Diffstat (limited to 'src/lookup.c')
-rw-r--r--src/lookup.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/lookup.c b/src/lookup.c
index f16e94b..2e737aa 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -199,7 +199,7 @@ parse_label(const char *str)
lst = grecs_value_list_create();
for (i = 0; i < ws.ws_wordc; i++) {
- struct grecs_value *p = grecs_malloc(sizeof(*p));
+ struct grecs_value *p = grecs_zalloc(sizeof(*p));
p->type = GRECS_TYPE_STRING;
p->v.string = ws.ws_wordv[i];
grecs_list_append(lst, p);
@@ -210,7 +210,7 @@ parse_label(const char *str)
} else {
if (wordsplit(str, &ws, WRDSF_DEFFLAGS))
return NULL;
- val = grecs_malloc(sizeof(*val));
+ val = grecs_zalloc(sizeof(*val));
if (ws.ws_wordc == 1) {
val->type = GRECS_TYPE_STRING;
val->v.string = ws.ws_wordv[0];
@@ -221,14 +221,14 @@ parse_label(const char *str)
sizeof(val->v.arg.v[0]));
for (i = 0; i < ws.ws_wordc; i++) {
val->v.arg.v[i] =
- grecs_malloc(sizeof(val->v.arg.v[0]));
+ grecs_zalloc(sizeof(*val->v.arg.v[0]));
val->v.arg.v[i]->type = GRECS_TYPE_STRING;
val->v.arg.v[i]->v.string = ws.ws_wordv[i];
}
}
- ws.ws_wordc = 0;
- wordsplit_free(&ws);
}
+ ws.ws_wordc = 0;
+ wordsplit_free(&ws);
return val;
}
@@ -244,15 +244,16 @@ split_cfg_path(const char *path, int *pargc, char ***pargv,
if (path[0] == '\\') {
argv = calloc(2, sizeof (*argv));
if (!argv)
- return ENOMEM;
+ return WRDSE_NOSPACE;
argv[0] = strdup(path + 1);
if (!argv[0]) {
free(argv);
- return ENOMEM;
+ return WRDSE_NOSPACE;
}
argv[1] = NULL;
argc = 1;
} else {
+ int rc;
struct wordsplit ws;
if (strchr("./:;,^~", path[0])) {
@@ -262,8 +263,10 @@ split_cfg_path(const char *path, int *pargc, char ***pargv,
}
ws.ws_delim = delim;
- if (wordsplit(path, &ws, WRDSF_DEFFLAGS|WRDSF_DELIM))
- return errno;
+ rc = wordsplit(path, &ws,
+ WRDSF_DELIM | WRDSF_DEFFLAGS);
+ if (rc)
+ return rc;
argc = ws.ws_wordc;
argv = ws.ws_wordv;
ws.ws_wordc = 0;
@@ -333,9 +336,25 @@ grecs_find_node(struct grecs_node *node, const char *path)
}
+static void
+fixup_loci(struct grecs_node *node,
+ grecs_locus_t const *plocus,
+ struct grecs_locus_point const *endp)
+{
+ grecs_locus_t loc = *plocus;
+
+ for (; node; node = node->down) {
+ node->idloc = loc;
+
+ node->locus = loc;
+ if (endp)
+ node->locus.end = *endp;
+ }
+}
+
struct grecs_node *
grecs_node_from_path_locus(const char *path, const char *value,
- grecs_locus_t *locus)
+ grecs_locus_t *plocus, grecs_locus_t *vallocus)
{
int rc;
int i;
@@ -346,10 +365,13 @@ grecs_node_from_path_locus(const char *path, const char *value,
rc = split_cfg_path(path, &argc, &argv, NULL);
if (rc)
return NULL;
- dn = grecs_node_create(grecs_node_stmt, locus);
+
+ dn = grecs_node_create(grecs_node_stmt, NULL);
dn->ident = argv[argc - 1];
if (value) {
struct grecs_value *gval = parse_label(value);
+ if (vallocus)
+ gval->locus = *vallocus;
dn->v.value = gval;
} else
dn->v.value = NULL;
@@ -371,7 +393,7 @@ grecs_node_from_path_locus(const char *path, const char *value,
break;
} while (*q);
- node = grecs_node_create(grecs_node_block, locus);
+ node = grecs_node_create(grecs_node_block, plocus);
node->ident = argv[i];
if (label)
node->v.value = label;
@@ -381,7 +403,11 @@ grecs_node_from_path_locus(const char *path, const char *value,
dn->up = node;
dn = node;
}
-
+
+ if (plocus)
+ fixup_loci(dn,
+ plocus, vallocus ? &vallocus->end : NULL);
+
free(argv);
return dn;
}
@@ -389,7 +415,7 @@ grecs_node_from_path_locus(const char *path, const char *value,
struct grecs_node *
grecs_node_from_path(const char *path, const char *value)
{
- return grecs_node_from_path_locus(path, value, NULL);
+ return grecs_node_from_path_locus(path, value, NULL, NULL);
}

Return to:

Send suggestions and report system problems to the System administrator.