vfwprintf.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Implementation of internals for printf and wprintf.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1990, 1993
The Regents of the University of California. All rights reserved.
This code is derived from software contributed to Berkeley by
Chris Torek.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
- Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
NetBSD: vfwprintf.c,v 1.9.2.1.4.1 2008/04/08 21:10:55 jdc Exp
vfprintf.c 8.1 (Berkeley) 6/4/93
**/
#include <LibConfig.h>
#include "namespace.h"
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wchar.h>
#include <wctype.h>
#include "reentrant.h"
#include "local.h"
#include "extern.h"
#include "fvwrite.h"
#ifdef _MSC_VER
// Keep compiler quiet about conversions from larger to smaller types.
#endif
#ifndef NARROW
#define MCHAR_T char
#define STRCONST(a) L ## a
#define WDECL(a, b) a ## w ## b
#define END_OF_FILE WEOF
#define MULTI 0
#else
#define CHAR_T char
#define STRCONST(a) a
#define WDECL(a, b) a ## b
#define END_OF_FILE EOF
#define MULTI 1
#endif
union arg {
int intarg;
long longarg;
unsigned long ulongarg;
long long longlongarg;
unsigned long long ulonglongarg;
void *pvoidarg;
char *pchararg;
signed char *pschararg;
short *pshortarg;
int *pintarg;
long *plongarg;
long long *plonglongarg;
#ifndef NO_FLOATING_POINT
double doublearg;
long double longdoublearg;
#endif
};
/*
* Type ids for argument type table.
*/
enum typeid {
};
char, const char *);
char, const char *);
#ifndef NARROW
#else
#endif
static int __grow_type_table(int, enum typeid **, int *);
/*
* Helper function for `fprintf to unbuffered unix file': creates a
* temporary buffer. We only work on write-only files; this avoids
* worries about ungetc buffers and so forth.
*/
static int
{
int ret;
struct __sfileext fakeext;
return (EOF);
}
/* copy the important variables */
/* set up the buffer */
/* do the work, then copy any error status */
ret = END_OF_FILE;
return (ret);
}
#ifndef NARROW
/*
* Like __fputwc, but handles fake string (__SSTR) files properly.
* File must already be locked.
*/
static wint_t
{
char buf[MB_LEN_MAX];
return (END_OF_FILE);
}
}
#else
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
*/
static int
{
int err;
return (EOF);
}
uio->uio_iovcnt = 0;
return (0);
}
uio->uio_iovcnt = 0;
return (err);
}
#endif
/*
* Macros for converting digits to letters and vice versa
*/
#define to_digit(c) ((c) - '0')
/*
* Convert an unsigned long to ASCII for printf purposes, returning
* a pointer to the first character of the string representation.
* Octal numbers can be forced to have a leading zero; hex numbers
* use the given digits.
*/
static CHAR_T *
{
int ndig;
/*
* Handle the three cases separately, in the hope of getting
*/
switch (base) {
case 10:
return (cp);
}
ndig = 0;
/*
* On many machines, unsigned arithmetic is harder than
* signed arithmetic, so we do at most one unsigned mod and
* divide; this is sufficient to reduce the range of
* the incoming value to where signed arithmetic works.
*/
ndig++;
} else
do {
ndig++;
/*
* If (*grp == CHAR_MAX) then no more grouping
* should be performed.
*/
&& sval > 9) {
ndig = 0;
/*
* If (*(grp+1) == '\0') then we have to
* use *grp character (last grouping rule)
* for all next cases
*/
grp++;
}
sval /= 10;
} while (sval != 0);
break;
case 8:
do {
val >>= 3;
} while (val);
*--cp = '0';
break;
case 16:
do {
val >>= 4;
} while (val);
break;
default: /* oops */
abort();
}
return (cp);
}
/* Identical to __ultoa, but for intmax_t. */
static CHAR_T *
{
int ndig;
/* quick test for small values; __ultoa is typically much faster */
/* (perhaps instead we should run until small, then call __ultoa?) */
switch (base) {
case 10:
if (val < 10) {
return (cp);
}
ndig = 0;
if (val > INTMAX_MAX) {
ndig++;
} else
do {
ndig++;
/*
* If (*grp == CHAR_MAX) then no more grouping
* should be performed.
*/
&& sval > 9) {
ndig = 0;
/*
* If (*(grp+1) == '\0') then we have to
* use *grp character (last grouping rule)
* for all next cases
*/
grp++;
}
sval /= 10;
} while (sval != 0);
break;
case 8:
do {
val >>= 3;
} while (val);
*--cp = '0';
break;
case 16:
do {
val >>= 4;
} while (val);
break;
default:
abort();
}
return (cp);
}
#ifndef NARROW
/*
* Convert a multibyte character string argument for the %s format to a wide
* string representation. ``prec'' specifies the maximum number of bytes
* to output. If ``prec'' is greater than or equal to zero, we can't assume
* that the multibyte char. string ends in a null character.
*/
static wchar_t *
{
const char *p;
return (NULL);
/*
* Supplied argument is a multibyte string; convert it to wide
* characters first.
*/
if (prec >= 0) {
/*
* String is not guaranteed to be NUL-terminated. Find the
* number of characters to print.
*/
p = mbsarg;
break;
p += nconv;
nchars++;
}
return (NULL);
} else
/*
* Allocate buffer for the result and perform the conversion,
* converting at most `size' bytes of the input multibyte string to
* wide characters for printing.
*/
return (NULL);
p = mbsarg;
nconv = 0;
while (insize != 0) {
break;
wcp++;
p += nconv;
}
return (NULL);
}
*wcp = L'\0';
return (convbuf);
}
#else
/*
* Convert a wide character string argument for the %ls format to a multibyte
* string representation. If not -1, prec specifies the maximum number of
* bytes to output, and also means that we can't assume that the wide char.
* string ends is null-terminated.
*/
static char *
{
char buf[MB_LEN_MAX];
wchar_t *p;
char *convbuf;
/* Allocate space for the maximum number of bytes we could output. */
if (prec < 0) {
p = wcsarg;
return (NULL);
} else {
/*
* Optimisation: if the output precision is small enough,
* just allocate enough memory for the maximum instead of
* scanning the string.
*/
if (prec < 128)
else {
nbytes = 0;
p = wcsarg;
for (;;) {
break;
}
}
}
return (NULL);
/* Fill the output buffer. */
p = wcsarg;
return (NULL);
}
return (convbuf);
}
#endif
/*
* MT-safe version
*/
int
{
int ret;
return (EOF);
}
return (ret);
}
#ifndef NO_FLOATING_POINT
#include <float.h>
#include <math.h>
#include "floatio.h"
#define DEFPREC 6
#ifndef WIDE_DOUBLE
static char *cvt(double, int, int, char *, int *, int, int *);
#endif
#endif /* !NO_FLOATING_POINT */
/*
* The size of the buffer we use as scratch space for integer
* conversions, among other things. Technically, we would need the
* most space for base 10 conversions with thousands' grouping
* characters between each pair of digits. 100 bytes is a
* conservative overestimate even for a 128-bit uintmax_t.
*/
#define BUF 100
/*
* Flags used during conversion.
*/
/* C99 additional size modifiers: */
/*
* Non-MT-safe version
*/
int
{
int ch; /* character from fmt */
int n, n2; /* handy integer (short term usage) */
int flags; /* flags as above */
int ret; /* return value accumulator (number of items converted)*/
int width; /* width from format (%8d), or 0 */
int prec; /* precision from format; <0 for N/A */
char thousands_sep; /* locale specific thousands separator */
const char *grouping; /* locale specific numeric grouping rules */
#ifndef NO_FLOATING_POINT
/*
* We can decompose the printed representation of floating
* point numbers into several parts, some of which may be empty:
*
* [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ
* A B ---C--- D E F
*
* A: 'sign' holds this value if present; '\0' otherwise
* B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal
* C: cp points to the string MMMNNN. Leading and trailing
* zeros are not in the string and must be added.
* D: expchar holds this character; '\0' if no exponent, e.g. %f
* F: at least two digits for decimal, at least one digit for hex
*/
char *decimal_point; /* locale specific decimal point */
#ifdef WIDE_DOUBLE
int signflag; /* true if float is negative */
union { /* floating point arguments %[aAeEfFgG] */
double dbl;
long double ldbl;
} fparg;
char *dtoaend; /* pointer to end of converted digits */
#else
double _double; /* double precision arguments %[eEfgG] */
char softsign; /* temporary negative sign for floats */
#endif
char *dtoaresult; /* buffer allocated by dtoa */
int expt = 0; /* integer value of exponent */
char expchar; /* exponent character: [eEpP\0] */
int expsize; /* character count for expstr */
int lead; /* sig figs before decimal or group sep */
int ndig; /* actual number of digits returned by dtoa */
int nseps; /* number of group separators with ' */
int nrepeats; /* number of repeats of the last group */
#endif
int base; /* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
int realsz; /* field size expanded by dprec, sign, etc */
int size; /* size of converted field or string */
int prsize; /* max size of printed field */
const char *xdigs; /* digits for %[xX] conversion */
#ifdef NARROW
#define NIOV 8
#else
int n3;
#endif
int nextarg; /* 1-based argument index */
/*
* Choose PADSIZE to trade efficiency vs. size. If larger printf
* fields occur frequently, increase PADSIZE and make the initialisers
* below longer.
*/
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
/*
* BEWARE, these `goto error' on error, PRINT uses `n2' and
* PAD uses `n'.
*/
#ifndef NARROW
} while (/*CONSTCOND*/0)
#define FLUSH()
#else
iovp++; \
goto error; \
} \
} while (/*CONSTCOND*/0)
#define FLUSH() do { \
goto error; \
uio.uio_iovcnt = 0; \
} while (/*CONSTCOND*/0)
#endif /* NARROW */
if ((n = (howmany)) > 0) { \
while (n > PADSIZE) { \
n -= PADSIZE; \
} \
} \
} while (/*CONSTCOND*/0)
if (n2 > 0) \
} while(/*CONSTCOND*/0)
/*
* Get the argument indexed by nextarg. If the argument table is
* built, use it to get the argument. If its not, get the next
* argument (and arguments must be gotten sequentially).
*/
/*
* To extend shorts properly, we need both signed and unsigned
* argument extraction methods.
*/
#define SARG() \
GETARG(int)))
#define UARG() \
#define SJARG() \
#define UJARG() \
/*
* Get * arguments, including the form *nn$. Preserve the nextarg
* that the argument can be gotten once the type is determined.
*/
n2 = 0; \
cp++; \
} \
if (*cp == '$') { \
argtable = statargtable; \
goto oomem; \
} \
} else { \
}
return (EOF);
}
thousands_sep = '\0';
#ifndef NO_FLOATING_POINT
expsize = 0; /* XXXGCC -Wuninitialized [sh3,m68000] */
#endif
/* sorry, f{w,}printf(read_only_file, L"") returns {W,}EOF, not 0 */
return (END_OF_FILE);
}
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
nextarg = 1;
#ifdef NARROW
uio.uio_iovcnt = 0;
#endif
ret = 0;
/*
* Scan the format for conversions (`%' character).
*/
for (;;)
{
continue;
ret = END_OF_FILE;
goto error;
}
ret += n;
}
if (ch == '\0')
goto done;
fmt++; /* skip over '%' */
flags = 0;
dprec = 0;
width = 0;
prec = -1;
sign = '\0';
expchar = '\0';
lead = 0;
ulval = 0;
ujval = 0;
case ' ':
/*-
* ``If the space and + flags both appear, the space
* flag will be ignored.''
* -- ANSI X3J11
*/
if (!sign)
sign = ' ';
goto rflag;
case '#':
goto rflag;
case '*':
/*-
* ``A negative field width argument is taken as a
* - flag followed by a positive field width.''
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
if (width >= 0)
goto rflag;
/* FALLTHROUGH */
case '-':
goto rflag;
case '+':
sign = '+';
goto rflag;
case '\'':
goto rflag;
case '.':
goto rflag;
}
prec = 0;
}
goto reswitch;
case '0':
/*-
* ``Note that 0 is taken as a flag, not as the
* beginning of a field width.''
* -- ANSI X3J11
*/
goto rflag;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
do {
if (ch == '$') {
nextarg = n;
&argtable) == -1)
goto oomem;
}
goto rflag;
}
width = n;
goto reswitch;
#ifndef NO_FLOATING_POINT
case 'L':
goto rflag;
#endif
case 'h':
} else
goto rflag;
case 'j':
goto rflag;
case 'l':
} else
goto rflag;
case 'q':
goto rflag;
case 't':
goto rflag;
case 'z':
goto rflag;
case 'C':
/*FALLTHROUGH*/
case 'c':
#ifdef NARROW
/* The compiler "knows" that wint_t may be smaller than an int so
it warns about it when used as the type argument to va_arg().
Since any type of parameter smaller than an int is promoted to an int on a
function call, we must call GETARG with type int instead of wint_t.
*/
goto error;
}
} else {
size = 1;
}
#else
else
size = 1;
#endif
sign = '\0';
break;
case 'D':
/*FALLTHROUGH*/
case 'd':
case 'i':
if (flags & INTMAX_SIZE) {
sign = '-';
}
} else {
if ((long)ulval < 0) {
sign = '-';
}
}
base = 10;
goto number;
#ifndef NO_FLOATING_POINT
#ifdef WIDE_DOUBLE
case 'a':
case 'A':
if (ch == 'a') {
xdigs = xdigs_lower;
expchar = 'p';
} else {
xdigs = xdigs_upper;
expchar = 'P';
}
} else {
}
if (dtoaresult == NULL)
goto oomem;
if (prec < 0)
#ifndef NARROW
#else
/*XXX inefficient*/
#endif
goto oomem;
goto fp_common;
case 'e':
case 'E':
if (prec < 0)
goto fp_begin;
case 'f':
case 'F':
expchar = '\0';
goto fp_begin;
case 'g':
case 'G':
if (prec == 0)
prec = 1;
if (prec < 0)
} else {
if (expt == 9999)
}
if (dtoaresult == NULL)
goto oomem;
#ifndef NARROW
#else
/*XXX inefficient*/
#endif
goto oomem;
if (signflag)
sign = '-';
if (*result == 'N') {
STRCONST("NAN");
sign = '\0';
} else
STRCONST("INF");
size = 3;
break;
}
#else
//case 'e':
//case 'E':
//case 'f':
//case 'F':
//case 'g':
//case 'G':
// if (prec == -1) {
// prec = DEFPREC;
// } else if ((ch == 'g' || ch == 'G') && prec == 0) {
// prec = 1;
// }
case 'e':
case 'E':
if (prec < 0)
goto fp_begin;
case 'f':
case 'F':
expchar = '\0';
goto fp_begin;
case 'g':
case 'G':
if (prec == 0)
prec = 1;
if (prec < 0)
} else {
}
/* do this before tricky precision changes */
if (_double < 0)
sign = '-';
else
size = 3;
break;
}
else
size = 3;
break;
}
if (dtoaresult == NULL)
goto oomem;
#ifndef NARROW
#else
/*XXX inefficient*/
#endif
goto oomem;
if (softsign)
sign = '-';
#endif
/* Make %[gG] smell like %[fF] */
expchar = '\0';
else
if (prec < 0)
prec = 0;
} else {
/*
* Make %[gG] smell like %[eE], but
* trim trailing zeroes if no # flag.
*
* Note: The precision field used with [gG] is the number significant
* digits to print. When converting to [eE] the digit before the
* decimal must not be included in the precision value.
*/
}
}
if (expchar) {
++size; /* Decimal point is added to character count */
} else {
/* space for digits before decimal point */
if (expt > 0)
else /* "0" */
size = 1;
/* space for decimal pt and following digits */
/* space for thousands' grouping */
break;
if (*(grouping+1)) {
nseps++;
grouping++;
} else
nrepeats++;
}
} else
}
break;
#endif /* !NO_FLOATING_POINT */
case 'n':
/*
* Assignment-like behavior is specified if the
* value overflows or is otherwise unrepresentable.
* C99 says to use `signed char' for %hhn conversions.
*/
else
continue; /* no output */
case 'O':
/*FALLTHROUGH*/
case 'o':
if (flags & INTMAX_SIZE)
else
base = 8;
goto nosign;
case 'p':
/*-
* ``The argument shall be a pointer to void. The
* value of the pointer is converted to a sequence
* of printable characters, in an implementation-
* defined manner.''
* -- ANSI X3J11
*/
base = 16;
xdigs = xdigs_lower;
goto nosign;
case 'S':
/*FALLTHROUGH*/
case 's':
} else {
else {
goto error;
}
}
}
if (prec >= 0) {
/*
* can't use STRLEN; can only look for the
* NUL in the first `prec' characters, and
* STRLEN() will go further.
*/
if (p != NULL) {
} else
} else
sign = '\0';
break;
case 'U':
/*FALLTHROUGH*/
case 'u':
if (flags & INTMAX_SIZE)
else
base = 10;
goto nosign;
case 'X':
xdigs = xdigs_upper;
goto hex;
case 'x':
xdigs = xdigs_lower;
hex:
if (flags & INTMAX_SIZE)
else
base = 16;
/* leading 0x/X only if non-zero */
/* unsigned conversions */
/*-
* ``... diouXx conversions ... if a precision is
* specified, the 0 flag will be ignored.''
* -- ANSI X3J11
*/
/*-
* ``The result of converting a zero value with an
* explicit precision of zero is no characters.''
* -- ANSI X3J11
*
* ``The C Standard is clear enough as is. The call
* printf("%#.0o", 0) should print 0.''
* -- Defect Report #151
*/
if (flags & INTMAX_SIZE) {
{
grouping);
}
} else {
grouping);
}
abort();
break;
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
/* pretend it was %c with argument ch */
size = 1;
sign = '\0';
break;
}
/*
* All reasonable formats wind up here. At this point, `result'
* points to a string which (if not flags&LADJUST) should be
* padded out to `width' places. If flags&ZEROPAD, it should
* first be prefixed by any sign or other prefix; otherwise,
* it should be blank padded before the prefix is emitted.
* After any left-hand padding and prefixing, emit zeroes
* required by a decimal [diouxX] precision, then print the
* string proper, then emit zeroes required by any leftover
* floating precision; finally, if LADJUST, pad with blanks.
*
* Compute actual size, so we know how much to pad.
* size excludes decimal prec; realsz includes it.
*/
if (sign)
realsz++;
if (ox[1])
realsz += 2;
ret = END_OF_FILE;
goto error;
}
/* right-adjusting blank padding */
/* prefix */
if (sign)
ox[0] = '0';
}
/* right-adjusting zero padding */
/* leading zeroes from decimal precision */
/* the string or number proper */
#ifndef NO_FLOATING_POINT
} else { /* glue together f_p fragments */
if (!expchar) { /* %[fF] or sufficiently short %[gG] */
if (expt <= 0) {
/* already handled initial 0's */
} else {
if (grouping) {
if (nrepeats > 0)
nrepeats--;
else {
grouping--;
nseps--;
}
1);
}
}
buf[0] = *decimal_point;
}
}
zeroes);
} else { /* %[eE] or sufficiently long %[gG] */
} else /* XeYYY */
}
}
#else
#endif
/* left-adjusting padding (always blank) */
/* finally, adjust ret */
FLUSH();
}
done:
FLUSH();
ret = END_OF_FILE;
return (ret);
/* NOTREACHED */
ret = END_OF_FILE;
goto error;
}
/*
* Find all arguments when a positional parameter is encountered. Returns a
* table, indexed by argument number, of pointers to each arguments. The
* initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
* It will be replaces with a malloc-ed one if it overflows.
*/
static int
{
int ch; /* character from fmt */
int n, n2; /* handy integer (short term usage) */
int flags; /* flags as above */
int tablesize; /* current size of type table */
int tablemax; /* largest used index in table */
int nextarg; /* 1-based argument index */
/*
* Add an argument type to the table, expanding if necessary.
*/
do { \
&tablesize) == -1) \
return -1; \
} while (/*CONSTCOND*/0)
#define ADDSARG() \
do { \
ADDTYPE(T_PTRDIFFT); \
else \
} while (/*CONSTCOND*/0)
#define ADDUARG() \
do { \
ADDTYPE(T_UINTMAXT); \
ADDTYPE(T_PTRDIFFT); \
else \
} while (/*CONSTCOND*/0)
/*
* Add * arguments to the type array.
*/
#define ADDASTER() \
n2 = 0; \
cp++; \
} \
if (*cp == '$') { \
} else { \
}
tablemax = 0;
nextarg = 1;
for (n = 0; n < STATIC_ARG_TBL_SIZE; n++)
/*
* Scan the format for conversions (`%' character).
*/
for (;;) {
/* void */;
if (ch == '\0')
goto done;
fmt++; /* skip over '%' */
flags = 0;
case ' ':
case '#':
goto rflag;
case '*':
ADDASTER ();
goto rflag;
case '-':
case '+':
case '\'':
goto rflag;
case '.':
ADDASTER ();
goto rflag;
}
}
goto reswitch;
case '0':
goto rflag;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
do {
if (ch == '$') {
nextarg = n;
goto rflag;
}
goto reswitch;
#ifndef NO_FLOATING_POINT
case 'L':
goto rflag;
#endif
case 'h':
} else
goto rflag;
case 'j':
goto rflag;
case 'l':
} else
goto rflag;
case 'q':
goto rflag;
case 't':
goto rflag;
case 'z':
goto rflag;
case 'C':
/*FALLTHROUGH*/
case 'c':
else
break;
case 'D':
/*FALLTHROUGH*/
case 'd':
case 'i':
ADDSARG();
break;
#ifndef NO_FLOATING_POINT
case 'a':
case 'A':
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
else
break;
#endif /* !NO_FLOATING_POINT */
case 'n':
else
continue; /* no output */
case 'O':
/*FALLTHROUGH*/
case 'o':
ADDUARG();
break;
case 'p':
break;
case 'S':
/*FALLTHROUGH*/
case 's':
else
break;
case 'U':
/*FALLTHROUGH*/
case 'u':
case 'X':
case 'x':
ADDUARG();
break;
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
break;
}
}
done:
/*
* Build the argument table.
*/
if (tablemax >= STATIC_ARG_TBL_SIZE) {
return -1;
}
for (n = 1; n <= tablemax; n++) {
switch (typetable [n]) {
case T_UNUSED: /* whoops! */
break;
case TP_SCHAR:
break;
case TP_SHORT:
break;
case T_INT:
break;
case T_U_INT:
break;
case TP_INT:
break;
case T_LONG:
break;
case T_U_LONG:
break;
case TP_LONG:
break;
case T_LLONG:
break;
case T_U_LLONG:
break;
case TP_LLONG:
break;
case T_PTRDIFFT:
break;
case TP_PTRDIFFT:
break;
case T_SIZET:
break;
case TP_SIZET:
break;
case T_INTMAXT:
break;
case T_UINTMAXT:
break;
case TP_INTMAXT:
break;
case T_DOUBLE:
#ifndef NO_FLOATING_POINT
#endif
break;
case T_LONG_DOUBLE:
#ifndef NO_FLOATING_POINT
#endif
break;
case TP_CHAR:
break;
case TP_VOID:
break;
case T_WINT:
break;
case TP_WCHAR:
break;
}
}
return 0;
}
/*
* Increase the size of the type table.
*/
static int
{
if (oldsize == STATIC_ARG_TBL_SIZE) {
return -1;
} else {
return -1;
}
}
return 0;
}
#ifndef NO_FLOATING_POINT
#ifndef WIDE_DOUBLE
static char *
int *length)
{
if (ch == 'f') {
} else {
/* To obtain ndigits after the decimal point for the 'e'
* and 'E' formats, round to ndigits + 1 significant
* figures.
*/
ndigits++;
}
}
return NULL;
if (dsgn) {
*sign = '-';
} else
*sign = '\000';
if (ch == 'f') {
}
*rve++ = '0';
}
return digits;
}
#endif
static int
{
CHAR_T *p, *t;
p = p0;
*p++ = fmtch;
if (expo < 0) {
*p++ = '-';
}
else
*p++ = '+';
if (expo > 9) {
do {
}
else {
/*
* Exponents for decimal floating point conversions
* (%[eEgG]) must be at least two characters long,
* whereas exponents for hexadecimal conversions can
* be only one character long.
*/
*p++ = '0';
}
return (p - p0);
}
#endif /* !NO_FLOATING_POINT */