3 #define PTR sizeof(char*)
4 #define SHORT sizeof(int)
5 #define INT sizeof(int)
6 #define LONG sizeof(long)
10 static int convcount = { 10 };
12 #define PUT(o, c) if((o)->p < (o)->ep) *(o)->p++ = c
14 static int noconv(Op*);
15 static int cconv(Op*);
16 static int dconv(Op*);
17 static int hconv(Op*);
18 static int lconv(Op*);
19 static int oconv(Op*);
20 static int sconv(Op*);
21 static int uconv(Op*);
22 static int xconv(Op*);
23 static int percent(Op*);
26 int (*fmtconv[MAXCON])(Op*) =
29 cconv, dconv, hconv, lconv,
30 oconv, sconv, uconv, xconv,
48 fmtinstall(char c, int (*f)(Op*))
52 if(fmtindex[c] == 0) {
53 if(convcount >= MAXCON)
55 fmtindex[c] = convcount++;
57 fmtconv[fmtindex[c]] = f;
62 doprint(char *p, char *ep, char *fmt, void *argp)
91 while(c >= '0' && c <= '9') {
92 o.f1 = o.f1*10 + c-'0';
100 while(c >= '0' && c <= '9') {
103 o.f2 = o.f2*10 + c-'0';
109 c = (*fmtconv[fmtindex[c&0177]])(&o);
115 o.argp = (char*)o.argp + c;
120 numbconv(Op *op, int base)
128 switch(op->f3 & (FLONG|FSHORT|FUNSIGN)) {
130 v = *(long*)op->argp;
135 v = *(ulong*)op->argp;
157 v = *(unsigned*)op->argp;
161 if(!(op->f3 & FUNSIGN) && v < 0) {
166 for(i = IDIGIT-2;; i--) {
175 if(op->f2 >= 0 && i >= IDIGIT-op->f2)
183 strconv(b+i, op, op->f1, -1);
188 strconv(char *o, Op *op, int f1, int f2)
217 strconv("***", op, 0, -1);
226 b[0] = *(int*)op->argp;
228 strconv(b, op, op->f1, -1);
236 return numbconv(op, 10);
257 return numbconv(op, 8);
264 strconv(*(char**)op->argp, op, op->f1, op->f2);
279 return numbconv(op, 16);