]> granicus.if.org Git - strace/commitdiff
Add print_quoted_string flag to generate comment
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 11 Jan 2018 21:46:23 +0000 (22:46 +0100)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 29 Jan 2018 13:10:10 +0000 (14:10 +0100)
Because there are never enough print_quoted_string flags.

* defs.h (QUOTE_EMIT_COMMENT): New quoting flag macro constant.
* util.c (string_quote): Emit " /* " in the beginning and " */" in the
end if QUOTE_EMIT_COMMENT is passed.
(print_quoted_string): Increase alloc_size by 7 if QUOTE_EMIT_COMMENT is
passed.

defs.h
util.c

diff --git a/defs.h b/defs.h
index b62b88c952fcd6a05aa80e9b3e4151fa2626131f..bbe0ecc9dd8270847d46dd350a4234bf132b4c09 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -512,6 +512,7 @@ str_strip_prefix_len(const char *str, const char *prefix, size_t prefix_len)
 #define QUOTE_OMIT_LEADING_TRAILING_QUOTES     0x02
 #define QUOTE_OMIT_TRAILING_0                  0x08
 #define QUOTE_FORCE_HEX                                0x10
+#define QUOTE_EMIT_COMMENT                     0x20
 
 extern int string_quote(const char *, char *, unsigned int, unsigned int);
 extern int print_quoted_string(const char *, unsigned int, unsigned int);
diff --git a/util.c b/util.c
index 1ede89895b5cf2b599f8c7908ac6bf62e3bdecde..a1e9621dcaf8a90b38e22ff75913c4849a32e621 100644 (file)
--- a/util.c
+++ b/util.c
@@ -497,6 +497,8 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
                }
        }
 
+       if (style & QUOTE_EMIT_COMMENT)
+               s = stpcpy(s, " /* ");
        if (!(style & QUOTE_OMIT_LEADING_TRAILING_QUOTES))
                *s++ = '\"';
 
@@ -576,6 +578,8 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
 
        if (!(style & QUOTE_OMIT_LEADING_TRAILING_QUOTES))
                *s++ = '\"';
+       if (style & QUOTE_EMIT_COMMENT)
+               s = stpcpy(s, " */");
        *s = '\0';
 
        /* Return zero if we printed entire ASCIZ string (didn't truncate it) */
@@ -591,6 +595,8 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
  asciz_ended:
        if (!(style & QUOTE_OMIT_LEADING_TRAILING_QUOTES))
                *s++ = '\"';
+       if (style & QUOTE_EMIT_COMMENT)
+               s = stpcpy(s, " */");
        *s = '\0';
        /* Return zero: we printed entire ASCIZ string (didn't truncate it) */
        return 0;
@@ -632,7 +638,8 @@ print_quoted_string(const char *str, unsigned int size,
                tprints("???");
                return -1;
        }
-       alloc_size += 1 + (style & QUOTE_OMIT_LEADING_TRAILING_QUOTES ? 0 : 2);
+       alloc_size += 1 + (style & QUOTE_OMIT_LEADING_TRAILING_QUOTES ? 0 : 2) +
+               (style & QUOTE_EMIT_COMMENT ? 7 : 0);
 
        if (use_alloca(alloc_size)) {
                outstr = alloca(alloc_size);