Chameleon

Chameleon Commit Details

Date:2016-05-19 20:36:31 (3 years 1 month ago)
Author:zenith432
Commit:2821
Parents: 2820
Message:Add %%, %i, %p and %n support to prf()
Changes:
M/branches/zenith432/i386/libsa/prf.c

File differences

branches/zenith432/i386/libsa/prf.c
6464
6565
6666
67
67
6868
6969
7070
......
8181
8282
8383
84
84
85
8586
8687
8788
......
104105
105106
106107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
107133
108134
109135
110136
111137
112
138
113139
114140
115141
......
172198
173199
174200
201
175202
176203
177204
......
221248
222249
223250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
224268
225269
226270
int minwidth,
int (*putfn_p)(),
void* putfn_arg
)
)
{
char prbuf[22];
register char *cp;
*cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + (int) (n%b)];
n /= b;
width++;
} while (n);
}
while (n);
if (neg)
{
return width;
}
/*
* Printp prints a pointer.
*/
static int printp(
const void* p,
int minwidth,
int (*putfn_p)(),
void* putfn_arg
)
{
int width = 0;
if (p)
{
if (putfn_p)
{
(void)(*putfn_p)('0', putfn_arg);
(void)(*putfn_p)('x', putfn_arg);
}
width = 2;
minwidth = (minwidth >= 2) ? (minwidth - 2) : 0;
}
return width + printn((unsigned long long) p, 16, ZERO, minwidth, putfn_p, putfn_arg);
}
int prf(
const char *fmt,
va_list ap,
int (*putfn_p)(),
void *putfn_arg
)
)
{
int b, c, len = 0;
const char *s;
b = 16;
goto number;
case 'd':
case 'i':
flag |= SIGNED;
/* fall through */
case 'u':
}
len++;
break;
case '%':
if (putfn_p)
{
(void)(*putfn_p)('%', putfn_arg);
}
len++;
break;
case 'p':
len += printp(va_arg(ap, const void*), minwidth, putfn_p, putfn_arg);
break;
case 'n':
s = va_arg(ap, const char*);
if (s)
{
*(int*) s = len;
}
break;
default:
break;
}

Archive Download the corresponding diff file

Revision: 2821