Add print_quoted_string flag to generate comment
PATCH 2/12 Add print_quoted_string flag to generate comment
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 | 1 + util.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
defs.h +1 -0
@@ -530,6 +530,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 0x20extern int string_quote (const char *,char *,unsigned int ,unsigned int );extern int print_quoted_string (const char *,unsigned int ,unsigned int );
util.c +8 -1
@@ -497,6 +497,8 @@ string_quote(const char *instr, char *outstr, const unsigned int size, } } +if (style "E_EMIT_COMMENT ) + s =stpcpy (s," /* " );if (!(style "E_OMIT_LEADING_TRAILING_QUOTES )) *s++ ='\"' ;
@@ -576,6 +578,8 @@ string_quote(const char *instr, char *outstr, const unsigned int size,if (!(style "E_OMIT_LEADING_TRAILING_QUOTES )) *s++ ='\"' ; +if (style "E_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 "E_OMIT_LEADING_TRAILING_QUOTES )) *s++ ='\"' ; +if (style "E_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 "E_OMIT_LEADING_TRAILING_QUOTES ?0 :2 ); + alloc_size +=1 + (style "E_OMIT_LEADING_TRAILING_QUOTES ?0 :2 ) + + (style "E_EMIT_COMMENT ?7 :0 );if (use_alloca (alloc_size)) { outstr =alloca (alloc_size);
Signature · 1 line
2.1.4