All of lore.kernel.org
 help / color / mirror / Atom feed
* Bug in man page
@ 2014-03-09 11:11 Jeroen van Dijke
  2014-03-14 12:09 ` Jilles Tjoelker
  2014-09-26 14:17 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Jeroen van Dijke @ 2014-03-09 11:11 UTC (permalink / raw)
  To: dash

Hi,

There seems to be a bug in the dash man page, at least in 0.5.7. It reads:

            Precision:
                    An optional period, `.', followed by an optional digit string giving a precision which specifies the number of digits to appear after the decimal point, for e and f formats, or the maximum number of *characters* to be printed from a string (b and s for-
                    mats); if the digit string is missing, the precision is treated as zero;

dash behaves cuts to the number of bytes

$ length=10; printf "%.${length}s\n" "eeeeeeeeeeeeeeeeeeeeeeeee"
eeeeeeeeee
$ length=10; printf "%.${length}s\n" "ëëëëëëëëëëëëëëëëëëëëëëëëë”
ëëëëë


The  POSIX specification (2008) says:

precision Gives the minimum number of digits to appear for the d, o, i, u, x, or X conversion specifiers (the field is padded with leading zeros), the number of digits to appear after the radix character for the e and f conversion specifiers, the maximum number of significant digits for the g conversion specifier; or the maximum number of *bytes* to be written from a string in the s conversion specifier. The precision shall take the form of a ( '.' ) followed by a decimal digit string; a null digit string is treated as zero.

So it seems to me that “characters” should be changed to “bytes”.

Kind Regards,

Jeroen van Dijke

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug in man page
  2014-03-09 11:11 Bug in man page Jeroen van Dijke
@ 2014-03-14 12:09 ` Jilles Tjoelker
  2014-09-26 14:17 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Jilles Tjoelker @ 2014-03-14 12:09 UTC (permalink / raw)
  To: Jeroen van Dijke; +Cc: dash

On Sun, Mar 09, 2014 at 12:11:43PM +0100, Jeroen van Dijke wrote:
> There seems to be a bug in the dash man page, at least in 0.5.7. It
> reads:

>             Precision:
>                     An optional period, `.', followed by an optional
> digit string giving a precision which specifies the number of digits
> to appear after the decimal point, for e and f formats, or the maximum
> number of *characters* to be printed from a string (b and s formats);
> if the digit string is missing, the precision is treated as zero;

> dash behaves cuts to the number of bytes

> $ length=10; printf "%.${length}s\n" "eeeeeeeeeeeeeeeeeeeeeeeee"
> eeeeeeeeee
> $ length=10; printf "%.${length}s\n" "ëëëëëëëëëëëëëëëëëëëëëëëëë”
> ëëëëë

> The  POSIX specification (2008) says:

> precision Gives the minimum number of digits to appear for the d, o,
> i, u, x, or X conversion specifiers (the field is padded with leading
> zeros), the number of digits to appear after the radix character for
> the e and f conversion specifiers, the maximum number of significant
> digits for the g conversion specifier; or the maximum number of
> *bytes* to be written from a string in the s conversion specifier. The
> precision shall take the form of a ( '.' ) followed by a decimal digit
> string; a null digit string is treated as zero.

> So it seems to me that “characters” should be changed to “bytes”.

Indeed, and the same applies to the field width. This behaviour may not
be the most useful, but it is standard and widely implemented.

Likewise, the sequences \num (in the format string) and \0num (in
arguments for %b) generate bytes, not characters.

On another note, the format string is said to be a "character string";
this may be a C'ism (meaning that it is not a wide character string).

Note that a "byte" in POSIX terminology is a "character" in C standard
terminology. I think the former is less ambiguous in general and should
be the preferred term in man pages where a unit of 8 bits is referred
to. A POSIX "character" may be more than one byte long.

-- 
Jilles Tjoelker

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug in man page
  2014-03-09 11:11 Bug in man page Jeroen van Dijke
  2014-03-14 12:09 ` Jilles Tjoelker
@ 2014-09-26 14:17 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2014-09-26 14:17 UTC (permalink / raw)
  To: Jeroen van Dijke; +Cc: dash

commit 63ab7ea86d12ff87f311e9a59dffdc4f1d47ff33
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Sep 26 22:16:26 2014 +0800

    [MAN] Change characters for printf precision to bytes
    
    On Sun, Mar 09, 2014 at 11:11:43AM +0000, Jeroen van Dijke wrote:
    >
    > There seems to be a bug in the dash man page, at least in 0.5.7. It reads:
    >
    >             Precision:
    >                     An optional period, `.', followed by an optional digit string giving a precision which specifies the number of digits to appear after the decimal point, for e and f formats, or the maximum number of *characters* to be printed from a string (b and s for-
    >                     mats); if the digit string is missing, the precision is treated as zero;
    >
    > dash behaves cuts to the number of bytes
    >
    > $ length=10; printf "%.${length}s\n" "eeeeeeeeeeeeeeeeeeeeeeeee"
    > eeeeeeeeee
    > $ length=10; printf "%.${length}s\n" "ëëëëëëëëëëëëëëëëëëëëëëëëë”
    > ëëëëë
    >
    >
    > The  POSIX specification (2008) says:
    >
    > precision Gives the minimum number of digits to appear for the d, o, i, u, x, or X conversion specifiers (the field is padded with leading zeros), the number of digits to appear after the radix character for the e and f conversion specifiers, the maximum number of significant digits for the g conversion specifier; or the maximum number of *bytes* to be written from a string in the s conversion specifier. The precision shall take the form of a ( '.' ) followed by a decimal digit string; a null digit string is treated as zero.
    >
    > So it seems to me that “characters” should be changed to “bytes”.
    
    Indeed and this patch makes that change.
    
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/ChangeLog b/ChangeLog
index 7b67c0c..6f27fd7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
 	* Small optimisation of command -pv change.
 	* Set command -p path to /usr/sbin:/usr/bin:/sbin:/bin.
+	* Change "characters" for printf precision to "bytes".
 
 2014-09-26  Harald van Dijk <harald@gigawatt.nl>
 
diff --git a/src/dash.1 b/src/dash.1
index 6241a61..6ceb16a 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -1670,7 +1670,7 @@ for
 .Cm e
 and
 .Cm f
-formats, or the maximum number of characters to be printed
+formats, or the maximum number of bytes to be printed
 from a string
 .Sm off
 .Pf ( Cm b
@@ -1758,7 +1758,7 @@ is printed.
 .It Cm s
 Characters from the string
 .Ar argument
-are printed until the end is reached or until the number of characters
+are printed until the end is reached or until the number of bytes
 indicated by the precision specification is reached; if the
 precision is omitted, all characters in the string are printed.
 .It Cm \&%

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-26 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-09 11:11 Bug in man page Jeroen van Dijke
2014-03-14 12:09 ` Jilles Tjoelker
2014-09-26 14:17 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.