-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathgenprotocol.awk
More file actions
114 lines (92 loc) · 2.15 KB
/
genprotocol.awk
File metadata and controls
114 lines (92 loc) · 2.15 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Feed cc -E /usr/include/X11/Xproto.h into this
BEGIN {
in_struct = 0;
types[BOOL] = types[BYTE] = 1;
types[INT8] = types[CARD8] = 1;
types[INT16] = types[CARD16] = 1;
types[INT32] = types[CARD32] = 1;
}
in_struct == 1 && $1 == "}" && $2 ~ /x.*;/ {
name = substr($2, 2, length($2) - 2);
memlist = "";
for (i = 0; i < memcount; i++)
memlist = memlist " " members[i];
# print name ", " memlist
if (name ~ /Req$/)
requests[substr(name, 1, length(name) - 3)] = memlist;
else if (name ~ /Reply$/)
replies[substr(name, 1, length(name) - 5)] = memlist;
else
structs[name] = memlist;
delete members;
in_struct = 0;
}
in_struct == 2 && $1 == "}" && $2 == "xEvent;" {
in_struct = 0;
}
in_struct == 1 && $1 != "}" {
fcount = split($0, f, "[ \t,;]+");
if (fcount > 0) {
if (f[1] == "")
i = 2;
else
i = 1;
if (next_type == "") {
type = f[i];
i++;
} else {
type = next_type;
}
if ($0 ~ /;[ \t]*$/) {
next_type = "";
} else {
next_type = type;
}
for (; i < fcount; i++) {
members[memcount] = type ":" f[i];
memcount++;
}
}
}
/^typedef struct.*\{/ {
if (in_struct)
{
print "typedef struct while in_struct!";
exit 1;
}
next_type = "";
in_struct = 1;
memcount = 0;
# hack to skip _xEvent
if ($3 == "_xEvent")
in_struct = 2;
}
/^typedef x.* x.*;/ {
if (in_struct)
{
print "typedef xFoo xBar; while in_struct!";
exit 1;
}
src = substr($2, 2);
dest = substr($3, 2, length($3) - 2);
if (src ~ /Req$/)
memlist = requests[substr(src, 1, length(src) - 3)];
else if (src ~ /Reply$/)
memlist = replies[substr(src, 1, length(src) - 5)];
else
memlist = structs[src];
if (dest ~ /Req$/)
requests[substr(dest, 1, length(dest) - 3)] = memlist;
else if (dest ~ /Reply$/)
replies[substr(dest, 1, length(dest) - 5)] = memlist;
else
structs[dest] = memlist;
}
END {
for (x in requests)
print "REQUEST " x " " requests[x];
for (x in replies)
print "REPLY " x " " replies[x];
for (x in structs)
print "STRUCT " x " " structs[x];
}