-
Notifications
You must be signed in to change notification settings - Fork 0
/
serpri.c
61 lines (59 loc) · 840 Bytes
/
serpri.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <quark.h>
#include "serim.h"
#include <ser.h>
static const char hex[] = "0123456789ABCDEF";
int
seroutf(const char *fmt, ...)
{
int st;
unsigned c;
unsigned v;
int *a;
const char *p;
char b[2];
__asm__("movl %%ebp,%0" : "=r"(a));
a += 3;
st = 0;
p = fmt;
while (*p) {
if (st == 0) {
if (*p == '%')
st = 1;
else {
b[0] = *p;
b[1] = '\0';
serout(b);
}
} else if (st == 1) {
switch (*p) {
case 'X':
st = 5;
break;
}
}
++p;
if (st == 5) {
int ov;
v = *(unsigned *)a++;
for (c = 16; c >= 16 && v / c; c *= 16)
;
if (c < 16)
ov = 1;
else
ov = 0;
do {
if (ov) {
c = 0x10000000;
ov = 0;
} else
c /= 16;
b[0] = hex[v / c];
b[1] = '\0';
serout(b);
v %= c;
} while (c > 1);
st = 0;
}
}
return 0;
}