* libc/include/stdio.h (__VALIST): Guard against multiple definition.

* libc/include/wchar.h: Include stdarg.h.
	(__VALIST): Define conditionally.
	(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
	(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
	 _wprintf_r): Declare.
	* libc/stdio/Makefile.am: Add new files.
	* libc/stdio/Makefile.in: Regenerate.
	* libc/stdio/fwprintf.c: New file.
	* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
	(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
	and move to the __ namespace.
	(__chclass, __state_table, __action_table): Declare.
	* libc/stdio/stdio.tex: Add new documentation references.
	* libc/stdio/swprintf.c: New file.
	* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
	__sprint_r function according to compilation unit.  Use throughout.
	(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
	Make externaly available.  Only define if INTEGER_ONLY is defined.
	(__sprint_r): Make externaly available.  Only define if INTEGER_ONLY
	is defined.  Handle stream orientation.
	(__sbprintf): Copy FILE's _flags2 member as well.
	(__chclass, __state_table, __action_table): Prepend __ to name and
	make externally available.
	* libc/stdio/vfwprintf.c: New file.
	* libc/stdio/vswprintf.c: New file.
	* libc/stdio/vwprintf.c: New file.
	* libc/stdio/wprintf.c: New file.
This commit is contained in:
Corinna Vinschen 2009-03-06 09:55:52 +00:00
parent 6e0e5a4fc2
commit 6121968b19
14 changed files with 2886 additions and 71 deletions

View File

@ -1,3 +1,34 @@
2009-03-06 Corinna Vinschen <corinna@vinschen.de>
* libc/include/stdio.h (__VALIST): Guard against multiple definition.
* libc/include/wchar.h: Include stdarg.h.
(__VALIST): Define conditionally.
(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
_wprintf_r): Declare.
* libc/stdio/Makefile.am: Add new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fwprintf.c: New file.
* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
and move to the __ namespace.
(__chclass, __state_table, __action_table): Declare.
* libc/stdio/stdio.tex: Add new documentation references.
* libc/stdio/swprintf.c: New file.
* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
__sprint_r function according to compilation unit. Use throughout.
(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
Make externaly available. Only define if INTEGER_ONLY is defined.
(__sprint_r): Make externaly available. Only define if INTEGER_ONLY
is defined. Handle stream orientation.
(__sbprintf): Copy FILE's _flags2 member as well.
(__chclass, __state_table, __action_table): Prepend __ to name and
make externally available.
* libc/stdio/vfwprintf.c: New file.
* libc/stdio/vswprintf.c: New file.
* libc/stdio/vwprintf.c: New file.
* libc/stdio/wprintf.c: New file.
2009-03-03 Corinna Vinschen <corinna@vinschen.de>
* libc/locale/locale.c (_setlocale_r): New implementation based on

View File

@ -164,11 +164,13 @@ typedef _fpos64_t fpos64_t;
* Functions defined in ANSI C standard.
*/
#ifndef __VALIST
#ifdef __GNUC__
#define __VALIST __gnuc_va_list
#else
#define __VALIST char*
#endif
#endif
FILE * _EXFUN(tmpfile, (void));
char * _EXFUN(tmpnam, (char *));

View File

@ -10,6 +10,9 @@
#define __need_wint_t
#include <stddef.h>
#define __need___va_list
#include <stdarg.h>
/* For _mbstate_t definition. */
#include <sys/_types.h>
@ -129,6 +132,28 @@ wint_t _EXFUN (_ungetwc_r, (struct _reent *, wint_t wc, __FILE *));
__FILE *_EXFUN (open_wmemstream, (wchar_t **, size_t *));
__FILE *_EXFUN (_open_wmemstream_r, (struct _reent *, wchar_t **, size_t *));
#ifndef __VALIST
#ifdef __GNUC__
#define __VALIST __gnuc_va_list
#else
#define __VALIST char*
#endif
#endif
int _EXFUN(fwprintf, (__FILE *, const wchar_t *, ...));
int _EXFUN(swprintf, (wchar_t *, size_t, const wchar_t *, ...));
int _EXFUN(vfwprintf, (__FILE *, const wchar_t *, __VALIST));
int _EXFUN(vswprintf, (wchar_t *, size_t, const wchar_t *, __VALIST));
int _EXFUN(vwprintf, (const wchar_t *, __VALIST));
int _EXFUN(wprintf, (const wchar_t *, ...));
int _EXFUN(_fwprintf_r, (struct _reent *, __FILE *, const wchar_t *, ...));
int _EXFUN(_swprintf_r, (struct _reent *, wchar_t *, size_t, const wchar_t *, ...));
int _EXFUN(_vfwprintf_r, (struct _reent *, __FILE *, const wchar_t *, __VALIST));
int _EXFUN(_vswprintf_r, (struct _reent *, wchar_t *, size_t, const wchar_t *, __VALIST));
int _EXFUN(_vwprintf_r, (struct _reent *, const wchar_t *, __VALIST));
int _EXFUN(_wprintf_r, (struct _reent *, const wchar_t *, ...));
#define getwc(fp) fgetwc(fp)
#define putwc(wc,fp) fputwc((wc), (fp))
#ifndef _REENT_ONLY

View File

@ -125,14 +125,20 @@ ELIX_4_SOURCES = \
fputws.c \
funopen.c \
fwide.c \
fwprintf.c \
getwc.c \
getwchar.c \
open_memstream.c \
putwc.c \
putwchar.c \
swprintf.c \
ungetwc.c \
vasniprintf.c \
vasnprintf.c
vasnprintf.c \
vswprintf.c \
vwprintf.c \
wprintf.c
endif !ELIX_LEVEL_3
endif !ELIX_LEVEL_2
endif !ELIX_LEVEL_1
@ -141,7 +147,9 @@ LIBADD_OBJS = \
$(lpfx)svfiprintf.$(oext) $(lpfx)svfprintf.$(oext) \
$(lpfx)svfiscanf.$(oext) $(lpfx)svfscanf.$(oext) \
$(lpfx)vfiprintf.$(oext) $(lpfx)vfprintf.$(oext) \
$(lpfx)vfscanf.$(oext) $(lpfx)vfiscanf.$(oext)
$(lpfx)vfscanf.$(oext) $(lpfx)vfiscanf.$(oext) \
$(lpfx)svfiwprintf.$(oext) $(lpfx)svfwprintf.$(oext) \
$(lpfx)vfiwprintf.$(oext) $(lpfx)vfwprintf.$(oext)
libstdio_la_LDFLAGS = -Xcompiler -nostdlib
@ -179,6 +187,18 @@ $(lpfx)svfprintf.$(oext): vfprintf.c
$(lpfx)svfiprintf.$(oext): vfprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@
$(lpfx)vfwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)vfiwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)svfwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)svfiwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)vfscanf.$(oext): vfscanf.c
$(LIB_COMPILE) -c $(srcdir)/vfscanf.c -o $@
@ -254,12 +274,14 @@ CHEWOUT_FILES = \
siscanf.def \
sprintf.def \
sscanf.def \
swprintf.def \
tmpfile.def \
tmpnam.def \
ungetc.def \
ungetwc.def \
vfprintf.def \
vfscanf.def \
vfwprintf.def \
viprintf.def \
viscanf.def
@ -298,9 +320,10 @@ $(lpfx)funopen.$(oext): local.h
$(lpfx)fvwrite.$(oext): local.h fvwrite.h
$(lpfx)fwalk.$(oext): local.h
$(lpfx)fwide.$(oext): local.h
$(lpfx)fwprintf.$(oext): local.h
$(lpfx)fwrite.$(oext): local.h fvwrite.h
$(lpfx)getwc.$(oext): local.h
$(lpfx)getwchar.$(oext): local.h
$(lpfx)fwrite.$(oext): local.h fvwrite.h
$(lpfx)iscanf.$(oext): local.h
$(lpfx)makebuf.$(oext): local.h
$(lpfx)open_memstream.$(oext): local.h
@ -312,25 +335,30 @@ $(lpfx)scanf.$(oext): local.h
$(lpfx)setbuf.$(oext): local.h
$(lpfx)setvbuf.$(oext): local.h
$(lpfx)siprintf.$(oext): local.h
$(lpfx)siscanf.$(oext): local.h
$(lpfx)sniprintf.$(oext): local.h
$(lpfx)sprintf.$(oext): local.h
$(lpfx)siscanf.$(oext): local.h
$(lpfx)sscanf.$(oext): local.h
$(lpfx)stdio.$(oext): local.h
$(lpfx)svfiprintf.$(oext): local.h
$(lpfx)svfiscanf.$(oext): local.h floatio.h
$(lpfx)svfprintf.$(oext): local.h
$(lpfx)svfscanf.$(oext): local.h floatio.h
$(lpfx)swprintf.$(oext): local.h
$(lpfx)ungetc.$(oext): local.h
$(lpfx)ungetwc.$(oext): local.h
$(lpfx)vfiprintf.$(oext): local.h
$(lpfx)vfprintf.$(oext): local.h
$(lpfx)vfiscanf.$(oext): local.h floatio.h
$(lpfx)vfprintf.$(oext): local.h
$(lpfx)vfscanf.$(oext): local.h floatio.h
$(lpfx)vfwprintf.$(oext): local.h
$(lpfx)viscanf.$(oext): local.h
$(lpfx)vscanf.$(oext): local.h
$(lpfx)vsniprintf.$(oext): local.h
$(lpfx)vsiscanf.$(oext): local.h
$(lpfx)vsniprintf.$(oext): local.h
$(lpfx)vsscanf.$(oext): local.h
$(lpfx)vswprintf.$(oext): local.h
$(lpfx)vwprintf.$(oext): local.h
$(lpfx)wbuf.$(oext): local.h fvwrite.h
$(lpfx)wprintf.$(oext): local.h
$(lpfx)wsetup.$(oext): local.h

View File

@ -60,7 +60,9 @@ am__DEPENDENCIES_1 = $(lpfx)svfiprintf.$(oext) \
$(lpfx)svfprintf.$(oext) $(lpfx)svfiscanf.$(oext) \
$(lpfx)svfscanf.$(oext) $(lpfx)vfiprintf.$(oext) \
$(lpfx)vfprintf.$(oext) $(lpfx)vfscanf.$(oext) \
$(lpfx)vfiscanf.$(oext)
$(lpfx)vfiscanf.$(oext) $(lpfx)svfiwprintf.$(oext) \
$(lpfx)svfwprintf.$(oext) $(lpfx)vfiwprintf.$(oext) \
$(lpfx)vfwprintf.$(oext)
am__objects_1 = lib_a-clearerr.$(OBJEXT) lib_a-fclose.$(OBJEXT) \
lib_a-fdopen.$(OBJEXT) lib_a-feof.$(OBJEXT) \
lib_a-ferror.$(OBJEXT) lib_a-fflush.$(OBJEXT) \
@ -123,14 +125,19 @@ am__objects_1 = lib_a-clearerr.$(OBJEXT) lib_a-fclose.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fputws.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-funopen.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fwide.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fwprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-getwc.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-getwchar.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-open_memstream.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-putwc.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-putwchar.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-swprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-ungetwc.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-vasniprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-vasnprintf.$(OBJEXT)
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-vasnprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-vswprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-vwprintf.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-wprintf.$(OBJEXT)
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
@USE_LIBTOOL_FALSE@ $(am__objects_2) $(am__objects_3)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
@ -166,14 +173,19 @@ am__objects_4 = clearerr.lo fclose.lo fdopen.lo feof.lo ferror.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputws.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ funopen.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwide.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ getwc.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ getwchar.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ open_memstream.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ putwc.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ putwchar.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ swprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ ungetwc.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasniprintf.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasnprintf.lo
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasnprintf.lo \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vswprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vwprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wprintf.c
@USE_LIBTOOL_TRUE@am_libstdio_la_OBJECTS = $(am__objects_4) \
@USE_LIBTOOL_TRUE@ $(am__objects_5) $(am__objects_6)
libstdio_la_OBJECTS = $(am_libstdio_la_OBJECTS)
@ -470,14 +482,19 @@ GENERAL_SOURCES = \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputws.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ funopen.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwide.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ getwc.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ getwchar.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ open_memstream.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ putwc.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ putwchar.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ swprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ ungetwc.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasniprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasnprintf.c
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vasnprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vswprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ vwprintf.c \
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wprintf.c
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_TRUE@ELIX_4_SOURCES =
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_TRUE@ELIX_4_SOURCES =
@ -486,7 +503,9 @@ LIBADD_OBJS = \
$(lpfx)svfiprintf.$(oext) $(lpfx)svfprintf.$(oext) \
$(lpfx)svfiscanf.$(oext) $(lpfx)svfscanf.$(oext) \
$(lpfx)vfiprintf.$(oext) $(lpfx)vfprintf.$(oext) \
$(lpfx)vfscanf.$(oext) $(lpfx)vfiscanf.$(oext)
$(lpfx)vfscanf.$(oext) $(lpfx)vfiscanf.$(oext) \
$(lpfx)svfiwprintf.$(oext) $(lpfx)svfwprintf.$(oext) \
$(lpfx)vfiwprintf.$(oext) $(lpfx)vfwprintf.$(oext)
libstdio_la_LDFLAGS = -Xcompiler -nostdlib
@USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libstdio.la
@ -565,12 +584,14 @@ CHEWOUT_FILES = \
siscanf.def \
sprintf.def \
sscanf.def \
swprintf.def \
tmpfile.def \
tmpnam.def \
ungetc.def \
ungetwc.def \
vfprintf.def \
vfscanf.def \
vfwprintf.def \
viprintf.def \
viscanf.def
@ -1299,6 +1320,36 @@ lib_a-vasnprintf.o: vasnprintf.c
lib_a-vasnprintf.obj: vasnprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vasnprintf.obj `if test -f 'vasnprintf.c'; then $(CYGPATH_W) 'vasnprintf.c'; else $(CYGPATH_W) '$(srcdir)/vasnprintf.c'; fi`
lib_a-vwprintf.o: vwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vwprintf.o `test -f 'vwprintf.c' || echo '$(srcdir)/'`vwprintf.c
lib_a-vwprintf.obj: vwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vwprintf.obj `if test -f 'vwprintf.c'; then $(CYGPATH_W) 'vwprintf.c'; else $(CYGPATH_W) '$(srcdir)/vwprintf.c'; fi`
lib_a-swprintf.o: swprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-swprintf.o `test -f 'swprintf.c' || echo '$(srcdir)/'`swprintf.c
lib_a-swprintf.obj: swprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-swprintf.obj `if test -f 'swprintf.c'; then $(CYGPATH_W) 'swprintf.c'; else $(CYGPATH_W) '$(srcdir)/swprintf.c'; fi`
lib_a-vswprintf.o: vswprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vswprintf.o `test -f 'vswprintf.c' || echo '$(srcdir)/'`vswprintf.c
lib_a-vswprintf.obj: vswprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vswprintf.obj `if test -f 'vswprintf.c'; then $(CYGPATH_W) 'vswprintf.c'; else $(CYGPATH_W) '$(srcdir)/vswprintf.c'; fi`
lib_a-wprintf.o: wprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wprintf.o `test -f 'wprintf.c' || echo '$(srcdir)/'`wprintf.c
lib_a-wprintf.obj: wprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wprintf.obj `if test -f 'wprintf.c'; then $(CYGPATH_W) 'wprintf.c'; else $(CYGPATH_W) '$(srcdir)/wprintf.c'; fi`
lib_a-fwprintf.o: fwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fwprintf.o `test -f 'fwprintf.c' || echo '$(srcdir)/'`fwprintf.c
lib_a-fwprintf.obj: fwprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fwprintf.obj `if test -f 'fwprintf.c'; then $(CYGPATH_W) 'fwprintf.c'; else $(CYGPATH_W) '$(srcdir)/fwprintf.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
@ -1468,6 +1519,18 @@ $(lpfx)svfprintf.$(oext): vfprintf.c
$(lpfx)svfiprintf.$(oext): vfprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@
$(lpfx)vfwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)vfiwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)svfwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)svfiwprintf.$(oext): vfwprintf.c
$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
$(lpfx)vfscanf.$(oext): vfscanf.c
$(LIB_COMPILE) -c $(srcdir)/vfscanf.c -o $@
@ -1507,9 +1570,10 @@ $(lpfx)funopen.$(oext): local.h
$(lpfx)fvwrite.$(oext): local.h fvwrite.h
$(lpfx)fwalk.$(oext): local.h
$(lpfx)fwide.$(oext): local.h
$(lpfx)fwprintf.$(oext): local.h
$(lpfx)fwrite.$(oext): local.h fvwrite.h
$(lpfx)getwc.$(oext): local.h
$(lpfx)getwchar.$(oext): local.h
$(lpfx)fwrite.$(oext): local.h fvwrite.h
$(lpfx)iscanf.$(oext): local.h
$(lpfx)makebuf.$(oext): local.h
$(lpfx)open_memstream.$(oext): local.h
@ -1521,27 +1585,32 @@ $(lpfx)scanf.$(oext): local.h
$(lpfx)setbuf.$(oext): local.h
$(lpfx)setvbuf.$(oext): local.h
$(lpfx)siprintf.$(oext): local.h
$(lpfx)siscanf.$(oext): local.h
$(lpfx)sniprintf.$(oext): local.h
$(lpfx)sprintf.$(oext): local.h
$(lpfx)siscanf.$(oext): local.h
$(lpfx)sscanf.$(oext): local.h
$(lpfx)stdio.$(oext): local.h
$(lpfx)svfiprintf.$(oext): local.h
$(lpfx)svfiscanf.$(oext): local.h floatio.h
$(lpfx)svfprintf.$(oext): local.h
$(lpfx)svfscanf.$(oext): local.h floatio.h
$(lpfx)swprintf.$(oext): local.h
$(lpfx)ungetc.$(oext): local.h
$(lpfx)ungetwc.$(oext): local.h
$(lpfx)vfiprintf.$(oext): local.h
$(lpfx)vfprintf.$(oext): local.h
$(lpfx)vfiscanf.$(oext): local.h floatio.h
$(lpfx)vfprintf.$(oext): local.h
$(lpfx)vfscanf.$(oext): local.h floatio.h
$(lpfx)vfwprintf.$(oext): local.h
$(lpfx)viscanf.$(oext): local.h
$(lpfx)vscanf.$(oext): local.h
$(lpfx)vsniprintf.$(oext): local.h
$(lpfx)vsiscanf.$(oext): local.h
$(lpfx)vsniprintf.$(oext): local.h
$(lpfx)vsscanf.$(oext): local.h
$(lpfx)vswprintf.$(oext): local.h
$(lpfx)vwprintf.$(oext): local.h
$(lpfx)wbuf.$(oext): local.h fvwrite.h
$(lpfx)wprintf.$(oext): local.h
$(lpfx)wsetup.$(oext): local.h
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in swprintf.c */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
int
_DEFUN(_fwprintf_r, (ptr, fp, fmt),
struct _reent *ptr _AND
FILE *fp _AND
const wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
va_start (ap, fmt);
ret = _vfwprintf_r (ptr, fp, fmt, ap);
va_end (ap);
return ret;
}
#ifndef _REENT_ONLY
int
_DEFUN(fwprintf, (fp, fmt),
FILE *fp _AND
const wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
va_start (ap, fmt);
ret = _vfwprintf_r (_REENT, fp, fmt, ap);
va_end (ap);
return ret;
}
#endif /* ! _REENT_ONLY */

View File

@ -44,6 +44,10 @@ int _EXFUN(_svfprintf_r,(struct _reent *, FILE *, const char *,
int _EXFUN(_svfiprintf_r,(struct _reent *, FILE *, const char *,
va_list)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(_svfwprintf_r,(struct _reent *, FILE *, const wchar_t *,
va_list));
int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *,
va_list));
extern FILE *_EXFUN(__sfp,(struct _reent *));
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
@ -167,3 +171,51 @@ _VOID _EXFUN(__sfp_lock_release,(_VOID));
_VOID _EXFUN(__sinit_lock_acquire,(_VOID));
_VOID _EXFUN(__sinit_lock_release,(_VOID));
#endif
/* Types used in positional argument support in vfprinf/vfwprintf.
The implementation is char/wchar_t dependent but the class and state
tables are only defined once in vfprintf.c. */
typedef enum {
ZERO, /* '0' */
DIGIT, /* '1-9' */
DOLLAR, /* '$' */
MODFR, /* spec modifier */
SPEC, /* format specifier */
DOT, /* '.' */
STAR, /* '*' */
FLAG, /* format flag */
OTHER, /* all other chars */
MAX_CH_CLASS /* place-holder */
} __CH_CLASS;
typedef enum {
START, /* start */
SFLAG, /* seen a flag */
WDIG, /* seen digits in width area */
WIDTH, /* processed width */
SMOD, /* seen spec modifier */
SDOT, /* seen dot */
VARW, /* have variable width specifier */
VARP, /* have variable precision specifier */
PREC, /* processed precision */
VWDIG, /* have digits in variable width specification */
VPDIG, /* have digits in variable precision specification */
DONE, /* done */
MAX_STATE, /* place-holder */
} __STATE;
typedef enum {
NOOP, /* do nothing */
NUMBER, /* build a number from digits */
SKIPNUM, /* skip over digits */
GETMOD, /* get and process format modifier */
GETARG, /* get and process argument */
GETPW, /* get variable precision or width */
GETPWB, /* get variable precision or width and pushback fmt char */
GETPOS, /* get positional parameter value */
PWPOS, /* get positional parameter value for variable width or precision */
} __ACTION;
_CONST __CH_CLASS __chclass[256];
_CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS];
_CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS];

View File

@ -84,12 +84,14 @@ structure.
* siscanf:: Scan and format input (integer only)
* sprintf:: Write formatted output
* sscanf:: Scan and format input
* swprintf:: Write formatted wide character output
* tmpfile:: Create a temporary file
* tmpnam:: Generate name for a temporary file
* ungetc:: Push data back into a stream
* ungetwc:: Push wide character data back into a stream
* vfprintf:: Format variable argument list
* vfscanf:: Scan variable argument list
* vfwprintf:: Format variable wide character argument list
* viprintf:: Format variable argument list (integer only)
* viscanf:: Scan variable format list (integer only)
@end menu
@ -274,6 +276,9 @@ structure.
@page
@include stdio/sscanf.def
@page
@include stdio/swprintf.def
@page
@include stdio/tmpfile.def
@ -292,6 +297,9 @@ structure.
@page
@include stdio/vfscanf.def
@page
@include stdio/vfwprintf.def
@page
@include stdio/viprintf.def

View File

@ -0,0 +1,592 @@
/*
* Copyright (c) 1990, 2007 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<swprintf>>, <<fwprintf>>, <<wprintf>>---wide character format output
INDEX
fwprintf
INDEX
_fwprintf_r
INDEX
wprintf
INDEX
_wprintf_r
INDEX
swprintf
INDEX
_swprintf_r
ANSI_SYNOPSIS
#include <stdio.h>
int wprintf(const wchar_t *<[format]>, ...);
int fwprintf(FILE *<[fd]>, const wchar_t *<[format]>, ...);
int swprintf(wchar_t *<[str]>, const wchar_t *<[format]>, ...);
int _wprintf_r(struct _reent *<[ptr]>, const wchar_t *<[format]>, ...);
int _fwprintf_r(struct _reent *<[ptr]>, FILE *<[fd]>,
const wchar_t *<[format]>, ...);
int _swprintf_r(struct _reent *<[ptr]>, wchar_t *<[str]>,
const wchar_t *<[format]>, ...);
DESCRIPTION
<<wprintf>> accepts a series of arguments, applies to each a
format specifier from <<*<[format]>>>, and writes the
formatted data to <<stdout>>, without a terminating NUL
wide character. The behavior of <<wprintf>> is undefined if there
are not enough arguments for the format. <<wprintf>> returns
when it reaches the end of the format string. If there are
more arguments than the format requires, excess arguments are
ignored.
<<fwprintf>> is like <<wprintf>>, except that output is directed
to the stream <[fd]> rather than <<stdout>>.
<<swprintf>> is like <<wprintf>>, except that output is directed
to the buffer <[str]>, and the resulting string length is limited
to at most <[size]> wide characters, including the terminating
<<NUL>>. As a special case, if <[size]> is 0, <[str]> can be NULL,
and <<swprintf>> merely calculates how many bytes would be printed.
For <<swprintf>> the behavior is undefined if the output
<<*<[str]>>> overlaps with one of the arguments. Behavior is also
undefined if the argument for <<%n>> within <<*<[format]>>>
overlaps another argument.
<[format]> is a pointer to a wide character string containing two
types of objects: ordinary characters (other than <<%>>),
which are copied unchanged to the output, and conversion
specifications, each of which is introduced by <<%>>. (To
include <<%>> in the output, use <<%%>> in the format string.)
A conversion specification has the following form:
. %[<[pos]>][<[flags]>][<[width]>][.<[prec]>][<[size]>]<[type]>
The fields of the conversion specification have the following
meanings:
O+
o <[pos]>
Conversions normally consume arguments in the order that they
are presented. However, it is possible to consume arguments
out of order, and reuse an argument for more than one
conversion specification (although the behavior is undefined
if the same argument is requested with different types), by
specifying <[pos]>, which is a decimal integer followed by
'$'. The integer must be between 1 and <NL_ARGMAX> from
limits.h, and if argument <<%n$>> is requested, all earlier
arguments must be requested somewhere within <[format]>. If
positional parameters are used, then all conversion
specifications except for <<%%>> must specify a position.
o <[flags]>
<[flags]> is an optional sequence of characters which control
output justification, numeric signs, decimal points, trailing
zeros, and octal and hex prefixes. The flag characters are
minus (<<->>), plus (<<+>>), space ( ), zero (<<0>>), sharp
(<<#>>), and quote (<<'>>). They can appear in any
combination, although not all flags can be used for all
conversion specification types.
o+
o '
Since newlib only supports the C locale, this
flag has no effect in this implementation.
But in other locales, when <[type]> is <<i>>,
<<d>>, <<u>>, <<f>>, <<F>>, <<g>>, or <<G>>,
the locale-dependent thousand's separator is
inserted prior to zero padding.
o -
The result of the conversion is left
justified, and the right is padded with
blanks. If you do not use this flag, the
result is right justified, and padded on the
left.
o +
The result of a signed conversion (as
determined by <[type]> of <<d>>, <<i>>, <<a>>,
<<A>>, <<e>>, <<E>>, <<f>>, <<F>>, <<g>>, or
<<G>>) will always begin with a plus or minus
sign. (If you do not use this flag, positive
values do not begin with a plus sign.)
o " " (space)
If the first character of a signed conversion
specification is not a sign, or if a signed
conversion results in no characters, the
result will begin with a space. If the space
( ) flag and the plus (<<+>>) flag both
appear, the space flag is ignored.
o 0
If the <[type]> character is <<d>>, <<i>>,
<<o>>, <<u>>, <<x>>, <<X>>, <<a>>, <<A>>,
<<e>>, <<E>>, <<f>>, <<g>>, or <<G>>: leading
zeros are used to pad the field width
(following any indication of sign or base); no
spaces are used for padding. If the zero
(<<0>>) and minus (<<->>) flags both appear,
the zero (<<0>>) flag will be ignored. For
<<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>>
conversions, if a precision <[prec]> is
specified, the zero (<<0>>) flag is ignored.
Note that <<0>> is interpreted as a flag, not
as the beginning of a field width.
o #
The result is to be converted to an
alternative form, according to the <[type]>
character:
o+
o o
Increases precision to force the first
digit of the result to be a zero.
o x
A non-zero result will have a <<0x>>
prefix.
o X
A non-zero result will have a <<0X>>
prefix.
o a, A, e, E, f, or F
The result will always contain a
decimal point even if no digits follow
the point. (Normally, a decimal point
appears only if a digit follows it.)
Trailing zeros are removed.
o g or G
The result will always contain a
decimal point even if no digits follow
the point. Trailing zeros are not
removed.
o all others
Undefined.
o-
o-
o <[width]>
<[width]> is an optional minimum field width. You can
either specify it directly as a decimal integer, or
indirectly by using instead an asterisk (<<*>>), in
which case an <<int>> argument is used as the field
width. If positional arguments are used, then the
width must also be specified positionally as <<*m$>>,
with m as a decimal integer. Negative field widths
are treated as specifying the minus (<<->>) flag for
left justfication, along with a positive field width.
The resulting format may be wider than the specified
width.
o <[prec]>
<[prec]> is an optional field; if present, it is
introduced with `<<.>>' (a period). You can specify
the precision either directly as a decimal integer or
indirectly by using an asterisk (<<*>>), in which case
an <<int>> argument is used as the precision. If
positional arguments are used, then the precision must
also be specified positionally as <<*m$>>, with m as a
decimal integer. Supplying a negative precision is
equivalent to omitting the precision. If only a
period is specified the precision is zero. The effect
depends on the conversion <[type]>.
o+
o d, i, o, u, x, or X
Minimum number of digits to appear. If no
precision is given, defaults to 1.
o a or A
Number of digits to appear after the decimal
point. If no precision is given, the
precision defaults to the minimum needed for
an exact representation.
o e, E, f or F
Number of digits to appear after the decimal
point. If no precision is given, the
precision defaults to 6.
o g or G
Maximum number of significant digits. A
precision of 0 is treated the same as a
precision of 1. If no precision is given, the
precision defaults to 6.
o s or S
Maximum number of characters to print from the
string. If no precision is given, the entire
string is printed.
o all others
undefined.
o-
o <[size]>
<[size]> is an optional modifier that changes the data
type that the corresponding argument has. Behavior is
unspecified if a size is given that does not match the
<[type]>.
o+
o hh
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument should be
converted to a <<signed char>> or <<unsigned
char>> before printing.
With <<n>>, specifies that the argument is a
pointer to a <<signed char>>.
o h
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument should be
converted to a <<short>> or <<unsigned short>>
before printing.
With <<n>>, specifies that the argument is a
pointer to a <<short>>.
o l
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument is a
<<long>> or <<unsigned long>>.
With <<c>>, specifies that the argument has
type <<wint_t>>.
With <<s>>, specifies that the argument is a
pointer to <<wchar_t>>.
With <<n>>, specifies that the argument is a
pointer to a <<long>>.
With <<a>>, <<A>>, <<e>>, <<E>>, <<f>>, <<F>>,
<<g>>, or <<G>>, has no effect (because of
vararg promotion rules, there is no need to
distinguish between <<float>> and <<double>>).
o ll
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument is a
<<long long>> or <<unsigned long long>>.
With <<n>>, specifies that the argument is a
pointer to a <<long long>>.
o j
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument is an
<<intmax_t>> or <<uintmax_t>>.
With <<n>>, specifies that the argument is a
pointer to an <<intmax_t>>.
o z
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument is a
<<ssize_t>> or <<size_t>>.
With <<n>>, specifies that the argument is a
pointer to a <<ssize_t>>.
o t
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or
<<X>>, specifies that the argument is a
<<ptrdiff_t>>.
With <<n>>, specifies that the argument is a
pointer to a <<ptrdiff_t>>.
o L
With <<a>>, <<A>>, <<e>>, <<E>>, <<f>>, <<F>>,
<<g>>, or <<G>>, specifies that the argument
is a <<long double>>.
o-
o <[type]>
<[type]> specifies what kind of conversion <<wprintf>>
performs. Here is a table of these:
o+
o %
Prints the percent character (<<%>>).
o c
If no <<l>> qualifier is present, the int argument shall
be converted to a wide character as if by calling
the btowc() function and the resulting wide character
shall be written. Otherwise, the wint_t argument
shall be converted to wchar_t, and written.
o C
Short for <<%lc>>.
o s
If no <<l>> qualifier is present, the application
shall ensure that the argument is a pointer to a
character array containing a character sequence
beginning in the initial shift state. Characters
from the array shall be converted as if by repeated
calls to the mbrtowc() function, with the conversion
state described by an mbstate_t object initialized to
zero before the first character is converted, and
written up to (but not including) the terminating
null wide character. If the precision is specified,
no more than that many wide characters shall be
written. If the precision is not specified, or is
greater than the size of the array, the application
shall ensure that the array contains a null wide
character.
If an <<l>> qualifier is present, the application
shall ensure that the argument is a pointer to an
array of type wchar_t. Wide characters from the array
shall be written up to (but not including) a
terminating null wide character. If no precision is
specified, or is greater than the size of the array,
the application shall ensure that the array contains
a null wide character. If a precision is specified,
no more than that many wide characters shall be
written.
o S
Short for <<%ls>>.
o d or i
Prints a signed decimal integer; takes an
<<int>>. Leading zeros are inserted as
necessary to reach the precision. A precision
of 0 produces an empty string.
o o
Prints an unsigned octal integer; takes an
<<unsigned>>. Leading zeros are inserted as
necessary to reach the precision. A precision
of 0 produces an empty string.
o u
Prints an unsigned decimal integer; takes an
<<unsigned>>. Leading zeros are inserted as
necessary to reach the precision. A precision
of 0 produces an empty string.
o x
Prints an unsigned hexadecimal integer (using
<<abcdef>> as digits beyond <<9>>); takes an
<<unsigned>>. Leading zeros are inserted as
necessary to reach the precision. A precision
of 0 produces an empty string.
o X
Like <<x>>, but uses <<ABCDEF>> as digits
beyond <<9>>.
o f
Prints a signed value of the form
<<[-]9999.9999>>, with the precision
determining how many digits follow the decimal
point; takes a <<double>> (remember that
<<float>> promotes to <<double>> as a vararg).
The low order digit is rounded to even. If
the precision results in at most DECIMAL_DIG
digits, the result is rounded correctly; if
more than DECIMAL_DIG digits are printed, the
result is only guaranteed to round back to the
original value.
If the value is infinite, the result is
<<inf>>, and no zero padding is performed. If
the value is not a number, the result is
<<nan>>, and no zero padding is performed.
o F
Like <<f>>, but uses <<INF>> and <<NAN>> for
non-finite numbers.
o e
Prints a signed value of the form
<<[-]9.9999e[+|-]999>>; takes a <<double>>.
The digit before the decimal point is non-zero
if the value is non-zero. The precision
determines how many digits appear between
<<.>> and <<e>>, and the exponent always
contains at least two digits. The value zero
has an exponent of zero. If the value is not
finite, it is printed like <<f>>.
o E
Like <<e>>, but using <<E>> to introduce the
exponent, and like <<F>> for non-finite
values.
o g
Prints a signed value in either <<f>> or <<e>>
form, based on the given value and
precision---an exponent less than -4 or
greater than the precision selects the <<e>>
form. Trailing zeros and the decimal point
are printed only if necessary; takes a
<<double>>.
o G
Like <<g>>, except use <<F>> or <<E>> form.
o a
Prints a signed value of the form
<<[-]0x1.ffffp[+|-]9>>; takes a <<double>>.
The letters <<abcdef>> are used for digits
beyond <<9>>. The precision determines how
many digits appear after the decimal point.
The exponent contains at least one digit, and
is a decimal value representing the power of
2; a value of 0 has an exponent of 0.
Non-finite values are printed like <<f>>.
o A
Like <<a>>, except uses <<X>>, <<P>>, and
<<ABCDEF>> instead of lower case.
o n
Takes a pointer to <<int>>, and stores a count
of the number of bytes written so far. No
output is created.
o p
Takes a pointer to <<void>>, and prints it in
an implementation-defined format. This
implementation is similar to <<%#tx>>), except
that <<0x>> appears even for the NULL pointer.
o-
O-
<<_wprintf_r>>, <<_fwprintf_r>>, <<_swprintf_r>>, are simply
reentrant versions of the functions above.
RETURNS
On success, <<swprintf>> return the number of wide characters in
the output string, except the concluding <<NUL>> is not counted.
<<wprintf>> and <<fwprintf>> return the number of characters transmitted.
If an error occurs, the result of <<wprintf>>, <<fwprintf>>, and
<<swprintf>> is a negative value. For <<wprintf>> and <<fwprintf>>,
<<errno>> may be set according to <<fputwc>>. For <<snwprintf>>, <<errno>>
may be set to EOVERFLOW if <[size]> or the output length exceeds
INT_MAX / sizeof (wchar_t).
PORTABILITY
POSIX-1.2008
Depending on how newlib was configured, not all format specifiers are
supported.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include "local.h"
int
_DEFUN(_swprintf_r, (ptr, str, size, fmt),
struct _reent *ptr _AND
wchar_t *str _AND
size_t size _AND
_CONST wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
FILE f;
if (size > INT_MAX / sizeof (wchar_t))
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0);
f._file = -1; /* No file. */
va_start (ap, fmt);
ret = _svfwprintf_r (ptr, &f, fmt, ap);
va_end (ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return (ret);
}
#ifndef _REENT_ONLY
int
_DEFUN(swprintf, (str, size, fmt),
wchar_t *str _AND
size_t size _AND
_CONST wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
FILE f;
struct _reent *ptr = _REENT;
if (size > INT_MAX / sizeof (wchar_t))
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0);
f._file = -1; /* No file. */
va_start (ap, fmt);
ret = _svfwprintf_r (ptr, &f, fmt, ap);
va_end (ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return (ret);
}
#endif

View File

@ -177,8 +177,18 @@ static char *rcsid = "$Id$";
#endif
#ifdef STRING_ONLY
static int
_DEFUN(__sprint_r, (ptr, fp, uio),
#define __SPRINT __ssprint_r
#else
#define __SPRINT __sprint_r
#endif
/* The __sprint_r/__ssprint_r functions are shared between all versions of
vfprintf and vfwprintf. They must only be defined once, which we do in
the INTEGER_ONLY versions here. */
#ifdef STRING_ONLY
#ifdef INTEGER_ONLY
int
_DEFUN(__ssprint_r, (ptr, fp, uio),
struct _reent *ptr _AND
FILE *fp _AND
register struct __suio *uio)
@ -268,29 +278,51 @@ err:
uio->uio_iovcnt = 0;
return EOF;
}
#endif /* INTEGER_ONLY */
#else /* !STRING_ONLY */
#ifdef INTEGER_ONLY
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
*/
static int
int
_DEFUN(__sprint_r, (ptr, fp, uio),
struct _reent *ptr _AND
FILE *fp _AND
register struct __suio *uio)
{
register int err;
register int err = 0;
if (uio->uio_resid == 0) {
uio->uio_iovcnt = 0;
return (0);
}
err = __sfvwrite_r(ptr, fp, uio);
if (fp->_flags2 & __SWID) {
struct __siov *iov;
wchar_t *p;
int i, len;
iov = uio->uio_iov;
for (; uio->uio_resid != 0;
uio->uio_resid -= len * sizeof (wchar_t), iov++) {
p = (wchar_t *) iov->iov_base;
len = iov->iov_len / sizeof (wchar_t);
for (i = 0; i < len; i++) {
if (_fputwc_r (ptr, p[i], fp) == WEOF) {
err = -1;
goto out;
}
}
}
} else
err = __sfvwrite_r(ptr, fp, uio);
out:
uio->uio_resid = 0;
uio->uio_iovcnt = 0;
return (err);
}
#endif /* INTEGER_ONLY */
/*
* Helper function for `fprintf to unbuffered unix file': creates a
@ -310,6 +342,7 @@ _DEFUN(__sbprintf, (rptr, fp, fmt, ap),
/* copy the important variables */
fake._flags = fp->_flags & ~__SNBF;
fake._flags2 = fp->_flags2;
fake._file = fp->_file;
fake._cookie = fp->_cookie;
fake._write = fp->_write;
@ -564,7 +597,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
uio.uio_resid += (len); \
iovp++; \
if (++uio.uio_iovcnt >= NIOV) { \
if (__sprint_r(data, fp, &uio)) \
if (__SPRINT(data, fp, &uio)) \
goto error; \
iovp = iov; \
} \
@ -579,7 +612,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
} \
}
#define FLUSH() { \
if (uio.uio_resid && __sprint_r(data, fp, &uio)) \
if (uio.uio_resid && __SPRINT(data, fp, &uio)) \
goto error; \
uio.uio_iovcnt = 0; \
iovp = iov; \
@ -1642,48 +1675,12 @@ exponent(char *p0, int exp, int fmtch)
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
typedef enum {
ZERO, /* '0' */
DIGIT, /* '1-9' */
DOLLAR, /* '$' */
MODFR, /* spec modifier */
SPEC, /* format specifier */
DOT, /* '.' */
STAR, /* '*' */
FLAG, /* format flag */
OTHER, /* all other chars */
MAX_CH_CLASS /* place-holder */
} CH_CLASS;
/* The below constant state tables are shared between all versions of
vfprintf and vfwprintf. They must only be defined once, which we do in
the STRING_ONLY/INTEGER_ONLY versions here. */
#if defined (STRING_ONLY) && defined(INTEGER_ONLY)
typedef enum {
START, /* start */
SFLAG, /* seen a flag */
WDIG, /* seen digits in width area */
WIDTH, /* processed width */
SMOD, /* seen spec modifier */
SDOT, /* seen dot */
VARW, /* have variable width specifier */
VARP, /* have variable precision specifier */
PREC, /* processed precision */
VWDIG, /* have digits in variable width specification */
VPDIG, /* have digits in variable precision specification */
DONE, /* done */
MAX_STATE, /* place-holder */
} STATE;
typedef enum {
NOOP, /* do nothing */
NUMBER, /* build a number from digits */
SKIPNUM, /* skip over digits */
GETMOD, /* get and process format modifier */
GETARG, /* get and process argument */
GETPW, /* get variable precision or width */
GETPWB, /* get variable precision or width and pushback fmt char */
GETPOS, /* get positional parameter value */
PWPOS, /* get positional parameter value for variable width or precision */
} ACTION;
_CONST static CH_CLASS chclass[256] = {
_CONST __CH_CLASS __chclass[256] = {
/* 00-07 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
/* 08-0f */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
/* 10-17 */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
@ -1718,7 +1715,7 @@ _CONST static CH_CLASS chclass[256] = {
/* f8-ff */ OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
};
_CONST static STATE state_table[MAX_STATE][MAX_CH_CLASS] = {
_CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS] = {
/* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
/* START */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
/* SFLAG */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
@ -1733,7 +1730,7 @@ _CONST static STATE state_table[MAX_STATE][MAX_CH_CLASS] = {
/* VPDIG */ { DONE, DONE, PREC, DONE, DONE, DONE, DONE, DONE, DONE },
};
_CONST static ACTION action_table[MAX_STATE][MAX_CH_CLASS] = {
_CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS] = {
/* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
/* START */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
/* SFLAG */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
@ -1748,6 +1745,8 @@ _CONST static ACTION action_table[MAX_STATE][MAX_CH_CLASS] = {
/* VPDIG */ { NOOP, NOOP, PWPOS, NOOP, NOOP, NOOP, NOOP, NOOP, NOOP },
};
#endif /* STRING_ONLY && INTEGER_ONLY */
/* function to get positional parameter N where n = N - 1 */
static union arg_val *
_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
@ -1764,9 +1763,9 @@ _DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
int number, flags;
int spec_type;
int numargs = *numargs_p;
CH_CLASS chtype;
STATE state, next_state;
ACTION action;
__CH_CLASS chtype;
__STATE state, next_state;
__ACTION action;
int pos, last_arg;
int max_pos_arg = n;
/* Only need types that can be reached via vararg promotions. */
@ -1818,9 +1817,9 @@ _DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
while (state != DONE)
{
ch = *fmt++;
chtype = chclass[ch];
next_state = state_table[state][chtype];
action = action_table[state][chtype];
chtype = __chclass[ch];
next_state = __state_table[state][chtype];
action = __action_table[state][chtype];
state = next_state;
switch (action)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in vfwprintf.c */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <wchar.h>
#include <limits.h>
#include <stdarg.h>
#include <errno.h>
int
_DEFUN(_vswprintf_r, (ptr, str, size, fmt, ap),
struct _reent *ptr _AND
wchar_t *str _AND
size_t size _AND
const wchar_t *fmt _AND
va_list ap)
{
int ret;
FILE f;
if (size > INT_MAX / sizeof (wchar_t))
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0);
f._file = -1; /* No file. */
ret = _svfwprintf_r (ptr, &f, fmt, ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return ret;
}
#ifndef _REENT_ONLY
int
_DEFUN(vswprintf, (str, size, fmt, ap),
wchar_t *str _AND
size_t size _AND
const wchar_t *fmt _AND
va_list ap)
{
return _vswprintf_r (_REENT, str, size, fmt, ap);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in vfwprintf.c */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vwprintf, (fmt, ap),
_CONST wchar_t *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (_REENT);
return _vfwprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_vwprintf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST wchar_t *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in swprintf.c */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
#include "local.h"
int
_DEFUN(_wprintf_r, (ptr, fmt),
struct _reent *ptr _AND
const wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
#ifndef _REENT_ONLY
int
_DEFUN(wprintf, (fmt),
const wchar_t *fmt _DOTS)
{
int ret;
va_list ap;
struct _reent *ptr = _REENT;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
#endif /* ! _REENT_ONLY */