Re: printf(1) man page has a small omission

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: printf(1) man page has a small omission

Andras Farkas
I have a diff attached which fixes the man page.

On Mon, Jun 3, 2019 at 2:12 PM Andras Farkas <[hidden email]> wrote:

>
> https://man.openbsd.org/man1/printf.1
> The section on the b format (%b) neglects to mention that for that
> format, it's \0num rather than \num
> Because of the way OpenBSD's printf is made, both \0num and \num work
> for %b, but, \0num is more correct and portable when using printf(1)'s
> %b format.
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
>
> For comparison:
> https://www.freebsd.org/cgi/man.cgi?query=printf&apropos=0&sektion=1&manpath=FreeBSD+12.0-RELEASE+and+Ports&arch=default&format=html
> https://netbsd.gw.com/cgi-bin/man-cgi?printf+1

printf1diff.txt (556 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: printf(1) man page has a small omission

Ingo Schwarze
Hi Andras,

please do not cross-post on OpenBSD lists, choose whatever list fits
best.  I trimmed bugs@ for this followup.

On Mon, Jun 3, 2019 at 2:12 PM Andras Farkas wrote:

> https://man.openbsd.org/man1/printf.1
> The section on the b format (%b) neglects to mention that for that
> format, it's \0num rather than \num
> Because of the way OpenBSD's printf is made, both \0num and \num work
> for %b, but, \0num is more correct and portable when using printf(1)'s
> %b format.
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

I agree that deserves describing, just in case some system ever
implements the standard and only the standard.


Andras Farkas wrote on Mon, Jul 29, 2019 at 11:54:18PM -0400:

> I have a diff attached which fixes the man page.

I don't quite agree with your patch.  In practice, both \0num
and \num work; i inspected the code of FreeBSD and NetBSD which
both appear to support \num, too, even though they don't document
it, and i tested on Linux, and on Solaris 9, 10, and 11, and both
forms work everywhere:

   $ printf '%b\n' '\0176x'
  ~x
   $ printf '%b\n' '\176x'
  ~x

So here is an alternative patch.

OK?
  Ingo


Index: printf.1
===================================================================
RCS file: /cvs/src/usr.bin/printf/printf.1,v
retrieving revision 1.32
diff -u -r1.32 printf.1
--- printf.1 2 Jun 2019 06:16:37 -0000 1.32
+++ printf.1 1 Aug 2019 21:53:11 -0000
@@ -319,6 +319,15 @@
 Characters from the string
 .Ar argument
 are printed with backslash-escape sequences expanded.
+In the
+.Ar argument ,
+ASCII characters can be octally encoded either as
+.Cm \e0 Ns Ar num
+or as
+.Cm \e Ns Ar num
+like in the
+.Ar format
+string.
 If the
 .Ar argument
 contains the special escape sequence
@@ -373,7 +382,17 @@
 .Ev LC_ALL Ns =C
 were set.
 .Pp
-The escape sequences \ee and \e' are extensions to that specification.
+The escape sequences
+.Cm \ee
+and
+.Cm \e' ,
+as well as omitting the leading digit
+.Cm 0
+from
+.Cm \e0 Ns Ar num
+octal escape sequences in
+.Cm %b
+arguments, are extensions to that specification.
 .Sh HISTORY
 The
 .Nm

Reply | Threaded
Open this post in threaded view
|

Re: printf(1) man page has a small omission

Andras Farkas
On Thu, Aug 1, 2019 at 5:54 PM Ingo Schwarze <[hidden email]> wrote:
> please do not cross-post on OpenBSD lists, choose whatever list fits
> best.  I trimmed bugs@ for this followup.
Ah, my bad.  I just found it unclear which list to send documentation
issues to.  I've normally sent them to bugs@ in the past, but then I
also sent a diff and I've been told diffs usually go to tech@
Any advice?
I'd totally subscribe to a docs@ if there was one. :D

> I don't quite agree with your patch.  In practice, both \0num
> and \num work; i inspected the code of FreeBSD and NetBSD which
> both appear to support \num, too, even though they don't document
> it, and i tested on Linux, and on Solaris 9, 10, and 11, and both
> forms work everywhere:
>
>    $ printf '%b\n' '\0176x'
>   ~x
>    $ printf '%b\n' '\176x'
>   ~x
True, that's right.
> So here is an alternative patch.
This patch looks great.
*thumbs-up*