From 58e1e767cda4bffeb0d0650df7231a924b2df9ac Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 26 Dec 1993 15:03:14 +0000 Subject: [PATCH] Added doubling of '\'s in filenames --- misc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/misc.c b/misc.c index ef030c2..12e4cf1 100644 --- 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 -- 2.50.0