+ /* leading 0x/X only if non-zero */
+ if (flags & ALT && _ulong != 0)
+ flags |= HEXPREFIX;
+
+ /* unsigned conversions */
+nosign: sign = '\0';
+ /*
+ * ``... diouXx conversions ... if a precision is
+ * specified, the 0 flag will be ignored.''
+ * -- ANSI X3J11
+ */
+number: if ((dprec = prec) >= 0)
+ flags &= ~ZEROPAD;
+
+ /*
+ * ``The result of converting a zero value with an
+ * explicit precision of zero is no characters.''
+ * -- ANSI X3J11
+ */
+ t = buf + BUF;
+ if (_ulong != 0 || prec != 0) {
+ do {
+ *--t = digs[_ulong % base];
+ _ulong /= base;
+ } while (_ulong);
+ digs = "0123456789abcdef";
+ if (flags & ALT && base == 8 && *t != '0')
+ *--t = '0'; /* octal leading 0 */
+ }
+ size = buf + BUF - t;
+
+pforw:
+ /*
+ * All reasonable formats wind up here. At this point,
+ * `t' points to a string which (if not flags&LADJUST)
+ * should be padded out to `width' places. If
+ * flags&ZEROPAD, it should first be prefixed by any
+ * sign or other prefix; otherwise, it should be blank
+ * padded before the prefix is emitted. After any
+ * left-hand padding and prefixing, emit zeroes
+ * required by a decimal [diouxX] precision, then print
+ * the string proper, then emit zeroes required by any
+ * leftover floating precision; finally, if LADJUST,
+ * pad with blanks.
+ */
+
+ /*
+ * compute actual size, so we know how much to pad
+ * fieldsz excludes decimal prec; realsz includes it
+ */
+ fieldsz = size + fpprec;
+ if (sign)
+ fieldsz++;
+ if (flags & HEXPREFIX)
+ fieldsz += 2;
+ realsz = dprec > fieldsz ? dprec : fieldsz;
+
+ /* right-adjusting blank padding */
+ if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
+ for (n = realsz; n < width; n++)
+ PUTC(' ');
+ /* prefix */
+ if (sign)
+ PUTC(sign);
+ if (flags & HEXPREFIX) {
+ PUTC('0');
+ PUTC((char)*fmt);
+ }
+ /* right-adjusting zero padding */
+ if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+ for (n = realsz; n < width; n++)
+ PUTC('0');
+ /* leading zeroes from decimal precision */
+ for (n = fieldsz; n < dprec; n++)
+ PUTC('0');
+
+ /* the string or number proper */
+ if (fp->_cnt - (n = size) >= 0 &&
+ (fp->_flag & _IOLBF) == 0) {
+ fp->_cnt -= n;
+ bcopy(t, (char *)fp->_ptr, n);
+ fp->_ptr += n;
+ } else
+ while (--n >= 0)
+ PUTC(*t++);
+ /* trailing f.p. zeroes */
+ while (--fpprec >= 0)
+ PUTC('0');
+ /* left-adjusting padding (always blank) */
+ if (flags & LADJUST)
+ for (n = realsz; n < width; n++)
+ PUTC(' ');
+ /* finally, adjust cnt */
+ cnt += width > realsz ? width : realsz;