History log of /freebsd-10.0-release/usr.bin/printf/
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


244407 18-Dec-2012 eadler

POSIX requires that non-existent or null arguments be treated as if a
zero argument were supplied.

Add a regression test to catch this case as well.

PR: bin/174521
Submitted by: Daniel Shahaf <danielsh@elego.de> (pr)
Submitted by: Mark Johnston <markjdb@gmail.com> (initial patch)
Reviewed by: jilles
Approved by: cperciva (implicit)
MFC after: 3 weeks


240541 15-Sep-2012 jilles

sh: Prefer internal nextopt() to libc getopt().

This reduces code duplication and code size.

/usr/bin/printf is not affected.

Side effect: different error messages when certain builtins are passed
invalid options.


233648 29-Mar-2012 eadler

Remove trailing whitespace per mdoc lint warning

Disussed with: gavin
No objection from: doc
Approved by: joel
MFC after: 3 days


230027 12-Jan-2012 pfg

Style cleanups for printf.

PR: bin/152934
Approved by: jhb (mentor)
Obtained from: Illumos
MFC after: 2 weeks


222421 28-May-2011 jilles

printf(1): Document that %c and precision for %b/%s use bytes, not chars.

This means these features do not work as expected with multibyte characters.

This perhaps less than ideal behaviour matches printf(3) and is specified by
POSIX.


222418 28-May-2011 jilles

printf: Allow multibyte characters for '<char> form, avoid negative codes.

Examples:
LC_ALL=en_US.UTF-8 printf '%d\n' $(printf \'\\303\\244)
LC_ALL=en_US.ISO8859-1 printf '%d\n' $(printf \'\\344)
Both of these should print 228.

Like some other shells, incomplete or invalid multibyte characters yield the
value of the first byte without a warning.

Note that there is no general way to go back from the character code to the
character.


221026 25-Apr-2011 jilles

printf(1): Move non-bugs from the BUGS section to a new section CAVEATS.


221013 25-Apr-2011 jilles

printf(1): Mention effect of '#' modifier on other conversions.


219153 01-Mar-2011 jilles

printf: Note that this is used both as a normal program and a shell builtin.


216809 29-Dec-2010 jilles

printf: Do not use sh memory functions in sh builtin.

These functions throw exceptions if they fail, possibly causing memory
leaks. The normal out-of-memory handling suffices. The INTOFF around almost
all of printf prevents memory leaks due to SIGINT.


216606 20-Dec-2010 jilles

sh: Make warnings in the printf builtin non-fatal, like in the program.

The #define for warnx now behaves much like the libc function (except that
it uses sh command name and output).

Also, it now uses C99 __VA_ARGS__ so there is no need for three different
macros for 0, 1 or 2 parameters.


216447 14-Dec-2010 delphij

Revert r216423 per request from Jilles.

The new behavior prevents us from being able to bail out explicitly
on unknown options that we have not implemented. BASH for instance
have introduced a '-v' for printf(1) builtin and it seems to be bad
to pretend that we supported it and have a script break silently.


216439 14-Dec-2010 delphij

When printf is being used as a sh(1) builtin, it can not call
exit(3) as pointed out by jilles@ so revert to using return(),
also change the return value back to 1 as requested by bde@.

This is logically a revert of revision 216422.


216424 14-Dec-2010 delphij

We work on ctype's and not only on numbers so set LC_ALL instead of
LC_NUMERIC.

PR: bin/152934
Submitted by: Pedro F. Giffuni <giffunip tutopia.com>
Obtained from: Illumos


216423 14-Dec-2010 delphij

IEEE Std 1003.1-2008, Section 1.4, Utility Description Defaults says
that when the options section is listed as "None", utility shall
recognize "--" as a first argument to be discarded.

This implementation is largely based on OpenBSD implementation but
we do slightly differently:

a) We skip argv[0] as the first step;
b) We test whether the next argument is "--" and ignore it.

With this change one will get:

%printf
usage: printf format [arguments ...]
%printf -v
-v%printf -- -v
-v%
%printf --
usage: printf format [arguments ...]

Which matches the behavior observed on a Debian system but different
from the Illumos change.


216422 14-Dec-2010 delphij

Make use of EX_USAGE for usage().


216418 13-Dec-2010 delphij

The only caller of mknum() provides a char instead of an int, so make it
match the definition.

PR: bin/152934
Submitted by: Pedro F. Giffuni <giffunip tutopia.com>
Obtained from: Illumos


216417 13-Dec-2010 delphij

Move locale.h include to the beginning header section as pointed out by
style(9)

Submitted by: Pedro F. Giffuni <giffunip tutopia.com>


216370 11-Dec-2010 joel

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


216310 08-Dec-2010 jilles

printf: Remove support for building as a csh builtin.

The #define BUILTIN was for building as a csh (not tcsh) builtin.
Given that csh was replaced by tcsh years ago there is no point in keeping
this.

The #define SHELL is for building as an sh builtin and is in active use.

This commit does not change the /bin/sh and /usr/bin/printf binaries.


215520 19-Nov-2010 jilles

sh: Add printf builtin.

This was removed in 2001 but I think it is appropriate to add it back:
* I do not want to encourage people to write fragile and non-portable echo
commands by making printf much slower than echo.
* Recent versions of Autoconf use it a lot.
* Almost no software still wants to support systems that do not have
printf(1) at all.
* In many other shells printf is already a builtin.

Side effect: printf is now always the builtin version (which behaves
identically to /usr/bin/printf) and cannot be overridden via PATH (except
via the undocumented %builtin mechanism).

Code size increases about 5K on i386. Embedded folks might want to replace
/usr/bin/printf with a hard link to /usr/bin/alias.


212374 09-Sep-2010 obrien

Note bug in trying to printf(1) things like: '-%s\n' "foo"


212244 05-Sep-2010 jilles

printf(1): Clarify that \OOO produces a byte, different %b escape sequences.

Octal escape sequences are expanded to bytes, not characters, and multiple
are required for a multibyte character.

The valid escape sequences in %b strings are slightly different from the
escape sequences in the format string.


201386 02-Jan-2010 ed

Build usr.bin/ with WARNS=6 by default.

Also add some missing $FreeBSD$ to keep svn happy.


181153 02-Aug-2008 das

POSIX says that octal escapes have the format \ddd in the format string,
but \0ddd in a %b argument, with a length restriction of 3 octal digits
in either case. This seems silly, but it needs to be right so it's possible
to write an octal escape followed by an ordinary digit. Solaris printf(1)
and GNU printf(1) also behave this way.

Example: "printf '\0752'" now produces "=2" instead of garbage.


148721 05-Aug-2005 stefanf

Prefer {u,}intmax_t over the deprecated {u_,}quad_t.


147370 14-Jun-2005 ru

Markup and wording fixes.

Approved by: re (blanket)


146466 21-May-2005 ru

Sync program's usage() with manpage's SYNOPSIS.


145084 14-Apr-2005 stefanf

Update the bugs section, null characters in the format string are now handled.


145078 14-Apr-2005 stefanf

Handle null characters in the format string. A \0 in the argument passed to %b
still results in trucation but this is be much harder to fix.


145074 14-Apr-2005 stefanf

No reason to write \a and \v as octal escape sequences.


145063 14-Apr-2005 stefanf

Printf(1) is WARNS 6 clean.


145061 14-Apr-2005 stefanf

- Move parts of the long main() function into a new function doformat().
- Rewrite the loop in main() to be more understandable.


145027 13-Apr-2005 stefanf

Assign 0.0 to the variable passed to getfloating() if the argument is missing.

MFC after: 1 week


144902 11-Apr-2005 stefanf

Replace buggy for-loops to skip certain character with strspn(). If *fmt was
'\0' (eg in the invocation 'printf %'), the for-loop would miss the terminating
null character.

MFC after: 1 week


143906 21-Mar-2005 das

Support the L modifier for floating-point values as an extension.
When L is omitted, double precision is used, so printf(1) gives
reproducable results. When L is specified, long double precision is
used, which may improve precision, depending on the machine.


140368 17-Jan-2005 ru

Added the EXIT STATUS section where appropriate.


135751 24-Sep-2004 keramida

Allow %' to be used as a format flag by printf(1). This makes it
possible to print the thousands separator in the locale setups that
have one, by something like this:

$ env -i LC_NUMERIC=en_US.ISO8859-1 ./printf "%'0.2f\n" 12345
12,345.00

Reviewed by: das


131519 03-Jul-2004 tjr

Fix a markup nit and a misplaced full stop in previous.

Noticed by: ru


131511 03-Jul-2004 tjr

Document missing multibyte character support in utilities specified
by POSIX.


131507 03-Jul-2004 ru

Deal with double whitespace.


131491 02-Jul-2004 ru

Mechanically kill hard sentence breaks.


130117 05-Jun-2004 das

s/latter/former/


130116 05-Jun-2004 das

- Document the %a, %A, and %F format specifiers.
- Document the way infinity and NaN are printed.
- Un-document the non-existent %w specifier.


130115 05-Jun-2004 das

Enable support for the %a, %A, and %F format specifiers.


126729 07-Mar-2004 cperciva

Make it possible for the %[eEfgG] formats to not result in an error
being reported by /usr/bin/printf.

This bug has been around for 22 months... either nobody uses printf
with floating-point values, or people are forgetting to check their
return codes.

Approved by: rwatson (mentor)


102944 04-Sep-2002 dwmalone

ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by: md5


100045 15-Jul-2002 keramida

Kill excessive whitespace between macro arguments.


98426 19-Jun-2002 tjr

Fix duplicate % in %b format introduced in rev 1.22.


98424 19-Jun-2002 tjr

Let printf(1) tell the difference between zero width/precision and
unspecified width/precision.

PR: 39116
Submitted by: Egil Brendsdal <egilb@ife.no>
MFC after: 1 week


98420 19-Jun-2002 tjr

Allow format strings containing "%%" to be reused.

PR: 39116
Submitted by: Egil Brendsdal <egilb@ife.no>
MFC after: 1 week


98419 19-Jun-2002 tjr

Allow `%' to be written out with an octal escape (\45 or \045).

PR: 39116
Submitted by: Egil Brendsdal <egilb@ife.no>
MFC after: 1 week


97643 31-May-2002 keramida

Typo: characer -> character


97541 30-May-2002 ru

mdoc(7) police: lint.


95409 25-Apr-2002 tjr

Handle numbers larger than QUAD_MAX for unsigned conversions correctly.
Exit with nonzero status if a conversion failed.
Play nice if used as a shell builtin (currently disabled).

Submitted by: bde (partially)
Approved by: mike


95300 23-Apr-2002 jmallett

- printf shouldn't bail out if a conversion fails, it should just keep
processing them.
- \c escape to immediately stop output (similar to echo's \c)
- \0NNN should be allowed for octal character escapes (instead of just \NNN)
- %b conversion, which is like %s but interprets \n \t etc. inside the
string is missing.

And I may not be any poet, but in lieu of an in-tree regression test:
ref5% ./printf '%s%b%b%c%s%d\n' 'PR' '\0072' '\t' '3' '56' 0x10
PR: 35616

Submitted by: tjr
MFC after: 1 week


95124 20-Apr-2002 charnier

Use `The .Nm utility'


92921 22-Mar-2002 imp

remove __P


90415 08-Feb-2002 markm

Remove leaf node WARNS?=2 (that mainly I added). This should
help the GCC3 transition and CURRENT in general.


89426 16-Jan-2002 ru

Replace reference to ANSI C draft with standard.

PR: docs/30731


87628 10-Dec-2001 dwmalone

Style improvements recommended by Bruce as a follow up to some
of the recent WARNS commits. The idea is:

1) FreeBSD id tags should follow vendor tags.
2) Vendor tags should not be compiled (though copyrights probably should).
3) There should be no blank line between including cdefs and __FBSDIF.


87298 03-Dec-2001 dwmalone

Warns cleanups.


86824 23-Nov-2001 dd

The RETURN VALUES section is not appropriate for section 1 manual
pages; rename it to DIAGNOSTICS. Also use the .Ex macro while I'm
here.


86692 20-Nov-2001 knu

Remove the printf builtin command from sh(1), which command is not
used so often that it's worth keeping it as a builtin.

Now that all the printf invocations from within the system startup
scripts, we can safely remove it.

Urged by: sheldonh :)

No MFC is planned so far because it may break compatibility and
violate POLA.


79755 15-Jul-2001 dd

Remove whitespace at EOL.


79366 06-Jul-2001 ru

mdoc(7) police: sort SEE ALSO xrefs (sort -b -f +2 -3 +1 -2).


72313 10-Feb-2001 ru

mdoc(7) police: mark LC_NUMERIC with .Dv.


72304 10-Feb-2001 ache

Localize it (LC_NUMERIC)


70256 21-Dec-2000 ben

Fix printf(1) for cases where a long string with no format specifiers is
followed by a %d (probably others too) format specifier.

Reviewed by: audit


70197 19-Dec-2000 ru

Prepare for mdoc(7)NG.


65429 04-Sep-2000 imp

When we have both a rcsid and sccsid, ifdef 0 the sccsid. This
appears to be the standard FreeBSD way to do this. style(9) is silent
about this, however.


63734 21-Jul-2000 chris

Revert to 1.8. I misread the sentence and its context.


63733 21-Jul-2000 chris

Properly document %.0f behavior.


62928 10-Jul-2000 se

Extend to deal with 64 bit numeric arguments.


59435 20-Apr-2000 cracauer

Remove redundat extern declaration


56264 19-Jan-2000 chris

Document truncation of strings when a NUL character is reached in a format
string.

PR: 15929
Submitted by: Daniel Hagan <dhagan@cs.vt.edu>


51275 14-Sep-1999 sheldonh

Correct some hard sentence breaks. Only those surrounding the previous
commit and those which cause ugly nroff output have been fixed, since
the purpose of the style guideline which they contravene is to reduce
the sizes of deltas.

Reported by: bde


51090 08-Sep-1999 sheldonh

Improve shell documentation:

* Consistently misspell built-in as builtin.

* Add a builtin(1) manpage and create builtin(1) MLINKS for all shell
builtin commands for which no standalone utility exists. These MLINKS
replace those that were created for csh(1).

* Add appropriate xrefs for builtin(1) to the csh(1) and sh(1) manpages,
as well as to the manpages of standalone utilities which are supported
as shell builtin commands in at least one of the shells. In such
manpages, explain that similar functionality may be provided as a
shell builtin command.

* Improve sh(1)'s description of the cd builtin command. Csh(1) already
describes it adequately. Replace the cd(1) manpage with a builtin(1)
MLINKS link.

* Clean up some mdoc problems: use Xr instead of literal "foo(n)"; use
Ic instead of Xr for shell builtin commands.

* Undo English contractions.

Reviewed by: mpp, rgrimes


50477 28-Aug-1999 peter

$Id$ -> $FreeBSD$


48792 12-Jul-1999 nik

Add $Id$, to make it simpler for members of the translation teams to
track.

The $Id$ line is normally at the bottom of the main comment block in the
man page, separated from the rest of the manpage by an empty comment,
like so;

.\" $Id$
.\"

If the immediately preceding comment is a @(#) format ID marker than the
the $Id$ will line up underneath it with no intervening blank lines.
Otherwise, an additional blank line is inserted.

Approved by: bde


41582 07-Dec-1998 bde

Fixed warnx format errors in printf and csh, and snprintf format errors
in sh, by using separate macros for the 1, 2 and 3-arg calls to warnx.
(The 3-arg warnx macro in sh/bltin/bltin.h used to require bogus dummy
args.)


31277 18-Nov-1997 jdp

Back out revision 1.10. It broke the build of sh, which compiles
this file with warnx() defined as a macro.


31224 18-Nov-1997 jdp

Fix: too many arguments for format string in 4 calls to warnx().


27966 07-Aug-1997 steve

#include <unistd.h> for getopt(3) call.


27887 04-Aug-1997 charnier

Correct Synopsys section.


24360 29-Mar-1997 imp

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


20409 14-Dec-1996 steve

-Wall cleaning.


18732 06-Oct-1996 steve

Remove annoying -Wall warning.


18613 01-Oct-1996 peter

When used as a shell builtin, this program decoded a subset of arguments
known to printf(3) and then used printf() to format it... The only
problem what the #define printf out1fmt. The code was behaving differently
when run as a shell builtin since out1fmt() isn't printf(3).

Simple hack. Print to a buffer and fputs (also #defined for sh) the
result. This should fix the printf builtin problem in PR#1673, rather
than leaving the call commented out. (printf.o was being statically linked
in anyway, we might as well use it)


15163 09-Apr-1996 mpp

Correctly match the format flags and their descriptions.

Submitted by: Dave Glowacki <dglo@ssec.wisc.edu>


12730 10-Dec-1995 joerg

Move out some of the shell builtin bogosity from printf's source to
sh's builtin/bltin.h.


8874 30-May-1995 rgrimes

Remove trailing whitespace.


8323 07-May-1995 joerg

Make the syntax checks for the format string more strict. The string
"%8*s" is no longer considered to be a valid format description.

This closes PR bin/386.


1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.