OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [powerpc/] [vfprintf.c] - Diff between revs 207 and 345

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
FUNCTION
FUNCTION
<<vprintf>>, <<vfprintf>>, <<vsprintf>>---format argument list
<<vprintf>>, <<vfprintf>>, <<vsprintf>>---format argument list
 
 
INDEX
INDEX
        vprintf
        vprintf
INDEX
INDEX
        vfprintf
        vfprintf
INDEX
INDEX
        vsprintf
        vsprintf
INDEX
INDEX
        vsnprintf
        vsnprintf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        #include <stdarg.h>
        #include <stdarg.h>
        int vprintf(const char *<[fmt]>, va_list <[list]>);
        int vprintf(const char *<[fmt]>, va_list <[list]>);
        int vfprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
        int vfprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
        int vsprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
        int vsprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
        int vsnprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
        int vsnprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
 
 
        int _vprintf_r(void *<[reent]>, const char *<[fmt]>,
        int _vprintf_r(void *<[reent]>, const char *<[fmt]>,
                        va_list <[list]>);
                        va_list <[list]>);
        int _vfprintf_r(void *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
        int _vfprintf_r(void *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
                        va_list <[list]>);
                        va_list <[list]>);
        int _vsprintf_r(void *<[reent]>, char *<[str]>, const char *<[fmt]>,
        int _vsprintf_r(void *<[reent]>, char *<[str]>, const char *<[fmt]>,
                        va_list <[list]>);
                        va_list <[list]>);
        int _vsnprintf_r(void *<[reent]>, char *<[str]>, size_t <[size]>, const char *<[fmt]>,
        int _vsnprintf_r(void *<[reent]>, char *<[str]>, size_t <[size]>, const char *<[fmt]>,
                        va_list <[list]>);
                        va_list <[list]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        #include <varargs.h>
        #include <varargs.h>
        int vprintf( <[fmt]>, <[list]>)
        int vprintf( <[fmt]>, <[list]>)
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int vfprintf(<[fp]>, <[fmt]>, <[list]>)
        int vfprintf(<[fp]>, <[fmt]>, <[list]>)
        FILE *<[fp]>;
        FILE *<[fp]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int vsprintf(<[str]>, <[fmt]>, <[list]>)
        int vsprintf(<[str]>, <[fmt]>, <[list]>)
        char *<[str]>;
        char *<[str]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int vsnprintf(<[str]>, <[size]>, <[fmt]>, <[list]>)
        int vsnprintf(<[str]>, <[size]>, <[fmt]>, <[list]>)
        char *<[str]>;
        char *<[str]>;
        size_t <[size]>;
        size_t <[size]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int _vprintf_r(<[reent]>, <[fmt]>, <[list]>)
        int _vprintf_r(<[reent]>, <[fmt]>, <[list]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int _vfprintf_r(<[reent]>, <[fp]>, <[fmt]>, <[list]>)
        int _vfprintf_r(<[reent]>, <[fp]>, <[fmt]>, <[list]>)
        char *<[reent]>;
        char *<[reent]>;
        FILE *<[fp]>;
        FILE *<[fp]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int _vsprintf_r(<[reent]>, <[str]>, <[fmt]>, <[list]>)
        int _vsprintf_r(<[reent]>, <[str]>, <[fmt]>, <[list]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[str]>;
        char *<[str]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
        int _vsnprintf_r(<[reent]>, <[str]>, <[size]>, <[fmt]>, <[list]>)
        int _vsnprintf_r(<[reent]>, <[str]>, <[size]>, <[fmt]>, <[list]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[str]>;
        char *<[str]>;
        size_t <[size]>;
        size_t <[size]>;
        char *<[fmt]>;
        char *<[fmt]>;
        va_list <[list]>;
        va_list <[list]>;
 
 
DESCRIPTION
DESCRIPTION
<<vprintf>>, <<vfprintf>>, <<vsprintf>> and <<vsnprintf>> are (respectively)
<<vprintf>>, <<vfprintf>>, <<vsprintf>> and <<vsnprintf>> are (respectively)
variants of <<printf>>, <<fprintf>>, <<sprintf>> and <<snprintf>>.  They differ
variants of <<printf>>, <<fprintf>>, <<sprintf>> and <<snprintf>>.  They differ
only in allowing their caller to pass the variable argument list as a
only in allowing their caller to pass the variable argument list as a
<<va_list>> object (initialized by <<va_start>>) rather than directly
<<va_list>> object (initialized by <<va_start>>) rather than directly
accepting a variable number of arguments.
accepting a variable number of arguments.
 
 
RETURNS
RETURNS
The return values are consistent with the corresponding functions:
The return values are consistent with the corresponding functions:
<<vsprintf>> returns the number of bytes in the output string,
<<vsprintf>> returns the number of bytes in the output string,
save that the concluding <<NULL>> is not counted.
save that the concluding <<NULL>> is not counted.
<<vprintf>> and <<vfprintf>> return the number of characters transmitted.
<<vprintf>> and <<vfprintf>> return the number of characters transmitted.
If an error occurs, <<vprintf>> and <<vfprintf>> return <<EOF>>. No
If an error occurs, <<vprintf>> and <<vfprintf>> return <<EOF>>. No
error returns occur for <<vsprintf>>.
error returns occur for <<vsprintf>>.
 
 
PORTABILITY
PORTABILITY
ANSI C requires all three functions.
ANSI C requires all three functions.
 
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
*/
 
 
/*-
/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * This code is derived from software contributed to Berkeley by
 * This code is derived from software contributed to Berkeley by
 * Chris Torek.
 * Chris Torek.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *    without specific prior written permission.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * 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
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)vfprintf.c   5.50 (Berkeley) 12/16/92";*/
/*static char *sccsid = "from: @(#)vfprintf.c   5.50 (Berkeley) 12/16/92";*/
static char *rcsid = "$Id: vfprintf.c 207 2010-07-19 17:43:24Z jeremybennett $";
static char *rcsid = "$Id: vfprintf.c 207 2010-07-19 17:43:24Z jeremybennett $";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
 
 
/*
/*
 * Actual printf innards.
 * Actual printf innards.
 *
 *
 * This code is large and complicated...
 * This code is large and complicated...
 */
 */
 
 
#ifdef INTEGER_ONLY
#ifdef INTEGER_ONLY
#define VFPRINTF vfiprintf
#define VFPRINTF vfiprintf
#define _VFPRINTF_R _vfiprintf_r
#define _VFPRINTF_R _vfiprintf_r
#else
#else
#define VFPRINTF vfprintf
#define VFPRINTF vfprintf
#define _VFPRINTF_R _vfprintf_r
#define _VFPRINTF_R _vfprintf_r
#ifndef NO_FLOATING_POINT
#ifndef NO_FLOATING_POINT
#define FLOATING_POINT
#define FLOATING_POINT
#endif
#endif
#endif
#endif
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <limits.h>
#include <limits.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <reent.h>
#include <reent.h>
#include <wchar.h>
#include <wchar.h>
#include <string.h>
#include <string.h>
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
#include <altivec.h>
#include <altivec.h>
#endif
#endif
 
 
#ifdef _HAVE_STDC
#ifdef _HAVE_STDC
#include <stdarg.h>
#include <stdarg.h>
#else
#else
#include <varargs.h>
#include <varargs.h>
#endif
#endif
 
 
#include "local.h"
#include "local.h"
#include "fvwrite.h"
#include "fvwrite.h"
#include "vfieeefp.h"
#include "vfieeefp.h"
 
 
/* Currently a test is made to see if long double processing is warranted.
/* Currently a test is made to see if long double processing is warranted.
   This could be changed in the future should the _ldtoa_r code be
   This could be changed in the future should the _ldtoa_r code be
   preferred over _dtoa_r.  */
   preferred over _dtoa_r.  */
#define _NO_LONGDBL
#define _NO_LONGDBL
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
#undef _NO_LONGDBL
#endif
#endif
 
 
#define _NO_LONGLONG
#define _NO_LONGLONG
#if defined _WANT_IO_LONG_LONG && defined __GNUC__
#if defined _WANT_IO_LONG_LONG && defined __GNUC__
# undef _NO_LONGLONG
# undef _NO_LONGLONG
#endif
#endif
 
 
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
typedef union
typedef union
{
{
  vector int v;
  vector int v;
  float f[4];
  float f[4];
  int   i[16 / sizeof(int)];
  int   i[16 / sizeof(int)];
  long  l[4];
  long  l[4];
  short s[8];
  short s[8];
  signed char c[16];
  signed char c[16];
} vec_16_byte_union;
} vec_16_byte_union;
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
 
 
/*
/*
 * Flush out all the vectors defined by the given uio,
 * Flush out all the vectors defined by the given uio,
 * then reset it so that it can be reused.
 * then reset it so that it can be reused.
 */
 */
static int
static int
__sprint_r(rptr, fp, uio)
__sprint_r(rptr, fp, uio)
        struct _reent *rptr;
        struct _reent *rptr;
        FILE *fp;
        FILE *fp;
        register struct __suio *uio;
        register struct __suio *uio;
{
{
        register int err;
        register int err;
 
 
        if (uio->uio_resid == 0) {
        if (uio->uio_resid == 0) {
                uio->uio_iovcnt = 0;
                uio->uio_iovcnt = 0;
                return (0);
                return (0);
        }
        }
        err = __sfvwrite_r(rptr, fp, uio);
        err = __sfvwrite_r(rptr, fp, uio);
        uio->uio_resid = 0;
        uio->uio_resid = 0;
        uio->uio_iovcnt = 0;
        uio->uio_iovcnt = 0;
        return (err);
        return (err);
}
}
 
 
/*
/*
 * Helper function for `fprintf to unbuffered unix file': creates a
 * Helper function for `fprintf to unbuffered unix file': creates a
 * temporary buffer.  We only work on write-only files; this avoids
 * temporary buffer.  We only work on write-only files; this avoids
 * worries about ungetc buffers and so forth.
 * worries about ungetc buffers and so forth.
 */
 */
static int
static int
__sbprintf_r(rptr, fp, fmt, ap)
__sbprintf_r(rptr, fp, fmt, ap)
        struct _reent *rptr;
        struct _reent *rptr;
        register FILE *fp;
        register FILE *fp;
        const char *fmt;
        const char *fmt;
        va_list ap;
        va_list ap;
{
{
        int ret;
        int ret;
        FILE fake;
        FILE fake;
        unsigned char buf[BUFSIZ];
        unsigned char buf[BUFSIZ];
 
 
        /* copy the important variables */
        /* copy the important variables */
        fake._flags = fp->_flags & ~__SNBF;
        fake._flags = fp->_flags & ~__SNBF;
        fake._file = fp->_file;
        fake._file = fp->_file;
        fake._cookie = fp->_cookie;
        fake._cookie = fp->_cookie;
        fake._write = fp->_write;
        fake._write = fp->_write;
 
 
        /* set up the buffer */
        /* set up the buffer */
        fake._bf._base = fake._p = buf;
        fake._bf._base = fake._p = buf;
        fake._bf._size = fake._w = sizeof(buf);
        fake._bf._size = fake._w = sizeof(buf);
        fake._lbfsize = 0;       /* not actually used, but Just In Case */
        fake._lbfsize = 0;       /* not actually used, but Just In Case */
 
 
        /* do the work, then copy any error status */
        /* do the work, then copy any error status */
        ret = _VFPRINTF_R(rptr, &fake, fmt, ap);
        ret = _VFPRINTF_R(rptr, &fake, fmt, ap);
        if (ret >= 0 && _fflush_r(rptr, &fake))
        if (ret >= 0 && _fflush_r(rptr, &fake))
                ret = EOF;
                ret = EOF;
        if (fake._flags & __SERR)
        if (fake._flags & __SERR)
                fp->_flags |= __SERR;
                fp->_flags |= __SERR;
        return (ret);
        return (ret);
}
}
 
 
 
 
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
#include <locale.h>
#include <locale.h>
#include <math.h>
#include <math.h>
#include "floatio.h"
#include "floatio.h"
 
 
#define BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
#define BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
#define DEFPREC         6
#define DEFPREC         6
 
 
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
static char *cvt _PARAMS((struct _reent *, double, int, int, char *, int *, int, int *));
static char *cvt _PARAMS((struct _reent *, double, int, int, char *, int *, int, int *));
#else
#else
static char *cvt _PARAMS((struct _reent *, _LONG_DOUBLE, int, int, char *, int *, int, int *));
static char *cvt _PARAMS((struct _reent *, _LONG_DOUBLE, int, int, char *, int *, int, int *));
extern int  _ldcheck _PARAMS((_LONG_DOUBLE *));
extern int  _ldcheck _PARAMS((_LONG_DOUBLE *));
#endif
#endif
 
 
static int exponent _PARAMS((char *, int, int));
static int exponent _PARAMS((char *, int, int));
 
 
#ifdef __SPE__
#ifdef __SPE__
static char *cvt_ufix64 _PARAMS((struct _reent *, unsigned long long, int,  int *, int *));
static char *cvt_ufix64 _PARAMS((struct _reent *, unsigned long long, int,  int *, int *));
#endif /* __SPE__ */
#endif /* __SPE__ */
 
 
#else /* no FLOATING_POINT */
#else /* no FLOATING_POINT */
 
 
#define BUF             40
#define BUF             40
 
 
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
 
 
 
 
/*
/*
 * Macros for converting digits to letters and vice versa
 * Macros for converting digits to letters and vice versa
 */
 */
#define to_digit(c)     ((c) - '0')
#define to_digit(c)     ((c) - '0')
#define is_digit(c)     ((unsigned)to_digit(c) <= 9)
#define is_digit(c)     ((unsigned)to_digit(c) <= 9)
#define to_char(n)      ((n) + '0')
#define to_char(n)      ((n) + '0')
 
 
/*
/*
 * Flags used during conversion.
 * Flags used during conversion.
 */
 */
#define ALT             0x001           /* alternate form */
#define ALT             0x001           /* alternate form */
#define HEXPREFIX       0x002           /* add 0x or 0X prefix */
#define HEXPREFIX       0x002           /* add 0x or 0X prefix */
#define LADJUST         0x004           /* left adjustment */
#define LADJUST         0x004           /* left adjustment */
#define LONGDBL         0x008           /* long double */
#define LONGDBL         0x008           /* long double */
#define LONGINT         0x010           /* long integer */
#define LONGINT         0x010           /* long integer */
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
#define QUADINT         0x020           /* quad integer */
#define QUADINT         0x020           /* quad integer */
#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
         that %lld behaves the same as %ld, not as %d, as expected if:
         that %lld behaves the same as %ld, not as %d, as expected if:
         sizeof (long long) = sizeof long > sizeof int  */
         sizeof (long long) = sizeof long > sizeof int  */
#define QUADINT         LONGINT
#define QUADINT         LONGINT
#endif
#endif
#define SHORTINT        0x040           /* short integer */
#define SHORTINT        0x040           /* short integer */
#define ZEROPAD         0x080           /* zero (as opposed to blank) pad */
#define ZEROPAD         0x080           /* zero (as opposed to blank) pad */
#define FPT             0x100           /* Floating point number */
#define FPT             0x100           /* Floating point number */
#define VECTOR          0x200           /* vector */
#define VECTOR          0x200           /* vector */
#define FIXEDPOINT      0x400           /* fixed-point */
#define FIXEDPOINT      0x400           /* fixed-point */
 
 
int
int
_DEFUN (VFPRINTF, (fp, fmt0, ap),
_DEFUN (VFPRINTF, (fp, fmt0, ap),
        FILE * fp _AND
        FILE * fp _AND
        _CONST char *fmt0 _AND
        _CONST char *fmt0 _AND
        va_list ap)
        va_list ap)
{
{
  CHECK_INIT (_REENT, fp);
  CHECK_INIT (_REENT, fp);
  return _VFPRINTF_R (_REENT, fp, fmt0, ap);
  return _VFPRINTF_R (_REENT, fp, fmt0, ap);
}
}
 
 
int
int
_DEFUN (_VFPRINTF_R, (data, fp, fmt0, ap),
_DEFUN (_VFPRINTF_R, (data, fp, fmt0, ap),
        struct _reent *data _AND
        struct _reent *data _AND
        FILE * fp _AND
        FILE * fp _AND
        _CONST char *fmt0 _AND
        _CONST char *fmt0 _AND
        va_list ap)
        va_list ap)
{
{
        register char *fmt;     /* format string */
        register char *fmt;     /* format string */
        register int ch;        /* character from fmt */
        register int ch;        /* character from fmt */
        register int n, m;      /* handy integers (short term usage) */
        register int n, m;      /* handy integers (short term usage) */
        register char *cp;      /* handy char pointer (short term usage) */
        register char *cp;      /* handy char pointer (short term usage) */
        register struct __siov *iovp;/* for PRINT macro */
        register struct __siov *iovp;/* for PRINT macro */
        register int flags;     /* flags as above */
        register int flags;     /* flags as above */
        int ret;                /* return value accumulator */
        int ret;                /* return value accumulator */
        int width;              /* width from format (%8d), or 0 */
        int width;              /* width from format (%8d), or 0 */
        int prec;               /* precision from format (%.3d), or -1 */
        int prec;               /* precision from format (%.3d), or -1 */
        char sign;              /* sign prefix (' ', '+', '-', or \0) */
        char sign;              /* sign prefix (' ', '+', '-', or \0) */
        char old_sign;          /* saved value of sign when looping for vectors */
        char old_sign;          /* saved value of sign when looping for vectors */
        int old_ch;             /* saved value of ch when looping for vectors */
        int old_ch;             /* saved value of ch when looping for vectors */
        char *format_anchor;    /* start of format to process */
        char *format_anchor;    /* start of format to process */
        wchar_t wc;
        wchar_t wc;
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
        char *decimal_point = localeconv()->decimal_point;
        char *decimal_point = localeconv()->decimal_point;
        char softsign;          /* temporary negative sign for floats */
        char softsign;          /* temporary negative sign for floats */
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
        union { int i; double d; } _double_ = {0};
        union { int i; double d; } _double_ = {0};
        #define _fpvalue (_double_.d)
        #define _fpvalue (_double_.d)
#else
#else
        union { int i; _LONG_DOUBLE ld; } _long_double_ = {0};
        union { int i; _LONG_DOUBLE ld; } _long_double_ = {0};
        #define _fpvalue (_long_double_.ld)
        #define _fpvalue (_long_double_.ld)
        int tmp;
        int tmp;
#endif
#endif
        int expt;               /* integer value of exponent */
        int expt;               /* integer value of exponent */
        int expsize = 0; /* character count for expstr */
        int expsize = 0; /* character count for expstr */
        int ndig;               /* actual number of digits returned by cvt */
        int ndig;               /* actual number of digits returned by cvt */
        char expstr[7];         /* buffer for exponent string */
        char expstr[7];         /* buffer for exponent string */
#endif
#endif
 
 
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
#define quad_t    long long
#define quad_t    long long
#define u_quad_t  unsigned long long
#define u_quad_t  unsigned long long
#else
#else
#define quad_t    long
#define quad_t    long
#define u_quad_t  u_long
#define u_quad_t  u_long
#endif
#endif
 
 
        u_quad_t _uquad;        /* integer arguments %[diouxX] */
        u_quad_t _uquad;        /* integer arguments %[diouxX] */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int realsz;             /* field size expanded by dprec */
        int realsz;             /* field size expanded by dprec */
        int size;               /* size of converted field or string */
        int size;               /* size of converted field or string */
        char *xdigs = NULL;     /* digits for [xX] conversion */
        char *xdigs = NULL;     /* digits for [xX] conversion */
#define NIOV 8
#define NIOV 8
        struct __suio uio;      /* output information: summary */
        struct __suio uio;      /* output information: summary */
        struct __siov iov[NIOV];/* ... and individual io vectors */
        struct __siov iov[NIOV];/* ... and individual io vectors */
        char buf[BUF];          /* space for %c, %[diouxX], %[eEfgG] */
        char buf[BUF];          /* space for %c, %[diouxX], %[eEfgG] */
        char ox[2];             /* space for 0x hex-prefix */
        char ox[2];             /* space for 0x hex-prefix */
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
        char vec_sep;           /* vector separator char */
        char vec_sep;           /* vector separator char */
        int vec_print_count;    /* number of vector chunks remaining */
        int vec_print_count;    /* number of vector chunks remaining */
        vec_16_byte_union vec_tmp;
        vec_16_byte_union vec_tmp;
#endif /* __ALTIVEC__ */ 
#endif /* __ALTIVEC__ */ 
        mbstate_t state;          /* mbtowc calls from library must not change state */
        mbstate_t state;          /* mbtowc calls from library must not change state */
 
 
        /*
        /*
         * Choose PADSIZE to trade efficiency vs. size.  If larger printf
         * Choose PADSIZE to trade efficiency vs. size.  If larger printf
         * fields occur frequently, increase PADSIZE and make the initialisers
         * fields occur frequently, increase PADSIZE and make the initialisers
         * below longer.
         * below longer.
         */
         */
#define PADSIZE 16              /* pad chunk size */
#define PADSIZE 16              /* pad chunk size */
        static _CONST char blanks[PADSIZE] =
        static _CONST char blanks[PADSIZE] =
         {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
         {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
        static _CONST char zeroes[PADSIZE] =
        static _CONST char zeroes[PADSIZE] =
         {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
         {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
 
 
        /*
        /*
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         */
         */
#define PRINT(ptr, len) { \
#define PRINT(ptr, len) { \
        iovp->iov_base = (ptr); \
        iovp->iov_base = (ptr); \
        iovp->iov_len = (len); \
        iovp->iov_len = (len); \
        uio.uio_resid += (len); \
        uio.uio_resid += (len); \
        iovp++; \
        iovp++; \
        if (++uio.uio_iovcnt >= NIOV) { \
        if (++uio.uio_iovcnt >= NIOV) { \
                if (__sprint_r(data, fp, &uio)) \
                if (__sprint_r(data, fp, &uio)) \
                        goto error; \
                        goto error; \
                iovp = iov; \
                iovp = iov; \
        } \
        } \
}
}
#define PAD(howmany, with) { \
#define PAD(howmany, with) { \
        if ((n = (howmany)) > 0) { \
        if ((n = (howmany)) > 0) { \
                while (n > PADSIZE) { \
                while (n > PADSIZE) { \
                        PRINT(with, PADSIZE); \
                        PRINT(with, PADSIZE); \
                        n -= PADSIZE; \
                        n -= PADSIZE; \
                } \
                } \
                PRINT(with, n); \
                PRINT(with, n); \
        } \
        } \
}
}
#define FLUSH() { \
#define FLUSH() { \
        if (uio.uio_resid && __sprint_r(data, fp, &uio)) \
        if (uio.uio_resid && __sprint_r(data, fp, &uio)) \
                goto error; \
                goto error; \
        uio.uio_iovcnt = 0; \
        uio.uio_iovcnt = 0; \
        iovp = iov; \
        iovp = iov; \
}
}
 
 
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
#define GET_SHORT(ap) \
#define GET_SHORT(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 8 ? (short)vec_tmp.s[8 - vec_print_count] : \
            (vec_print_count < 8 ? (short)vec_tmp.s[8 - vec_print_count] : \
                (vec_tmp.v = va_arg(ap, vector int), (short)vec_tmp.s[0])) : \
                (vec_tmp.v = va_arg(ap, vector int), (short)vec_tmp.s[0])) : \
            (short)va_arg(ap, int))
            (short)va_arg(ap, int))
#define GET_USHORT(ap) \
#define GET_USHORT(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 8 ? (u_short)vec_tmp.s[8 - vec_print_count] : \
            (vec_print_count < 8 ? (u_short)vec_tmp.s[8 - vec_print_count] : \
                (vec_tmp.v = va_arg(ap, vector int), (u_short)vec_tmp.s[0])) : \
                (vec_tmp.v = va_arg(ap, vector int), (u_short)vec_tmp.s[0])) : \
            (u_short)va_arg(ap, int))
            (u_short)va_arg(ap, int))
 
 
#define GET_LONG(ap) \
#define GET_LONG(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 4 ? (long)vec_tmp.l[4 - vec_print_count] : \
            (vec_print_count < 4 ? (long)vec_tmp.l[4 - vec_print_count] : \
                (vec_tmp.v = va_arg(ap, vector int), vec_tmp.l[0])) : \
                (vec_tmp.v = va_arg(ap, vector int), vec_tmp.l[0])) : \
            va_arg(ap, long int))
            va_arg(ap, long int))
#define GET_ULONG(ap) \
#define GET_ULONG(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 4 ? (u_long)vec_tmp.l[4 - vec_print_count] : \
            (vec_print_count < 4 ? (u_long)vec_tmp.l[4 - vec_print_count] : \
                (vec_tmp.v = va_arg(ap, vector int), (u_long)vec_tmp.l[0])) : \
                (vec_tmp.v = va_arg(ap, vector int), (u_long)vec_tmp.l[0])) : \
            (u_long)va_arg(ap, unsigned long int))
            (u_long)va_arg(ap, unsigned long int))
 
 
#define GET_INT(ap) \
#define GET_INT(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 16 ? \
            (vec_print_count < 16 ? \
                vec_tmp.c[16 - vec_print_count] : \
                vec_tmp.c[16 - vec_print_count] : \
                (vec_tmp.v = va_arg(ap, vector int), (int)vec_tmp.c[0])) : \
                (vec_tmp.v = va_arg(ap, vector int), (int)vec_tmp.c[0])) : \
            va_arg(ap, int))
            va_arg(ap, int))
#define GET_UINT(ap) \
#define GET_UINT(ap) \
        (flags&VECTOR ? \
        (flags&VECTOR ? \
            (vec_print_count < 16 ? \
            (vec_print_count < 16 ? \
                (u_int)((unsigned char)vec_tmp.c[16 - vec_print_count]) : \
                (u_int)((unsigned char)vec_tmp.c[16 - vec_print_count]) : \
                (vec_tmp.v = va_arg(ap, vector int), (u_int)((unsigned char)vec_tmp.c[0]))) : \
                (vec_tmp.v = va_arg(ap, vector int), (u_int)((unsigned char)vec_tmp.c[0]))) : \
            (u_int)va_arg(ap, unsigned int))
            (u_int)va_arg(ap, unsigned int))
#else /* !__ALTIVEC__ */
#else /* !__ALTIVEC__ */
#define GET_SHORT(ap) ((short)va_arg(ap, int))
#define GET_SHORT(ap) ((short)va_arg(ap, int))
#define GET_USHORT(ap) ((u_short)va_arg(ap, int))
#define GET_USHORT(ap) ((u_short)va_arg(ap, int))
#define GET_LONG(ap) (va_arg(ap, long int))
#define GET_LONG(ap) (va_arg(ap, long int))
#define GET_ULONG(ap) ((u_long)va_arg(ap, unsigned long int))
#define GET_ULONG(ap) ((u_long)va_arg(ap, unsigned long int))
#define GET_INT(ap) ((int)va_arg(ap, int))
#define GET_INT(ap) ((int)va_arg(ap, int))
#define GET_UINT(ap) ((u_int)va_arg(ap, unsigned int))
#define GET_UINT(ap) ((u_int)va_arg(ap, unsigned int))
#endif /* !__ALTIVEC__ */
#endif /* !__ALTIVEC__ */
 
 
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
#define SARG() \
#define SARG() \
        (flags&QUADINT ? va_arg(ap, quad_t) : \
        (flags&QUADINT ? va_arg(ap, quad_t) : \
            flags&LONGINT ? GET_LONG(ap) : \
            flags&LONGINT ? GET_LONG(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            (long)GET_INT(ap))
            (long)GET_INT(ap))
#define UARG() \
#define UARG() \
        (flags&QUADINT ? va_arg(ap, u_quad_t) : \
        (flags&QUADINT ? va_arg(ap, u_quad_t) : \
            flags&LONGINT ? GET_ULONG(ap) : \
            flags&LONGINT ? GET_ULONG(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            (u_long)GET_UINT(ap))
            (u_long)GET_UINT(ap))
#ifdef __SPE__
#ifdef __SPE__
#define SFPARG() \
#define SFPARG() \
        (flags&LONGINT ? va_arg(ap, quad_t) : \
        (flags&LONGINT ? va_arg(ap, quad_t) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            (long)va_arg(ap, int))
            (long)va_arg(ap, int))
#define UFPARG() \
#define UFPARG() \
        (flags&LONGINT ? va_arg(ap, u_quad_t) : \
        (flags&LONGINT ? va_arg(ap, u_quad_t) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            (u_long)va_arg(ap, u_int))
            (u_long)va_arg(ap, u_int))
#endif /* __SPE__ */
#endif /* __SPE__ */
#else
#else
#define SARG() \
#define SARG() \
        (flags&LONGINT ? GET_LONG(ap) : \
        (flags&LONGINT ? GET_LONG(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            (long)GET_INT(ap))
            (long)GET_INT(ap))
#define UARG() \
#define UARG() \
        (flags&LONGINT ? GET_ULONG(ap) : \
        (flags&LONGINT ? GET_ULONG(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            (u_long)GET_UINT(ap))
            (u_long)GET_UINT(ap))
#ifdef __SPE__
#ifdef __SPE__
#define SFPARG() \
#define SFPARG() \
        (flags&LONGINT ? (va_arg(ap, long) << 32) : \
        (flags&LONGINT ? (va_arg(ap, long) << 32) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            flags&SHORTINT ? (long)GET_SHORT(ap) : \
            (long)va_arg(ap, int))
            (long)va_arg(ap, int))
#define UFPARG() \
#define UFPARG() \
        (flags&LONGINT ? (va_arg(ap, u_long) <<32) : \
        (flags&LONGINT ? (va_arg(ap, u_long) <<32) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            flags&SHORTINT ? (u_long)GET_USHORT(ap) : \
            (u_long)va_arg(ap, u_int))
            (u_long)va_arg(ap, u_int))
#endif /* __SPE__ */
#endif /* __SPE__ */
#endif
#endif
 
 
        memset (&state, '\0', sizeof (state));
        memset (&state, '\0', sizeof (state));
 
 
        /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
        /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
        if (cantwrite (data, fp)) {
        if (cantwrite (data, fp)) {
                _funlockfile (fp);
                _funlockfile (fp);
                return (EOF);
                return (EOF);
        }
        }
 
 
        /* optimise fprintf(stderr) (and other unbuffered Unix files) */
        /* optimise fprintf(stderr) (and other unbuffered Unix files) */
        if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
        if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
            fp->_file >= 0)
            fp->_file >= 0)
                return (__sbprintf_r(data, fp, fmt0, ap));
                return (__sbprintf_r(data, fp, fmt0, ap));
 
 
        fmt = (char *)fmt0;
        fmt = (char *)fmt0;
        uio.uio_iov = iovp = iov;
        uio.uio_iov = iovp = iov;
        uio.uio_resid = 0;
        uio.uio_resid = 0;
        uio.uio_iovcnt = 0;
        uio.uio_iovcnt = 0;
        ret = 0;
        ret = 0;
 
 
        /*
        /*
         * Scan the format for conversions (`%' character).
         * Scan the format for conversions (`%' character).
         */
         */
 
 
        for (;;) {
        for (;;) {
                cp = fmt;
                cp = fmt;
                while ((n = _mbtowc_r(data, &wc, fmt, MB_CUR_MAX, &state)) > 0) {
                while ((n = _mbtowc_r(data, &wc, fmt, MB_CUR_MAX, &state)) > 0) {
                        fmt += n;
                        fmt += n;
                        if (wc == '%') {
                        if (wc == '%') {
                                fmt--;
                                fmt--;
                                break;
                                break;
                        }
                        }
                }
                }
                if ((m = fmt - cp) != 0) {
                if ((m = fmt - cp) != 0) {
                        PRINT(cp, m);
                        PRINT(cp, m);
                        ret += m;
                        ret += m;
                }
                }
                if (n <= 0)
                if (n <= 0)
                        goto done;
                        goto done;
                fmt++;          /* skip over '%' */
                fmt++;          /* skip over '%' */
 
 
                flags = 0;
                flags = 0;
                dprec = 0;
                dprec = 0;
                width = 0;
                width = 0;
                prec = -1;
                prec = -1;
                sign = '\0';
                sign = '\0';
                old_sign = '\0';
                old_sign = '\0';
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                vec_print_count = 0;
                vec_print_count = 0;
                vec_sep = ' ';
                vec_sep = ' ';
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
 
 
                format_anchor = fmt;
                format_anchor = fmt;
rflag:          ch = *fmt++;
rflag:          ch = *fmt++;
                old_ch = ch;
                old_ch = ch;
reswitch:       switch (ch) {
reswitch:       switch (ch) {
                case ' ':
                case ' ':
                        /*
                        /*
                         * ``If the space and + flags both appear, the space
                         * ``If the space and + flags both appear, the space
                         * flag will be ignored.''
                         * flag will be ignored.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        if (!sign)
                        if (!sign)
                                sign = ' ';
                                sign = ' ';
                        goto rflag;
                        goto rflag;
                case '#':
                case '#':
                        flags |= ALT;
                        flags |= ALT;
                        goto rflag;
                        goto rflag;
                case '*':
                case '*':
                        /*
                        /*
                         * ``A negative field width argument is taken as a
                         * ``A negative field width argument is taken as a
                         * - flag followed by a positive field width.''
                         * - flag followed by a positive field width.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         * They don't exclude field widths read from args.
                         * They don't exclude field widths read from args.
                         */
                         */
                        if ((width = va_arg(ap, int)) >= 0)
                        if ((width = va_arg(ap, int)) >= 0)
                                goto rflag;
                                goto rflag;
                        width = -width;
                        width = -width;
                        /* FALLTHROUGH */
                        /* FALLTHROUGH */
                case '-':
                case '-':
                        flags |= LADJUST;
                        flags |= LADJUST;
                        goto rflag;
                        goto rflag;
                case '+':
                case '+':
                        sign = '+';
                        sign = '+';
                        goto rflag;
                        goto rflag;
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                case ',':
                case ',':
                case ';':
                case ';':
                case ':':
                case ':':
                case '_':
                case '_':
                        if (vec_sep != ' ')
                        if (vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
                        vec_sep = ch;
                        vec_sep = ch;
                        goto rflag;
                        goto rflag;
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                case '.':
                case '.':
                        if ((ch = *fmt++) == '*') {
                        if ((ch = *fmt++) == '*') {
                                n = va_arg(ap, int);
                                n = va_arg(ap, int);
                                prec = n < 0 ? -1 : n;
                                prec = n < 0 ? -1 : n;
                                goto rflag;
                                goto rflag;
                        }
                        }
                        n = 0;
                        n = 0;
                        while (is_digit(ch)) {
                        while (is_digit(ch)) {
                                n = 10 * n + to_digit(ch);
                                n = 10 * n + to_digit(ch);
                                ch = *fmt++;
                                ch = *fmt++;
                        }
                        }
                        prec = n < 0 ? -1 : n;
                        prec = n < 0 ? -1 : n;
                        goto reswitch;
                        goto reswitch;
                case '0':
                case '0':
                        /*
                        /*
                         * ``Note that 0 is taken as a flag, not as the
                         * ``Note that 0 is taken as a flag, not as the
                         * beginning of a field width.''
                         * beginning of a field width.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        flags |= ZEROPAD;
                        flags |= ZEROPAD;
                        goto rflag;
                        goto rflag;
                case '1': case '2': case '3': case '4':
                case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                case '5': case '6': case '7': case '8': case '9':
                        n = 0;
                        n = 0;
                        do {
                        do {
                                n = 10 * n + to_digit(ch);
                                n = 10 * n + to_digit(ch);
                                ch = *fmt++;
                                ch = *fmt++;
                        } while (is_digit(ch));
                        } while (is_digit(ch));
                        width = n;
                        width = n;
                        goto reswitch;
                        goto reswitch;
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
                case 'L':
                case 'L':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        flags |= LONGDBL;
                        flags |= LONGDBL;
                        goto rflag;
                        goto rflag;
#endif
#endif
                case 'h':
                case 'h':
                        if (flags & LONGINT)
                        if (flags & LONGINT)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
                        flags |= SHORTINT;
                        flags |= SHORTINT;
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          vec_print_count = 8;
                          vec_print_count = 8;
#endif
#endif
                        goto rflag;
                        goto rflag;
                case 'l':
                case 'l':
                        if (flags & SHORTINT)
                        if (flags & SHORTINT)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
                        if (*fmt == 'l') {
                        if (*fmt == 'l') {
                                fmt++;
                                fmt++;
                                flags |= QUADINT;
                                flags |= QUADINT;
                                flags &= ~VECTOR;
                                flags &= ~VECTOR;
                        } else {
                        } else {
                                flags |= LONGINT;
                                flags |= LONGINT;
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                                if (flags & VECTOR)
                                if (flags & VECTOR)
                                  vec_print_count = 4;
                                  vec_print_count = 4;
#endif
#endif
                        }
                        }
                        goto rflag;
                        goto rflag;
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                case 'v':
                case 'v':
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
                        flags |= VECTOR;
                        flags |= VECTOR;
                        vec_print_count = (flags & SHORTINT) ? 8 :
                        vec_print_count = (flags & SHORTINT) ? 8 :
                          ((flags & LONGINT) ? 4 : 16);
                          ((flags & LONGINT) ? 4 : 16);
                        goto rflag;
                        goto rflag;
#endif
#endif
                case 'q':
                case 'q':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        flags |= QUADINT;
                        flags |= QUADINT;
                        goto rflag;
                        goto rflag;
                case 'c':
                case 'c':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            int k;
                            int k;
                            vec_16_byte_union tmp;
                            vec_16_byte_union tmp;
                            if (flags & (SHORTINT | LONGINT))
                            if (flags & (SHORTINT | LONGINT))
                              {
                              {
                                fmt = format_anchor;
                                fmt = format_anchor;
                                continue;
                                continue;
                              }
                              }
                            tmp.v = va_arg(ap, vector int);
                            tmp.v = va_arg(ap, vector int);
                            cp = buf;
                            cp = buf;
                            for (k = 0; k < 15; ++k)
                            for (k = 0; k < 15; ++k)
                              {
                              {
                                *cp++ = tmp.c[k];
                                *cp++ = tmp.c[k];
                                if (vec_sep != ' ')
                                if (vec_sep != ' ')
                                  *cp++ = vec_sep;
                                  *cp++ = vec_sep;
                              }
                              }
                            *cp++ = tmp.c[15];
                            *cp++ = tmp.c[15];
                            size = cp - buf;
                            size = cp - buf;
                            cp = buf;
                            cp = buf;
                            vec_print_count = 0;
                            vec_print_count = 0;
                          }
                          }
                        else
                        else
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                          {
                          {
                            *(cp = buf) = va_arg(ap, int);
                            *(cp = buf) = va_arg(ap, int);
                            size = 1;
                            size = 1;
                          }
                          }
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                case 'D':
                case 'D':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'd':
                case 'd':
                case 'i':
                case 'i':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (!(flags & VECTOR) && vec_sep != ' ')
                        if (!(flags & VECTOR) && vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        _uquad = SARG();
                        _uquad = SARG();
                        if ((quad_t)_uquad < 0)
                        if ((quad_t)_uquad < 0)
                        {
                        {
                                _uquad = -(quad_t)_uquad;
                                _uquad = -(quad_t)_uquad;
                                old_sign = sign;
                                old_sign = sign;
                                sign = '-';
                                sign = '-';
                        }
                        }
                        base = DEC;
                        base = DEC;
                        goto number;
                        goto number;
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
                case 'e':
                case 'e':
                case 'E':
                case 'E':
                case 'f':
                case 'f':
                case 'g':
                case 'g':
                case 'G':
                case 'G':
                        if (prec == -1) {
                        if (prec == -1) {
                                prec = DEFPREC;
                                prec = DEFPREC;
                        } else if ((ch == 'g' || ch == 'G') && prec == 0) {
                        } else if ((ch == 'g' || ch == 'G') && prec == 0) {
                                prec = 1;
                                prec = 1;
                        }
                        }
 
 
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
                        if (flags & LONGDBL) {
                        if (flags & LONGDBL) {
                                _fpvalue = (double) va_arg(ap, _LONG_DOUBLE);
                                _fpvalue = (double) va_arg(ap, _LONG_DOUBLE);
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        } else if (flags & VECTOR) {
                        } else if (flags & VECTOR) {
                                if (vec_print_count >= 4)
                                if (vec_print_count >= 4)
                                  {
                                  {
                                    vec_print_count = 4;
                                    vec_print_count = 4;
                                    vec_tmp.v = va_arg(ap, vector int);
                                    vec_tmp.v = va_arg(ap, vector int);
                                  }
                                  }
                                _fpvalue = (double)vec_tmp.f[4 - vec_print_count];
                                _fpvalue = (double)vec_tmp.f[4 - vec_print_count];
                        } else if (vec_sep != ' ') {
                        } else if (vec_sep != ' ') {
                                 fmt = format_anchor;
                                 fmt = format_anchor;
                                 continue;
                                 continue;
 
 
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        } else {
                        } else {
                                _fpvalue = va_arg(ap, double);
                                _fpvalue = va_arg(ap, double);
                        }
                        }
 
 
                        /* do this before tricky precision changes */
                        /* do this before tricky precision changes */
                        if (isinf(_fpvalue)) {
                        if (isinf(_fpvalue)) {
                                if (_fpvalue < 0)
                                if (_fpvalue < 0)
                                  {
                                  {
                                    old_sign = sign;
                                    old_sign = sign;
                                    sign = '-';
                                    sign = '-';
                                  }
                                  }
 
 
                                cp = "Inf";
                                cp = "Inf";
                                size = 3;
                                size = 3;
                                break;
                                break;
                        }
                        }
                        if (isnan(_fpvalue)) {
                        if (isnan(_fpvalue)) {
                                cp = "NaN";
                                cp = "NaN";
                                size = 3;
                                size = 3;
                                break;
                                break;
                        }
                        }
 
 
#else /* !_NO_LONGDBL */
#else /* !_NO_LONGDBL */
 
 
                        if (flags & LONGDBL) {
                        if (flags & LONGDBL) {
                                _fpvalue = va_arg(ap, _LONG_DOUBLE);
                                _fpvalue = va_arg(ap, _LONG_DOUBLE);
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        } else if (flags & VECTOR) {
                        } else if (flags & VECTOR) {
                                if (vec_print_count >= 4)
                                if (vec_print_count >= 4)
                                  {
                                  {
                                    vec_print_count = 4;
                                    vec_print_count = 4;
                                    vec_tmp.v = va_arg(ap, vector int);
                                    vec_tmp.v = va_arg(ap, vector int);
                                  }
                                  }
                                _fpvalue = (_LONG_DOUBLE)k.f[4 - vec_print_count];
                                _fpvalue = (_LONG_DOUBLE)k.f[4 - vec_print_count];
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        } else {
                        } else {
                                _fpvalue = (_LONG_DOUBLE)va_arg(ap, double);
                                _fpvalue = (_LONG_DOUBLE)va_arg(ap, double);
                        }
                        }
 
 
                        /* do this before tricky precision changes */
                        /* do this before tricky precision changes */
                        tmp = _ldcheck (&_fpvalue);
                        tmp = _ldcheck (&_fpvalue);
                        if (tmp == 2) {
                        if (tmp == 2) {
                                if (_fpvalue < 0)
                                if (_fpvalue < 0)
                                  {
                                  {
                                    old_sign = sign;
                                    old_sign = sign;
                                    sign = '-';
                                    sign = '-';
                                  }
                                  }
                                cp = "Inf";
                                cp = "Inf";
                                size = 3;
                                size = 3;
                                break;
                                break;
                        }
                        }
                        if (tmp == 1) {
                        if (tmp == 1) {
                                cp = "NaN";
                                cp = "NaN";
                                size = 3;
                                size = 3;
                                break;
                                break;
                        }
                        }
#endif /* !_NO_LONGDBL */
#endif /* !_NO_LONGDBL */
 
 
                        flags |= FPT;
                        flags |= FPT;
 
 
                        cp = cvt(data, _fpvalue, prec, flags, &softsign,
                        cp = cvt(data, _fpvalue, prec, flags, &softsign,
                                &expt, ch, &ndig);
                                &expt, ch, &ndig);
 
 
                        if (ch == 'g' || ch == 'G') {
                        if (ch == 'g' || ch == 'G') {
                                if (expt <= -4 || expt > prec)
                                if (expt <= -4 || expt > prec)
                                  {
                                  {
                                    old_ch = ch;
                                    old_ch = ch;
                                    ch = (ch == 'g') ? 'e' : 'E';
                                    ch = (ch == 'g') ? 'e' : 'E';
                                  }
                                  }
                                else
                                else
                                        ch = 'g';
                                        ch = 'g';
                        }
                        }
                        if (ch <= 'e') {        /* 'e' or 'E' fmt */
                        if (ch <= 'e') {        /* 'e' or 'E' fmt */
                                --expt;
                                --expt;
                                expsize = exponent(expstr, expt, ch);
                                expsize = exponent(expstr, expt, ch);
                                size = expsize + ndig;
                                size = expsize + ndig;
                                if (ndig > 1 || flags & ALT)
                                if (ndig > 1 || flags & ALT)
                                        ++size;
                                        ++size;
                        } else if (ch == 'f') {         /* f fmt */
                        } else if (ch == 'f') {         /* f fmt */
                                if (expt > 0) {
                                if (expt > 0) {
                                        size = expt;
                                        size = expt;
                                        if (prec || flags & ALT)
                                        if (prec || flags & ALT)
                                                size += prec + 1;
                                                size += prec + 1;
                                } else  /* "0.X" */
                                } else  /* "0.X" */
                                        size = (prec || flags & ALT)
                                        size = (prec || flags & ALT)
                                                  ? prec + 2
                                                  ? prec + 2
                                                  : 1;
                                                  : 1;
                        } else if (expt >= ndig) {      /* fixed g fmt */
                        } else if (expt >= ndig) {      /* fixed g fmt */
                                size = expt;
                                size = expt;
                                if (flags & ALT)
                                if (flags & ALT)
                                        ++size;
                                        ++size;
                        } else
                        } else
                                size = ndig + (expt > 0 ?
                                size = ndig + (expt > 0 ?
                                        1 : 2 - expt);
                                        1 : 2 - expt);
 
 
                        if (softsign)
                        if (softsign)
                          {
                          {
                            old_sign = sign;
                            old_sign = sign;
                            sign = '-';
                            sign = '-';
                          }
                          }
                        break;
                        break;
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
#ifdef __SPE__
#ifdef __SPE__
                case 'r':
                case 'r':
                        flags |= FIXEDPOINT;
                        flags |= FIXEDPOINT;
                        _uquad = SFPARG();
                        _uquad = SFPARG();
                        if ((quad_t)_uquad < 0)
                        if ((quad_t)_uquad < 0)
                          {
                          {
                            sign = '-';
                            sign = '-';
                            _uquad = -(quad_t)_uquad;
                            _uquad = -(quad_t)_uquad;
                          }
                          }
                        if (flags & SHORTINT)
                        if (flags & SHORTINT)
                          _uquad <<= (sizeof(quad_t) - sizeof(short)) * 8 + 1;
                          _uquad <<= (sizeof(quad_t) - sizeof(short)) * 8 + 1;
                        else if (flags & LONGINT)
                        else if (flags & LONGINT)
                          _uquad <<= 1;
                          _uquad <<= 1;
                        else
                        else
                          _uquad <<= (sizeof(quad_t) - sizeof(long)) * 8 + 1;
                          _uquad <<= (sizeof(quad_t) - sizeof(long)) * 8 + 1;
 
 
                        if (_uquad == 0 && sign)
                        if (_uquad == 0 && sign)
                          {
                          {
                            /* we have -1.0 which has to be handled special */
                            /* we have -1.0 which has to be handled special */
                            cp = "100000";
                            cp = "100000";
                            expt = 1;
                            expt = 1;
                            ndig = 6;
                            ndig = 6;
                            break;
                            break;
                          }
                          }
 
 
                        goto fixed_nosign;
                        goto fixed_nosign;
                case 'R':
                case 'R':
                        flags |= FIXEDPOINT;
                        flags |= FIXEDPOINT;
                        _uquad = UFPARG();
                        _uquad = UFPARG();
                        if (flags & SHORTINT)
                        if (flags & SHORTINT)
                          _uquad <<= (sizeof(quad_t) - sizeof(short)) * 8;
                          _uquad <<= (sizeof(quad_t) - sizeof(short)) * 8;
                        else if (!(flags & LONGINT))
                        else if (!(flags & LONGINT))
                          _uquad <<= (sizeof(quad_t) - sizeof(long)) * 8;
                          _uquad <<= (sizeof(quad_t) - sizeof(long)) * 8;
 
 
fixed_nosign:
fixed_nosign:
                        if (prec == -1)
                        if (prec == -1)
                          prec = DEFPREC;
                          prec = DEFPREC;
 
 
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
                        cp = cvt_ufix64 (data, _uquad, prec, &expt, &ndig);
                        cp = cvt_ufix64 (data, _uquad, prec, &expt, &ndig);
#else
#else
                        cp = cvs_ufix32 (data, _uquad, prec, &expt, &ndig);
                        cp = cvs_ufix32 (data, _uquad, prec, &expt, &ndig);
#endif
#endif
 
 
                        /* act like %f of format "0.X" */
                        /* act like %f of format "0.X" */
                        size = prec + 2;
                        size = prec + 2;
 
 
                        break;
                        break;
#endif /* __SPE__ */
#endif /* __SPE__ */
                case 'n':
                case 'n':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
                        if (flags & QUADINT)
                        if (flags & QUADINT)
                                *va_arg(ap, quad_t *) = ret;
                                *va_arg(ap, quad_t *) = ret;
                        else
                        else
#endif
#endif
                        if (flags & LONGINT)
                        if (flags & LONGINT)
                                *va_arg(ap, long *) = ret;
                                *va_arg(ap, long *) = ret;
                        else if (flags & SHORTINT)
                        else if (flags & SHORTINT)
                                *va_arg(ap, short *) = ret;
                                *va_arg(ap, short *) = ret;
                        else
                        else
                                *va_arg(ap, int *) = ret;
                                *va_arg(ap, int *) = ret;
                        continue;       /* no output */
                        continue;       /* no output */
                case 'O':
                case 'O':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'o':
                case 'o':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (!(flags & VECTOR) && vec_sep != ' ')
                        if (!(flags & VECTOR) && vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        _uquad = UARG();
                        _uquad = UARG();
                        base = OCT;
                        base = OCT;
                        goto nosign;
                        goto nosign;
                case 'p':
                case 'p':
                        /*
                        /*
                         * ``The argument shall be a pointer to void.  The
                         * ``The argument shall be a pointer to void.  The
                         * value of the pointer is converted to a sequence
                         * value of the pointer is converted to a sequence
                         * of printable characters, in an implementation-
                         * of printable characters, in an implementation-
                         * defined manner.''
                         * defined manner.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        /* NOSTRICT */
                        /* NOSTRICT */
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          _uquad = UARG();
                          _uquad = UARG();
                        else if (vec_sep != ' ')
                        else if (vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
                        else
                        else
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                          _uquad = (u_long)(unsigned _POINTER_INT)va_arg(ap, void *);
                          _uquad = (u_long)(unsigned _POINTER_INT)va_arg(ap, void *);
                        base = HEX;
                        base = HEX;
                        xdigs = "0123456789abcdef";
                        xdigs = "0123456789abcdef";
                        flags |= HEXPREFIX;
                        flags |= HEXPREFIX;
                        ch = 'x';
                        ch = 'x';
                        goto nosign;
                        goto nosign;
                case 's':
                case 's':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (flags & VECTOR)
                        if (flags & VECTOR)
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        if ((cp = va_arg(ap, char *)) == NULL)
                        if ((cp = va_arg(ap, char *)) == NULL)
                                cp = "(null)";
                                cp = "(null)";
                        if (prec >= 0) {
                        if (prec >= 0) {
                                /*
                                /*
                                 * can't use strlen; can only look for the
                                 * can't use strlen; can only look for the
                                 * NUL in the first `prec' characters, and
                                 * NUL in the first `prec' characters, and
                                 * strlen() will go further.
                                 * strlen() will go further.
                                 */
                                 */
                                char *p = memchr(cp, 0, prec);
                                char *p = memchr(cp, 0, prec);
 
 
                                if (p != NULL) {
                                if (p != NULL) {
                                        size = p - cp;
                                        size = p - cp;
                                        if (size > prec)
                                        if (size > prec)
                                                size = prec;
                                                size = prec;
                                } else
                                } else
                                        size = prec;
                                        size = prec;
                        } else
                        } else
                                size = strlen(cp);
                                size = strlen(cp);
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                case 'U':
                case 'U':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'u':
                case 'u':
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (!(flags & VECTOR) && vec_sep != ' ')
                        if (!(flags & VECTOR) && vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                        _uquad = UARG();
                        _uquad = UARG();
                        base = DEC;
                        base = DEC;
                        goto nosign;
                        goto nosign;
                case 'X':
                case 'X':
                        xdigs = "0123456789ABCDEF";
                        xdigs = "0123456789ABCDEF";
                        goto hex;
                        goto hex;
                case 'x':
                case 'x':
                        xdigs = "0123456789abcdef";
                        xdigs = "0123456789abcdef";
#ifdef __ALTIVEC__
#ifdef __ALTIVEC__
                        if (!(flags & VECTOR) && vec_sep != ' ')
                        if (!(flags & VECTOR) && vec_sep != ' ')
                          {
                          {
                            fmt = format_anchor;
                            fmt = format_anchor;
                            continue;
                            continue;
                          }
                          }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
hex:                    _uquad = UARG();
hex:                    _uquad = UARG();
                        base = HEX;
                        base = HEX;
                        /* leading 0x/X only if non-zero */
                        /* leading 0x/X only if non-zero */
                        if (flags & ALT && _uquad != 0)
                        if (flags & ALT && _uquad != 0)
                                flags |= HEXPREFIX;
                                flags |= HEXPREFIX;
 
 
                        /* unsigned conversions */
                        /* unsigned conversions */
nosign:                 sign = '\0';
nosign:                 sign = '\0';
                        /*
                        /*
                         * ``... diouXx conversions ... if a precision is
                         * ``... diouXx conversions ... if a precision is
                         * specified, the 0 flag will be ignored.''
                         * specified, the 0 flag will be ignored.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
number:                 if ((dprec = prec) >= 0)
number:                 if ((dprec = prec) >= 0)
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
 
 
                        /*
                        /*
                         * ``The result of converting a zero value with an
                         * ``The result of converting a zero value with an
                         * explicit precision of zero is no characters.''
                         * explicit precision of zero is no characters.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        cp = buf + BUF;
                        cp = buf + BUF;
                        if (_uquad != 0 || prec != 0) {
                        if (_uquad != 0 || prec != 0) {
                                /*
                                /*
                                 * Unsigned mod is hard, and unsigned mod
                                 * Unsigned mod is hard, and unsigned mod
                                 * by a constant is easier than that by
                                 * by a constant is easier than that by
                                 * a variable; hence this switch.
                                 * a variable; hence this switch.
                                 */
                                 */
                                switch (base) {
                                switch (base) {
                                case OCT:
                                case OCT:
                                        do {
                                        do {
                                                *--cp = to_char(_uquad & 7);
                                                *--cp = to_char(_uquad & 7);
                                                _uquad >>= 3;
                                                _uquad >>= 3;
                                        } while (_uquad);
                                        } while (_uquad);
                                        /* handle octal leading 0 */
                                        /* handle octal leading 0 */
                                        if (flags & ALT && *cp != '0')
                                        if (flags & ALT && *cp != '0')
                                                *--cp = '0';
                                                *--cp = '0';
                                        break;
                                        break;
 
 
                                case DEC:
                                case DEC:
                                        /* many numbers are 1 digit */
                                        /* many numbers are 1 digit */
                                        while (_uquad >= 10) {
                                        while (_uquad >= 10) {
                                                *--cp = to_char(_uquad % 10);
                                                *--cp = to_char(_uquad % 10);
                                                _uquad /= 10;
                                                _uquad /= 10;
                                        }
                                        }
                                        *--cp = to_char(_uquad);
                                        *--cp = to_char(_uquad);
                                        break;
                                        break;
 
 
                                case HEX:
                                case HEX:
                                        do {
                                        do {
                                                *--cp = xdigs[_uquad & 15];
                                                *--cp = xdigs[_uquad & 15];
                                                _uquad >>= 4;
                                                _uquad >>= 4;
                                        } while (_uquad);
                                        } while (_uquad);
                                        break;
                                        break;
 
 
                                default:
                                default:
                                        cp = "bug in vfprintf: bad base";
                                        cp = "bug in vfprintf: bad base";
                                        size = strlen(cp);
                                        size = strlen(cp);
                                        goto skipsize;
                                        goto skipsize;
                                }
                                }
                        }
                        }
                       /*
                       /*
                        * ...result is to be converted to an 'alternate form'.
                        * ...result is to be converted to an 'alternate form'.
                        * For o conversion, it increases the precision to force
                        * For o conversion, it increases the precision to force
                        * the first digit of the result to be a zero."
                        * the first digit of the result to be a zero."
                        *     -- ANSI X3J11
                        *     -- ANSI X3J11
                        *
                        *
                        * To demonstrate this case, compile and run:
                        * To demonstrate this case, compile and run:
                        *    printf ("%#.0o",0);
                        *    printf ("%#.0o",0);
                        */
                        */
                       else if (base == OCT && (flags & ALT))
                       else if (base == OCT && (flags & ALT))
                         *--cp = '0';
                         *--cp = '0';
 
 
                        size = buf + BUF - cp;
                        size = buf + BUF - cp;
                skipsize:
                skipsize:
                        break;
                        break;
                default:        /* "%?" prints ?, unless ? is NUL */
                default:        /* "%?" prints ?, unless ? is NUL */
                        flags &= ~VECTOR;
                        flags &= ~VECTOR;
                        if (ch == '\0')
                        if (ch == '\0')
                                goto done;
                                goto done;
                        /* pretend it was %c with argument ch */
                        /* pretend it was %c with argument ch */
                        cp = buf;
                        cp = buf;
                        *cp = ch;
                        *cp = ch;
                        size = 1;
                        size = 1;
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                }
                }
 
 
                /*
                /*
                 * All reasonable formats wind up here.  At this point, `cp'
                 * All reasonable formats wind up here.  At this point, `cp'
                 * points to a string which (if not flags&LADJUST) should be
                 * points to a string which (if not flags&LADJUST) should be
                 * padded out to `width' places.  If flags&ZEROPAD, it should
                 * padded out to `width' places.  If flags&ZEROPAD, it should
                 * first be prefixed by any sign or other prefix; otherwise,
                 * first be prefixed by any sign or other prefix; otherwise,
                 * it should be blank padded before the prefix is emitted.
                 * it should be blank padded before the prefix is emitted.
                 * After any left-hand padding and prefixing, emit zeroes
                 * After any left-hand padding and prefixing, emit zeroes
                 * required by a decimal [diouxX] precision, then print the
                 * required by a decimal [diouxX] precision, then print the
                 * string proper, then emit zeroes required by any leftover
                 * string proper, then emit zeroes required by any leftover
                 * floating precision; finally, if LADJUST, pad with blanks.
                 * floating precision; finally, if LADJUST, pad with blanks.
                 *
                 *
                 * Compute actual size, so we know how much to pad.
                 * Compute actual size, so we know how much to pad.
                 * size excludes decimal prec; realsz includes it.
                 * size excludes decimal prec; realsz includes it.
                 */
                 */
                realsz = dprec > size ? dprec : size;
                realsz = dprec > size ? dprec : size;
                if (sign)
                if (sign)
                        realsz++;
                        realsz++;
                else if (flags & HEXPREFIX)
                else if (flags & HEXPREFIX)
                        realsz+= 2;
                        realsz+= 2;
 
 
                /* right-adjusting blank padding */
                /* right-adjusting blank padding */
                if ((flags & (LADJUST|ZEROPAD)) == 0)
                if ((flags & (LADJUST|ZEROPAD)) == 0)
                        PAD(width - realsz, blanks);
                        PAD(width - realsz, blanks);
 
 
                /* prefix */
                /* prefix */
                if (sign) {
                if (sign) {
                        PRINT(&sign, 1);
                        PRINT(&sign, 1);
                } else if (flags & HEXPREFIX) {
                } else if (flags & HEXPREFIX) {
                        ox[0] = '0';
                        ox[0] = '0';
                        ox[1] = ch;
                        ox[1] = ch;
                        PRINT(ox, 2);
                        PRINT(ox, 2);
                }
                }
 
 
                /* right-adjusting zero padding */
                /* right-adjusting zero padding */
                if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
                if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
                        PAD(width - realsz, zeroes);
                        PAD(width - realsz, zeroes);
 
 
                /* leading zeroes from decimal precision */
                /* leading zeroes from decimal precision */
                PAD(dprec - size, zeroes);
                PAD(dprec - size, zeroes);
 
 
                /* the string or number proper */
                /* the string or number proper */
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
                if ((flags & FPT) == 0) {
                if ((flags & FPT) == 0) {
#ifdef __SPE__
#ifdef __SPE__
                        if (flags & FIXEDPOINT) {
                        if (flags & FIXEDPOINT) {
                                if (_uquad == 0 && !sign) {
                                if (_uquad == 0 && !sign) {
                                        /* kludge for __dtoa irregularity */
                                        /* kludge for __dtoa irregularity */
                                        PRINT("0", 1);
                                        PRINT("0", 1);
                                        if (expt < ndig || (flags & ALT) != 0) {
                                        if (expt < ndig || (flags & ALT) != 0) {
                                                PRINT(decimal_point, 1);
                                                PRINT(decimal_point, 1);
                                                PAD(ndig - 1, zeroes);
                                                PAD(ndig - 1, zeroes);
                                        }
                                        }
                                } else if (expt <= 0) {
                                } else if (expt <= 0) {
                                        PRINT("0", 1);
                                        PRINT("0", 1);
                                        if(expt || ndig) {
                                        if(expt || ndig) {
                                                PRINT(decimal_point, 1);
                                                PRINT(decimal_point, 1);
                                                PAD(-expt, zeroes);
                                                PAD(-expt, zeroes);
                                                PRINT(cp, ndig);
                                                PRINT(cp, ndig);
                                        }
                                        }
                                } else if (expt >= ndig) {
                                } else if (expt >= ndig) {
                                        PRINT(cp, ndig);
                                        PRINT(cp, ndig);
                                        PAD(expt - ndig, zeroes);
                                        PAD(expt - ndig, zeroes);
                                        if (flags & ALT)
                                        if (flags & ALT)
                                                PRINT(".", 1);
                                                PRINT(".", 1);
                                } else {
                                } else {
                                        PRINT(cp, expt);
                                        PRINT(cp, expt);
                                        cp += expt;
                                        cp += expt;
                                        PRINT(".", 1);
                                        PRINT(".", 1);
                                        PRINT(cp, ndig-expt);
                                        PRINT(cp, ndig-expt);
                                }
                                }
                        } else
                        } else
#endif /* __SPE__ */
#endif /* __SPE__ */
                                PRINT(cp, size);
                                PRINT(cp, size);
                } else {        /* glue together f_p fragments */
                } else {        /* glue together f_p fragments */
                        if (ch >= 'f') {        /* 'f' or 'g' */
                        if (ch >= 'f') {        /* 'f' or 'g' */
                                if (_fpvalue == 0) {
                                if (_fpvalue == 0) {
                                        /* kludge for __dtoa irregularity */
                                        /* kludge for __dtoa irregularity */
                                        PRINT("0", 1);
                                        PRINT("0", 1);
                                        if (expt < ndig || (flags & ALT) != 0) {
                                        if (expt < ndig || (flags & ALT) != 0) {
                                                PRINT(decimal_point, 1);
                                                PRINT(decimal_point, 1);
                                                PAD(ndig - 1, zeroes);
                                                PAD(ndig - 1, zeroes);
                                        }
                                        }
                                } else if (expt <= 0) {
                                } else if (expt <= 0) {
                                        PRINT("0", 1);
                                        PRINT("0", 1);
                                        if(expt || ndig) {
                                        if(expt || ndig) {
                                                PRINT(decimal_point, 1);
                                                PRINT(decimal_point, 1);
                                                PAD(-expt, zeroes);
                                                PAD(-expt, zeroes);
                                                PRINT(cp, ndig);
                                                PRINT(cp, ndig);
                                        }
                                        }
                                } else if (expt >= ndig) {
                                } else if (expt >= ndig) {
                                        PRINT(cp, ndig);
                                        PRINT(cp, ndig);
                                        PAD(expt - ndig, zeroes);
                                        PAD(expt - ndig, zeroes);
                                        if (flags & ALT)
                                        if (flags & ALT)
                                                PRINT(".", 1);
                                                PRINT(".", 1);
                                } else {
                                } else {
                                        PRINT(cp, expt);
                                        PRINT(cp, expt);
                                        cp += expt;
                                        cp += expt;
                                        PRINT(".", 1);
                                        PRINT(".", 1);
                                        PRINT(cp, ndig-expt);
                                        PRINT(cp, ndig-expt);
                                }
                                }
                        } else {        /* 'e' or 'E' */
                        } else {        /* 'e' or 'E' */
                                if (ndig > 1 || flags & ALT) {
                                if (ndig > 1 || flags & ALT) {
                                        ox[0] = *cp++;
                                        ox[0] = *cp++;
                                        ox[1] = '.';
                                        ox[1] = '.';
                                        PRINT(ox, 2);
                                        PRINT(ox, 2);
                                       if (_fpvalue) {
                                       if (_fpvalue) {
                                                PRINT(cp, ndig-1);
                                                PRINT(cp, ndig-1);
                                        } else  /* 0.[0..] */
                                        } else  /* 0.[0..] */
                                                /* __dtoa irregularity */
                                                /* __dtoa irregularity */
                                                PAD(ndig - 1, zeroes);
                                                PAD(ndig - 1, zeroes);
                                } else  /* XeYYY */
                                } else  /* XeYYY */
                                        PRINT(cp, 1);
                                        PRINT(cp, 1);
                                PRINT(expstr, expsize);
                                PRINT(expstr, expsize);
                        }
                        }
                }
                }
#else
#else
                PRINT(cp, size);
                PRINT(cp, size);
#endif
#endif
                /* left-adjusting padding (always blank) */
                /* left-adjusting padding (always blank) */
                if (flags & LADJUST)
                if (flags & LADJUST)
                        PAD(width - realsz, blanks);
                        PAD(width - realsz, blanks);
 
 
                /* finally, adjust ret */
                /* finally, adjust ret */
                ret += width > realsz ? width : realsz;
                ret += width > realsz ? width : realsz;
 
 
#ifdef __ALTIVEC__              
#ifdef __ALTIVEC__              
                if ((flags & VECTOR) && vec_print_count-- > 1)
                if ((flags & VECTOR) && vec_print_count-- > 1)
                  {
                  {
                    /* add vector separator */
                    /* add vector separator */
                    if (ch != 'c' || vec_sep != ' ')
                    if (ch != 'c' || vec_sep != ' ')
                      {
                      {
                        PRINT(&vec_sep, 1);
                        PRINT(&vec_sep, 1);
                        ret += 1;
                        ret += 1;
                      }
                      }
                    FLUSH();
                    FLUSH();
                    sign = old_sign;
                    sign = old_sign;
                    ch = old_ch;
                    ch = old_ch;
                    goto reswitch;
                    goto reswitch;
                  }
                  }
#endif /* __ALTIVEC__ */
#endif /* __ALTIVEC__ */
                FLUSH();        /* copy out the I/O vectors */
                FLUSH();        /* copy out the I/O vectors */
        }
        }
done:
done:
        FLUSH();
        FLUSH();
error:
error:
        return (__sferror(fp) ? EOF : ret);
        return (__sferror(fp) ? EOF : ret);
        /* NOTREACHED */
        /* NOTREACHED */
}
}
 
 
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
 
 
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
                              int, int *, int *, char **));
                              int, int *, int *, char **));
#else
#else
extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
                              int, int *, int *, char **));
                              int, int *, int *, char **));
#undef word0
#undef word0
#define word0(x) ldword0(x)
#define word0(x) ldword0(x)
#endif
#endif
 
 
static char *
static char *
cvt(data, value, ndigits, flags, sign, decpt, ch, length)
cvt(data, value, ndigits, flags, sign, decpt, ch, length)
        struct _reent *data;
        struct _reent *data;
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
        double value;
        double value;
#else
#else
        _LONG_DOUBLE value;
        _LONG_DOUBLE value;
#endif
#endif
        int ndigits, flags, *decpt, ch, *length;
        int ndigits, flags, *decpt, ch, *length;
        char *sign;
        char *sign;
{
{
        int mode, dsgn;
        int mode, dsgn;
        char *digits, *bp, *rve;
        char *digits, *bp, *rve;
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
        union double_union tmp;
        union double_union tmp;
#else
#else
        struct ldieee *ldptr;
        struct ldieee *ldptr;
#endif
#endif
 
 
        if (ch == 'f') {
        if (ch == 'f') {
                mode = 3;               /* ndigits after the decimal point */
                mode = 3;               /* ndigits after the decimal point */
        } else {
        } else {
                /* To obtain ndigits after the decimal point for the 'e'
                /* To obtain ndigits after the decimal point for the 'e'
                 * and 'E' formats, round to ndigits + 1 significant
                 * and 'E' formats, round to ndigits + 1 significant
                 * figures.
                 * figures.
                 */
                 */
                if (ch == 'e' || ch == 'E') {
                if (ch == 'e' || ch == 'E') {
                        ndigits++;
                        ndigits++;
                }
                }
                mode = 2;               /* ndigits significant digits */
                mode = 2;               /* ndigits significant digits */
        }
        }
 
 
#ifdef _NO_LONGDBL
#ifdef _NO_LONGDBL
        tmp.d = value;
        tmp.d = value;
 
 
        if (word0(tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
        if (word0(tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
                value = -value;
                value = -value;
                *sign = '-';
                *sign = '-';
        } else
        } else
                *sign = '\000';
                *sign = '\000';
 
 
        digits = _dtoa_r(data, value, mode, ndigits, decpt, &dsgn, &rve);
        digits = _dtoa_r(data, value, mode, ndigits, decpt, &dsgn, &rve);
#else /* !_NO_LONGDBL */
#else /* !_NO_LONGDBL */
        ldptr = (struct ldieee *)&value;
        ldptr = (struct ldieee *)&value;
        if (ldptr->sign) { /* this will check for < 0 and -0.0 */
        if (ldptr->sign) { /* this will check for < 0 and -0.0 */
                value = -value;
                value = -value;
                *sign = '-';
                *sign = '-';
        } else
        } else
                *sign = '\000';
                *sign = '\000';
 
 
        digits = _ldtoa_r(data, value, mode, ndigits, decpt, &dsgn, &rve);
        digits = _ldtoa_r(data, value, mode, ndigits, decpt, &dsgn, &rve);
#endif /* !_NO_LONGDBL */
#endif /* !_NO_LONGDBL */
 
 
        if ((ch != 'g' && ch != 'G') || flags & ALT) {  /* Print trailing zeros */
        if ((ch != 'g' && ch != 'G') || flags & ALT) {  /* Print trailing zeros */
                bp = digits + ndigits;
                bp = digits + ndigits;
                if (ch == 'f') {
                if (ch == 'f') {
                        if (*digits == '0' && value)
                        if (*digits == '0' && value)
                                *decpt = -ndigits + 1;
                                *decpt = -ndigits + 1;
                        bp += *decpt;
                        bp += *decpt;
                }
                }
                if (value == 0)  /* kludge for __dtoa irregularity */
                if (value == 0)  /* kludge for __dtoa irregularity */
                        rve = bp;
                        rve = bp;
                while (rve < bp)
                while (rve < bp)
                        *rve++ = '0';
                        *rve++ = '0';
        }
        }
        *length = rve - digits;
        *length = rve - digits;
        return (digits);
        return (digits);
}
}
 
 
static int
static int
exponent(p0, exp, fmtch)
exponent(p0, exp, fmtch)
        char *p0;
        char *p0;
        int exp, fmtch;
        int exp, fmtch;
{
{
        register char *p, *t;
        register char *p, *t;
        char expbuf[40];
        char expbuf[40];
 
 
        p = p0;
        p = p0;
        *p++ = fmtch;
        *p++ = fmtch;
        if (exp < 0) {
        if (exp < 0) {
                exp = -exp;
                exp = -exp;
                *p++ = '-';
                *p++ = '-';
        }
        }
        else
        else
                *p++ = '+';
                *p++ = '+';
        t = expbuf + 40;
        t = expbuf + 40;
        if (exp > 9) {
        if (exp > 9) {
                do {
                do {
                        *--t = to_char(exp % 10);
                        *--t = to_char(exp % 10);
                } while ((exp /= 10) > 9);
                } while ((exp /= 10) > 9);
                *--t = to_char(exp);
                *--t = to_char(exp);
                for (; t < expbuf + 40; *p++ = *t++);
                for (; t < expbuf + 40; *p++ = *t++);
        }
        }
        else {
        else {
                *p++ = '0';
                *p++ = '0';
                *p++ = to_char(exp);
                *p++ = to_char(exp);
        }
        }
        return (p - p0);
        return (p - p0);
}
}
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
 
 
#ifdef __SPE__
#ifdef __SPE__
extern char *_ufix64toa_r _PARAMS((struct _reent *, unsigned long long, int,
extern char *_ufix64toa_r _PARAMS((struct _reent *, unsigned long long, int,
                                   int, int *, int *, char **));
                                   int, int *, int *, char **));
static char *
static char *
cvt_ufix64 (data, value, ndigits, decpt, length)
cvt_ufix64 (data, value, ndigits, decpt, length)
        struct _reent *data;
        struct _reent *data;
        unsigned long long value;
        unsigned long long value;
        int ndigits, *decpt, *length;
        int ndigits, *decpt, *length;
{
{
        int dsgn;
        int dsgn;
        char *digits, *bp, *rve;
        char *digits, *bp, *rve;
 
 
        /* treat the same as %f format and use mode=3 */
        /* treat the same as %f format and use mode=3 */
        digits = _ufix64toa_r (data, value, 3, ndigits, decpt, &dsgn, &rve);
        digits = _ufix64toa_r (data, value, 3, ndigits, decpt, &dsgn, &rve);
 
 
        /* print trailing zeroes */
        /* print trailing zeroes */
        bp = digits + ndigits;
        bp = digits + ndigits;
        if (*digits == '0' && value)
        if (*digits == '0' && value)
          *decpt = -ndigits + 1;
          *decpt = -ndigits + 1;
        bp += *decpt;
        bp += *decpt;
        if (value == 0)  /* kludge for __dtoa irregularity */
        if (value == 0)  /* kludge for __dtoa irregularity */
          rve = bp;
          rve = bp;
        while (rve < bp)
        while (rve < bp)
          *rve++ = '0';
          *rve++ = '0';
        *length = rve - digits;
        *length = rve - digits;
        return (digits);
        return (digits);
}
}
#endif /* __SPE__ */
#endif /* __SPE__ */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.