aboutsummaryrefslogtreecommitdiff
path: root/gcc/cccp.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@gnu.org>1993-09-29 01:29:31 +0000
committerPaul Eggert <eggert@gnu.org>1993-09-29 01:29:31 +0000
commitbb2f42b1caa59cbb7eaf86a9b9dad78621ce0ad9 (patch)
tree68ae2015706ed8b5f1b7657425960ecf497a9476 /gcc/cccp.c
parentdb6b21866df8c448eb783b015cb92106a3ab750a (diff)
downloadgcc-bb2f42b1caa59cbb7eaf86a9b9dad78621ce0ad9.zip
gcc-bb2f42b1caa59cbb7eaf86a9b9dad78621ce0ad9.tar.gz
gcc-bb2f42b1caa59cbb7eaf86a9b9dad78621ce0ad9.tar.bz2
(quote_string): New function.
(special_symbol): Use it to properly quote special chars in __FILE__. From-SVN: r5526
Diffstat (limited to 'gcc/cccp.c')
-rw-r--r--gcc/cccp.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cccp.c b/gcc/cccp.c
index f8001c4..a73ef1b 100644
--- a/gcc/cccp.c
+++ b/gcc/cccp.c
@@ -308,6 +308,7 @@ static char *macarg ();
static U_CHAR *skip_to_end_of_comment ();
static U_CHAR *skip_quoted_string ();
static U_CHAR *skip_paren_group ();
+static void quote_string ();
static char *check_precompiled ();
/* static struct macrodef create_definition (); [moved below] */
@@ -3663,8 +3664,8 @@ special_symbol (hp, op)
if (string)
{
- buf = (char *) alloca (3 + strlen (string));
- sprintf (buf, "\"%s\"", string);
+ buf = (char *) alloca (3 + 2 * strlen (string));
+ quote_string (buf, string);
}
else
buf = "\"\"";
@@ -6907,6 +6908,31 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
return bp;
}
+/* Place into DST a quoted string representing the string SRC. */
+static void
+quote_string (dst, src)
+ char *dst, *src;
+{
+ char c;
+
+ for (*dst++ = '\"'; ; *dst++ = c)
+ switch ((c = *src++))
+ {
+ case '\n':
+ c = 'n';
+ /* fall through */
+ case '\"':
+ case '\\':
+ *dst++ = '\\';
+ break;
+
+ case '\0':
+ *dst++ = '\"';
+ *dst = '\0';
+ return;
+ }
+}
+
/* Skip across a group of balanced parens, starting from IP->bufp.
IP->bufp is updated. Use this with IP->bufp pointing at an open-paren.