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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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
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)
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
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
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
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.
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.
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
* 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
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
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)