Blob Blame Raw
--- a2ps-4.13/src/sheets-map.l.includes	2000-02-04 21:07:47.000000000 +0000
+++ a2ps-4.13/src/sheets-map.l	2004-09-07 16:06:27.575891868 +0100
@@ -40,6 +40,7 @@
 
 #define MAX_INCLUDE_DEPTH 10
 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+static int lineno_stack[MAX_INCLUDE_DEPTH];
 static char *filename_stack[MAX_INCLUDE_DEPTH];
 static int include_stack_ptr;
 static char *yyfilename;
@@ -93,7 +94,7 @@
 white         [[:space:]]+
 key           [-a-zA-Z0-9_]+:
 comment       #.*
-include       include([^)]+)
+include       include\([^)]+\)
 %%
 
 {key}         token_val = xstrndup (yytext, yyleng - 1); return tKEY;
@@ -102,7 +103,7 @@
 {white}       ;
 {comment}     ;
 {include}     {	/* Kill the closing paren and pass the file name. */
-                yytext[yyleng] = '\0';
+                yytext[yyleng-1] = '\0';
                 yy_include_push (yytext + strlen ("include("));
               }
 
@@ -210,11 +211,13 @@
     error (1, 0, _("too many includes"));
 
   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
-  filename_stack[include_stack_ptr++] = file;
+  lineno_stack[include_stack_ptr] = yylineno;
+  filename_stack[include_stack_ptr++] = yyfilename;
 
   message (msg_file, (stderr, "%s:%d: includes %s\n",
 		      yyfilename, yylineno, file));
 
+  yyfilename = file;
   yyin = xrfopen (yyfilename);
 
   yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
@@ -227,8 +230,8 @@
 {
   fclose (yyin);
   yy_delete_buffer (YY_CURRENT_BUFFER);
-  free (yyfilename);
   yyfilename = filename_stack[include_stack_ptr];
+  yylineno = lineno_stack[include_stack_ptr];
   yy_switch_to_buffer (include_stack[include_stack_ptr]);
   message (msg_file, (stderr, "Back to file `%s'.\n", yyfilename));
 }
@@ -254,6 +257,7 @@
 yy_close (void)
 {
   fclose (yyin);
+  free (yyfilename);
 }
 
 int