-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.c
61 lines (51 loc) · 1.78 KB
/
driver.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 "hdl.h"
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
void print_hole_descriptor_list(struct hole_descriptor_list *hdl)
{
if (!hdl) {
printf("<empty>\n");
}
while (hdl) {
printf("%10s: %10d\n", "first", hdl->first);
printf("%10s: %10d\n", "last", hdl->last);
for (struct frag_list *fl = hdl->frag_head; fl != NULL; fl = fl->next) {
printf("%10s (%d,%d)\n", "--", fl->offset, fl->len);
}
hdl = hdl->next;
}
}
void print_frag(void *caller_ctx, const void *frag, const int32_t offset, const int32_t len)
{
printf("* (%d,%d,%p)\n", offset, len, frag);
}
#define HDL_ADD(hdl, off, len, final, verbose) \
do { \
printf("--- inserting (%d,%d)%s\n", off, len, final ? "F" : ""); \
assert(hole_descriptor_list_add(hdl, off, len, final, NULL)); \
if (verbose) print_hole_descriptor_list(hdl); \
} while(0)
int main(int argc, char **argv)
{
struct hole_descriptor_list *hdl;
if (!hole_descriptor_list_init(&hdl)) {
printf("Failed to create hole descriptor list\n");
return 1;
}
HDL_ADD(hdl, 69, 22, false, false);
HDL_ADD(hdl, 75, 16, false, false);
HDL_ADD(hdl, 80, 10, false, false);
HDL_ADD(hdl, 81, 12, false, false);
HDL_ADD(hdl, 59, 23, false, false);
HDL_ADD(hdl, 30, 10, false, false);
HDL_ADD(hdl, 63, 34, false, false);
HDL_ADD(hdl, 87, 9, false, false);
HDL_ADD(hdl, 13, 32, false, false);
HDL_ADD(hdl, 44, 56, true, true);
HDL_ADD(hdl, 0, 13, false, true);
assert(hole_descriptor_list_complete(hdl));
hole_descriptor_list_walk(hdl, print_frag, NULL);
hole_descriptor_list_destroy(hdl);
return 0;
}