Commit Graph

128 Commits

Author SHA1 Message Date
Xin LI
9180853b89 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
2010-12-13 19:54:42 +00:00
Xin LI
c9aca921b8 Move locale.h include to the beginning header section as pointed out by
style(9)

Submitted by:	Pedro F. Giffuni <giffunip tutopia.com>
2010-12-13 19:50:12 +00:00
Joel Dahl
da52b4caaf 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
2010-12-11 08:32:16 +00:00
Jilles Tjoelker
1866e8abab 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.
2010-12-08 22:13:27 +00:00
Jilles Tjoelker
9897c45f31 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.
2010-11-19 12:56:13 +00:00
David E. O'Brien
4b2f915321 Note bug in trying to printf(1) things like: '-%s\n' "foo" 2010-09-09 19:27:40 +00:00
Jilles Tjoelker
3cf53e8550 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.
2010-09-05 21:44:50 +00:00
Ed Schouten
b7946da96b Build usr.bin/ with WARNS=6 by default.
Also add some missing $FreeBSD$ to keep svn happy.
2010-01-02 10:27:05 +00:00
David Schultz
9d65050e7b 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.
2008-08-02 06:02:02 +00:00
Stefan Farfeleder
d41d23e1cd Prefer {u,}intmax_t over the deprecated {u_,}quad_t. 2005-08-05 08:18:00 +00:00
Ruslan Ermilov
39c59153e9 Markup and wording fixes.
Approved by:	re (blanket)
2005-06-14 11:50:53 +00:00
Ruslan Ermilov
f682f10c76 Sync program's usage() with manpage's SYNOPSIS. 2005-05-21 09:55:10 +00:00
Stefan Farfeleder
e897c4d6fb Update the bugs section, null characters in the format string are now handled. 2005-04-14 18:29:59 +00:00
Stefan Farfeleder
3ec96caf72 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.
2005-04-14 17:02:34 +00:00
Stefan Farfeleder
f3f148d238 No reason to write \a and \v as octal escape sequences. 2005-04-14 15:32:21 +00:00
Stefan Farfeleder
54fee07e0d Printf(1) is WARNS 6 clean. 2005-04-14 08:43:36 +00:00
Stefan Farfeleder
fbd086844a - Move parts of the long main() function into a new function doformat().
- Rewrite the loop in main() to be more understandable.
2005-04-14 08:40:28 +00:00
Stefan Farfeleder
5ec2b8dc8a Assign 0.0 to the variable passed to getfloating() if the argument is missing.
MFC after:	1 week
2005-04-13 19:54:03 +00:00
Stefan Farfeleder
0ba01198fc 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
2005-04-11 10:57:54 +00:00
David Schultz
fd757c50f6 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.
2005-03-21 08:01:09 +00:00
Ruslan Ermilov
a866e17077 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
Giorgos Keramidas
6ac6319b32 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
2004-09-24 18:20:43 +00:00
Tim J. Robbins
2e94ae7e0e Fix a markup nit and a misplaced full stop in previous.
Noticed by:	ru
2004-07-03 07:07:11 +00:00
Tim J. Robbins
4f45d81178 Document missing multibyte character support in utilities specified
by POSIX.
2004-07-03 01:28:21 +00:00
Ruslan Ermilov
557b7fa148 Deal with double whitespace. 2004-07-03 00:24:45 +00:00
Ruslan Ermilov
6a3e8b0adc Mechanically kill hard sentence breaks. 2004-07-02 22:22:35 +00:00
David Schultz
939e953ed0 s/latter/former/ 2004-06-05 09:35:44 +00:00
David Schultz
08cdb7cdaf - Document the %a, %A, and %F format specifiers.
- Document the way infinity and NaN are printed.
- Un-document the non-existent %w specifier.
2004-06-05 09:32:27 +00:00
David Schultz
03b2eaac40 Enable support for the %a, %A, and %F format specifiers. 2004-06-05 09:32:17 +00:00
Colin Percival
8c423a998e 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)
2004-03-07 22:22:13 +00:00
David Malone
f4ac32def2 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
2002-09-04 23:29:10 +00:00
Giorgos Keramidas
b4e164347b Kill excessive whitespace between macro arguments. 2002-07-15 07:35:36 +00:00
Tim J. Robbins
12e8db4067 Fix duplicate % in %b format introduced in rev 1.22. 2002-06-19 09:42:20 +00:00
Tim J. Robbins
98dd638658 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
2002-06-19 09:24:30 +00:00
Tim J. Robbins
5f19035b04 Allow format strings containing "%%" to be reused.
PR:		39116
Submitted by:	Egil Brendsdal <egilb@ife.no>
MFC after:	1 week
2002-06-19 08:18:37 +00:00
Tim J. Robbins
37fd459046 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
2002-06-19 08:16:14 +00:00
Giorgos Keramidas
806968d6a7 Typo: characer -> character 2002-05-31 00:33:40 +00:00
Ruslan Ermilov
3a0f91d5ae mdoc(7) police: lint. 2002-05-30 05:59:25 +00:00
Tim J. Robbins
bacab7d655 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
2002-04-25 01:10:11 +00:00
Juli Mallett
ab5a295bdc - 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
2002-04-23 02:56:16 +00:00
Philippe Charnier
e8937ba009 Use `The .Nm utility' 2002-04-20 12:18:28 +00:00
Warner Losh
d3cb5ded92 remove __P 2002-03-22 01:33:25 +00:00
Mark Murray
91bd71d206 Remove leaf node WARNS?=2 (that mainly I added). This should
help the GCC3 transition and CURRENT in general.
2002-02-08 22:31:43 +00:00
Ruslan Ermilov
3e4f59ce06 Replace reference to ANSI C draft with standard.
PR:		docs/30731
2002-01-16 14:55:18 +00:00
David Malone
9f5b04e925 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.
2001-12-10 21:13:08 +00:00
David Malone
45af1a4cbd Warns cleanups. 2001-12-03 21:27:45 +00:00
Dima Dorfman
c24ca63d98 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.
2001-11-23 14:40:35 +00:00
Akinori MUSHA
018d9f6237 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.
2001-11-20 18:33:59 +00:00
Dima Dorfman
f247324df7 Remove whitespace at EOL. 2001-07-15 08:06:20 +00:00
Ruslan Ermilov
5521ff5a4d mdoc(7) police: sort SEE ALSO xrefs (sort -b -f +2 -3 +1 -2). 2001-07-06 16:46:48 +00:00
Ruslan Ermilov
429d919c70 mdoc(7) police: mark LC_NUMERIC with .Dv. 2001-02-10 10:26:52 +00:00
Andrey A. Chernov
dc7d8c99d0 Localize it (LC_NUMERIC) 2001-02-10 06:49:53 +00:00
Ben Smithurst
3c6e4a5c16 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
2000-12-21 22:21:38 +00:00
Ruslan Ermilov
9b88faecd3 Prepare for mdoc(7)NG. 2000-12-19 16:00:12 +00:00
Warner Losh
c9e0534901 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.
2000-09-04 06:11:25 +00:00
Chris Costello
4977617679 Revert to 1.8. I misread the sentence and its context. 2000-07-21 20:18:50 +00:00
Chris Costello
c4619be2d5 Properly document %.0f behavior. 2000-07-21 20:04:58 +00:00
Stefan Eßer
62a721e79c Extend to deal with 64 bit numeric arguments. 2000-07-10 21:32:41 +00:00
Martin Cracauer
1ea7321b72 Remove redundat extern declaration 2000-04-20 09:31:54 +00:00
Chris Costello
1ead4519b6 Document truncation of strings when a NUL character is reached in a format
string.

PR:		15929
Submitted by:	Daniel Hagan <dhagan@cs.vt.edu>
2000-01-19 04:16:48 +00:00
Sheldon Hearn
e6d3cf2648 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
1999-09-14 11:46:04 +00:00
Sheldon Hearn
c644db6aa2 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
1999-09-08 15:40:46 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
Nik Clayton
3be5f1f5ce 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
1999-07-12 20:24:20 +00:00
Bruce Evans
3b53d3803e 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.)
1998-12-07 12:14:04 +00:00
John Polstra
b0c9a86d12 Back out revision 1.10. It broke the build of sh, which compiles
this file with warnx() defined as a macro.
1997-11-18 15:23:23 +00:00
John Polstra
c8a2e15007 Fix: too many arguments for format string in 4 calls to warnx(). 1997-11-18 05:45:19 +00:00
Steve Price
9d19feb501 #include <unistd.h> for getopt(3) call. 1997-08-07 21:47:31 +00:00
Philippe Charnier
69d8513530 Correct Synopsys section. 1997-08-04 06:42:51 +00:00
Warner Losh
1c8af87873 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-29 04:34:07 +00:00
Steve Price
3ec30b7943 -Wall cleaning. 1996-12-14 05:32:27 +00:00
Steve Price
e6068a345f Remove annoying -Wall warning. 1996-10-06 02:40:39 +00:00
Peter Wemm
d72f654c65 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)
1996-10-01 04:56:59 +00:00
Mike Pritchard
457788f888 Correctly match the format flags and their descriptions.
Submitted by:	Dave Glowacki <dglo@ssec.wisc.edu>
1996-04-09 21:46:24 +00:00
Joerg Wunsch
d9f9371008 Move out some of the shell builtin bogosity from printf's source to
sh's builtin/bltin.h.
1995-12-10 15:40:42 +00:00
Rodney W. Grimes
7799f52a32 Remove trailing whitespace. 1995-05-30 06:41:30 +00:00
Joerg Wunsch
d867cefdcb 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.
1995-05-07 07:00:18 +00:00
Rodney W. Grimes
9b50d90275 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00