* fix seg fault caused by missing DLIST_REMOVE in free_fn()
[Samba.git] / source / aparser / header.awk
blobba7117436b8598867aabf819f6efd191418d5abe
1 # produce a header file for a parsed struct file
3 function header_elstring(elnum,
4 LOCAL, elem)
6 array_len = elements[elnum, "array_len"];
7 elem=elements[elnum, "elem"];
8 if (elements[elnum, "ptr"]=="1") elem="*"elem;
9 if (array_len!="") {
10 if (is_constant(array_len) == 1) {
11 elem=elem"["array_len"]";
12 } else {
13 elem="*"elem;
16 return elem;
19 function header_element(f, elnum,
20 LOCAL, type)
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,
28 LOCAL, i)
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);
42 } else {
43 header_element(f, elnum);
47 function header_struct(f, struct_num,
48 LOCAL, i)
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,
61 LOCAL, i)
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);
67 xprintf(f,"\n\n");
68 for (i=0;i < num_options;i++) {
69 xprintf(f,"#define OPTION_%s %s\n",
70 options[i, "name"], options[i, "value"]);
72 xprintf(f,"\n\n");
74 for (i=0;i < num_structs;i++) {
75 header_struct(f, i);
77 xprintf(f,"/* end auto-generated headers */\n\n");
78 xprintf(f,"#endif /* _%s_ */\n", module);