8
int main(int argc, char *argv[]) {
10
size_t count = 0, total = 0, size;
11
int offset = 3, toread = 1, toskip = 3;
14
uint32_t expected = 0;
15
uint32_t blocks = 0, status_good = 0;
20
if ((argc != 2)&&(argc != 5)) {
21
printf("Usage: %s <file> [offset_dwords read_dwords skip_dwords] \n", argv[0]);
25
FILE *f = fopen(argv[1], "r");
27
printf("Can't open %s\n", argv[1]);
31
stat(argv[1], &st_buf);
32
size = st_buf.st_size / sizeof(uint32_t);
35
buf = malloc(size * sizeof(uint32_t));
37
printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t));
42
offset = atoi(argv[2]);
43
toread = atoi(argv[3]);
44
toskip = atoi(argv[4]);
48
num = fread(buf, 4, size, f);
50
printf("Failed to read %lu dwords, only %lu read\n", size, num);
55
sprintf(fixed, "%s.fixed", argv[1]);
56
f = fopen(fixed, "w");
58
printf("Failed to open %s for output\n", fixed);
62
expected = (buf[offset]>>24) + 2;
63
for (i = 1; i < size; i += (toread + toskip)) {
66
value = buf[i + offset] >> 24;
67
// printf("0x%lx: value (%lx) = expected (%lx)\n", i + offset, value, expected);
68
if (value == expected) {
73
fwrite(&buf[i], 4, toread + toskip, f);
77
} else if ((!status_good)&&(value == 0)&&((i + toread + toskip)< size)) {
78
value = buf[i + offset + toread + toskip] >> 24;
82
fwrite(&buf[i], 4, toread + toskip, f);
88
printf("0x%lx: value (%x) = expected (%x)\n", (i + offset)*sizeof(uint32_t), value, expected);
96
printf("%lu of %lu is wrong\n", count, total);