From af805ca0353df8c0e73ae3ab1e4f26786fa7b99a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Sep 2004 11:28:25 +0000 Subject: [PATCH] Lemon escapes backslashes in filenames in #line directives it generates. Ticket #892. (CVS 1943) FossilOrigin-Name: d53047cbbc4e618c7bb5161b6f82876bb113db25 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lemon.c | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index de94f09967..d2863b1670 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\smore\sname\scollisions.\s\sAllow\ssqlite.h\sand\ssqlite3.h\sto\sboth\sbe\sincluded\nin\sthe\ssame\sC/C++\ssource\sfile.\s(CVS\s1942) -D 2004-09-06T17:34:13 +C Lemon\sescapes\sbackslashes\sin\sfilenames\sin\s#line\sdirectives\sit\sgenerates.\nTicket\s#892.\s(CVS\s1943) +D 2004-09-07T11:28:25 F Makefile.in 65a7c43fcaf9a710d62f120b11b6e435eeb4a450 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -193,7 +193,7 @@ F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/view.test ca5c296989d3045f121be9a67588ff88c64874a8 F test/where.test 40dcffcb77ad0a00960cef2b5b1212c77fd02199 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b -F tool/lemon.c ece41a3cd100e68fef5f136267cf02c44366c263 +F tool/lemon.c b64210ca04268681a74b32a830c64be523ccc859 F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57 F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8 @@ -248,7 +248,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 3ddf5a9d1c480a2e3aa32685879063b11afddbe1 -R 4e21ecb2dca1b0e6b2292d8785d52007 +P 23e5bed1c5062f0f639751f89873bf1a277547bd +R e40cf5a15ff3721d6f9f87371f66f8fc U drh -Z 6b0395c7e689562e57eb91318a8ed3d1 +Z 9268fa6b52f2c5d13e0dc61c8a84d6ef diff --git a/manifest.uuid b/manifest.uuid index f95ff803f0..96bb6f9a3b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -23e5bed1c5062f0f639751f89873bf1a277547bd \ No newline at end of file +d53047cbbc4e618c7bb5161b6f82876bb113db25 \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index 7b9b0c2e5a..97f3dc8ef6 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -2923,6 +2923,21 @@ struct lemon *lemp; return in; } +/* Print a #line directive line to the output file. */ +PRIVATE void tplt_linedir(out,lineno,filename) +FILE *out; +int lineno; +char *filename; +{ + fprintf(out,"#line %d \"",lineno); + while( *filename ){ + if( *filename == '\\' ) putc('\\',out); + putc(*filename,out); + filename++; + } + fprintf(out,"\"\n"); +} + /* Print a string to the file and keep the linenumber up to date */ PRIVATE void tplt_print(out,lemp,str,strln,lineno) FILE *out; @@ -2932,13 +2947,15 @@ int strln; int *lineno; { if( str==0 ) return; - fprintf(out,"#line %d \"%s\"\n",strln,lemp->filename); (*lineno)++; + tplt_linedir(out,strln,lemp->filename); + (*lineno)++; while( *str ){ if( *str=='\n' ) (*lineno)++; putc(*str,out); str++; } - fprintf(out,"\n#line %d \"%s\"\n",*lineno+2,lemp->outname); (*lineno)+=2; + tplt_linedir(out,*lineno+2,lemp->outname); + (*lineno)+=2; return; } @@ -2958,14 +2975,17 @@ int *lineno; if( sp->type==TERMINAL ){ cp = lemp->tokendest; if( cp==0 ) return; - fprintf(out,"#line %d \"%s\"\n{",lemp->tokendestln,lemp->filename); + tplt_linedir(out,lemp->tokendestln,lemp->filename); + fprintf(out,"{"); }else if( sp->destructor ){ cp = sp->destructor; - fprintf(out,"#line %d \"%s\"\n{",sp->destructorln,lemp->filename); + tplt_linedir(out,sp->destructorln,lemp->filename); + fprintf(out,"{"); }else if( lemp->vardest ){ cp = lemp->vardest; if( cp==0 ) return; - fprintf(out,"#line %d \"%s\"\n{",lemp->vardestln,lemp->filename); + tplt_linedir(out,lemp->vardestln,lemp->filename); + fprintf(out,"{"); }else{ assert( 0 ); /* Cannot happen */ } @@ -2979,7 +2999,8 @@ int *lineno; fputc(*cp,out); } (*lineno) += 3 + linecnt; - fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname); + fprintf(out,"}\n"); + tplt_linedir(out,*lineno,lemp->outname); return; } @@ -3015,7 +3036,7 @@ PRIVATE char *append_str(char *zText, int n, int p1, int p2){ static char *z = 0; static int alloced = 0; static int used = 0; - int i, c; + int c; char zInt[40]; if( zText==0 ){ @@ -3054,9 +3075,9 @@ PRIVATE char *append_str(char *zText, int n, int p1, int p2){ /* ** zCode is a string that is the action associated with a rule. Expand ** the symbols in this string so that the refer to elements of the parser -** stack. Return a new string stored in space obtained from malloc. +** stack. */ -PRIVATE char *translate_code(struct lemon *lemp, struct rule *rp){ +PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ char *cp, *xp; int i; char lhsused = 0; /* True if the LHS element has been used */ @@ -3142,13 +3163,14 @@ int *lineno; /* Generate code to do the reduce action */ if( rp->code ){ - fprintf(out,"#line %d \"%s\"\n{",rp->line,lemp->filename); - fprintf(out,"%s",rp->code); + tplt_linedir(out,rp->line,lemp->filename); + fprintf(out,"{%s",rp->code); for(cp=rp->code; *cp; cp++){ if( *cp=='\n' ) linecnt++; } /* End loop */ (*lineno) += 3 + linecnt; - fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname); + fprintf(out,"}\n"); + tplt_linedir(out,*lineno,lemp->outname); } /* End if( rp->code ) */ return;