[PATCH 1/8] show-mod: add helper to show the modifiers but without ending space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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 51a151911e3b..17a4de8be64e 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 c2b60ce91c27..4792b008efe3 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);
-- 
2.28.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux