]> granicus.if.org Git - flex/commitdiff
Added doubling of '\'s in filenames
authorVern Paxson <vern@ee.lbl.gov>
Sun, 26 Dec 1993 15:03:14 +0000 (15:03 +0000)
committerVern Paxson <vern@ee.lbl.gov>
Sun, 26 Dec 1993 15:03:14 +0000 (15:03 +0000)
misc.c

diff --git a/misc.c b/misc.c
index ef030c23cf098160a40b3f37bcc179fe7d08526e..12e4cf13077e9b57777faa9d545288d84842e687 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -387,7 +387,8 @@ void line_directive_out( output_file, do_infile )
 FILE *output_file;
 int do_infile;
        {
-       char directive[MAXLINE];
+       char directive[MAXLINE], filename[MAXLINE];
+       char *s1, *s2, *s3;
        static char line_fmt[] = "# line %d \"%s\"\n";
 
        if ( ! gen_line_dirs )
@@ -397,15 +398,30 @@ int do_infile;
                /* don't know the filename to use, skip */
                return;
 
+       s1 = do_infile ? infilename : outfilename;
+       s2 = filename;
+       s3 = &filename[sizeof( filename ) - 2];
+
+       while ( s2 < s3 && *s1 )
+               {
+               if ( *s1 == '\\' )
+                       /* Escape the '\' */
+                       *s2++ = '\\';
+
+               *s2++ = *s1++;
+               }
+
+       *s2 = '\0';
+
        if ( do_infile )
-               sprintf( directive, line_fmt, linenum, infilename );
+               sprintf( directive, line_fmt, linenum, filename );
        else
                {
                if ( output_file == stdout )
                        /* Account for the line directive itself. */
                        ++out_linenum;
 
-               sprintf( directive, line_fmt, out_linenum, outfilename );
+               sprintf( directive, line_fmt, out_linenum, filename );
                }
 
        /* If output_file is nil then we should put the directive in