psset bug in Slackware 12.0

Paul Novak <[email protected]> Tue, 2 Oct 2007 19:19:10 -0500
Newsgroups gmane.comp.printing.a2ps.bugs
Message-ID <20071003001910.GA5505@baba>
I've spent some time debugging a problem printing on new install 
of a Slackware 12.0 system, running lprng and apsfilter.

Slackware 12.0 versions:

    gcc (GCC) 4.1.2
    GNU groff version 1.19.2
    psset 1.3 (GNU a2ps 4.13)
    GNU sed version 4.1.5
    This is perl, v5.8.8 built for i486-linux-thread-multi

I believe I have tracked down the problem to something in the psset command.

Here's how to recreate the problem:

run this command on a Slackware 12.0 system:

    echo ".P" | groff -mm -S -Tps - | psset -n -q -s -  | grep untdictstack

you'll get this invalid Postscript output (indented by me)

    /CNT countdictstack def
    countdictstack CNT sub{end}repeat
    untdictstack
    untdictstack exch sub dup 0 gt

After looking at the psset script, I sent a question to the maintainer of
sed (Paulo Bonzini) and included a copy of the $sedscript that is created
by psset.  Here is a snippet of Paulo's  reply:


> \countdictstack\
> \{\
> \%%BeginFeature \
> \%%EndFeature\
> \} stop\
> \countdictstack \

> This script is buggy.  There is no reason to put the slashes in the 
> beginning of these lines, and it invokes undefined behavior.  In 
> particular, sed 4.x will interpret "\cX" as in Perl, i.e. as "convert X 
> to uppercase flip bit 6".  Then, "\co" becomes ASCII 15.

I looked again at psset and saw these lines:

    # Prepare the sed command we want to run.
    # End of lines must be protected by `\' but the last one, and leading
    # spaces with a `\' too...
    pspagedevicelen=`echo "$pspagedevice" | wc -l`
    pspagedevice=`echo "$pspagedevice" | \
    sed -e "$pspagedevicelen!s/\$/\\\\\\/;s/^/\\\\\\/"`

The shell comment says "leading spaces with a `\`....".  However, the
sed command puts a leading '\' on the beginning of all lines, not just
those that start with spaces.  

Based on Paulo's reply and the comment in psset, I tried changing the 
sed command in psset to 

    sed -e "$pspagedevicelen!s/\$/\\\\\\/;s/^[	]/\\\\\\/"`

(that's a space and tab inside the square brackets)

This fixed the problem for me in all cases I tried on my 12.0 system
and 10.2.  I have no explanation as to why this problem only appeared
on Slackware 12.0 and not 10.2 since psset has not changed.

I would appreciate it greatly if you experts could look into this
matter and determine if this really is a problem in psset and if so,
come up with a permanent correct fix.  

Kind Regards,

Paul Novak
[email protected]