1 # produce a header file for a parsed struct file
3 function header_elstring
(elnum
,
6 array_len = elements
[elnum
, "array_len"];
7 elem=elements
[elnum
, "elem"];
8 if (elements
[elnum
, "ptr"]==
"1") elem=
"*"elem
;
10 if (is_constant
(array_len
) ==
1) {
11 elem=elem
"["array_len
"]";
19 function header_element
(f
, elnum
,
22 type=elements
[elnum
, "type"];
23 if (substr(type
,1,1) ==
".") return;
24 xprintf
(f
,"\t%s %s;\n", type
, header_elstring
(elnum
));
27 function header_union
(f
, elnum
,
30 xprintf
(f
,"\tunion {\n");
31 for (i=
0;i
<unions
[elnum
, "num_elems"];i
++) {
32 header_element
(f
, unions
[elnum
, i
]);
34 xprintf
(f
,"\t} %s;\n", header_elstring
(elnum
));
37 function header_elem
(f
, elnum
)
40 if (elements
[elnum
, "type"] ==
"union") {
41 header_union
(f
, elnum
);
43 header_element
(f
, elnum
);
47 function header_struct
(f
, struct_num
,
50 xprintf
(f
,"/* structure %s */\n",
51 structs
[struct_num
, "name"]);
52 xprintf
(f
,"typedef struct {\n");
53 for (i=
0;i
< structs
[struct_num
, "num_elems"];i
++) {
54 header_elem
(f
, structs
[struct_num
, i
]);
56 xprintf
(f
,"} %s;\n\n\n", structs
[struct_num
, "name"]);
60 function produce_headers
(f
, NIL
,
63 xprintf
(f
,"/* auto-generated headers for %s */\n\n\n", module
);
64 xprintf
(f
,"#ifndef _%s_\n", module
);
65 xprintf
(f
,"#define _%s_\n", module
);
68 for (i=
0;i
< num_options
;i
++) {
69 xprintf
(f
,"#define OPTION_%s %s\n",
70 options
[i
, "name"], options
[i
, "value"]);
74 for (i=
0;i
< num_structs
;i
++) {
77 xprintf
(f
,"/* end auto-generated headers */\n\n");
78 xprintf
(f
,"#endif /* _%s_ */\n", module
);