From a020d116280f49318777fae0bb71f22d0e4827aa Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Sun, 24 Nov 2019 23:20:48 +0100 Subject: [PATCH] add a pprint function pointer to HTTEntry --- src/internal.h | 1 + src/pprint.c | 6 ++++-- src/registry.c | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/internal.h b/src/internal.h index 0e92e99e..79d6c978 100644 --- a/src/internal.h +++ b/src/internal.h @@ -428,6 +428,7 @@ typedef struct HTTEntry_ { const char* name; HTokenType value; void (*unamb_sub)(const HParsedToken *tok, struct result_buf *buf); + void (*pprint)(FILE* stream, const HParsedToken* tok, int indent, int delta); } HTTEntry; const HTTEntry* h_get_token_type_entry(HTokenType token_type); diff --git a/src/pprint.c b/src/pprint.c index 15c14f83..2c9fbc2e 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -69,9 +69,11 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) { break; default: if(tok->token_type >= TT_USER) { - const char *name = h_get_token_type_name(tok->token_type); + const HTTEntry *e = h_get_token_type_entry(tok->token_type); int num = tok->token_type-TT_USER; - fprintf(stream, "%*sUSER:%s %d\n", indent, "", name, num); + fprintf(stream, "%*sUSER:%s %d\n", indent, "", e->name, num); + if (e->pprint) + e->pprint(stream, tok, indent + delta, delta); } else { assert_message(0, "Should not reach here."); } diff --git a/src/registry.c b/src/registry.c index 00486db4..f0201c61 100644 --- a/src/registry.c +++ b/src/registry.c @@ -60,6 +60,7 @@ HTokenType h_allocate_token_new( new_entry->name = name; new_entry->value = 0; new_entry->unamb_sub = unamb_sub; + new_entry->pprint = NULL; HTTEntry* probe = *(HTTEntry**)tsearch(new_entry, &tt_registry, compare_entries); if (probe->value != 0) { // Token type already exists... -- GitLab