Loading...
stdio/FreeBSD/vfwprintf.c.patch Libc-763.11 Libc-320.1.3
--- Libc/Libc-763.11/stdio/FreeBSD/vfwprintf.c.patch
+++ Libc/Libc-320.1.3/stdio/FreeBSD/vfwprintf.c.patch
@@ -1,15 +1,6 @@
---- vfwprintf.c.orig	2010-07-15 10:03:36.000000000 -0700
-+++ vfwprintf.c	2010-07-15 10:49:02.000000000 -0700
-@@ -38,6 +38,8 @@ static char sccsid[] = "@(#)vfprintf.c	8
- #include <sys/cdefs.h>
- __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.42 2009/11/25 04:27:55 wollman Exp $");
- 
-+#include "xlocale_private.h"
-+
- /*
-  * Actual wprintf innards.
-  *
-@@ -59,6 +61,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
+--- vfwprintf.c.orig	Tue Apr  6 17:39:47 2004
++++ vfwprintf.c	Tue Apr  6 17:46:51 2004
+@@ -64,15 +64,27 @@
  #include <string.h>
  #include <wchar.h>
  #include <wctype.h>
@@ -17,246 +8,133 @@
  #include "un-namespace.h"
  
  #include "libc_private.h"
-@@ -66,10 +69,11 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
+ #include "local.h"
  #include "fvwrite.h"
- #include "printflocal.h"
- 
--static int	__sprint(FILE *, struct __suio *);
--static int	__sbprintf(FILE *, const wchar_t *, va_list) __noinline;
--static wint_t	__xfputwc(wchar_t, FILE *);
--static wchar_t	*__mbsconv(char *, int);
-+static int	__sprint(FILE *, locale_t, struct __suio *);
-+static int	__sbprintf(FILE *, locale_t, const wchar_t *, va_list);
-+static wint_t	__xfputwc(wchar_t, FILE *, locale_t);
-+static wchar_t	*__mbsconv(char *, int, locale_t);
-+__private_extern__ const char *__fix_nogrouping(const char *);
- 
- #define	CHAR	wchar_t
- #include "printfcommon.h"
-@@ -85,29 +89,29 @@ struct grouping_state {
- static const mbstate_t initial_mbs;
- 
- static inline wchar_t
--get_decpt(void)
-+get_decpt(locale_t loc)
- {
- 	mbstate_t mbs;
- 	wchar_t decpt;
- 	int nconv;
- 
- 	mbs = initial_mbs;
--	nconv = mbrtowc(&decpt, localeconv()->decimal_point, MB_CUR_MAX, &mbs);
-+	nconv = mbrtowc_l(&decpt, localeconv_l(loc)->decimal_point, MB_CUR_MAX_L(loc), &mbs, loc);
- 	if (nconv == (size_t)-1 || nconv == (size_t)-2)
- 		decpt = '.';    /* failsafe */
- 	return (decpt);
- }
- 
- static inline wchar_t
--get_thousep(void)
-+get_thousep(locale_t loc)
- {
- 	mbstate_t mbs;
- 	wchar_t thousep;
- 	int nconv;
- 
- 	mbs = initial_mbs;
--	nconv = mbrtowc(&thousep, localeconv()->thousands_sep,
--	    MB_CUR_MAX, &mbs);
-+	nconv = mbrtowc_l(&thousep, localeconv_l(loc)->thousands_sep,
-+	    MB_CUR_MAX_L(loc), &mbs, loc);
- 	if (nconv == (size_t)-1 || nconv == (size_t)-2)
- 		thousep = '\0';    /* failsafe */
- 	return (thousep);
-@@ -119,11 +123,11 @@ get_thousep(void)
-  * of wide characters that will be printed.
-  */
- static int
--grouping_init(struct grouping_state *gs, int ndigits)
-+grouping_init(struct grouping_state *gs, int ndigits, locale_t loc)
- {
- 
--	gs->grouping = localeconv()->grouping;
--	gs->thousands_sep = get_thousep();
-+	gs->grouping = __fix_nogrouping(localeconv_l(loc)->grouping);
-+	gs->thousands_sep = get_thousep(loc);
- 
- 	gs->nseps = gs->nrepeats = 0;
- 	gs->lead = ndigits;
-@@ -145,11 +149,11 @@ grouping_init(struct grouping_state *gs,
-  */
- static int
- grouping_print(struct grouping_state *gs, struct io_state *iop,
--	       const CHAR *cp, const CHAR *ep)
-+	       const CHAR *cp, const CHAR *ep, locale_t loc)
- {
- 	const CHAR *cp0 = cp;
- 
--	if (io_printandpad(iop, cp, ep, gs->lead, zeroes))
-+	if (io_printandpad(iop, cp, ep, gs->lead, zeroes, loc))
- 		return (-1);
- 	cp += gs->lead;
- 	while (gs->nseps > 0 || gs->nrepeats > 0) {
-@@ -159,9 +163,9 @@ grouping_print(struct grouping_state *gs
- 			gs->grouping--;
- 			gs->nseps--;
- 		}
--		if (io_print(iop, &gs->thousands_sep, 1))
-+		if (io_print(iop, &gs->thousands_sep, 1, loc))
- 			return (-1);
--		if (io_printandpad(iop, cp, ep, *gs->grouping, zeroes))
-+		if (io_printandpad(iop, cp, ep, *gs->grouping, zeroes, loc))
- 			return (-1);
- 		cp += *gs->grouping;
- 	}
-@@ -180,7 +184,7 @@ grouping_print(struct grouping_state *gs
-  * string eclipses the benefits of buffering.
-  */
- static int
--__sprint(FILE *fp, struct __suio *uio)
-+__sprint(FILE *fp, locale_t loc, struct __suio *uio)
- {
- 	struct __siov *iov;
- 	wchar_t *p;
-@@ -191,7 +195,7 @@ __sprint(FILE *fp, struct __suio *uio)
- 		p = (wchar_t *)iov->iov_base;
- 		len = iov->iov_len;
- 		for (i = 0; i < len; i++) {
--			if (__xfputwc(p[i], fp) == WEOF)
-+			if (__xfputwc(p[i], fp, loc) == WEOF)
- 				return (-1);
- 		}
- 	}
-@@ -205,11 +209,14 @@ __sprint(FILE *fp, struct __suio *uio)
-  * worries about ungetc buffers and so forth.
-  */
- static int
--__sbprintf(FILE *fp, const wchar_t *fmt, va_list ap)
-+__sbprintf(FILE *fp, locale_t loc, const wchar_t *fmt, va_list ap)
- {
- 	int ret;
- 	FILE fake;
- 	unsigned char buf[BUFSIZ];
-+	struct __sFILEX ext;
-+	fake._extra = &ext;
-+	INITEXTRA(&fake);
- 
- 	/* XXX This is probably not needed. */
- 	if (prepwrite(fp) != 0)
-@@ -229,7 +236,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
- 	fake._lbfsize = 0;	/* not actually used, but Just In Case */
- 
- 	/* do the work, then copy any error status */
--	ret = __vfwprintf(&fake, fmt, ap);
-+	ret = __vfwprintf(&fake, loc, fmt, ap);
- 	if (ret >= 0 && __fflush(&fake))
- 		ret = WEOF;
- 	if (fake._flags & __SERR)
-@@ -242,7 +249,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
-  * File must already be locked.
-  */
- static wint_t
--__xfputwc(wchar_t wc, FILE *fp)
-+__xfputwc(wchar_t wc, FILE *fp, locale_t loc)
- {
- 	mbstate_t mbs;
- 	char buf[MB_LEN_MAX];
-@@ -251,10 +258,10 @@ __xfputwc(wchar_t wc, FILE *fp)
- 	size_t len;
- 
- 	if ((fp->_flags & __SSTR) == 0)
--		return (__fputwc(wc, fp));
-+		return (__fputwc(wc, fp, loc));
- 
- 	mbs = initial_mbs;
--	if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
-+	if ((len = wcrtomb_l(buf, wc, &mbs, loc)) == (size_t)-1) {
- 		fp->_flags |= __SERR;
- 		return (WEOF);
- 	}
-@@ -273,12 +280,13 @@ __xfputwc(wchar_t wc, FILE *fp)
-  * that the multibyte char. string ends in a null character.
-  */
- static wchar_t *
--__mbsconv(char *mbsarg, int prec)
-+__mbsconv(char *mbsarg, int prec, locale_t loc)
- {
- 	mbstate_t mbs;
- 	wchar_t *convbuf, *wcp;
- 	const char *p;
--	size_t insize, nchars, nconv;
-+	size_t insize, nchars, nconv = 0;
-+	int mb_cur_max = MB_CUR_MAX_L(loc);
- 
- 	if (mbsarg == NULL)
- 		return (NULL);
-@@ -296,7 +304,7 @@ __mbsconv(char *mbsarg, int prec)
- 		insize = nchars = nconv = 0;
- 		mbs = initial_mbs;
- 		while (nchars != (size_t)prec) {
--			nconv = mbrlen(p, MB_CUR_MAX, &mbs);
-+			nconv = mbrlen_l(p, mb_cur_max, &mbs, loc);
- 			if (nconv == 0 || nconv == (size_t)-1 ||
- 			    nconv == (size_t)-2)
- 				break;
-@@ -323,7 +331,7 @@ __mbsconv(char *mbsarg, int prec)
- 	p = mbsarg;
- 	mbs = initial_mbs;
- 	while (insize != 0) {
--		nconv = mbrtowc(wcp, p, insize, &mbs);
-+		nconv = mbrtowc_l(wcp, p, insize, &mbs, loc);
- 		if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
- 			break;
- 		wcp++;
-@@ -343,22 +351,28 @@ __mbsconv(char *mbsarg, int prec)
-  * MT-safe version
-  */
- int
--vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
--
-+vfwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt0, va_list ap)
- {
- 	int ret;
- 
-+	NORMALIZE_LOCALE(loc);
- 	FLOCKFILE(fp);
- 	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
- 	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
- 	    fp->_file >= 0)
--		ret = __sbprintf(fp, fmt0, ap);
-+		ret = __sbprintf(fp, loc, fmt0, ap);
- 	else
--		ret = __vfwprintf(fp, fmt0, ap);
-+		ret = __vfwprintf(fp, loc, fmt0, ap);
- 	FUNLOCKFILE(fp);
- 	return (ret);
- }
- 
-+int
-+vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
+ 
++#ifdef ALTIVEC
++#include <machine/cpu_capabilities.h>
++
++#define VECTORTYPE	vector unsigned char
++#endif /* ALTIVEC */
++
+ /* Define FLOATING_POINT to get floating point. */
+ #define	FLOATING_POINT
+ 
++/* if no floating point, turn off HEXFLOAT as well */
++#if defined(HEXFLOAT) && !defined(FLOATING_POINT)
++#undef HEXFLOAT
++#endif /* defined(HEXFLOAT) && !defined(FLOATING_POINT) */
++
+ union arg {
+ 	int	intarg;
+ 	u_int	uintarg;
+@@ -92,7 +104,7 @@
+ 	long	*plongarg;
+ 	long long *plonglongarg;
+ 	ptrdiff_t *pptrdiffarg;
+-	size_t	*psizearg;
++	ssize_t	*psizearg;
+ 	intmax_t *pintmaxarg;
+ #ifdef FLOATING_POINT
+ 	double	doublearg;
+@@ -100,6 +112,16 @@
+ #endif
+ 	wint_t	wintarg;
+ 	wchar_t	*pwchararg;
++#ifdef ALTIVEC
++	VECTORTYPE		vectorarg;
++	unsigned char		vuchararg[16];
++	signed char		vchararg[16];
++	unsigned short		vushortarg[8];
++	signed short		vshortarg[8];
++	unsigned int		vuintarg[4];
++	signed int		vintarg[4];
++	float			vfloatarg[4];
++#endif /* ALTIVEC */
+ };
+ 
+ /*
+@@ -110,7 +132,11 @@
+ 	T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
+ 	T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
+ 	T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
++#ifdef ALTIVEC
++	T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR, T_VECTOR
++#else /* ! ALTIVEC */
+ 	T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
++#endif /* ALTIVEC */
+ };
+ 
+ static int	__sbprintf(FILE *, const wchar_t *, va_list);
+@@ -123,6 +149,37 @@
+ static void	__find_arguments(const wchar_t *, va_list, union arg **);
+ static void	__grow_type_table(int, enum typeid **, int *);
+ 
++	/*
++	 * Get the argument indexed by nextarg.   If the argument table is
++	 * built, use it to get the argument.  If its not, get the next
++	 * argument (and arguments must be gotten sequentially).
++	 */
++#define GETARG(type) \
++	((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \
++	    (nextarg++, va_arg(ap, type)))
++
++#ifdef ALTIVEC
++#define hasAltivec	(_cpu_capabilities & kHasAltivec)
++/*-----------------------------------------------------------------------
++ * getvec() must be a real subroutine.  If it is a #define, then __vfprintf()
++ * would have its calling sequence changed by Altivec so that a non-Altivec
++ * processor would crash on illegal instruction.  By isolating the calling
++ * sequence in getvec(), __vprintf() is callable by a non-Altivec processor.
++ *-----------------------------------------------------------------------*/
++static va_list
++getvec(union arg *dst, const union arg *argtable, int nextarg, va_list ap)
 +{
-+	return vfwprintf_l(fp, __current_locale(), fmt0, ap);
++	dst->vectorarg = GETARG(VECTORTYPE);
++	return ap;
 +}
++
++#define SETVEC(dst)	\
++{ \
++	ap = getvec(&dst, argtable, nextarg, ap); \
++	nextarg++; \
++}
++#endif /* ALTIVEC */
++
+ /*
+  * Helper function for `fprintf to unbuffered unix file': creates a
+  * temporary buffer.  We only work on write-only files; this avoids
+@@ -444,6 +501,15 @@
+ 
+ #endif /* FLOATING_POINT */
+ 
++#ifdef HEXFLOAT
++extern int __hdtoa(double d, const char *xdigs, int prec, char *cp,
++    int *expt, int *signflag, char **dtoaend);
++#if !__TYPE_LONGDOUBLE_IS_DOUBLE
++extern int __hldtoa(long double d, const char *xdigs, int prec, char *cp,
++    int *expt, int *signflag, char **dtoaend);
++#endif /* !__TYPE_LONGDOUBLE_IS_DOUBLE */
++#endif /* HEXFLOAT */
 +
  /*
   * The size of the buffer we use as scratch space for integer
-  * conversions, among other things.  We need enough space to
-@@ -373,8 +387,8 @@ vfwprintf(FILE * __restrict fp, const wc
+  * conversions, among other things.  Technically, we would need the
+@@ -472,6 +538,9 @@
+ #define	PTRDIFFT	0x800		/* ptrdiff_t */
+ #define	INTMAXT		0x1000		/* intmax_t */
+ #define	CHARINT		0x2000		/* print char using int format */
++#ifdef ALTIVEC
++#define	VECTOR		0x4000		/* Altivec vector */
++#endif /* ALTIVEC */
+ 
  /*
   * Non-MT-safe version
-  */
--int
--__vfwprintf(FILE *fp, const wchar_t *fmt0, va_list ap)
-+__private_extern__ int
-+__vfwprintf(FILE *fp, locale_t loc, const wchar_t *fmt0, va_list ap)
- {
- 	wchar_t *fmt;		/* format string */
- 	wchar_t ch;		/* character from fmt */
-@@ -415,6 +429,11 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 	wchar_t expstr[MAXEXPDIG+2];	/* buffer for exponent string: e+ZZZ */
- 	char *dtoaresult;	/* buffer allocated by dtoa */
+@@ -522,6 +591,11 @@
+ 	int nseps;		/* number of group separators with ' */
+ 	int nrepeats;		/* number of repeats of the last group */
  #endif
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +	union arg vval;		/* Vector argument. */
 +	wchar_t *pct;		/* Pointer to '%' at beginning of specifier. */
 +	wchar_t vsep;		/* Vector separator character. */
@@ -264,365 +142,342 @@
  	u_long	ulval;		/* integer arguments %[diouxX] */
  	uintmax_t ujval;	/* %j, %ll, %q, %t, %z integers */
  	int base;		/* base for [diouxX] conversion */
-@@ -437,19 +456,19 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 
- 	/* BEWARE, these `goto error' on error. */
- #define	PRINT(ptr, len)	do {			\
--	if (io_print(&io, (ptr), (len)))	\
-+	if (io_print(&io, (ptr), (len), loc))	\
- 		goto error; \
- } while (0)
- #define	PAD(howmany, with) { \
--	if (io_pad(&io, (howmany), (with))) \
-+	if (io_pad(&io, (howmany), (with), loc)) \
- 		goto error; \
- }
- #define	PRINTANDPAD(p, ep, len, with) {	\
--	if (io_printandpad(&io, (p), (ep), (len), (with))) \
-+	if (io_printandpad(&io, (p), (ep), (len), (with), loc)) \
- 		goto error; \
- }
- #define	FLUSH() { \
--	if (io_flush(&io)) \
-+	if (io_flush(&io, loc)) \
- 		goto error; \
- }
- 
-@@ -485,7 +504,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- #define	UJARG() \
- 	(flags&INTMAXT ? GETARG(uintmax_t) : \
- 	    flags&SIZET ? (uintmax_t)GETARG(size_t) : \
--	    flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
-+	    flags&PTRDIFFT ? (uintmax_t)(unsigned long)GETARG(ptrdiff_t) : \
- 	    (uintmax_t)GETARG(unsigned long long))
+@@ -551,6 +625,15 @@
+ 
+ 	static const wchar_t xdigs_lower[16] = L"0123456789abcdef";
+ 	static const wchar_t xdigs_upper[16] = L"0123456789ABCDEF";
++#ifdef HEXFLOAT
++#define HEXFLOATDELTA	32
++#define HEXFLOATSTART	32
++	static char *hexfloat = NULL;
++	static int hexfloatlen = 0;
++	const char *xdigs0;	/* digits for [aA] conversion */
++	static const char xdigs_lower0[16] = "0123456789abcdef";
++	static const char xdigs_upper0[16] = "0123456789ABCDEF";
++#endif /* HEXFLOAT */
  
  	/*
-@@ -518,8 +537,11 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 
- 
+ 	 * BEWARE, these `goto error' on error, PRINT uses `n2' and
+@@ -579,15 +662,6 @@
+ } while(0)
+ 
+ 	/*
+-	 * Get the argument indexed by nextarg.   If the argument table is
+-	 * built, use it to get the argument.  If its not, get the next
+-	 * argument (and arguments must be gotten sequentially).
+-	 */
+-#define GETARG(type) \
+-	((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \
+-	    (nextarg++, va_arg(ap, type)))
+-
+-	/*
+ 	 * To extend shorts properly, we need both signed and unsigned
+ 	 * argument extraction methods.
+ 	 */
+@@ -638,7 +712,6 @@
+ 		val = GETARG (int); \
+ 	}
+ 
+-
+ 	thousands_sep = '\0';
+ 	grouping = NULL;
+ #ifdef FLOATING_POINT
+@@ -646,8 +719,10 @@
+ #endif
+ 	convbuf = NULL;
  	/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
--	if (prepwrite(fp) != 0)
-+	if (prepwrite(fp) != 0) {
+-	if (cantwrite(fp))
++	if (cantwrite(fp)) {
 +		errno = EBADF;
  		return (EOF);
 +	}
-+	ORIENT(fp, 1);
- 
- 	convbuf = NULL;
- 	fmt = (wchar_t *)fmt0;
-@@ -529,7 +551,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 	io_init(&io, fp);
- 	ret = 0;
- #ifndef NO_FLOATING_POINT
--	decimal_point = get_decpt();
-+	decimal_point = get_decpt(loc);
- #endif
- 
- 	/*
-@@ -548,6 +570,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
+ 
+ 	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
+ 	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+@@ -676,6 +751,9 @@
  		}
  		if (ch == '\0')
  			goto done;
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +		pct = fmt;
-+#endif /* VECTORS */
++#endif /* ALTIVEC */
  		fmt++;		/* skip over '%' */
  
  		flags = 0;
-@@ -557,6 +582,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 		gs.grouping = NULL;
+@@ -684,6 +762,9 @@
+ 		prec = -1;
  		sign = '\0';
  		ox[1] = '\0';
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +		vsep = 'X'; /* Illegal value, changed to defaults later. */
-+#endif /* VECTORS */
++#endif /* ALTIVEC */
  
  rflag:		ch = *fmt++;
  reswitch:	switch (ch) {
-@@ -572,6 +600,11 @@ reswitch:	switch (ch) {
+@@ -699,6 +780,11 @@
  		case '#':
  			flags |= ALT;
  			goto rflag;
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +		case ',': case ';': case ':': case '_':
 +			vsep = ch;
 +			goto rflag;
-+#endif /* VECTORS */
++#endif /* ALTIVEC */
  		case '*':
  			/*-
  			 * ``A negative field width argument is taken as a
-@@ -668,10 +701,14 @@ reswitch:	switch (ch) {
- 			flags |= LONGINT;
- 			/*FALLTHROUGH*/
+@@ -796,8 +882,18 @@
  		case 'c':
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
  			if (flags & LONGINT)
  				*(cp = buf) = (wchar_t)GETARG(wint_t);
++#ifdef ALTIVEC
++			else {
++				if (flags & VECTOR) {
++					SETVEC(vval);
++					break;
++				}
++				*(cp = buf) = (wchar_t)btowc(GETARG(int));
++			}
++#else /* ALTIVEC */
  			else
--				*(cp = buf) = (wchar_t)btowc(GETARG(int));
-+				*(cp = buf) = (wchar_t)btowc_l(GETARG(int), loc);
+ 				*(cp = buf) = (wchar_t)btowc(GETARG(int));
++#endif /* ALTIVEC */
  			size = 1;
  			sign = '\0';
  			break;
-@@ -680,6 +717,10 @@ reswitch:	switch (ch) {
+@@ -806,6 +902,12 @@
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
++#ifdef ALTIVEC
++			if (flags & VECTOR) {
++				SETVEC(vval);
++				break;
++			} else
++#endif /* ALTIVEC */
  			if (flags & INTMAX_SIZE) {
  				ujval = SJARG();
  				if ((intmax_t)ujval < 0) {
-@@ -698,6 +739,12 @@ reswitch:	switch (ch) {
- #ifndef NO_FLOATING_POINT
+@@ -825,38 +927,74 @@
+ #ifdef HEXFLOAT
  		case 'a':
  		case 'A':
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +			if (flags & VECTOR) {
 +				flags |= FPT;
-+				break;
-+			}
-+#endif /* VECTORS */
++				SETVEC(vval);
++				break;
++			}
++#endif /* ALTIVEC */
  			if (ch == 'a') {
  				ox[1] = 'x';
- 				xdigs = xdigs_lower;
-@@ -709,6 +756,12 @@ reswitch:	switch (ch) {
+-				xdigs = xdigs_lower;
++				xdigs0 = xdigs_lower0;
+ 				expchar = 'p';
+ 			} else {
+ 				ox[1] = 'X';
+-				xdigs = xdigs_upper;
++				xdigs0 = xdigs_upper0;
+ 				expchar = 'P';
  			}
- 			if (prec >= 0)
- 				prec++;
-+#ifdef LDBL_COMPAT
-+			fparg.dbl = GETARG(double);
-+			dtoaresult =
-+			    __hdtoa(fparg.dbl, xdigs, prec,
-+				&expt, &signflag, &dtoaend);
-+#else /* !LDBL_COMPAT */
+-			/*
+-			 * XXX We don't actually have a conversion
+-			 * XXX routine for this yet.
+-			 */
++			if (!hexfloat) {
++				hexfloat = malloc(hexfloatlen = HEXFLOATSTART);
++				if (!hexfloat)
++					goto error;
++			}
++			/* one extra for integer part and another for null */
++			if (prec > hexfloatlen - 2) {
++				int hlen = prec + HEXFLOATDELTA;
++				char *hf = realloc(hexfloat, hlen);
++				if (hf == NULL)
++					goto error;
++				hexfloat = hf;
++				hexfloatlen = hlen;
++			}
  			if (flags & LONGDBL) {
- 				fparg.ldbl = GETARG(long double);
- 				dtoaresult =
-@@ -720,6 +773,7 @@ reswitch:	switch (ch) {
- 				    __hdtoa(fparg.dbl, xdigs, prec,
- 				        &expt, &signflag, &dtoaend);
+-				fparg.ldbl = (double)GETARG(long double);
+-				dtoaresult =
+-				    __hldtoa(fparg.ldbl, xdigs, prec,
+-				        &expt, &signflag, &dtoaend);
++#if __TYPE_LONGDOUBLE_IS_DOUBLE
++				fparg.dbl = (double)GETARG(long double);
++				prec = __hdtoa(fparg.dbl, xdigs0, prec,
++				    hexfloat, &expt, &signflag, &dtoaend);
++#else /* ! __TYPE_LONGDOUBLE_IS_DOUBLE */
++				fparg.ldbl = GETARG(long double);
++				prec = __hldtoa(fparg.ldbl, xdigs0, prec,
++				    hexfloat, &expt, &signflag, &dtoaend);
++#endif /* __TYPE_LONGDOUBLE_IS_DOUBLE */
+ 			} else {
+ 				fparg.dbl = GETARG(double);
+-				dtoaresult =
+-				    __hdtoa(fparg.dbl, xdigs, prec,
+-				        &expt, &signflag, &dtoaend);
++				prec = __hdtoa(fparg.dbl, xdigs0, prec,
++				    hexfloat, &expt, &signflag, &dtoaend);
++			}
++			prec++;
++			if (expt == INT_MAX) {
++				ox[1] = 0;
++				hexfloat[1] = 0;
++			} else {
++				expt++;
++				*dtoaend = 0;
++				ndig = dtoaend - hexfloat;
  			}
-+#endif /* LDBL_COMPAT */
- 			if (prec < 0)
- 				prec = dtoaend - dtoaresult;
- 			if (expt == INT_MAX)
-@@ -727,11 +781,17 @@ reswitch:	switch (ch) {
  			if (convbuf != NULL)
  				free(convbuf);
- 			ndig = dtoaend - dtoaresult;
 -			cp = convbuf = __mbsconv(dtoaresult, -1);
-+			cp = convbuf = __mbsconv(dtoaresult, -1, loc);
- 			freedtoa(dtoaresult);
- 			goto fp_common;
+-			freedtoa(dtoaresult);
+-			goto fp_begin;
++			cp = convbuf = __mbsconv(hexfloat, -1);
++			goto hex_begin;
+ #endif
  		case 'e':
  		case 'E':
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +			if (flags & VECTOR) {
 +				flags |= FPT;
-+				break;
-+			}
-+#endif /* VECTORS */
++				SETVEC(vval);
++				break;
++			}
++#endif /* ALTIVEC */
  			expchar = ch;
  			if (prec < 0)	/* account for digit before decpt */
  				prec = DEFPREC + 1;
-@@ -740,10 +800,22 @@ reswitch:	switch (ch) {
+@@ -865,10 +1003,24 @@
  			goto fp_begin;
  		case 'f':
  		case 'F':
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +			if (flags & VECTOR) {
 +				flags |= FPT;
-+				break;
-+			}
-+#endif /* VECTORS */
++				SETVEC(vval);
++				break;
++			}
++#endif /* ALTIVEC */
  			expchar = '\0';
  			goto fp_begin;
  		case 'g':
  		case 'G':
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +			if (flags & VECTOR) {
 +				flags |= FPT;
-+				break;
-+			}
-+#endif /* VECTORS */
++				SETVEC(vval);
++				break;
++			}
++#endif /* ALTIVEC */
  			expchar = ch - ('g' - 'e');
  			if (prec == 0)
  				prec = 1;
-@@ -752,6 +824,14 @@ fp_begin:
+@@ -877,6 +1029,17 @@
  				prec = DEFPREC;
  			if (convbuf != NULL)
  				free(convbuf);
-+#ifdef LDBL_COMPAT
-+			fparg.dbl = GETARG(double);
++#if __TYPE_LONGDOUBLE_IS_DOUBLE
++			if (flags & LONGDBL)
++				fparg.ldbl = GETARG(long double);
++			else
++				fparg.dbl = GETARG(double);
 +			dtoaresult =
 +			    dtoa(fparg.dbl, expchar ? 2 : 3, prec,
 +			    &expt, &signflag, &dtoaend);
 +			if (expt == 9999)
 +				expt = INT_MAX;
-+#else /* !LDBL_COMPAT */
++#else /* ! __TYPE_LONGDOUBLE_IS_DOUBLE */
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult =
-@@ -765,8 +845,9 @@ fp_begin:
+@@ -890,9 +1053,13 @@
  				if (expt == 9999)
  					expt = INT_MAX;
  			}
-+#endif /* LDBL_COMPAT */
++#endif /* __TYPE_LONGDOUBLE_IS_DOUBLE */
  			ndig = dtoaend - dtoaresult;
--			cp = convbuf = __mbsconv(dtoaresult, -1);
-+			cp = convbuf = __mbsconv(dtoaresult, -1, loc);
+ 			cp = convbuf = __mbsconv(dtoaresult, -1);
  			freedtoa(dtoaresult);
- fp_common:
++#ifdef HEXFLOAT
++hex_begin:
++#endif /* HEXFLOAT */
  			if (signflag)
-@@ -816,37 +897,46 @@ fp_common:
- 				if (prec || flags & ALT)
- 					size += prec + 1;
- 				if ((flags & GROUPING) && expt > 0)
--					size += grouping_init(&gs, expt);
-+					size += grouping_init(&gs, expt, loc);
- 			}
- 			break;
- #endif /* !NO_FLOATING_POINT */
- 		case 'n':
-+		{
- 			/*
- 			 * Assignment-like behavior is specified if the
- 			 * value overflows or is otherwise unrepresentable.
- 			 * C99 says to use `signed char' for %hhn conversions.
- 			 */
--			if (flags & LLONGINT)
--				*GETARG(long long *) = ret;
-+			void *ptr = GETARG(void *);
-+			if (ptr == NULL)
-+				continue;
-+			else if (flags & LLONGINT)
-+				*(long long *)ptr = ret;
- 			else if (flags & SIZET)
--				*GETARG(ssize_t *) = (ssize_t)ret;
-+				*(ssize_t *)ptr = (ssize_t)ret;
- 			else if (flags & PTRDIFFT)
--				*GETARG(ptrdiff_t *) = ret;
-+				*(ptrdiff_t *)ptr = ret;
- 			else if (flags & INTMAXT)
--				*GETARG(intmax_t *) = ret;
-+				*(intmax_t *)ptr = ret;
- 			else if (flags & LONGINT)
--				*GETARG(long *) = ret;
-+				*(long *)ptr = ret;
- 			else if (flags & SHORTINT)
--				*GETARG(short *) = ret;
-+				*(short *)ptr = ret;
- 			else if (flags & CHARINT)
--				*GETARG(signed char *) = ret;
-+				*(signed char *)ptr = ret;
- 			else
--				*GETARG(int *) = ret;
-+				*(int *)ptr = ret;
- 			continue;	/* no output */
-+		}
- 		case 'O':
+ 				sign = '-';
+ 			if (expt == INT_MAX) {	/* inf or nan */
+@@ -985,6 +1152,12 @@
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
++#ifdef ALTIVEC
++			if (flags & VECTOR) {
++				SETVEC(vval);
++				break;
++			} else
++#endif /* ALTIVEC */
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -861,6 +951,10 @@ fp_common:
+@@ -999,6 +1172,12 @@
  			 * defined manner.''
  			 *	-- ANSI X3J11
  			 */
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
++#ifdef ALTIVEC
++			if (flags & VECTOR) {
++				SETVEC(vval);
++				break;
++			}
++#endif /* ALTIVEC */
  			ujval = (uintmax_t)(uintptr_t)GETARG(void *);
  			base = 16;
  			xdigs = xdigs_lower;
-@@ -882,7 +976,7 @@ fp_common:
- 				if ((mbp = GETARG(char *)) == NULL)
- 					cp = L"(null)";
- 				else {
--					convbuf = __mbsconv(mbp, prec);
-+					convbuf = __mbsconv(mbp, prec, loc);
- 					if (convbuf == NULL) {
- 						fp->_flags |= __SERR;
- 						goto error;
-@@ -890,13 +984,23 @@ fp_common:
- 					cp = convbuf;
- 				}
- 			}
-+#if 0 // wcsnlen needs API review first
- 			size = (prec >= 0) ? wcsnlen(cp, prec) : wcslen(cp);
-+#else
-+			size = wcslen(cp);
-+			if(prec >= 0 && prec < size)
-+				size = prec;
-+#endif
- 			sign = '\0';
- 			break;
- 		case 'U':
+@@ -1051,6 +1230,12 @@
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'u':
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
++#ifdef ALTIVEC
++			if (flags & VECTOR) {
++				SETVEC(vval);
++				break;
++			} else
++#endif /* ALTIVEC */
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -909,6 +1013,10 @@ fp_common:
+@@ -1063,6 +1248,12 @@
  		case 'x':
  			xdigs = xdigs_lower;
  hex:
-+#ifdef VECTORS
-+			if (flags & VECTOR)
-+				break;
-+#endif /* VECTORS */
++#ifdef ALTIVEC
++			if (flags & VECTOR) {
++				SETVEC(vval);
++				break;
++			} else
++#endif /* ALTIVEC */
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -926,6 +1034,7 @@ nosign:			sign = '\0';
- 			 * ``... diouXx conversions ... if a precision is
- 			 * specified, the 0 flag will be ignored.''
- 			 *	-- ANSI X3J11
-+			 * except for %#.0o and zero value
- 			 */
- number:			if ((dprec = prec) >= 0)
- 				flags &= ~ZEROPAD;
-@@ -953,10 +1062,15 @@ number:			if ((dprec = prec) >= 0)
- 			}
- 			size = buf + BUF - cp;
+@@ -1107,6 +1298,14 @@
  			if (size > BUF)	/* should never happen */
--				abort();
-+				LIBC_ABORT("size (%d) > BUF (%d)", size, BUF);
- 			if ((flags & GROUPING) && size != 0)
--				size += grouping_init(&gs, size);
-+				size += grouping_init(&gs, size, loc);
- 			break;
-+#ifdef VECTORS
+ 				abort();
+ 			break;
++#ifdef ALTIVEC
 +		case 'v':
-+			flags |= VECTOR;
-+			goto rflag;
-+#endif /* VECTORS */
++			if (hasAltivec) {
++				flags |= VECTOR;
++				goto rflag;
++			}
++			/* drop through */
++#endif /* ALTIVEC */
  		default:	/* "%?" prints ?, unless ? is NUL */
  			if (ch == '\0')
  				goto done;
-@@ -968,6 +1082,288 @@ number:			if ((dprec = prec) >= 0)
+@@ -1118,6 +1317,185 @@
  			break;
  		}
  
-+#ifdef VECTORS
++#ifdef ALTIVEC
 +		if (flags & VECTOR) {
 +			/*
 +			 * Do the minimum amount of work necessary to construct
@@ -632,32 +487,24 @@
 +			int i, j;	/* Counter. */
 +			int vcnt;	/* Number of elements in vector. */
 +			char *vfmt;	/* Pointer to format specifier. */
-+#define EXTRAHH 2
-+			char vfmt_buf[32 + EXTRAHH]; /* Static buffer for format spec. */
++			char vfmt_buf[32]; /* Static buffer for format spec. */
 +			int vwidth = 0;	/* Width specified via '*'. */
 +			int vprec = 0;	/* Precision specified via '*'. */
++			union {		/* Element. */
++				int i;
++				float f;
++			} velm;
 +			char *vstr;	/* Used for asprintf(). */
 +			int vlen;	/* Length returned by asprintf(). */
-+			enum {
-+			    V_CHAR, V_SHORT, V_INT,
-+			    V_PCHAR, V_PSHORT, V_PINT,
-+			    V_FLOAT,
-+#ifdef V64TYPE
-+			    V_LONGLONG, V_PLONGLONG,
-+			    V_DOUBLE,
-+#endif /* V64TYPE */
-+			} vtype;
-+
-+			vval.vectorarg = GETARG(VECTORTYPE);
++
 +			/*
 +			 * Set vfmt.  If vfmt_buf may not be big enough,
 +			 * malloc() space, taking care to free it later.
-+			 * (EXTRAHH is for possible extra "hh")
 +			 */
-+			if (&fmt[-1] - pct + EXTRAHH < sizeof(vfmt_buf))
++			if (&fmt[-1] - pct < sizeof(vfmt_buf))
 +				vfmt = vfmt_buf;
 +			else
-+				vfmt = (char *)malloc(&fmt[-1] - pct + EXTRAHH + 1);
++				vfmt = (char *)malloc(&fmt[-1] - pct + 1);
 +
 +			/* Set the separator character, if not specified. */
 +			if (vsep == 'X') {
@@ -690,57 +537,11 @@
 +			 * finish up the format specifier.
 +			 */
 +			if (flags & SHORTINT) {
-+				switch (ch) {
-+				case 'c':
-+					vtype = V_SHORT;
-+					break;
-+				case 'p':
-+					vtype = V_PSHORT;
-+					break;
-+				default:
-+					vfmt[j++] = 'h';
-+					vtype = V_SHORT;
-+					break;
-+				}
++				vfmt[j++] = 'h';
 +				vcnt = 8;
 +			} else if (flags & LONGINT) {
++				vfmt[j++] = 'l';
 +				vcnt = 4;
-+				vtype = (ch == 'p') ? V_PINT : V_INT;
-+#ifdef V64TYPE
-+			} else if (flags & LLONGINT) {
-+				switch (ch) {
-+				case 'a':
-+				case 'A':
-+				case 'e':
-+				case 'E':
-+				case 'f':
-+				case 'g':
-+				case 'G':
-+					vcnt = 2;
-+					vtype = V_DOUBLE;
-+					break;
-+				case 'd':
-+				case 'i':
-+				case 'u':
-+				case 'o':
-+				case 'p':
-+				case 'x':
-+				case 'X':
-+					vfmt[j++] = 'l';
-+					vfmt[j++] = 'l';
-+					vcnt = 2;
-+					vtype = (ch == 'p') ? V_PLONGLONG : V_LONGLONG;
-+					break;
-+				default:
-+					/*
-+					 * The default case should never
-+					 * happen.
-+					 */
-+				case 'c':
-+					vcnt = 16;
-+					vtype = V_CHAR;
-+				}
-+#endif /* V64TYPE */
 +			} else {
 +				switch (ch) {
 +				case 'a':
@@ -751,148 +552,99 @@
 +				case 'g':
 +				case 'G':
 +					vcnt = 4;
-+					vtype = V_FLOAT;
 +					break;
 +				default:
 +					/*
 +					 * The default case should never
 +					 * happen.
 +					 */
++				case 'c':
 +				case 'd':
 +				case 'i':
 +				case 'u':
 +				case 'o':
++				case 'p':
 +				case 'x':
 +				case 'X':
-+					vfmt[j++] = 'h';
-+					vfmt[j++] = 'h';
-+					/* drop through */
-+				case 'p':
-+				case 'c':
 +					vcnt = 16;
-+					vtype = (ch == 'p') ? V_PCHAR : V_CHAR;
 +				}
 +			}
 +			vfmt[j++] = ch;
 +			vfmt[j++] = '\0';
 +
 +/* Get a vector element. */
-+#ifdef V64TYPE
-+#define VPRINT(type, ind, args...) do {					\
-+	switch (type) {							\
-+	case V_CHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuchararg[ind]); \
-+		break;							\
-+	case V_PCHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuchararg[ind]); \
-+		break;							\
-+	case V_SHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vushortarg[ind]); \
-+		break;							\
-+	case V_PSHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vushortarg[ind]); \
-+		break;							\
-+	case V_INT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuintarg[ind]); \
-+		break;							\
-+	case V_PINT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuintarg[ind]); \
-+		break;							\
-+	case V_LONGLONG:						\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vulonglongarg[ind]); \
-+		break;							\
-+	case V_PLONGLONG:						\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vulonglongarg[ind]); \
-+		break;							\
-+	case V_FLOAT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vfloatarg[ind]); \
-+		break;							\
-+	case V_DOUBLE:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vdoublearg[ind]); \
-+		break;							\
++#define VPRINT(cnt, ind, args...) do {					\
++	if (flags & FPT) {						\
++		velm.f = vval.vfloatarg[ind];				\
++		vlen = asprintf(&vstr, vfmt , ## args, velm.f);		\
++	} else {							\
++		switch (cnt) {						\
++		default:						\
++		/* The default case should never happen. */		\
++		case 4:							\
++			velm.i = (unsigned)vval.vintarg[ind];		\
++			break;						\
++		case 8:							\
++			velm.i = (unsigned short)vval.vshortarg[ind];	\
++			break;						\
++		case 16:						\
++			velm.i = (unsigned char)vval.vchararg[ind];	\
++			break;						\
++		}							\
++		vlen = asprintf(&vstr, vfmt , ## args, velm.i);		\
 +	}								\
 +	ret += vlen;							\
 +	PRINT(vstr, vlen);						\
 +	free(vstr);							\
 +} while (0)
-+#else /* !V64TYPE */
-+#define VPRINT(type, ind, args...) do {					\
-+	switch (type) {							\
-+	case V_CHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuchararg[ind]); \
-+		break;							\
-+	case V_PCHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuchararg[ind]); \
-+		break;							\
-+	case V_SHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vushortarg[ind]); \
-+		break;							\
-+	case V_PSHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vushortarg[ind]); \
-+		break;							\
-+	case V_INT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuintarg[ind]); \
-+		break;							\
-+	case V_PINT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuintarg[ind]); \
-+		break;							\
-+	case V_FLOAT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vfloatarg[ind]); \
-+		break;							\
-+	}								\
-+	ret += vlen;							\
-+	PRINT(vstr, vlen);						\
-+	free(vstr);							\
-+} while (0)
-+#endif /* V64TYPE */
 +
 +			/* Actually print. */
 +			if (vwidth == 0) {
 +				if (vprec == 0) {
 +					/* First element. */
-+					VPRINT(vtype, 0);
++					VPRINT(vcnt, 0);
 +					for (i = 1; i < vcnt; i++) {
 +						/* Separator. */
-+						if(vsep)
++						if (vsep)
 +							PRINT(&vsep, 1);
 +
 +						/* Element. */
-+						VPRINT(vtype, i);
++						VPRINT(vcnt, i);
 +					}
 +				} else {
 +					/* First element. */
-+					VPRINT(vtype, 0, prec);
++					VPRINT(vcnt, 0, prec);
 +					for (i = 1; i < vcnt; i++) {
 +						/* Separator. */
-+						if(vsep)
++						if (vsep)
 +							PRINT(&vsep, 1);
 +
 +						/* Element. */
-+						VPRINT(vtype, i, prec);
++						VPRINT(vcnt, i, prec);
 +					}
 +				}
 +			} else {
 +				if (vprec == 0) {
 +					/* First element. */
-+					VPRINT(vtype, 0, width);
++					VPRINT(vcnt, 0, width);
 +					for (i = 1; i < vcnt; i++) {
 +						/* Separator. */
-+						if(vsep)
++						if (vsep)
 +							PRINT(&vsep, 1);
 +
 +						/* Element. */
-+						VPRINT(vtype, i, width);
++						VPRINT(vcnt, i, width);
 +					}
 +				} else {
 +					/* First element. */
-+					VPRINT(vtype, 0, width, prec);
++					VPRINT(vcnt, 0, width, prec);
 +					for (i = 1; i < vcnt; i++) {
 +						/* Separator. */
-+						if(vsep)
++						if (vsep)
 +							PRINT(&vsep, 1);
 +
 +						/* Element. */
-+						VPRINT(vtype, i, width, prec);
++						VPRINT(vcnt, i, width, prec);
 +					}
 +				}
 +			}
@@ -903,25 +655,97 @@
 +
 +			continue;
 +		}
-+#endif /* VECTORS */
++#endif /* ALTIVEC */
  		/*
  		 * All reasonable formats wind up here.  At this point, `cp'
  		 * points to a string which (if not flags&LADJUST) should be
-@@ -1018,7 +1414,7 @@ number:			if ((dprec = prec) >= 0)
- 			/* leading zeroes from decimal precision */
- 			PAD(dprec - size, zeroes);
- 			if (gs.grouping) {
--				if (grouping_print(&gs, &io, cp, buf+BUF) < 0)
-+				if (grouping_print(&gs, &io, cp, buf+BUF, loc) < 0)
- 					goto error;
- 			} else {
- 				PRINT(cp, size);
-@@ -1036,7 +1432,7 @@ number:			if ((dprec = prec) >= 0)
- 				} else {
- 					if (gs.grouping) {
- 						n = grouping_print(&gs, &io,
--						    cp, convbuf + ndig);
-+						    cp, convbuf + ndig, loc);
- 						if (n < 0)
- 							goto error;
- 						cp += n;
+@@ -1135,7 +1513,7 @@
+ 		realsz = dprec > size ? dprec : size;
+ 		if (sign)
+ 			realsz++;
+-		else if (ox[1])
++		if (ox[1])
+ 			realsz += 2;
+ 
+ 		prsize = width > realsz ? width : realsz;
+@@ -1149,9 +1527,9 @@
+ 			PAD(width - realsz, blanks);
+ 
+ 		/* prefix */
+-		if (sign) {
++		if (sign)
+ 			PRINT(&sign, 1);
+-		} else if (ox[1]) {	/* ox[1] is either x, X, or \0 */
++		if (ox[1]) {	/* ox[1] is either x, X, or \0 */
+ 			ox[0] = '0';
+ 			PRINT(ox, 2);
+ 		}
+@@ -1394,6 +1772,11 @@
+ 			if (flags & LONGINT)
+ 				ADDTYPE(T_WINT);
+ 			else
++#ifdef ALTIVEC
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* ALTIVEC */
+ 				ADDTYPE(T_INT);
+ 			break;
+ 		case 'D':
+@@ -1413,6 +1796,11 @@
+ 		case 'f':
+ 		case 'g':
+ 		case 'G':
++#ifdef ALTIVEC
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* ALTIVEC */
+ 			if (flags & LONGDBL)
+ 				ADDTYPE(T_LONG_DOUBLE);
+ 			else
+@@ -1441,9 +1829,19 @@
+ 			flags |= LONGINT;
+ 			/*FALLTHROUGH*/
+ 		case 'o':
++#ifdef ALTIVEC
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* ALTIVEC */
+ 			ADDUARG();
+ 			break;
+ 		case 'p':
++#ifdef ALTIVEC
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* ALTIVEC */
+ 			ADDTYPE(TP_VOID);
+ 			break;
+ 		case 'S':
+@@ -1461,6 +1859,11 @@
+ 		case 'u':
+ 		case 'X':
+ 		case 'x':
++#ifdef ALTIVEC
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* ALTIVEC */
+ 			ADDUARG();
+ 			break;
+ 		default:	/* "%?" prints ?, unless ? is NUL */
+@@ -1546,6 +1949,12 @@
+ 			(*argtable) [n].longdoublearg = va_arg (ap, long double);
+ 			break;
+ #endif
++#ifdef ALTIVEC
++		    case T_VECTOR:
++			if (hasAltivec)
++				ap = getvec( &((*argtable) [n]), NULL, 0, ap );
++			break;
++#endif /* ALTIVEC */
+ 		    case TP_CHAR:
+ 			(*argtable) [n].pchararg = va_arg (ap, char *);
+ 			break;