From a5b6ef2a18bf25f293a9759080a29217aabce040 Mon Sep 17 00:00:00 2001 From: kaashoek Date: Sun, 29 May 1988 13:52:54 +0000 Subject: [PATCH] Quotes en back-slahses moeten ook speciaal behandeld worden in strings. --- util/ceg/as_parser/conversion.c | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/util/ceg/as_parser/conversion.c b/util/ceg/as_parser/conversion.c index 8052c03a2..9885641f5 100644 --- a/util/ceg/as_parser/conversion.c +++ b/util/ceg/as_parser/conversion.c @@ -6,18 +6,14 @@ pr_text_with_conversions( str) char *str; { - char *s, *ptr, *next_conversion(), *pr_conversion(); + char *ptr, *next_conversion(), *pr_conversion(); while ( ptr = next_conversion( str)) { /* ptr points to '%'-sign */ *ptr = '\0'; out( "fprint( outfile, \""); - for ( s = str; *s != '\0'; s++) - if ( *s == '\n') - out( "\\n"); - else - out( "%c", *s); + out_string( str); out( "\");"); *ptr = '%'; @@ -25,14 +21,30 @@ char *str; } out( "fprint( outfile, \""); - for ( s = str; *s != '\0'; s++) - if ( *s == '\n') - out( "\\n"); - else - out( "%c", *s); + out_string( str); out( "\");"); } + +out_string( s) +char *s; +{ + for ( ; *s != '\0'; s++) + switch ( *s) { + case '"' : out( "\\\""); + break; + + case '\\': out( "\\\\"); + break; + + case '\n': out( "\\n"); + break; + + default : out( "%c", *s); + } +} + + char *next_conversion( str) char *str;