bug-a2ps
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[a2ps-4.13b] include() does not seem to work


From: Vasco Pedro
Subject: [a2ps-4.13b] include() does not seem to work
Date: Fri, 25 Jan 2002 14:59:37 +0000

Hi,

I tried using

        include(/usr/share/a2ps/sheets/sheets.map)

from `~/.a2ps/sheets.map' but a2ps complained that there were
``too many includes''.

`strace'ing the execution, it was apparent that `~/.a2ps/sheets.map'
was being repeatedly opened, so I took a look at the source code
and found several bugs in `sheets-map.l':

1. in yy_include_push(), `yyfilename' was being opened instead of
   the included `file', which was being inserted onto the stack
   in place of the former.

2. the parenthesis in definition of the token `include(.*)' should
   have been quoted.

3. `free(yyfilenames)' does not belong in yy_include_pop() since
   this function is never called for the first `sheets.map' opened;
   it should instead reside in yy_close().

4. since `yylineno' wasn't being restored when the parsing of an
   included file finished, errors after the `include' command were
   reported as being on a line whose number was relative to the
   beginning of the included file.

Please find below a patch which (hopefully) fixes the above bugs.

Btw, I like a2ps a lot.

Best regards,
vasco

--- a2ps-4.13/src/sheets-map.l.orig     Fri Feb  4 21:07:47 2000
+++ a2ps-4.13/src/sheets-map.l  Fri Jan 25 14:21:40 2002
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]