From e5d710cac54ffc472cd839060a7a18ddc563a608 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Mon, 25 May 2020 23:10:53 +0200 Subject: show-mod: add helper to show the modifiers but without ending space modifier_string() returns either "" or a string with one or several modifiers separated by a space. In this last case the string has also a trailing space. This trailing space is sometimes desired (for example when composed with identifier name: "%s%s") but is also sometimes not desired (for example when only the modifiers must be displayed). So, create a variant of modifier_string() which doesn't add the ending space: modifier_name(). Signed-off-by: Luc Van Oostenryck --- show-parse.c | 18 +++++++++++++++++- symbol.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/show-parse.c b/show-parse.c index 51a15191..17a4de8b 100644 --- a/show-parse.c +++ b/show-parse.c @@ -107,7 +107,7 @@ void debug_symbol(struct symbol *sym) * Symbol type printout. The type system is by far the most * complicated part of C - everything else is trivial. */ -const char *modifier_string(unsigned long mod) +static const char *show_modifiers(unsigned long mod, int term) { static char buffer[100]; int len = 0; @@ -155,10 +155,26 @@ const char *modifier_string(unsigned long mod) buffer[len++] = ' '; } } + if (len && !term) // strip the trailing space + --len; buffer[len] = 0; return buffer; } +/// +// show the modifiers, terminated by a space if not empty +const char *modifier_string(unsigned long mod) +{ + return show_modifiers(mod, 1); +} + +/// +// show the modifiers, without an ending space +const char *modifier_name(unsigned long mod) +{ + return show_modifiers(mod, 0); +} + static void show_struct_member(struct symbol *sym) { printf("\t%s:%d:%ld at offset %ld.%d", show_ident(sym->ident), sym->bit_size, sym->ctype.alignment, sym->offset, sym->bit_offset); diff --git a/symbol.h b/symbol.h index c2b60ce9..4792b008 100644 --- a/symbol.h +++ b/symbol.h @@ -327,6 +327,7 @@ extern void init_linearized_builtins(int stream); extern void init_ctype(void); extern struct symbol *alloc_symbol(struct position, int type); extern void show_type(struct symbol *); +extern const char *modifier_name(unsigned long mod); extern const char *modifier_string(unsigned long mod); extern void show_symbol(struct symbol *); extern int show_symbol_expr_init(struct symbol *sym); -- cgit 1.2.3-korg