/ Check-in [d53047cb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Lemon escapes backslashes in filenames in #line directives it generates. Ticket #892. (CVS 1943)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d53047cbbc4e618c7bb5161b6f82876bb113db25
User & Date: drh 2004-09-07 11:28:25
Context
2004-09-07
13:20
Fix the onecolumn method in the TCL interface so that it works the same as the eval method in all ways except for returning just the first value in the result set. (CVS 1944) check-in: f323e4f8 user: drh tags: trunk
11:28
Lemon escapes backslashes in filenames in #line directives it generates. Ticket #892. (CVS 1943) check-in: d53047cb user: drh tags: trunk
2004-09-06
17:34
Fix more name collisions. Allow sqlite.h and sqlite3.h to both be included in the same C/C++ source file. (CVS 1942) check-in: 23e5bed1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

  2918   2918     if( in==0 ){
  2919   2919       fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
  2920   2920       lemp->errorcnt++;
  2921   2921       return 0;
  2922   2922     }
  2923   2923     return in;
  2924   2924   }
         2925  +
         2926  +/* Print a #line directive line to the output file. */
         2927  +PRIVATE void tplt_linedir(out,lineno,filename)
         2928  +FILE *out;
         2929  +int lineno;
         2930  +char *filename;
         2931  +{
         2932  +  fprintf(out,"#line %d \"",lineno);
         2933  +  while( *filename ){
         2934  +    if( *filename == '\\' ) putc('\\',out);
         2935  +    putc(*filename,out);
         2936  +    filename++;
         2937  +  }
         2938  +  fprintf(out,"\"\n");
         2939  +}
  2925   2940   
  2926   2941   /* Print a string to the file and keep the linenumber up to date */
  2927   2942   PRIVATE void tplt_print(out,lemp,str,strln,lineno)
  2928   2943   FILE *out;
  2929   2944   struct lemon *lemp;
  2930   2945   char *str;
  2931   2946   int strln;
  2932   2947   int *lineno;
  2933   2948   {
  2934   2949     if( str==0 ) return;
  2935         -  fprintf(out,"#line %d \"%s\"\n",strln,lemp->filename); (*lineno)++;
         2950  +  tplt_linedir(out,strln,lemp->filename);
         2951  +  (*lineno)++;
  2936   2952     while( *str ){
  2937   2953       if( *str=='\n' ) (*lineno)++;
  2938   2954       putc(*str,out);
  2939   2955       str++;
  2940   2956     }
  2941         -  fprintf(out,"\n#line %d \"%s\"\n",*lineno+2,lemp->outname); (*lineno)+=2;
         2957  +  tplt_linedir(out,*lineno+2,lemp->outname); 
         2958  +  (*lineno)+=2;
  2942   2959     return;
  2943   2960   }
  2944   2961   
  2945   2962   /*
  2946   2963   ** The following routine emits code for the destructor for the
  2947   2964   ** symbol sp
  2948   2965   */
................................................................................
  2954   2971   {
  2955   2972    char *cp = 0;
  2956   2973   
  2957   2974    int linecnt = 0;
  2958   2975    if( sp->type==TERMINAL ){
  2959   2976      cp = lemp->tokendest;
  2960   2977      if( cp==0 ) return;
  2961         -   fprintf(out,"#line %d \"%s\"\n{",lemp->tokendestln,lemp->filename);
         2978  +   tplt_linedir(out,lemp->tokendestln,lemp->filename);
         2979  +   fprintf(out,"{");
  2962   2980    }else if( sp->destructor ){
  2963   2981      cp = sp->destructor;
  2964         -   fprintf(out,"#line %d \"%s\"\n{",sp->destructorln,lemp->filename);
         2982  +   tplt_linedir(out,sp->destructorln,lemp->filename);
         2983  +   fprintf(out,"{");
  2965   2984    }else if( lemp->vardest ){
  2966   2985      cp = lemp->vardest;
  2967   2986      if( cp==0 ) return;
  2968         -   fprintf(out,"#line %d \"%s\"\n{",lemp->vardestln,lemp->filename);
         2987  +   tplt_linedir(out,lemp->vardestln,lemp->filename);
         2988  +   fprintf(out,"{");
  2969   2989    }else{
  2970   2990      assert( 0 );  /* Cannot happen */
  2971   2991    }
  2972   2992    for(; *cp; cp++){
  2973   2993      if( *cp=='$' && cp[1]=='$' ){
  2974   2994        fprintf(out,"(yypminor->yy%d)",sp->dtnum);
  2975   2995        cp++;
  2976   2996        continue;
  2977   2997      }
  2978   2998      if( *cp=='\n' ) linecnt++;
  2979   2999      fputc(*cp,out);
  2980   3000    }
  2981   3001    (*lineno) += 3 + linecnt;
  2982         - fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
         3002  + fprintf(out,"}\n");
         3003  + tplt_linedir(out,*lineno,lemp->outname);
  2983   3004    return;
  2984   3005   }
  2985   3006   
  2986   3007   /*
  2987   3008   ** Return TRUE (non-zero) if the given symbol has a destructor.
  2988   3009   */
  2989   3010   int has_destructor(sp, lemp)
................................................................................
  3011   3032   **
  3012   3033   ** If n==-1, then the previous character is overwritten.
  3013   3034   */
  3014   3035   PRIVATE char *append_str(char *zText, int n, int p1, int p2){
  3015   3036     static char *z = 0;
  3016   3037     static int alloced = 0;
  3017   3038     static int used = 0;
  3018         -  int i, c;
         3039  +  int c;
  3019   3040     char zInt[40];
  3020   3041   
  3021   3042     if( zText==0 ){
  3022   3043       used = 0;
  3023   3044       return z;
  3024   3045     }
  3025   3046     if( n<=0 ){
................................................................................
  3050   3071     z[used] = 0;
  3051   3072     return z;
  3052   3073   }
  3053   3074   
  3054   3075   /*
  3055   3076   ** zCode is a string that is the action associated with a rule.  Expand
  3056   3077   ** the symbols in this string so that the refer to elements of the parser
  3057         -** stack.  Return a new string stored in space obtained from malloc.
         3078  +** stack.
  3058   3079   */
  3059         -PRIVATE char *translate_code(struct lemon *lemp, struct rule *rp){
         3080  +PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
  3060   3081     char *cp, *xp;
  3061   3082     int i;
  3062   3083     char lhsused = 0;    /* True if the LHS element has been used */
  3063   3084     char used[MAXRHS];   /* True for each RHS element which is used */
  3064   3085   
  3065   3086     for(i=0; i<rp->nrhs; i++) used[i] = 0;
  3066   3087     lhsused = 0;
................................................................................
  3138   3159   int *lineno;
  3139   3160   {
  3140   3161    char *cp;
  3141   3162    int linecnt = 0;
  3142   3163   
  3143   3164    /* Generate code to do the reduce action */
  3144   3165    if( rp->code ){
  3145         -   fprintf(out,"#line %d \"%s\"\n{",rp->line,lemp->filename);
  3146         -   fprintf(out,"%s",rp->code);
         3166  +   tplt_linedir(out,rp->line,lemp->filename);
         3167  +   fprintf(out,"{%s",rp->code);
  3147   3168      for(cp=rp->code; *cp; cp++){
  3148   3169        if( *cp=='\n' ) linecnt++;
  3149   3170      } /* End loop */
  3150   3171      (*lineno) += 3 + linecnt;
  3151         -   fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
         3172  +   fprintf(out,"}\n");
         3173  +   tplt_linedir(out,*lineno,lemp->outname);
  3152   3174    } /* End if( rp->code ) */
  3153   3175   
  3154   3176    return;
  3155   3177   }
  3156   3178   
  3157   3179   /*
  3158   3180   ** Print the definition of the union used for the parser's data stack.