Clean up a comment noticed by Jonathan Shao@Panasas.com and remove an
[Samba/gebeck_regimport.git] / source3 / aparser / token.awk
blobfb2982f077797b133ad01bbf4459b999455a15f8
1 # tokenise the input file
3 function parse_error(msg) {
4 printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg);
5 exit 1;
8 # ignore multi-line C comments.
10 if (t = index($0, "/*")) {
11 if (t > 1)
12 tmp = substr($0, 1, t - 1)
13 else
14 tmp = ""
15 u = index(substr($0, t + 2), "*/")
16 while (u == 0) {
17 getline
18 t = -1
19 u = index($0, "*/")
21 if (u <= length($0) - 2)
22 $0 = tmp substr($0, t + u + 3)
23 else
24 $0 = tmp
28 # ignore blank lines
29 /^[ \t]*$/ {
30 next;
33 /^\#define.*/ {
34 split($0,a,"[ \t;]*");
35 parse_define(a[2], a[3]);
36 next;
39 # ignore comments
40 /^[ \t]*\#/ {
41 next;
44 /^[ \t]*module/ {
45 {if (module!="") parse_error("you can only specify one module name");}
46 start_module($2);
47 next;
50 {if (module=="") parse_error("you must specify the module name first");}
52 /^[ \t]*option/ {
53 set_option($2, $3);
54 next;
57 /^[ \t]*typedef struct.*\{/ {
58 {if (current_struct!="") parse_error("you cannot have nested structures");}
59 start_struct($3);
60 next;
63 /^[ \t]*struct.*\{/ {
64 {if (current_struct!="") parse_error("you cannot have nested structures");}
65 start_struct($2);
66 next;
69 /^[ \t]*typedef union.*\{/ {
70 {if (current_struct!="") parse_error("this cannot appear inside a structure");}
71 split($0,a,"[ \t;()]*");
72 start_union_encap(a[4], a[6], a[7], a[8]);
73 next;
76 /^[ \t]*void.*\(/ {
77 {if (current_struct!="") parse_error("you cannot have nested structures");}
78 split($0,a,"[ \t;()]*");
79 start_function(a[2], a[3]);
80 return_result="void";
81 next;
84 /^[ \t]*STATUS.*\(|^[ \t]*void.*\(/ {
85 {if (current_struct!="") parse_error("you cannot have nested structures");}
86 split($0,a,"[ \t;()]*");
87 start_function(a[2], a[3]);
88 return_result="STATUS";
89 next;
92 {if (current_struct=="") parse_error("this must appear inside a structure");}
94 /^[ \t]*union.*\{/ {
95 {if (current_union!="") parse_error("you cannot have nested unions");}
96 start_union($2);
97 next;
100 /^[ \t]*\[switch_is.*union.*\{/ {
101 {if (current_union!="") parse_error("you cannot have nested unions");}
102 split($0,a,"[ \t;()]*");
103 start_union_notencap(a[3]);
104 next;
107 /^[ \t]*case.*;/ {
108 {if (current_union=="") parse_error("this must appear inide a union");}
109 split($0,a,"[ \t;]*");
110 parse_case(a[3],a[4],a[5]);
111 next;
114 /^[ \t]*\[case(.*)\].*;/ {
115 {if (current_union=="") parse_error("this must appear inide a union");}
116 split($0,a,"[ \t;()[\]]*");
117 parse_case(a[6],a[8],a[9]);
118 next;
121 /^[ \t]*\}$/ {
122 {if (current_union=="") parse_error("this must appear inside a union");}
123 end_union("");
124 next;
127 /^[ \t]*\} .*;/ {
128 if (current_union!="") {
129 split($2,a,"[ \t;]*");
130 end_union(a[1]);
131 next;
135 {if (current_union!="") parse_error("this cannot appear inside a union");}
137 /^[ \t]*\};/ {
138 end_struct("");
139 next;
142 /^[ \t]*\} .*;/ {
143 split($2,a,"[ \t;]*");
144 end_struct(a[1]);
145 next;
148 /^[ \t]*\);/ {
149 end_function();
150 return_result="";
151 next;
154 /^.*size_is.*\*.*;/ {
155 split($0,a,"[ \t;()]*");
156 add_sizeis_array(a[3], a[5], a[6]);
157 next;
160 /^.*;/ {
161 split($0,a,"[ \t;]*");
162 add_struct_elem(a[2], a[3]);
163 next;
166 /^[\t ]*void/ {
167 next;
170 /^[ \t]*\[.*\].*/ {
171 split($0,a,"[ \t;]*");
172 split(a[4], b, "[,]");
173 add_function_param(a[2], a[3], b[1]);
174 next;
178 parse_error("Unknown construct.");