summaryrefslogtreecommitdiff
path: root/source3/aparser/parsefn.awk
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-05-16 11:55:06 +0000
committerAndrew Tridgell <tridge@samba.org>2000-05-16 11:55:06 +0000
commitf3a3a05ade784ff6906e5c8b132c9440a8db44e5 (patch)
tree35f1cfbb0a880a592487450c5a9b8d37cfe302b9 /source3/aparser/parsefn.awk
parent466338b165a19149e7a938bf4302c95dcab82beb (diff)
downloadsamba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.tar.gz
samba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.tar.bz2
samba-f3a3a05ade784ff6906e5c8b132c9440a8db44e5.zip
another awk parser update
we can now handle arrays of structures, pointers to structures, pointers in unions etc (This used to be commit 1df80cd1e8475b6b2fe7b80b6c9089692ab7691b)
Diffstat (limited to 'source3/aparser/parsefn.awk')
-rw-r--r--source3/aparser/parsefn.awk150
1 files changed, 82 insertions, 68 deletions
diff --git a/source3/aparser/parsefn.awk b/source3/aparser/parsefn.awk
index 7348984eaa..68f08618a6 100644
--- a/source3/aparser/parsefn.awk
+++ b/source3/aparser/parsefn.awk
@@ -1,106 +1,118 @@
# build parse functions for a parsed struct file
-function parse_elem(f, v, struct_num, elem_num,
- LOCAL, type, elem)
+function elem_name(v, elem)
{
- type = structs[struct_num, elem_num, "type"];
- elem = structs[struct_num, elem_num, "elem"];
- v["ELEM"] = noptr(elem);
+ return v["UNION"]elem;
+}
+
+function parse_array(f, v, elnum, flags,
+ LOCAL, type, elem)
+{
+ type = elements[elnum, "type"];
+ elem = elements[elnum, "elem"];
+ v["ELEM"] = elem_name(v, elem);
v["TYPE"] = type;
- if (structs[type] != "") {
- if (isaptr(elem)) {
- print_template(f, "prs_struct_alloc.tpl", v);
- } else {
- print_template(f, "prs_struct.tpl", v);
- }
+ v["FLAGS"] = flags;
+ v["ARRAY_LEN"] = elements[elnum, "array_len"];
+
+ if (type == "uint16") {
+ print_template(f, "prs_wstring.tpl", v);
} else {
- print_template(f, "prs_"type".tpl", v);
+ print_template(f, "prs_array.tpl", v);
}
}
+
-
-function parse_array(f, v, struct_num, elem_num,
- LOCAL, elem, type)
+function parse_element(f, v, elnum, flags,
+ LOCAL, type, elem)
{
- elem = structs[struct_num, elem_num, "elem"];
- type = structs[struct_num, elem_num, "type"];
- v["ARRAYLEN"] = structs[struct_num, elem_num, "array_len"]
- v["ELEM"] = elem;
+ type = elements[elnum, "type"];
+ elem = elements[elnum, "elem"];
+ if (elements[elnum,"ptr"] == "") {
+ v["PTR"] = "\\&";
+ } else {
+ v["PTR"] = " ";
+ }
+ v["ELEM"] = elem_name(v, elem);
v["TYPE"] = type;
- print_template(f, "prs_array.tpl", v);
+ v["FLAGS"] = flags;
+ print_template(f, "prs_element.tpl", v);
}
-function parse_union(f, v, struct_num, elem_num,
- LOCAL, union, type, i, elem, value)
+function parse_union(f, v, elnum, flags,
+ LOCAL, i)
{
- union = structs[struct_num, elem_num, "elem"];
- v["UNION"] = noptr(union);
- v["SWITCH"] = structs[struct_num, "unions", union, "switch"];
+ v["UNION"] = elements[elnum, "elem"];
+ v["SWITCH"] = elements[elnum, "switch"];
+
+ if (elements[elnum, "ptr"] == "1") {
+ v["UNION"] = v["UNION"]"->";
+ } else {
+ v["UNION"] = v["UNION"]".";
+ }
print_template(f, "union_start.tpl", v);
- for (i=0;i<structs[struct_num, "unions", union, "num_elems"];i++) {
- elem = structs[struct_num, "unions", union, i, "elem"];
- type = structs[struct_num, "unions", union, i, "type"];
- value = structs[struct_num, "unions", union, i, "value"];
- v["ELEM"] = v["UNION"]"->"noptr(elem);
- v["TYPE"] = type;
- v["VALUE"] = value;
+ for (i=0;i<unions[elnum, "num_elems"];i++) {
+ v["CASE"] = elements[unions[elnum, i], "case"];
print_template(f, "prs_case.tpl", v);
- if (structs[type] != "") {
- print_template(f, "prs_struct.tpl", v);
+ if (elements[elnum, "ptr"] == "1") {
+ parse_scalars(f, v, unions[elnum, i], "PARSE_SCALARS");
+ parse_buffers(f, v, unions[elnum, i], "PARSE_BUFFERS");
} else {
- print_template(f, "prs_"type".tpl", v);
+ if (flags == "PARSE_SCALARS") {
+ parse_scalars(f, v, unions[elnum, i], flags);
+ } else {
+ parse_buffers(f, v, unions[elnum, i], flags);
+ }
}
- print_template(f, "prs_case_end.tpl", v);
+ print_template(f, "prs_break.tpl", v);
}
+ v["UNION"] = "";
print_template(f, "union_end.tpl", v);
}
-function parse_ptr_elem(f, v, struct_num, elem_num,
- LOCAL, elem, type)
-{
- elem = structs[struct_num, elem_num, "elem"];
- type = structs[struct_num, elem_num, "type"];
- v["ELEM"] = noptr(elem);
- print_template(f, "ifptr_start.tpl", v);
- if (type == "union") {
- parse_union(f, v, struct_num, elem_num);
- } else {
- parse_elem(f, v, struct_num, elem_num);
- }
- print_template(f, "ifptr_end.tpl", v);
-}
-
-function parse_scalar(f, v, elnum,
- LOCAL, elem, type)
+function parse_scalar(f, v, elnum, flags)
{
if (elements[elnum, "type"] == "union") {
- parse_union(f, v, elnum);
+ parse_union(f, v, elnum, flags);
} else if (elements[elnum, "array_len"]!="") {
- parse_array(f, v, elnum);
+ parse_array(f, v, elnum, flags);
} else {
-
+ parse_element(f, v, elnum, flags);
}
- elem = elements[elnum, "elem"];
- v["ELEM"] = elem;
- print_template(f, "prs_pointer.tpl", v);
}
-function parse_pointer(f, v, elnum,
+function parse_pointer(f, v, elnum, flags,
LOCAL, elem)
{
elem = elements[elnum, "elem"];
- v["ELEM"] = elem;
+ v["ELEM"] = elem_name(v, elem);
+ v["FLAGS"] = flags;
print_template(f, "prs_pointer.tpl", v);
}
-function parse_scalars(f, v, elnum)
+function parse_scalars(f, v, elnum, flags)
+{
+ if (elements[elnum, "ptr"] == "1") {
+ parse_pointer(f, v, elnum, flags);
+ } else {
+ parse_scalar(f, v, elnum, flags);
+ }
+}
+
+function parse_buffers(f, v, elnum, flags,
+ LOCAL, elem, type)
{
+ elem = elements[elnum, "elem"];
+ type = elements[elnum, "type"];
+ v["ELEM"] = elem_name(v, elem);
if (elements[elnum, "ptr"] == "1") {
- parse_pointer(f, v, elnum);
+ print_template(f, "ifptr_start.tpl", v);
+ parse_scalar(f, v, elnum, "PARSE_SCALARS|PARSE_BUFFERS");
+ print_template(f, "ifptr_end.tpl", v);
} else {
- parse_scalar(f, v, elnum);
+ parse_scalar(f, v, elnum, flags);
}
}
@@ -108,24 +120,26 @@ function struct_parser(f, v, struct_num,
LOCAL, i)
{
v["STRUCTNAME"] = structs[struct_num, "name"];
- v["FUNCNAME"] = "prs_" v["STRUCTNAME"];
+ v["FUNCNAME"] = "io_" v["STRUCTNAME"];
print_template(f, "fn_start.tpl", v);
# first all the structure pointers, scalars and arrays
for (i=0;i<structs[struct_num, "num_elems"];i++) {
- parse_scalars(f, v, structs[struct_num, i]);
+ parse_scalars(f, v, structs[struct_num, i], "PARSE_SCALARS");
}
+ print_template(f, "fn_mid.tpl", v);
+
# now the buffers
for (i=0;i<structs[struct_num, "num_elems"];i++) {
- parse_buffers(f, v, structs[struct_num, i]);
+ parse_buffers(f, v, structs[struct_num, i], "PARSE_BUFFERS");
}
print_template(f, "fn_end.tpl", v);
}
function produce_parsers(f,
- LOCAL, v)
+ LOCAL, v, i)
{
v["MODULE"]=module;