aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-25 23:10:53 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-25 23:10:46 +0200
commite5d710cac54ffc472cd839060a7a18ddc563a608 (patch)
treef6a32af46f2fa51565db2194a2edc59a3f2eb827
parenteb6779f6f62173672b533cfbbff59758f710fb4f (diff)
downloadsparse-e5d710cac54ffc472cd839060a7a18ddc563a608.tar.gz
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 <luc.vanoostenryck@gmail.com>
-rw-r--r--show-parse.c18
-rw-r--r--symbol.h1
2 files changed, 18 insertions, 1 deletions
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);