Quad support in printf(3) family
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 3 Jun 1992 07:05:34 +0000 (23:05 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 3 Jun 1992 07:05:34 +0000 (23:05 -0800)
SCCS-vsn: lib/libc/stdio/vfprintf.c 5.49
SCCS-vsn: lib/libc/stdio/printf.3 6.15

usr/src/lib/libc/stdio/printf.3
usr/src/lib/libc/stdio/vfprintf.c

index 46798e7..480d7e9 100644 (file)
@@ -7,7 +7,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"     @(#)printf.3   6.14 (Berkeley) %G%
+.\"     @(#)printf.3   6.15 (Berkeley) %G%
 .\"
 .Dd 
 .Dt PRINTF 3
 .\"
 .Dd 
 .Dt PRINTF 3
@@ -146,9 +146,9 @@ the following appear in sequence:
 .Bl -bullet
 .It
 Zero or more of the following flags:
 .Bl -bullet
 .It
 Zero or more of the following flags:
-.Bl -hyphen -offset indent
+.Bl -hyphen
 .It
 .It
-a
+A
 .Cm #
 character
 specifying that the value should be converted to an ``alternate form''.
 .Cm #
 character
 specifying that the value should be converted to an ``alternate form''.
@@ -238,7 +238,7 @@ produced by a signed conversion
 or
 .Cm i ) .
 .It
 or
 .Cm i ) .
 .It
-a
+A
 .Sq Cm +
 character specifying that a sign always be placed before a
 number produced by a signed conversion.
 .Sq Cm +
 character specifying that a sign always be placed before a
 number produced by a signed conversion.
@@ -319,6 +319,26 @@ conversion corresponds to a pointer to a
 .Em long int
 argument.
 .It
 .Em long int
 argument.
 .It
+The optional character
+.Cm q ,
+specifying that a following
+.Cm d ,
+.Cm i ,
+.Cm o ,
+.Cm u ,
+.Cm x ,
+or
+.Cm X
+conversion corresponds to a
+.Em quad int
+or
+.Em unsigned quad int
+argument, or that a following
+.Cm n
+conversion corresponds to a pointer to a
+.Em quad int
+argument.
+.It
 The character
 .Cm L
 specifying that a following
 The character
 .Cm L
 specifying that a following
index 2ffdafe..44d3ce7 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfprintf.c 5.48 (Berkeley) %G%";
+static char sccsid[] = "@(#)vfprintf.c 5.49 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -115,21 +115,19 @@ static int cvt();
 /*
  * Flags used during conversion.
  */
 /*
  * Flags used during conversion.
  */
-#define        LONGINT         0x01            /* long integer */
-#define        LONGDBL         0x02            /* long double; unimplemented */
-#define        SHORTINT        0x04            /* short integer */
-#define        ALT             0x08            /* alternate form */
-#define        LADJUST         0x10            /* left adjustment */
-#define        ZEROPAD         0x20            /* zero (as opposed to blank) pad */
-#define        HEXPREFIX       0x40            /* add 0x or 0X prefix */
+#define        ALT             0x001           /* alternate form */
+#define        HEXPREFIX       0x002           /* add 0x or 0X prefix */
+#define        LADJUST         0x004           /* left adjustment */
+#define        LONGDBL         0x008           /* long double; unimplemented */
+#define        LONGINT         0x010           /* long integer */
+#define        QUADINT         0x020           /* quad integer */
+#define        SHORTINT        0x040           /* short integer */
+#define        ZEROPAD         0x080           /* zero (as opposed to blank) pad */
 
 int
 vfprintf(fp, fmt0, ap)
        FILE *fp;
        const char *fmt0;
 
 int
 vfprintf(fp, fmt0, ap)
        FILE *fp;
        const char *fmt0;
-#if tahoe
- register /* technically illegal, since we do not know what type va_list is */
-#endif
        va_list ap;
 {
        register char *fmt;     /* format string */
        va_list ap;
 {
        register char *fmt;     /* format string */
@@ -147,7 +145,7 @@ vfprintf(fp, fmt0, ap)
        double _double;         /* double precision arguments %[eEfgG] */
        int fpprec;             /* `extra' floating precision in [eEfgG] */
 #endif
        double _double;         /* double precision arguments %[eEfgG] */
        int fpprec;             /* `extra' floating precision in [eEfgG] */
 #endif
-       u_long _ulong;          /* integer arguments %[diouxX] */
+       u_quad_t _uquad;        /* integer arguments %[diouxX] */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int fieldsz;            /* field size expanded by sign, etc */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int fieldsz;            /* field size expanded by sign, etc */
@@ -161,9 +159,9 @@ vfprintf(fp, fmt0, ap)
        char ox[2];             /* space for 0x hex-prefix */
 
        /*
        char ox[2];             /* space for 0x hex-prefix */
 
        /*
-        * Choose PADSIZE to trade efficiency vs size.  If larger
-        * printf fields occur frequently, increase PADSIZE (and make
-        * the initialisers below longer).
+        * Choose PADSIZE to trade efficiency vs. size.  If larger printf
+        * fields occur frequently, increase PADSIZE and make the initialisers
+        * below longer.
         */
 #define        PADSIZE 16              /* pad chunk size */
        static char blanks[PADSIZE] =
         */
 #define        PADSIZE 16              /* pad chunk size */
        static char blanks[PADSIZE] =
@@ -206,11 +204,13 @@ vfprintf(fp, fmt0, ap)
         * argument extraction methods.
         */
 #define        SARG() \
         * argument extraction methods.
         */
 #define        SARG() \
-       (flags&LONGINT ? va_arg(ap, long) : \
+       (flags&QUADINT ? va_arg(ap, quad_t) : \
+           flags&LONGINT ? va_arg(ap, long) : \
            flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
            (long)va_arg(ap, int))
 #define        UARG() \
            flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
            (long)va_arg(ap, int))
 #define        UARG() \
-       (flags&LONGINT ? va_arg(ap, u_long) : \
+       (flags&QUADINT ? va_arg(ap, u_quad_t) : \
+           flags&LONGINT ? va_arg(ap, u_long) : \
            flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
            (u_long)va_arg(ap, u_int))
 
            flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
            (u_long)va_arg(ap, u_int))
 
@@ -324,6 +324,9 @@ reswitch:   switch (ch) {
                case 'l':
                        flags |= LONGINT;
                        goto rflag;
                case 'l':
                        flags |= LONGINT;
                        goto rflag;
+               case 'q':
+                       flags |= QUADINT;
+                       goto rflag;
                case 'c':
                        *(cp = buf) = va_arg(ap, int);
                        size = 1;
                case 'c':
                        *(cp = buf) = va_arg(ap, int);
                        size = 1;
@@ -334,9 +337,9 @@ reswitch:   switch (ch) {
                        /*FALLTHROUGH*/
                case 'd':
                case 'i':
                        /*FALLTHROUGH*/
                case 'd':
                case 'i':
-                       _ulong = SARG();
-                       if ((long)_ulong < 0) {
-                               _ulong = -_ulong;
+                       _uquad = SARG();
+                       if ((quad_t)_uquad < 0) {
+                               _uquad = -_uquad;
                                sign = '-';
                        }
                        base = DEC;
                                sign = '-';
                        }
                        base = DEC;
@@ -389,7 +392,9 @@ reswitch:   switch (ch) {
                        break;
 #endif /* FLOATING_POINT */
                case 'n':
                        break;
 #endif /* FLOATING_POINT */
                case 'n':
-                       if (flags & LONGINT)
+                       if (flags & QUADINT)
+                               *va_arg(ap, quad_t *) = ret;
+                       else if (flags & LONGINT)
                                *va_arg(ap, long *) = ret;
                        else if (flags & SHORTINT)
                                *va_arg(ap, short *) = ret;
                                *va_arg(ap, long *) = ret;
                        else if (flags & SHORTINT)
                                *va_arg(ap, short *) = ret;
@@ -400,7 +405,7 @@ reswitch:   switch (ch) {
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                case 'o':
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                case 'o':
-                       _ulong = UARG();
+                       _uquad = UARG();
                        base = OCT;
                        goto nosign;
                case 'p':
                        base = OCT;
                        goto nosign;
                case 'p':
@@ -412,7 +417,7 @@ reswitch:   switch (ch) {
                         *      -- ANSI X3J11
                         */
                        /* NOSTRICT */
                         *      -- ANSI X3J11
                         */
                        /* NOSTRICT */
-                       _ulong = (u_long)va_arg(ap, void *);
+                       _uquad = (u_quad_t)va_arg(ap, void *);
                        base = HEX;
                        xdigs = "0123456789abcdef";
                        flags |= HEXPREFIX;
                        base = HEX;
                        xdigs = "0123456789abcdef";
                        flags |= HEXPREFIX;
@@ -443,7 +448,7 @@ reswitch:   switch (ch) {
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                case 'u':
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                case 'u':
-                       _ulong = UARG();
+                       _uquad = UARG();
                        base = DEC;
                        goto nosign;
                case 'X':
                        base = DEC;
                        goto nosign;
                case 'X':
@@ -451,10 +456,10 @@ reswitch: switch (ch) {
                        goto hex;
                case 'x':
                        xdigs = "0123456789abcdef";
                        goto hex;
                case 'x':
                        xdigs = "0123456789abcdef";
-hex:                   _ulong = UARG();
+hex:                   _uquad = UARG();
                        base = HEX;
                        /* leading 0x/X only if non-zero */
                        base = HEX;
                        /* leading 0x/X only if non-zero */
-                       if (flags & ALT && _ulong != 0)
+                       if (flags & ALT && _uquad != 0)
                                flags |= HEXPREFIX;
 
                        /* unsigned conversions */
                                flags |= HEXPREFIX;
 
                        /* unsigned conversions */
@@ -473,18 +478,18 @@ number:                   if ((dprec = prec) >= 0)
                         *      -- ANSI X3J11
                         */
                        cp = buf + BUF;
                         *      -- ANSI X3J11
                         */
                        cp = buf + BUF;
-                       if (_ulong != 0 || prec != 0) {
+                       if (_uquad != 0 || prec != 0) {
                                /*
                                /*
-                                * unsigned mod is hard, and unsigned mod
+                                * Unsigned mod is hard, and unsigned mod
                                 * by a constant is easier than that by
                                 * a variable; hence this switch.
                                 */
                                switch (base) {
                                case OCT:
                                        do {
                                 * by a constant is easier than that by
                                 * a variable; hence this switch.
                                 */
                                switch (base) {
                                case OCT:
                                        do {
-                                               *--cp = to_char(_ulong & 7);
-                                               _ulong >>= 3;
-                                       } while (_ulong);
+                                               *--cp = to_char(_uquad & 7);
+                                               _uquad >>= 3;
+                                       } while (_uquad);
                                        /* handle octal leading 0 */
                                        if (flags & ALT && *cp != '0')
                                                *--cp = '0';
                                        /* handle octal leading 0 */
                                        if (flags & ALT && *cp != '0')
                                                *--cp = '0';
@@ -492,18 +497,18 @@ number:                   if ((dprec = prec) >= 0)
 
                                case DEC:
                                        /* many numbers are 1 digit */
 
                                case DEC:
                                        /* many numbers are 1 digit */
-                                       while (_ulong >= 10) {
-                                               *--cp = to_char(_ulong % 10);
-                                               _ulong /= 10;
+                                       while (_uquad >= 10) {
+                                               *--cp = to_char(_uquad % 10);
+                                               _uquad /= 10;
                                        }
                                        }
-                                       *--cp = to_char(_ulong);
+                                       *--cp = to_char(_uquad);
                                        break;
 
                                case HEX:
                                        do {
                                        break;
 
                                case HEX:
                                        do {
-                                               *--cp = xdigs[_ulong & 15];
-                                               _ulong >>= 4;
-                                       } while (_ulong);
+                                               *--cp = xdigs[_uquad & 15];
+                                               _uquad >>= 4;
+                                       } while (_uquad);
                                        break;
 
                                default:
                                        break;
 
                                default: