aboutsummaryrefslogtreecommitdiff
path: root/src/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format.c')
-rw-r--r--src/format.c59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/format.c b/src/format.c
index d65f712..f1a876f 100644
--- a/src/format.c
+++ b/src/format.c
@@ -31,7 +31,7 @@ grecs_data_type_string(enum grecs_data_type type)
switch (type) {
case grecs_type_void:
return "void";
-
+
case grecs_type_string:
return "string";
@@ -47,13 +47,13 @@ grecs_data_type_string(enum grecs_data_type type)
case grecs_type_time:
return "time";
-
+
case grecs_type_bool:
return "boolean";
-
+
case grecs_type_ipv4:
return "IPv4";
-
+
case grecs_type_cidr:
return "CIDR";
@@ -125,7 +125,7 @@ grecs_print_simple_statement(struct grecs_keyword *kwp, unsigned level,
FILE *stream)
{
const char *argstr;
-
+
if (kwp->docstring)
grecs_print_docstring(kwp->docstring, level, stream);
format_level(level, stream);
@@ -192,7 +192,33 @@ grecs_format_locus(grecs_locus_t *locus, struct grecs_format_closure *clos)
if (locus) {
char *str = NULL;
size_t size = 0;
- grecs_asprintf(&str, &size, "%s:%d", locus->file, locus->line);
+
+ if (locus->beg.col == 0)
+ grecs_asprintf(&str, &size, "%s:%u",
+ locus->beg.file,
+ locus->beg.line);
+ else if (strcmp(locus->beg.file, locus->end.file))
+ grecs_asprintf(&str, &size, "%s:%u.%u-%s:%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.file,
+ locus->end.line, locus->end.col);
+ else if (locus->beg.line != locus->end.line)
+ grecs_asprintf(&str, &size, "%s:%u.%u-%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.line, locus->end.col);
+ else if (locus->beg.col != locus->end.col)
+ grecs_asprintf(&str, &size, "%s:%u.%u-%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.col);
+ else
+ grecs_asprintf(&str, &size, "%s:%u.%u",
+ locus->beg.file,
+ locus->beg.line,
+ locus->beg.col);
+
clos->fmtfun(str, clos->data);
free(str);
}
@@ -203,7 +229,7 @@ grecs_format_node_path(struct grecs_node *node, int flags,
struct grecs_format_closure *clos)
{
char delim[2] = ".";
-
+
if (node->up)
grecs_format_node_path(node->up, flags, clos);
if (node->type == grecs_node_root)
@@ -277,7 +303,7 @@ grecs_format_node(struct grecs_node *node, int flags,
struct grecs_format_closure *clos)
{
const char *delim_str = NULL;
-
+
if (!(flags & _GRECS_NODE_MASK_OUTPUT)) {
errno = EINVAL;
return 1;
@@ -297,7 +323,18 @@ grecs_format_node(struct grecs_node *node, int flags,
case grecs_node_stmt:
if (flags & GRECS_NODE_FLAG_LOCUS) {
- grecs_format_locus(&node->locus, clos);
+ grecs_locus_t *locus;
+
+ if (flags & GRECS_NODE_FLAG_PATH) {
+ if (flags & GRECS_NODE_FLAG_VALUE)
+ locus = &node->locus;
+ else
+ locus = &node->idloc;
+ } else if (flags & GRECS_NODE_FLAG_VALUE)
+ locus = &node->v.value->locus;
+ else
+ locus = &node->locus;
+ grecs_format_locus(locus, clos);
delim_str = ": ";
}
if (flags & GRECS_NODE_FLAG_PATH) {
@@ -367,7 +404,3 @@ grecs_print_node(struct grecs_node *node, int flags, FILE *fp)
struct grecs_format_closure clos = { file_fmt, fp };
return grecs_format_node(node, flags, &clos);
}
-
-
-
-

Return to:

Send suggestions and report system problems to the System administrator.