Bootstrapped and regtested on x86_64-linux-gnu. Ok for trunk?
fixincludes/
* fixfixes.c (print_quote): Define it unconditionally, taking
and returning const char *.
(machine_name_fix): Output quoted strings verbatim.
---
fixincludes/fixfixes.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/fixincludes/fixfixes.c b/fixincludes/fixfixes.c
index 5b23a8b640d..2f4ee28a897 100644
--- a/fixincludes/fixfixes.c
+++ b/fixincludes/fixfixes.c
@@ -78,15 +78,14 @@ static void fix (const char* filname ATTRIBUTE_UNUSED , \
const char* text ATTRIBUTE_UNUSED , \
tFixDesc* p_fixd ATTRIBUTE_UNUSED )
-#ifdef NEED_PRINT_QUOTE
/*
* Skip over a quoted string. Single quote strings may
* contain multiple characters if the first character is
* a backslash. Especially a backslash followed by octal digits.
* We are not doing a correctness syntax check here.
*/
-static char*
-print_quote(char q, char* text )
+static const char*
+print_quote(char q, const char* text )
{
fputc( q, stdout );
@@ -118,7 +117,6 @@ print_quote(char q, char* text )
return text;
}
-#endif /* NEED_PRINT_QUOTE */
/*
@@ -488,7 +486,7 @@ FIX_PROC_HEAD( char_macro_def_fix )
FIX_PROC_HEAD( machine_name_fix )
{
regmatch_t match[2];
- const char *line, *base, *limit, *p, *q;
+ const char *line, *base, *limit, *p, *q, *quote;
regex_t *label_re, *name_re;
char scratch[SCRATCHSZ];
size_t len;
@@ -533,7 +531,7 @@ FIX_PROC_HEAD( machine_name_fix )
for (;;)
{
again:
- if (base == limit)
+ if (base >= limit)
break;
if (xregexec (name_re, base, 1, match, REG_NOTBOL))
@@ -543,6 +541,26 @@ FIX_PROC_HEAD( machine_name_fix )
if (match[0].rm_eo > limit - base)
break;
+ /* Looking for the next non-escaped quote in the line. */
+ quote = base - 1;
+ do
+ {
+ quote++;
+ quote = strpbrk (quote, "'\"");
+ if (quote && quote > limit)
+ quote = NULL;
+ }
+ while (quote && quote[-1] == '\\');
+
+ if (quote && match[0].rm_eo > quote - base)
+ {
+ /* Match is after the quote: print the quoted string and
+ everything before it verbatim. */
+ fwrite (text, 1, quote - text, stdout);
+ base = text = print_quote (*quote, quote + 1);
+ goto again;
+ }
+
p = base + match[0].rm_so;
base += match[0].rm_eo;
--
2.32.0