Quotes en back-slashes moeten ook speciaal behandeld wordeni\b in strings.
authorkaashoek <none@none>
Sun, 29 May 1988 13:55:56 +0000 (13:55 +0000)
committerkaashoek <none@none>
Sun, 29 May 1988 13:55:56 +0000 (13:55 +0000)
util/ceg/as_parser/eval/eval.c

index af3a788..98d55e6 100644 (file)
@@ -225,34 +225,42 @@ char *quest;
 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';
                printf( "fprint( outfile, \"");
-
-               for ( s = str; *s != '\0'; s++)
-                       if ( *s == '\n')
-                               printf( "\\n");
-                       else
-                               putchar( *s);
-
+               pr_string( str);
                printf( "\");");
                *ptr = '%';
                str = pr_conversion( ptr);
        }
        printf( "fprint( outfile, \"");
+       pr_string( str);
+       printf( "\");");
+}
 
-       for ( s = str; *s != '\0'; s++)
-               if ( *s == '\n')
-                       printf( "\\n");
-               else
-                       putchar( *s);
 
-       printf( "\");");
+pr_string( s)
+char *s;
+{
+       for ( ; *s != '\0'; s++)
+               switch ( *s) {
+                 case '"' : printf( "\\\"");
+                            break;
+
+                 case '\\': printf( "\\\\");
+                            break;
+
+                 case '\n': printf( "\\n");
+                            break;
+
+                 default  : printf( "%c", *s);
+               }
 }
 
+
 char *next_conversion( str)
 char *str;
 {