blob: 4d8679355bf3cc04b8e6f72357d7ce703e6fc913 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
bug-2452.c
*/
#include <stdbool.h>
#include <testfwk.h>
typedef struct
{
unsigned char byte[5];
} value_t;
static void
output_digit (unsigned char n)
{
ASSERT(n == 9);
}
static void
calculate_digit (value_t *value)
{
value->byte[4] = 9;
}
int
xprint_format (const char *format)
{
value_t value;
bool lsd;
int i;
unsigned char length;
while( *format++ )
{
unsigned char store[6];
unsigned char *pstore = &store[5];
format++;
lsd = 1;
i = 1;
do {
value.byte[4] = 0;
calculate_digit(&value);
if (!lsd)
{
*pstore = (value.byte[4] << 4) | (value.byte[4] >> 4) | *pstore;
pstore--;
}
else
{
*pstore = value.byte[4];
}
lsd = !lsd;
} while( i-- );
length = 2;
ASSERT(lsd);
while( length-- )
{
lsd = !lsd;
if (!lsd)
{
pstore++;
value.byte[4] = *pstore >> 4;
}
else
{
value.byte[4] = *pstore & 0x0F;
}
output_digit( value.byte[4]);
}
}
return 0;
}
void
test_xprintf (void)
{
xprint_format ("%d");
}
|