On Wed, 2021-02-10 at 17:06 +0100, Erik Auerswald wrote:
> Hi,
> 
> On Wed, Feb 10, 2021 at 01:42:29PM +0100, Leonard Janis Robert König
> wrote:
> > I'm sorry if I this is not a bug but to be expected, but I thnk pr
> > doesn't get the alignment of tabs in multicolumn output right.
> > [...]
> > Unfortunately the POSIX spec is, in my reading, a bit unclear here.
> 
> I do not think so:
> 
> -column
>   Produce multi-column output that is arranged in column
> columns[...].
>   The options -e and -i shall be assumed for multiple text-column
> output.
> 
> -e[char][gap]
>   Expand each input <tab> to the next greater column position[...].
> 
> -i[char][gap]
>   In output, replace multiple <space>s with <tab>s wherever[...].
> 
> https://pubs.opengroup.org/onlinepubs/009695399/utilities/pr.html
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pr.html
> 
> The way I read the POSIX spec, "pr" needs to account for the column
> separation by adjusting whitespace while still using tab characters
> in
> the output.

What's unclear however, whether this adjusting whitespace (replacing
space by tab, as is the default) should happen on input or after
arranging the text into columns.  The former produces something
resembling the GNU output as the tabs in the input files are kept,
despite not aligning to 8 characters anymore.  The latter produces the
SunOS/FreeBSD output, as first the text is arranged and then tabs
recalculated.

> > But I think the behavior of GNU/pr is rather unexpected when
> > printing
> > multicolumn source code and not in line what the original authors
> > intended.
> 
> I concur.

This makes tabs as input while using column or merge basically unusable
though, as the characters are completely misaligned.  This is
especially bad for code.  My use case is a script that prints the UNIX
v6 source code in fashion of John Lion (see v6.cuzoco.com) and it
breaks under GNU pr, but not on BSD, Solaris.  And it seems to have
worked also on Amdahl UTS in the late 80s for that matter.  

With regards to the original intent, I just tested this on Research
UNIX v6 with SIMH
(https://gunkies.org/wiki/Installing_Unix_v6_(PDP-11)_on_SIMH), and
indeed the output is like the SunOS and FreeBSD version do:

# pr -t -2 foo
123456781234567812345678123456781   123456781234567812345678123456781
x       x       x       x       x   x       x       x       x       x

N.B. that the input file must be little longer since the original
version didn't produce identical vertical lengths as is allowed as per
the standard:

> Whether or not text  columns  are produced with identical vertical
> lengths is unspecified [...] .

At least to me this behavior of GNU pr came as a big surprise, maybe
this should be described in the FAQ/Gotchas or the BUGS section of the
manual?

~ leo




Reply via email to