Commit Graph

80 Commits

Author SHA1 Message Date
kre
8ad10c91e9 Amend the previous change: we can have (almost) the best of both
worlds, as when the first arg (which should be the format) contains
no % conversions, and there are more args, the results are unspecified
(according to POSIX).

We can use this so the previous usage
	printf -- format arg...
(which is stupid, and pointless, but used to work) continues to
simply ignore the -- (unspecified results mean we can do whatever
feels good...)

This brings back the #if 0'd block from the previous modification
(so there is no longer anything that needs cleaning up later) but runs
the getopt() loop it contained only when there are at least 2 args
(so any 1 arg printf always uses that arg as the format string,
whatever it contains, including just "--") and also only when the
first (format) arg contains no '%' characters (which guarantees no %
conversions without needing to actually parse the arg).  This is the
(or a) "unspecified results" case from POSIX, so we are free to do
anything we like - including assuming that we might have options
(we don't) and pretending to process them.
2019-07-22 17:34:31 +00:00
kre
b6a771f35e Stop assuming that printf handles options in any way at all
(it doesn't - that is, shouldn't) which includes processing -- as an
"end of options".  The first arg is (always) the format string.

Remove call to getopt() (but still do associated changes to argc/argv)

Note: for now this is #if 0's out instead of being deleted, the old
code should be fully removed sometime soon.

Problem pointed out on tech-userlevel by Thierry Laronde.
2019-07-21 15:25:39 +00:00
kre
d5635413aa Revert previous, it was based upon a misreading of the POSIX
spec.   POSIX requires "as if by calling strtod()" which we
did already ... by calling strtod().   Go back to doing that.
2019-01-27 12:03:09 +00:00
kre
4ca169f245 Always convert input numbers (from the command line) in the C
locale, not as set in the environment.   Conforms with POSIX spec.
2019-01-26 15:22:54 +00:00
kre
f910883c96 A truly ancient bug found by Edgar Fuss
When printf is running builtin in a sh, global vars aren't reset to
0 between invocations.   This affects "rval" which remembers state
from a previous %b \c and thereafter always exits after the first
format conversion, until we get a conversion that generates an
error (which resets the flag almost by accident)

	printf %b abc\\c
	abc				(no \n)
	printf %s%s hello world
	hello				(no \n, of course, no world ...)
	printf %s%s hello world
	hello
	printf %s%s hello world
	hello
	printf %d hello
	printf: hello: expected numeric value
	0				(no \n)
	printf %s%s hello world
	helloworld			(no \n, and we are back!)

This affects both /bin/sh and /bin/csh (and has for a very long time).

XXX pullup -8
2018-09-10 14:42:29 +00:00
kre
8b37a6dbec Printf's that support \e for escape all seem to also support \E.
Except us.   Now we do as well.
2018-09-04 01:13:50 +00:00
kre
68b40b6c11 Tighten syntax a little (no more %*4.*2d nonsense).
Include the format collected so far in "missing format char" err message.
Minor KNF and whitespace.
2018-09-03 04:10:20 +00:00
kre
24f342dfd6 PR standards/53563
POSIX requires that signed numbers (strings preceded by '+' or '-')
be allowed as inputs to all of the integer format conversions, including
those which treat the data as unsigned.

Hence we do not need a variant function whose only difference from its
companion is to reject strings starting with '-' - instead we use
the primary function (getintmax()) for everything and remove getuintmax().

Minor update to the man page to indicate that the arg to all of the
integer conversions (diouxX) must be an integer constant (with an
optional sign) and to make it blatantly clear that %o is octal and
%u is unsigned decimal (for some reason those weren't explicitly stated
unlike d i x and X).  Delete "respectively", it is not needed (and does
not really apply).

XXX pullup -8
2018-08-31 17:27:35 +00:00
kre
47ea218fd1 NFC: More KNF (remove () around returned constants). 2018-07-25 15:35:27 +00:00
kre
5755a4ea22 NFC: whitespace & KNF. 2018-07-25 14:41:52 +00:00
kre
2fb3e9fabf Add the new formats to the list of format cracters (oops...) 2018-07-24 20:58:39 +00:00
kre
ddc0976a72 Add support for F a and A formats (which go with the eEfgG formats
already supported.)
2018-07-24 20:49:19 +00:00
kre
520d24e3eb Correct a typo (off by one (key)) ...
There is no 'w' format, but there is an 'e'
2018-07-24 19:49:33 +00:00
kre
4bcba09122 Avoid printing error messages twice when an invalid
escape sequence (\ sequence) is present in an arg to a %b
conversion.
2018-07-03 01:56:39 +00:00
kre
a78ff1f90a From leot@ on tech-userlevel:
Avoid running off into oblivion when a format string,
or arg to a %b conversion ends in an unescaped backslash.

Patch from Leo slightly modified by me.
2018-07-03 01:54:42 +00:00
wiz
2458e695f0 Remove Tn. 2018-03-12 09:29:43 +00:00
dholland
ab87b60207 Explicitly mention use of -- for format strings beginning with -,
per PR 21970.
2018-03-12 00:42:05 +00:00
christos
ff53269704 fix some error handling. 2015-06-16 22:54:10 +00:00
snj
fc99b6a4d6 Change some standard exit status text to ".Ex -std"
From Eitan Adler in PR bin/47790.
2014-04-13 01:45:34 +00:00
christos
b294e9655c WARNS=6 2013-07-16 17:48:22 +00:00
christos
5353040f23 document non-literal format strings 2011-08-16 10:35:03 +00:00
christos
ca5bce8901 support grouping format. 2011-03-15 23:11:49 +00:00
joerg
57e0101802 \\*(Pm -> \*(Pm 2010-04-05 21:24:14 +00:00
christos
a49ff4deac Avoid segv on "printf '%*********s' 666", from Maksymilian Arciemowicz 2009-10-13 19:28:31 +00:00
lukem
c1ceae17f0 Enable WARNS=4 by default for usr.bin, except for:
awk  bdes  checknr  compile_et  error  gss  hxtool  kgetcred  kinit
	klist  ldd  less  lex  locale  login  m4  man  menuc  mk_cmds
	mklocale  msgc  openssl  rpcgen  rpcinfo  sdiff  spell  ssh
	string2key  telnet  tn3270  verify_krb5_conf  xlint
2009-04-14 22:15:16 +00:00
joerg
31ea1ec643 Use semantic markup 2009-03-11 13:57:11 +00:00
dholland
0a268c3ebf Fix description of %b format. PR 39111 from Paul Goyette. 2008-09-01 09:20:41 +00:00
lukem
98e5374ccb Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
2008-07-21 14:19:20 +00:00
apb
76807ad91e Add a note about the stupid behaviour of "%c" format. 2008-05-06 12:01:35 +00:00
christos
56fd57d26f detect more errors from printf/malloc. 2008-03-28 18:05:39 +00:00
dsl
a2a01de947 Remember to consume input bytes when processing '\0nnn' for %b formats 2005-03-22 23:55:46 +00:00
christos
175795754a WARNS=3, and remove comment about WFORMAT issues. 2004-10-30 19:28:35 +00:00
christos
a7e7123b05 - KNF, WARNS=3, pass lint.
- Simplify octal parsing code.
2004-10-30 19:28:10 +00:00
agc
89aaa1bb64 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22365, verified by myself.
2003-08-07 11:13:06 +00:00
dsl
630ca1a3e3 Revert previous. 'None' means that the "Utility Syntax Guidlines" apply. 2003-06-25 12:56:59 +00:00
dsl
0ac8c637fd Remove getopt() loop, IEEE 1003.1 doesn't say that printf(1) should conform
to the "Utility Syntax Guidlines".
Fixes PR 21970.
2003-06-25 09:54:15 +00:00
wiz
abe0b8ad64 Use .Aq instead of \*[Lt]...\*[Gt]; sort SEE ALSO; add some more commas;
new sentence, new line; fix some mdoc nits.
2003-04-28 09:38:19 +00:00
augustss
86be450da2 Add missing comma. 2003-04-28 09:26:34 +00:00
dsl
a5f7364038 Fix the output of NUL bytes within %b formats.
(Approved by Christos)
2003-02-24 14:42:27 +00:00
christos
c02b3bbdf4 Fixes from David Laight:
- ansification
- format of output of jobs command (etc)
- job identiers %+, %- etc
- $? and $(...)
- correct quoting of output of set, export -p and readonly -p
- differentiation between nornal and 'posix special' builtins
- correct behaviour (posix) for errors on builtins and special builtins
- builtin printf and kill
- set -o debug (if compiled with DEBUG)
- cd src obj (as ksh - too useful to do without)
- unset -e name, remove non-readonly variable from export list.
  (so I could unset -e PS1 before running the test shell...)
2002-11-24 22:35:38 +00:00
grant
be8ae688ae New sentence, new line. 2002-09-30 11:08:56 +00:00
tron
5456dc6136 Complete declaration of progprintf() to fix build problem in csh(1). 2002-06-14 11:32:15 +00:00
wiz
085ddec445 Remove #ifdef __STDC__. De-__P() and ANSIfy. Fix a prototype mismatch
uncovered by this.
2002-06-14 01:12:15 +00:00
wiz
6fbcffc530 WARNS=2 2002-06-14 01:10:36 +00:00
ross
2a76afae02 Generate <>& symbolically. I'm avoiding .../dist/... directories for now. 2002-02-08 01:36:18 +00:00
wiz
b28000888d Punctuation nits. 2001-12-08 19:10:43 +00:00
wiz
aded0d2cce Whitespace cleanup. 2001-12-01 16:43:07 +00:00
kleink
dd849fecca Change to use {u,}intmax_t internally (was: (unsigned) long). 2001-05-05 17:29:39 +00:00
jhawk
404ef082e4 Xr printf(9) 2001-04-03 13:59:22 +00:00
is
135600f947 More format string cleanup by sommerfeld. 2000-10-11 14:46:00 +00:00