4 #define PTR sizeof(char*)
5 #define SHORT sizeof(int)
6 #define INT sizeof(int)
7 #define LONG sizeof(long)
13 #define FUNSIGN (1<<2)
26 static int noconv(Op*);
27 static int cconv(Op*);
28 static int dconv(Op*);
29 static int hconv(Op*);
30 static int lconv(Op*);
31 static int oconv(Op*);
32 static int sconv(Op*);
33 static int uconv(Op*);
34 static int xconv(Op*);
35 static int Xconv(Op*);
36 static int percent(Op*);
39 int (*fmtconv[MAXCON])(Op*) =
42 cconv, dconv, hconv, lconv,
43 oconv, sconv, uconv, xconv,
61 static int convcount = { 11 };
73 while(opos++ < pos && o->p < o->ep)
86 fmtinstall(char c, int (*f)(Op*))
90 if(fmtindex[c] == 0) {
91 if(convcount >= MAXCON)
93 fmtindex[c] = convcount++;
95 fmtconv[fmtindex[c]] = f;
100 donprint(char *p, char *ep, char *fmt, void *argp)
129 while(c >= '0' && c <= '9') {
130 o.f1 = o.f1*10 + c-'0';
138 while(c >= '0' && c <= '9') {
141 o.f2 = o.f2*10 + c-'0';
147 c = (*fmtconv[fmtindex[c&0177]])(&o);
153 o.argp = (char*)o.argp + c;
158 strconv(char *o, Op *op, int f1, int f2)
184 numbconv(Op *op, int base)
192 switch(op->f3 & (FLONG|FSHORT|FUNSIGN)) {
194 v = *(long*)op->argp;
199 v = *(ulong*)op->argp;
221 v = *(unsigned*)op->argp;
225 if(!(op->f3 & FUNSIGN) && v < 0) {
230 for(i = IDIGIT-2;; i--) {
242 if(op->f2 >= 0 && i >= IDIGIT-op->f2)
249 strconv(b+i, op, op->f1, -1);
257 strconv("***", op, 0, -1);
266 b[0] = *(int*)op->argp;
268 strconv(b, op, op->f1, -1);
275 return numbconv(op, 10);
293 return numbconv(op, 8);
299 strconv(*(char**)op->argp, op, op->f1, op->f2);
312 return numbconv(op, 16);
321 r = numbconv(op, 16);