aboutsummaryrefslogtreecommitdiff
path: root/src/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format.c')
-rw-r--r--src/format.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/format.c b/src/format.c
index 1302520..a6b3bd9 100644
--- a/src/format.c
+++ b/src/format.c
@@ -262,6 +262,60 @@ grecs_format_value(struct grecs_value *val, int flags, FILE *fp)
}
void
+grecs_txtacc_format_value(struct grecs_value *val, int flags,
+ struct grecs_txtacc *acc)
+{
+ int i;
+ struct grecs_list_entry *ep;
+ size_t clen;
+ int need_quote;
+
+ if (!val)
+ return;
+ switch (val->type) {
+ case GRECS_TYPE_STRING:
+ clen = wordsplit_c_quoted_length(val->v.string,
+ flags & GRECS_NODE_FLAG_QUOTE_HEX,
+ &need_quote);
+ if (flags & GRECS_NODE_FLAG_QUOTE)
+ need_quote = 1;
+ else if (flags & GRECS_NODE_FLAG_NOQUOTE)
+ need_quote = 0;
+ if (need_quote) {
+ char *cbuf = grecs_malloc(clen + 1);
+ wordsplit_c_quote_copy(cbuf, val->v.string,
+ flags & GRECS_NODE_FLAG_QUOTE_HEX);
+ grecs_txtacc_grow_char(acc, '"');
+ grecs_txtacc_grow(acc, cbuf, clen);
+ grecs_txtacc_grow_char(acc, '"');
+ grecs_free(cbuf);
+ } else
+ grecs_txtacc_grow(acc, val->v.string,
+ strlen(val->v.string));
+ break;
+
+ case GRECS_TYPE_LIST:
+ grecs_txtacc_grow_char(acc, '(');
+ for (ep = val->v.list->head; ep; ep = ep->next) {
+ grecs_txtacc_format_value(ep->data, flags, acc);
+ if (ep->next) {
+ grecs_txtacc_grow_char(acc, ',');
+ grecs_txtacc_grow_char(acc, ' ');
+ }
+ }
+ grecs_txtacc_grow_char(acc, ')');
+ break;
+
+ case GRECS_TYPE_ARRAY:
+ for (i = 0; i < val->v.arg.c; i++) {
+ if (i)
+ grecs_txtacc_grow_char(acc, ' ');
+ grecs_txtacc_format_value(val->v.arg.v[i], flags, acc);
+ }
+ }
+}
+
+void
grecs_format_node(struct grecs_node *node, int flags, FILE *fp)
{
const char *delim_str = NULL;

Return to:

Send suggestions and report system problems to the System administrator.