annotate loadagent/libprintf/doprnt.c @ 3:45bf8af5f061

libprintf brought in from older PPC/m68k code, but fucking GCC refuses to compile <varargs.h> - need to convert to Anshit C <stdarg.h>
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 29 Apr 2013 07:00:22 +0000
parents
children 5c7b3d5d5702
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /* the guts of printf - this implementation came from 4.3BSD-Tahoe */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <sys/types.h>
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <ctype.h>
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <varargs.h>
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #define PUTC(ch) ((*outfunc)((ch), outfunc_param))
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #define ARG() \
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 _ulong = flags&LONGINT ? va_arg(argp, long) : \
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 flags&SHORTINT ? va_arg(argp, short) : va_arg(argp, int);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #define BUF 256
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #define todigit(c) ((c) - '0')
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #define tochar(n) ((n) + '0')
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 /* have to deal with the negative buffer count kludge */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #define NEGATIVE_COUNT_KLUDGE
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 #define LONGINT 0x01 /* long integer */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 #define LONGDBL 0x02 /* long double; unimplemented */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 #define SHORTINT 0x04 /* short integer */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 #define ALT 0x08 /* alternate form */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 #define LADJUST 0x10 /* left adjustment */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 #define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 #define HEXPREFIX 0x40 /* add 0x or 0X prefix */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 _doprnt(fmt0, argp, outfunc, outfunc_param)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 u_char *fmt0;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 va_list argp;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 void (*outfunc)();
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 void *outfunc_param;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 register u_char *fmt; /* format string */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 register int ch; /* character from fmt */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 register int cnt; /* return value accumulator */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 register int n; /* random handy integer */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 register char *t; /* buffer pointer */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 u_long _ulong; /* integer arguments %[diouxX] */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 int base; /* base for [diouxX] conversion */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 int dprec; /* decimal precision in [diouxX] */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 int fieldsz; /* field size expanded by sign, etc */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 int flags; /* flags as above */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 int prec; /* precision from format (%.3d), or -1 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 int realsz; /* field size expanded by decimal precision */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 int size; /* size of converted field or string */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 int width; /* width from format (%8d), or 0 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 char sign; /* sign prefix (' ', '+', '-', or \0) */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 char softsign; /* temporary negative sign for floats */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 char *digs; /* digits for [diouxX] conversion */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 fmt = fmt0;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 digs = "0123456789abcdef";
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 for (cnt = 0;; ++fmt) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 for (; (ch = *fmt) && ch != '%'; ++cnt, ++fmt)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 PUTC(ch);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (!ch)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 return (cnt);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 flags = 0; dprec = 0; width = 0;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 prec = -1;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 sign = '\0';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 rflag: switch (*++fmt) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 case ' ':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 * ``If the space and + flags both appear, the space
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 * flag will be ignored.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (!sign)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 sign = ' ';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 case '#':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 flags |= ALT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 case '*':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 * ``A negative field width argument is taken as a
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 * - flag followed by a positive field width.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 * They don't exclude field widths read from args.
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 if ((width = va_arg(argp, int)) >= 0)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 width = -width;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 /* FALLTHROUGH */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 case '-':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 flags |= LADJUST;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 case '+':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 sign = '+';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 case '.':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 if (*++fmt == '*')
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 n = va_arg(argp, int);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 else {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 n = 0;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 while (isascii(*fmt) && isdigit(*fmt))
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 n = 10 * n + todigit(*fmt++);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 --fmt;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 prec = n < 0 ? -1 : n;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 case '0':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 * ``Note that 0 is taken as a flag, not as the
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 * beginning of a field width.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 flags |= ZEROPAD;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 case '1': case '2': case '3': case '4':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 case '5': case '6': case '7': case '8': case '9':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 n = 0;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 do {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 n = 10 * n + todigit(*fmt);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 } while (isascii(*++fmt) && isdigit(*fmt));
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 width = n;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 --fmt;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 case 'L':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 flags |= LONGDBL;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 case 'h':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 flags |= SHORTINT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 case 'l':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 flags |= LONGINT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 goto rflag;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 case 'c':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 *(t = buf) = va_arg(argp, int);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 size = 1;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 sign = '\0';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 goto pforw;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 case 'D':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 flags |= LONGINT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 /*FALLTHROUGH*/
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 case 'd':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 case 'i':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 ARG();
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 if ((long)_ulong < 0) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 _ulong = -_ulong;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 sign = '-';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 base = 10;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 goto number;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 case 'n':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 if (flags & LONGINT)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 *va_arg(argp, long *) = cnt;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 else if (flags & SHORTINT)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 *va_arg(argp, short *) = cnt;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 else
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 *va_arg(argp, int *) = cnt;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 break;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 case 'O':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 flags |= LONGINT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 /*FALLTHROUGH*/
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 case 'o':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 ARG();
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 base = 8;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 goto nosign;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 case 'p':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 * ``The argument shall be a pointer to void. The
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 * value of the pointer is converted to a sequence
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 * of printable characters, in an implementation-
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 * defined manner.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 /* NOSTRICT */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 _ulong = (u_long)va_arg(argp, void *);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 base = 16;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 goto nosign;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 case 's':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 if (!(t = va_arg(argp, char *)))
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 t = "(null)";
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 if (prec >= 0) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 * can't use strlen; can only look for the
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 * NUL in the first `prec' characters, and
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 * strlen() will go further.
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 char *p;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 for (p = t, size = 0; size < prec; p++, size++)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 if (*p == '\0')
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 break;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 } else
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 size = strlen(t);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 sign = '\0';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 goto pforw;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 case 'U':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 flags |= LONGINT;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 /*FALLTHROUGH*/
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 case 'u':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 ARG();
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 base = 10;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 goto nosign;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 case 'X':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 digs = "0123456789ABCDEF";
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 /* FALLTHROUGH */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 case 'x':
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 ARG();
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 base = 16;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 /* leading 0x/X only if non-zero */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 if (flags & ALT && _ulong != 0)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 flags |= HEXPREFIX;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 /* unsigned conversions */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 nosign: sign = '\0';
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 * ``... diouXx conversions ... if a precision is
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 * specified, the 0 flag will be ignored.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 number: if ((dprec = prec) >= 0)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 flags &= ~ZEROPAD;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 * ``The result of converting a zero value with an
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 * explicit precision of zero is no characters.''
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 * -- ANSI X3J11
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 t = buf + BUF;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 if (_ulong != 0 || prec != 0) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 do {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 *--t = digs[_ulong % base];
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 _ulong /= base;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 } while (_ulong);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 digs = "0123456789abcdef";
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 if (flags & ALT && base == 8 && *t != '0')
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 *--t = '0'; /* octal leading 0 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 size = buf + BUF - t;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 pforw:
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 * All reasonable formats wind up here. At this point,
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 * `t' points to a string which (if not flags&LADJUST)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 * should be padded out to `width' places. If
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 * flags&ZEROPAD, it should first be prefixed by any
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 * sign or other prefix; otherwise, it should be blank
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 * padded before the prefix is emitted. After any
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 * left-hand padding and prefixing, emit zeroes
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 * required by a decimal [diouxX] precision, then print
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 * the string proper, then emit zeroes required by any
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 * leftover floating precision; finally, if LADJUST,
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 * pad with blanks.
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 /*
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 * compute actual size, so we know how much to pad
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 * fieldsz excludes decimal prec; realsz includes it
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 fieldsz = size;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 if (sign)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 fieldsz++;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 if (flags & HEXPREFIX)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 fieldsz += 2;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 realsz = dprec > fieldsz ? dprec : fieldsz;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 /* right-adjusting blank padding */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 for (n = realsz; n < width; n++)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 PUTC(' ');
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 /* prefix */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 if (sign)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 PUTC(sign);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 if (flags & HEXPREFIX) {
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 PUTC('0');
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 PUTC((char)*fmt);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 /* right-adjusting zero padding */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 for (n = realsz; n < width; n++)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 PUTC('0');
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 /* leading zeroes from decimal precision */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 for (n = fieldsz; n < dprec; n++)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 PUTC('0');
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 for (n = size; --n >= 0; )
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 PUTC(*t++);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 /* left-adjusting padding (always blank) */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 if (flags & LADJUST)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 for (n = realsz; n < width; n++)
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 PUTC(' ');
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 /* finally, adjust cnt */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 cnt += width > realsz ? width : realsz;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 break;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293 case '\0': /* "%?" prints ?, unless ? is NULL */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 return (cnt);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 default:
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 PUTC((char)*fmt);
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 cnt++;
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 }
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 /* NOTREACHED */
45bf8af5f061 libprintf brought in from older PPC/m68k code, but fucking GCC
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301 }