reversed back to 2.2.5
enabled printf_fp git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11655 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
SubDir OBOS_TOP src kernel libroot posix glibc stdio-common ;
|
||||
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include arch $(OBOS_ARCH) ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc stdio-common ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include ;
|
||||
SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;
|
||||
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include arch $(OBOS_ARCH) ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc stdio-common ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc locale ;
|
||||
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc ;
|
||||
|
||||
@@ -11,7 +13,7 @@ SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc ;
|
||||
|
||||
KernelMergeObject posix_gnu_stdio.o : #_common.o :
|
||||
<$(SOURCE_GRIST)>_itoa.c
|
||||
# <$(SOURCE_GRIST)>_itowa.c
|
||||
<$(SOURCE_GRIST)>_itowa.c
|
||||
<$(SOURCE_GRIST)>asprintf.c
|
||||
<$(SOURCE_GRIST)>dprintf.c
|
||||
<$(SOURCE_GRIST)>fprintf.c
|
||||
@@ -20,11 +22,12 @@ KernelMergeObject posix_gnu_stdio.o : #_common.o :
|
||||
<$(SOURCE_GRIST)>getw.c
|
||||
<$(SOURCE_GRIST)>itoa-digits.c
|
||||
<$(SOURCE_GRIST)>itoa-udigits.c
|
||||
# <$(SOURCE_GRIST)>itowa-digits.c
|
||||
<$(SOURCE_GRIST)>itowa-digits.c
|
||||
<$(SOURCE_GRIST)>perror.c
|
||||
<$(SOURCE_GRIST)>printf-parse.c
|
||||
<$(SOURCE_GRIST)>printf-prs.c
|
||||
<$(SOURCE_GRIST)>printf.c
|
||||
<$(SOURCE_GRIST)>printf_fp.c
|
||||
<$(SOURCE_GRIST)>printf_fphex.c
|
||||
# <$(SOURCE_GRIST)>printf_size.c
|
||||
<$(SOURCE_GRIST)>putw.c
|
||||
<$(SOURCE_GRIST)>reg-printf.c
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Internal header for parsing printf format strings.
|
||||
Copyright (C) 1995-1999, 2000, 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of th GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@@ -87,27 +87,28 @@ read_int (const UCHAR_T * *pstr)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Find the next spec in FORMAT, or the end of the string. Returns
|
||||
a pointer into FORMAT, to a '%' or a '\0'. */
|
||||
static inline const UCHAR_T *
|
||||
//#ifdef COMPILE_WPRINTF
|
||||
#ifdef COMPILE_WPRINTF
|
||||
find_spec (const UCHAR_T *format)
|
||||
//#else
|
||||
//find_spec (const UCHAR_T *format, mbstate_t *ps)
|
||||
//#endif
|
||||
#else
|
||||
find_spec (const UCHAR_T *format, mbstate_t *ps)
|
||||
#endif
|
||||
{
|
||||
#ifdef COMPILE_WPRINTF
|
||||
return (const UCHAR_T *) __wcschrnul ((const CHAR_T *) format, L'%');
|
||||
#else
|
||||
while (*format != L_('\0') && *format != L_('%'))
|
||||
{
|
||||
// int len;
|
||||
int len;
|
||||
|
||||
/* Remove any hints of a wrong encoding. */
|
||||
// ps->__count = 0;
|
||||
// if (! isascii (*format) && (len = __mbrlen (format, MB_CUR_MAX, ps)) > 0)
|
||||
// format += len;
|
||||
// else
|
||||
ps->__count = 0;
|
||||
if (! isascii (*format) && (len = __mbrlen (format, MB_CUR_MAX, ps)) > 0)
|
||||
format += len;
|
||||
else
|
||||
++format;
|
||||
}
|
||||
return format;
|
||||
@@ -116,8 +117,8 @@ find_spec (const UCHAR_T *format)
|
||||
|
||||
|
||||
/* These are defined in reg-printf.c. */
|
||||
extern printf_arginfo_function **__printf_arginfo_table attribute_hidden;
|
||||
extern printf_function **__printf_function_table attribute_hidden;
|
||||
extern printf_arginfo_function *__printf_arginfo_table[];
|
||||
extern printf_function **__printf_function_table;
|
||||
|
||||
|
||||
/* FORMAT must point to a '%' at the beginning of a spec. Fills in *SPEC
|
||||
@@ -126,13 +127,13 @@ extern printf_function **__printf_function_table attribute_hidden;
|
||||
the number of args consumed by this spec; *MAX_REF_ARG is updated so it
|
||||
remains the highest argument index used. */
|
||||
static inline size_t
|
||||
//#ifdef COMPILE_WPRINTF
|
||||
#ifdef COMPILE_WPRINTF
|
||||
parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||
size_t *max_ref_arg)
|
||||
//#else
|
||||
//parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||
// size_t *max_ref_arg, mbstate_t *ps)
|
||||
//#endif
|
||||
#else
|
||||
parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||
size_t *max_ref_arg, mbstate_t *ps)
|
||||
#endif
|
||||
{
|
||||
unsigned int n;
|
||||
size_t nargs = 0;
|
||||
@@ -353,7 +354,7 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||
|
||||
/* Get the format specification. */
|
||||
spec->info.spec = (wchar_t) *format++;
|
||||
if (__builtin_expect (__printf_function_table != NULL, 0)
|
||||
if (__printf_function_table != NULL
|
||||
&& spec->info.spec <= UCHAR_MAX
|
||||
&& __printf_arginfo_table[spec->info.spec] != NULL)
|
||||
/* We don't try to get the types for all arguments if the format
|
||||
@@ -442,11 +443,11 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||
{
|
||||
/* Find the next format spec. */
|
||||
spec->end_of_fmt = format;
|
||||
//#ifdef COMPILE_WPRINTF
|
||||
#ifdef COMPILE_WPRINTF
|
||||
spec->next_fmt = find_spec (format);
|
||||
//#else
|
||||
// spec->next_fmt = find_spec (format, ps);
|
||||
//#endif
|
||||
#else
|
||||
spec->next_fmt = find_spec (format, ps);
|
||||
#endif
|
||||
}
|
||||
|
||||
return nargs;
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* Copyright (C) 1991,1992,1995,1996,1999,2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <printf.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef COMPILE_WPRINTF
|
||||
# define CHAR_T char
|
||||
# define UCHAR_T unsigned char
|
||||
# define INT_T int
|
||||
# define L_(Str) Str
|
||||
# define ISDIGIT(Ch) isdigit (Ch)
|
||||
# define ISASCII(Ch) isascii (Ch)
|
||||
# define MBRLEN(Cp, L, St) __mbrlen (Cp, L, St)
|
||||
|
||||
# ifdef USE_IN_LIBIO
|
||||
# define PUT(F, S, N) _IO_sputn (F, S, N)
|
||||
# define PAD(Padchar) \
|
||||
if (width > 0) \
|
||||
done += _IO_padn (s, Padchar, width)
|
||||
# else
|
||||
# define PUTC(C, F) putc (C, F)
|
||||
ssize_t __printf_pad __P ((FILE *, char pad, size_t n));
|
||||
# define PAD(Padchar) \
|
||||
if (width > 0) \
|
||||
{ if (__printf_pad (s, Padchar, width) == -1) \
|
||||
return -1; else done += width; }
|
||||
# endif
|
||||
#else
|
||||
# define vfprintf vfwprintf
|
||||
# define CHAR_T wchar_t
|
||||
# define UCHAR_T uwchar_t
|
||||
# define INT_T wint_t
|
||||
# define L_(Str) L##Str
|
||||
# define ISDIGIT(Ch) iswdigit (Ch)
|
||||
|
||||
# ifdef USE_IN_LIBIO
|
||||
# define PUT(F, S, N) _IO_sputn (F, S, N)
|
||||
# define PAD(Padchar) \
|
||||
if (width > 0) \
|
||||
done += _IO_wpadn (s, Padchar, width)
|
||||
# else
|
||||
# define PUTC(C, F) wputc (C, F)
|
||||
ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
|
||||
# define PAD(Padchar) \
|
||||
if (width > 0) \
|
||||
{ if (__wprintf_pad (s, Padchar, width) == -1) \
|
||||
return -1; else done += width; }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "printf-parse.h"
|
||||
|
||||
|
||||
size_t
|
||||
parse_printf_format (fmt, n, argtypes)
|
||||
const char *fmt;
|
||||
size_t n;
|
||||
int *argtypes;
|
||||
{
|
||||
size_t nargs; /* Number of arguments. */
|
||||
size_t max_ref_arg; /* Highest index used in a positional arg. */
|
||||
struct printf_spec spec;
|
||||
mbstate_t mbstate;
|
||||
|
||||
nargs = 0;
|
||||
max_ref_arg = 0;
|
||||
|
||||
/* Search for format specifications. */
|
||||
for (fmt = find_spec (fmt, &mbstate); *fmt != '\0'; fmt = spec.next_fmt)
|
||||
{
|
||||
/* Parse this spec. */
|
||||
nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg, &mbstate);
|
||||
|
||||
/* If the width is determined by an argument this is an int. */
|
||||
if (spec.width_arg != -1 && (size_t) spec.width_arg < n)
|
||||
argtypes[spec.width_arg] = PA_INT;
|
||||
|
||||
/* If the precision is determined by an argument this is an int. */
|
||||
if (spec.prec_arg != -1 && (size_t) spec.prec_arg < n)
|
||||
argtypes[spec.prec_arg] = PA_INT;
|
||||
|
||||
if ((size_t) spec.data_arg < n)
|
||||
switch (spec.ndata_args)
|
||||
{
|
||||
case 0: /* No arguments. */
|
||||
break;
|
||||
case 1: /* One argument; we already have the type. */
|
||||
argtypes[spec.data_arg] = spec.data_arg_type;
|
||||
break;
|
||||
default:
|
||||
/* We have more than one argument for this format spec. We must
|
||||
call the arginfo function again to determine all the types. */
|
||||
(void) (*__printf_arginfo_table[spec.info.spec])
|
||||
(&spec.info, n - spec.data_arg, &argtypes[spec.data_arg]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return MAX (nargs, max_ref_arg);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Floating point output for `printf'.
|
||||
Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Ulrich Drepper <[email protected]>, 1995.
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
/* The gmp headers need some configuration frobs. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
#include <stdio_private.h>
|
||||
// ToDo: implement this function for real
|
||||
#include <printf.h>
|
||||
#if 0
|
||||
#ifdef USE_IN_LIBIO
|
||||
# include <libioP.h>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
#include <alloca.h>
|
||||
#include <ctype.h>
|
||||
#include <float.h>
|
||||
@@ -36,6 +37,7 @@
|
||||
#include <locale/localeinfo.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <printf.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@@ -50,7 +52,7 @@
|
||||
the GNU I/O library. */
|
||||
#ifdef USE_IN_LIBIO
|
||||
# define PUT(f, s, n) _IO_sputn (f, s, n)
|
||||
# define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : INTUSE(_IO_padn) (f, c, n))
|
||||
# define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : _IO_padn (f, c, n))
|
||||
/* We use this file GNU C library and GNU I/O library. So make
|
||||
names equal. */
|
||||
# undef putc
|
||||
@@ -118,8 +120,7 @@ ssize_t __printf_pad __P ((FILE *, char pad, int n)); /* In vfprintf.c. */
|
||||
#define MPN_GE(u,v) \
|
||||
(u##size > v##size || (u##size == v##size && __mpn_cmp (u, v, u##size) >= 0))
|
||||
|
||||
extern int __isinfl_internal (long double) attribute_hidden;
|
||||
extern int __isnanl_internal (long double) attribute_hidden;
|
||||
extern int __isinfl (long double), __isnanl (long double);
|
||||
|
||||
extern mp_size_t __mpn_extract_double (mp_ptr res_ptr, mp_size_t size,
|
||||
int *expt, int *is_neg,
|
||||
@@ -210,7 +211,8 @@ __printf_fp (FILE *fp,
|
||||
else if (scalesize == 0)
|
||||
{
|
||||
hi = frac[fracsize - 1];
|
||||
frac[fracsize - 1] = __mpn_mul_1 (frac, frac, fracsize - 1, 10);
|
||||
cy = __mpn_mul_1 (frac, frac, fracsize - 1, 10);
|
||||
frac[fracsize - 1] = cy;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -234,11 +236,9 @@ __printf_fp (FILE *fp,
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
mp_limb_t _cy = __mpn_mul_1 (frac, frac, fracsize, 10);
|
||||
if (_cy != 0)
|
||||
frac[fracsize++] = _cy;
|
||||
}
|
||||
cy = __mpn_mul_1 (frac, frac, fracsize, 10);
|
||||
if (cy != 0)
|
||||
frac[fracsize++] = cy;
|
||||
}
|
||||
|
||||
return L'0' + hi;
|
||||
@@ -304,7 +304,7 @@ __printf_fp (FILE *fp,
|
||||
multibyte representation for the thousands separator,
|
||||
we must ensure the wide character thousands separator
|
||||
is available, even if it is fake. */
|
||||
thousands_sepwc = (wchar_t)0xfffffffe;
|
||||
thousands_sepwc = 0xfffffffe;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -363,7 +363,6 @@ __printf_fp (FILE *fp,
|
||||
/* Check for special values: not a number or infinity. */
|
||||
if (__isnan (fpnum.dbl))
|
||||
{
|
||||
is_neg = 0;
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "NAN";
|
||||
@@ -374,10 +373,10 @@ __printf_fp (FILE *fp,
|
||||
special = "nan";
|
||||
wspecial = L"nan";
|
||||
}
|
||||
is_neg = 0;
|
||||
}
|
||||
else if (__isinf (fpnum.dbl))
|
||||
{
|
||||
is_neg = fpnum.dbl < 0;
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "INF";
|
||||
@@ -388,6 +387,7 @@ __printf_fp (FILE *fp,
|
||||
special = "inf";
|
||||
wspecial = L"inf";
|
||||
}
|
||||
is_neg = fpnum.dbl < 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -493,9 +493,6 @@ __printf_fp (FILE *fp,
|
||||
&__tens[powers->arrayoff],
|
||||
tmpsize * sizeof (mp_limb_t));
|
||||
MPN_ZERO (tmp, _FPIO_CONST_SHIFT);
|
||||
/* Adjust exponent, as scaleexpo will be this much
|
||||
bigger too. */
|
||||
exponent += _FPIO_CONST_SHIFT * BITS_PER_MP_LIMB;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -809,12 +806,10 @@ __printf_fp (FILE *fp,
|
||||
dig_max = INT_MAX; /* Unlimited. */
|
||||
significant = 1; /* Does not matter here. */
|
||||
}
|
||||
else if (_tolower (info->spec) == 'f')
|
||||
else if (info->spec == 'f')
|
||||
{
|
||||
type = 'f';
|
||||
fracdig_min = fracdig_max = info->prec < 0 ? 6 : info->prec;
|
||||
dig_max = INT_MAX; /* Unlimited. */
|
||||
significant = 1; /* Does not matter here. */
|
||||
if (expsign == 0)
|
||||
{
|
||||
intdig_max = exponent + 1;
|
||||
@@ -826,6 +821,8 @@ __printf_fp (FILE *fp,
|
||||
intdig_max = 1;
|
||||
chars_needed = 1 + 1 + fracdig_max;
|
||||
}
|
||||
dig_max = INT_MAX; /* Unlimited. */
|
||||
significant = 1; /* Does not matter here. */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -869,7 +866,7 @@ __printf_fp (FILE *fp,
|
||||
it is possible that we need two more characters in front of all the
|
||||
other output. If the amount of memory we have to allocate is too
|
||||
large use `malloc' instead of `alloca'. */
|
||||
buffer_malloced = ! __libc_use_alloca (chars_needed * 2 * sizeof (wchar_t));
|
||||
buffer_malloced = chars_needed > 5000;
|
||||
if (buffer_malloced)
|
||||
{
|
||||
wbuffer = (wchar_t *) malloc ((2 + chars_needed) * sizeof (wchar_t));
|
||||
@@ -911,7 +908,7 @@ __printf_fp (FILE *fp,
|
||||
{
|
||||
++fracdig_no;
|
||||
*wcp = hack_digit ();
|
||||
if (*wcp++ != L'0')
|
||||
if (*wcp != L'0')
|
||||
significant = 1;
|
||||
else if (significant == 0)
|
||||
{
|
||||
@@ -919,6 +916,7 @@ __printf_fp (FILE *fp,
|
||||
if (fracdig_min > 0)
|
||||
++fracdig_min;
|
||||
}
|
||||
++wcp;
|
||||
}
|
||||
|
||||
/* Do rounding. */
|
||||
@@ -1144,7 +1142,6 @@ __printf_fp (FILE *fp,
|
||||
}
|
||||
return done;
|
||||
}
|
||||
libc_hidden_def (__printf_fp)
|
||||
|
||||
/* Return the number of extra grouping characters that will be inserted
|
||||
into a number with INTDIG_MAX integer digits. */
|
||||
@@ -1230,10 +1227,3 @@ group_number (wchar_t *buf, wchar_t *bufend, unsigned int intdig_no,
|
||||
|
||||
return bufend + ngroups;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
__printf_fp(FILE *fp, const struct printf_info *info, const void * const *args)
|
||||
{
|
||||
return fputs("NaN-FIXME", fp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,493 @@
|
||||
/* Print floating point number in hexadecimal notation according to ISO C99.
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <ieee754.h>
|
||||
#include <math.h>
|
||||
#include <printf.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "_itoa.h"
|
||||
#include "_itowa.h"
|
||||
#include <locale/localeinfo.h>
|
||||
|
||||
/* #define NDEBUG 1*/ /* Undefine this for debugging assertions. */
|
||||
#include <assert.h>
|
||||
|
||||
/* This defines make it possible to use the same code for GNU C library and
|
||||
the GNU I/O library. */
|
||||
#ifdef USE_IN_LIBIO
|
||||
# include <libioP.h>
|
||||
# define PUT(f, s, n) _IO_sputn (f, s, n)
|
||||
# define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : _IO_padn (f, c, n))
|
||||
/* We use this file GNU C library and GNU I/O library. So make
|
||||
names equal. */
|
||||
# undef putc
|
||||
# define putc(c, f) (wide \
|
||||
? (int)_IO_putwc_unlocked (c, f) : _IO_putc_unlocked (c, f))
|
||||
# define size_t _IO_size_t
|
||||
# define FILE _IO_FILE
|
||||
#else /* ! USE_IN_LIBIO */
|
||||
# define PUT(f, s, n) fwrite (s, 1, n, f)
|
||||
# define PAD(f, c, n) __printf_pad (f, c, n)
|
||||
ssize_t __printf_pad __P ((FILE *, char pad, int n)); /* In vfprintf.c. */
|
||||
#endif /* USE_IN_LIBIO */
|
||||
|
||||
/* Macros for doing the actual output. */
|
||||
|
||||
#define outchar(ch) \
|
||||
do \
|
||||
{ \
|
||||
register const int outc = (ch); \
|
||||
if (putc (outc, fp) == EOF) \
|
||||
return -1; \
|
||||
++done; \
|
||||
} while (0)
|
||||
|
||||
#define PRINT(ptr, wptr, len) \
|
||||
do \
|
||||
{ \
|
||||
register size_t outlen = (len); \
|
||||
if (wide) \
|
||||
while (outlen-- > 0) \
|
||||
outchar (*wptr++); \
|
||||
else \
|
||||
while (outlen-- > 0) \
|
||||
outchar (*ptr++); \
|
||||
} while (0)
|
||||
|
||||
#define PADN(ch, len) \
|
||||
do \
|
||||
{ \
|
||||
if (PAD (fp, ch, len) != len) \
|
||||
return -1; \
|
||||
done += len; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
__printf_fphex (FILE *fp,
|
||||
const struct printf_info *info,
|
||||
const void *const *args)
|
||||
{
|
||||
/* The floating-point value to output. */
|
||||
union
|
||||
{
|
||||
union ieee754_double dbl;
|
||||
union ieee854_long_double ldbl;
|
||||
}
|
||||
fpnum;
|
||||
|
||||
/* Locale-dependent representation of decimal point. */
|
||||
const char *decimal;
|
||||
wchar_t decimalwc;
|
||||
|
||||
/* "NaN" or "Inf" for the special cases. */
|
||||
const char *special = NULL;
|
||||
const wchar_t *wspecial = NULL;
|
||||
|
||||
/* Buffer for the generated number string for the mantissa. The
|
||||
maximal size for the mantissa is 128 bits. */
|
||||
char numbuf[32];
|
||||
char *numstr;
|
||||
char *numend;
|
||||
wchar_t wnumbuf[32];
|
||||
wchar_t *wnumstr;
|
||||
wchar_t *wnumend;
|
||||
int negative;
|
||||
|
||||
/* The maximal exponent of two in decimal notation has 5 digits. */
|
||||
char expbuf[5];
|
||||
char *expstr;
|
||||
wchar_t wexpbuf[5];
|
||||
wchar_t *wexpstr;
|
||||
int expnegative;
|
||||
int exponent;
|
||||
|
||||
/* Non-zero is mantissa is zero. */
|
||||
int zero_mantissa;
|
||||
|
||||
/* The leading digit before the decimal point. */
|
||||
char leading;
|
||||
|
||||
/* Precision. */
|
||||
int precision = info->prec;
|
||||
|
||||
/* Width. */
|
||||
int width = info->width;
|
||||
|
||||
/* Number of characters written. */
|
||||
int done = 0;
|
||||
|
||||
/* Nonzero if this is output on a wide character stream. */
|
||||
int wide = info->wide;
|
||||
|
||||
|
||||
/* Figure out the decimal point character. */
|
||||
if (info->extra == 0)
|
||||
{
|
||||
decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
|
||||
decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
|
||||
}
|
||||
else
|
||||
{
|
||||
decimal = _NL_CURRENT (LC_MONETARY, MON_DECIMAL_POINT);
|
||||
decimalwc = _NL_CURRENT_WORD (LC_MONETARY,
|
||||
_NL_MONETARY_DECIMAL_POINT_WC);
|
||||
}
|
||||
/* The decimal point character must never be zero. */
|
||||
assert (*decimal != '\0' && decimalwc != L'\0');
|
||||
|
||||
|
||||
/* Fetch the argument value. */
|
||||
#ifndef __NO_LONG_DOUBLE_MATH
|
||||
if (info->is_long_double && sizeof (long double) > sizeof (double))
|
||||
{
|
||||
fpnum.ldbl.d = *(const long double *) args[0];
|
||||
|
||||
/* Check for special values: not a number or infinity. */
|
||||
if (__isnanl (fpnum.ldbl.d))
|
||||
{
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "NAN";
|
||||
wspecial = L"NAN";
|
||||
}
|
||||
else
|
||||
{
|
||||
special = "nan";
|
||||
wspecial = L"nan";
|
||||
}
|
||||
negative = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__isinfl (fpnum.ldbl.d))
|
||||
{
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "INF";
|
||||
wspecial = L"INF";
|
||||
}
|
||||
else
|
||||
{
|
||||
special = "inf";
|
||||
wspecial = L"inf";
|
||||
}
|
||||
}
|
||||
|
||||
negative = signbit (fpnum.ldbl.d);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* no long double */
|
||||
{
|
||||
fpnum.dbl.d = *(const double *) args[0];
|
||||
|
||||
/* Check for special values: not a number or infinity. */
|
||||
if (__isnan (fpnum.dbl.d))
|
||||
{
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "NAN";
|
||||
wspecial = L"NAN";
|
||||
}
|
||||
else
|
||||
{
|
||||
special = "nan";
|
||||
wspecial = L"nan";
|
||||
}
|
||||
negative = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__isinf (fpnum.dbl.d))
|
||||
{
|
||||
if (isupper (info->spec))
|
||||
{
|
||||
special = "INF";
|
||||
wspecial = L"INF";
|
||||
}
|
||||
else
|
||||
{
|
||||
special = "inf";
|
||||
wspecial = L"inf";
|
||||
}
|
||||
}
|
||||
|
||||
negative = signbit (fpnum.dbl.d);
|
||||
}
|
||||
}
|
||||
|
||||
if (special)
|
||||
{
|
||||
int width = info->width;
|
||||
|
||||
if (negative || info->showsign || info->space)
|
||||
--width;
|
||||
width -= 3;
|
||||
|
||||
if (!info->left && width > 0)
|
||||
PADN (' ', width);
|
||||
|
||||
if (negative)
|
||||
outchar ('-');
|
||||
else if (info->showsign)
|
||||
outchar ('+');
|
||||
else if (info->space)
|
||||
outchar (' ');
|
||||
|
||||
PRINT (special, wspecial, 3);
|
||||
|
||||
if (info->left && width > 0)
|
||||
PADN (' ', width);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
if (info->is_long_double == 0 || sizeof (double) == sizeof (long double))
|
||||
{
|
||||
/* We have 52 bits of mantissa plus one implicit digit. Since
|
||||
52 bits are representable without rest using hexadecimal
|
||||
digits we use only the implicit digits for the number before
|
||||
the decimal point. */
|
||||
unsigned long long int num;
|
||||
|
||||
num = (((unsigned long long int) fpnum.dbl.ieee.mantissa0) << 32
|
||||
| fpnum.dbl.ieee.mantissa1);
|
||||
|
||||
zero_mantissa = num == 0;
|
||||
|
||||
if (sizeof (unsigned long int) > 6)
|
||||
{
|
||||
wnumstr = _itowa_word (num, wnumbuf + (sizeof wnumbuf) / sizeof (wchar_t), 16,
|
||||
info->spec == 'A');
|
||||
numstr = _itoa_word (num, numbuf + sizeof numbuf, 16,
|
||||
info->spec == 'A');
|
||||
}
|
||||
else
|
||||
{
|
||||
wnumstr = _itowa (num, wnumbuf + sizeof wnumbuf / sizeof (wchar_t), 16,
|
||||
info->spec == 'A');
|
||||
numstr = _itoa (num, numbuf + sizeof numbuf, 16,
|
||||
info->spec == 'A');
|
||||
}
|
||||
|
||||
/* Fill with zeroes. */
|
||||
while (wnumstr > wnumbuf + (sizeof wnumbuf - 52) / sizeof (wchar_t))
|
||||
{
|
||||
*--wnumstr = L'0';
|
||||
*--numstr = '0';
|
||||
}
|
||||
|
||||
leading = fpnum.dbl.ieee.exponent == 0 ? '0' : '1';
|
||||
|
||||
exponent = fpnum.dbl.ieee.exponent;
|
||||
|
||||
if (exponent == 0)
|
||||
{
|
||||
if (zero_mantissa)
|
||||
expnegative = 0;
|
||||
else
|
||||
{
|
||||
/* This is a denormalized number. */
|
||||
expnegative = 1;
|
||||
exponent = IEEE754_DOUBLE_BIAS - 1;
|
||||
}
|
||||
}
|
||||
else if (exponent >= IEEE754_DOUBLE_BIAS)
|
||||
{
|
||||
expnegative = 0;
|
||||
exponent -= IEEE754_DOUBLE_BIAS;
|
||||
}
|
||||
else
|
||||
{
|
||||
expnegative = 1;
|
||||
exponent = -(exponent - IEEE754_DOUBLE_BIAS);
|
||||
}
|
||||
}
|
||||
#ifdef PRINT_FPHEX_LONG_DOUBLE
|
||||
else
|
||||
PRINT_FPHEX_LONG_DOUBLE;
|
||||
#endif
|
||||
|
||||
/* Look for trailing zeroes. */
|
||||
if (! zero_mantissa)
|
||||
{
|
||||
wnumend = wnumbuf + sizeof wnumbuf;
|
||||
numend = numbuf + sizeof numbuf;
|
||||
while (wnumend[-1] == L'0')
|
||||
{
|
||||
--wnumend;
|
||||
--numend;
|
||||
}
|
||||
|
||||
if (precision == -1)
|
||||
precision = numend - numstr;
|
||||
else if (precision < numend - numstr
|
||||
&& (numstr[precision] > '8'
|
||||
|| (('A' < '0' || 'a' < '0')
|
||||
&& numstr[precision] < '0')
|
||||
|| (numstr[precision] == '8'
|
||||
&& (precision + 1 < numend - numstr
|
||||
/* Round to even. */
|
||||
|| (precision > 0
|
||||
&& ((numstr[precision - 1] & 1)
|
||||
^ (isdigit (numstr[precision - 1]) == 0)))
|
||||
|| (precision == 0
|
||||
&& ((leading & 1)
|
||||
^ (isdigit (leading) == 0)))))))
|
||||
{
|
||||
/* Round up. */
|
||||
int cnt = precision;
|
||||
while (--cnt >= 0)
|
||||
{
|
||||
char ch = numstr[cnt];
|
||||
/* We assume that the digits and the letters are ordered
|
||||
like in ASCII. This is true for the rest of GNU, too. */
|
||||
if (ch == '9')
|
||||
{
|
||||
wnumstr[cnt] = (wchar_t) info->spec;
|
||||
numstr[cnt] = info->spec; /* This is tricky,
|
||||
think about it! */
|
||||
break;
|
||||
}
|
||||
else if (tolower (ch) < 'f')
|
||||
{
|
||||
++numstr[cnt];
|
||||
++wnumstr[cnt];
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
numstr[cnt] = '0';
|
||||
wnumstr[cnt] = L'0';
|
||||
}
|
||||
}
|
||||
if (cnt < 0)
|
||||
{
|
||||
/* The mantissa so far was fff...f Now increment the
|
||||
leading digit. Here it is again possible that we
|
||||
get an overflow. */
|
||||
if (leading == '9')
|
||||
leading = info->spec;
|
||||
else if (tolower (leading) < 'f')
|
||||
++leading;
|
||||
else
|
||||
{
|
||||
leading = 1;
|
||||
if (expnegative)
|
||||
{
|
||||
exponent += 4;
|
||||
if (exponent >= 0)
|
||||
expnegative = 0;
|
||||
}
|
||||
else
|
||||
exponent += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision == -1)
|
||||
precision = 0;
|
||||
numend = numstr;
|
||||
wnumend = wnumstr;
|
||||
}
|
||||
|
||||
/* Now we can compute the exponent string. */
|
||||
expstr = _itoa_word (exponent, expbuf + sizeof expbuf, 10, 0);
|
||||
wexpstr = _itowa_word (exponent,
|
||||
wexpbuf + sizeof wexpbuf / sizeof (wchar_t), 10, 0);
|
||||
|
||||
/* Now we have all information to compute the size. */
|
||||
width -= ((negative || info->showsign || info->space)
|
||||
/* Sign. */
|
||||
+ 2 + 1 + 0 + precision + 1 + 1
|
||||
/* 0x h . hhh P ExpoSign. */
|
||||
+ ((expbuf + sizeof expbuf) - expstr));
|
||||
/* Exponent. */
|
||||
|
||||
/* Count the decimal point. */
|
||||
if (precision > 0 || info->alt)
|
||||
width -= wide ? 1 : strlen (decimal);
|
||||
|
||||
/* A special case when the mantissa or the precision is zero and the `#'
|
||||
is not given. In this case we must not print the decimal point. */
|
||||
if (precision == 0 && !info->alt)
|
||||
++width; /* This nihilates the +1 for the decimal-point
|
||||
character in the following equation. */
|
||||
|
||||
if (!info->left && width > 0)
|
||||
PADN (' ', width);
|
||||
|
||||
if (negative)
|
||||
outchar ('-');
|
||||
else if (info->showsign)
|
||||
outchar ('+');
|
||||
else if (info->space)
|
||||
outchar (' ');
|
||||
|
||||
outchar ('0');
|
||||
if ('X' - 'A' == 'x' - 'a')
|
||||
outchar (info->spec + ('x' - 'a'));
|
||||
else
|
||||
outchar (info->spec == 'A' ? 'X' : 'x');
|
||||
outchar (leading);
|
||||
|
||||
if (precision > 0 || info->alt)
|
||||
{
|
||||
const wchar_t *wtmp = &decimalwc;
|
||||
PRINT (decimal, wtmp, wide ? 1 : strlen (decimal));
|
||||
}
|
||||
|
||||
if (precision > 0)
|
||||
{
|
||||
ssize_t tofill = precision - (numend - numstr);
|
||||
PRINT (numstr, wnumstr, MIN (numend - numstr, precision));
|
||||
if (tofill > 0)
|
||||
PADN ('0', tofill);
|
||||
}
|
||||
|
||||
if (info->left && info->pad == '0' && width > 0)
|
||||
PADN ('0', width);
|
||||
|
||||
if ('P' - 'A' == 'p' - 'a')
|
||||
outchar (info->spec + ('p' - 'a'));
|
||||
else
|
||||
outchar (info->spec == 'A' ? 'P' : 'p');
|
||||
|
||||
outchar (expnegative ? '-' : '+');
|
||||
|
||||
PRINT (expstr, wexpstr, (expbuf + sizeof expbuf) - expstr);
|
||||
|
||||
if (info->left && info->pad != '0' && width > 0)
|
||||
PADN (info->pad, width);
|
||||
|
||||
return done;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user