summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/aparser/dump.awk61
-rw-r--r--source3/aparser/header.awk49
-rw-r--r--source3/aparser/main.awk10
-rw-r--r--source3/aparser/parsefn.awk54
-rw-r--r--source3/aparser/parser.c8
-rw-r--r--source3/aparser/parsetree.awk63
-rw-r--r--source3/aparser/spool.struct44
-rw-r--r--source3/aparser/templates/prs_pointer.tpl3
8 files changed, 147 insertions, 145 deletions
diff --git a/source3/aparser/dump.awk b/source3/aparser/dump.awk
index 0a72bb8414..65e5675513 100644
--- a/source3/aparser/dump.awk
+++ b/source3/aparser/dump.awk
@@ -1,39 +1,50 @@
# dump the current parse tree
-function dump_union(f, struct_num, union,
- LOCAL, i)
+
+function element_string(elnum,
+ LOCAL, elem)
+{
+ elem = elements[elnum, "elem"];
+ if (elements[elnum, "ptr"]=="1") elem="*"elem;
+ if (elements[elnum, "array_len"]!="")
+ elem=elem"["elements[elnum, "array_len"]"]";
+ if (elements[elnum, "switch"]!="")
+ elem=elem"["elements[elnum, "switch"]"]";
+ return elem;
+}
+
+function dump_element(f, elnum,
+ LOCAL, elem, type)
{
- xprintf(f,"\tunion %s %s {\n",
- structs[struct_num, "unions", union, "switch"],
- union);
- for (i=0;i<structs[struct_num, "unions", union, "num_elems"];i++) {
- xprintf(f,"\t\tcase %d %s %s;\n",
- structs[struct_num, "unions", union, i, "value"],
- structs[struct_num, "unions", union, i, "type"],
- structs[struct_num, "unions", union, i, "elem"]);
+ type = elements[elnum, "type"];
+ case = elements[elnum, "case"];
+ elem = element_string(elnum);
+ if (case != "") {
+ xprintf(f,"\t\tcase %d %s %s;\n", case, type, elem);
+ } else {
+ xprintf(f,"\t%s %s;\n", type, elem);
}
- xprintf(f,"\t}\n");
}
-function dump_array(f, struct_num, elem_num,
+function dump_union(f, elnum,
LOCAL, i)
{
- xprintf(f,"\t{%s} %s %s;\n",
- structs[struct_num, elem_num, "array_len"],
- structs[struct_num, elem_num, "type"],
- structs[struct_num, elem_num, "elem"]);
+ xprintf(f,"\tunion %s {\n", element_string(elnum));
+ for (i=0;i<unions[elnum, "num_elems"];i++) {
+ dump_element(f, unions[elnum, i]);
+ }
+ xprintf(f,"\t}\n");
}
-function dump_elem(f, struct_num, elem_num)
+function dump_elem(f, struct_num, elem_num,
+ LOCAL, enum)
{
- if (structs[struct_num, elem_num, "type"] == "union") {
- dump_union(f, struct_num, structs[struct_num, elem_num, "elem"]);
- } else if (structs[struct_num, elem_num, "array_len"]) {
- dump_array(f, struct_num, elem_num);
+ elnum = structs[struct_num, elem_num];
+
+ if (elements[elnum, "type"] == "union") {
+ dump_union(f, elnum);
} else {
- xprintf(f,"\t%s %s;\n",
- structs[struct_num, elem_num, "type"],
- structs[struct_num, elem_num, "elem"]);
+ dump_element(f, elnum);
}
}
@@ -51,5 +62,3 @@ function dump_structs(f, NIL,
}
xprintf(f,"/* end dump */\n\n");
}
-
-
diff --git a/source3/aparser/header.awk b/source3/aparser/header.awk
index e7e5b2cff4..406335c930 100644
--- a/source3/aparser/header.awk
+++ b/source3/aparser/header.awk
@@ -1,37 +1,38 @@
# produce a header file for a parsed struct file
-function header_union(f, struct_num, union,
- LOCAL, i)
+function header_elstring(elnum,
+ LOCAL, elem)
{
- xprintf(f,"\tunion {\n");
- for (i=0;i<structs[struct_num, "unions", union, "num_elems"];i++) {
- xprintf(f,"\t\t%s %s;\n",
- structs[struct_num, "unions", union, i, "type"],
- structs[struct_num, "unions", union, i, "elem"]);
- }
- xprintf(f,"\t} %s;\n", union);
+ elem=elements[elnum, "elem"];
+ if (elements[elnum, "ptr"]=="1") elem="*"elem;
+ if (elements[elnum, "array_len"]!="") elem="*"elem;
+ return elem;
}
-function header_array(f, struct_num, elem_num)
+function header_element(f, elnum,
+ LOCAL, type)
{
- xprintf(f,"\t%s *%s; /* array of length %s */ \n",
- structs[struct_num, elem_num, "type"],
- structs[struct_num, elem_num, "elem"],
- structs[struct_num, elem_num, "array_len"]);
+ type=elements[elnum, "type"];
+ xprintf(f,"\t%s %s;\n", type, header_elstring(elnum));
}
-function header_elem(f, struct_num, elem_num)
+function header_union(f, elnum,
+ LOCAL, i)
{
- if (structs[struct_num, elem_num, "type"] == ".align") return;
+ xprintf(f,"\tunion {\n");
+ for (i=0;i<unions[elnum, "num_elems"];i++) {
+ header_element(f, unions[elnum, i]);
+ }
+ xprintf(f,"\t} %s;\n", header_elstring(elnum));
+}
- if (structs[struct_num, elem_num, "type"] == "union") {
- header_union(f, struct_num, structs[struct_num, elem_num, "elem"]);
- } else if (structs[struct_num, elem_num, "array_len"]) {
- header_array(f, struct_num, elem_num);
+function header_elem(f, elnum)
+{
+
+ if (elements[elnum, "type"] == "union") {
+ header_union(f, elnum);
} else {
- xprintf(f,"\t%s %s;\n",
- structs[struct_num, elem_num, "type"],
- structs[struct_num, elem_num, "elem"]);
+ header_element(f, elnum);
}
}
@@ -42,7 +43,7 @@ function header_struct(f, struct_num,
structs[struct_num, "name"]);
xprintf(f,"typedef struct {\n");
for (i=0;i < structs[struct_num, "num_elems"];i++) {
- header_elem(f, struct_num, i);
+ header_elem(f, structs[struct_num, i]);
}
xprintf(f,"} %s;\n\n\n", structs[struct_num, "name"]);
}
diff --git a/source3/aparser/main.awk b/source3/aparser/main.awk
index c3e8c2539c..d891970c68 100644
--- a/source3/aparser/main.awk
+++ b/source3/aparser/main.awk
@@ -24,7 +24,7 @@
}
/^[ \t]*union.*\{/ {
- start_union($2, $3);
+ start_union($2);
next;
}
@@ -44,15 +44,9 @@
next;
}
-/^[ \t]*\{.*\}.*;/ {
- split($0,a,"[ \t;{}]*");
- add_array(a[2], a[3], a[4]);
- next;
-}
-
/.*;/ {
split($0,a,"[ \t;]*");
- add_elem(a[2], a[3]);
+ add_struct_elem(a[2], a[3]);
}
END {
diff --git a/source3/aparser/parsefn.awk b/source3/aparser/parsefn.awk
index b3421a7e54..7348984eaa 100644
--- a/source3/aparser/parsefn.awk
+++ b/source3/aparser/parsefn.awk
@@ -19,14 +19,6 @@ function parse_elem(f, v, struct_num, elem_num,
}
-function parse_pointer(f, v, struct_num, elem_num,
- LOCAL, elem)
-{
- elem = structs[struct_num, elem_num, "elem"];
- v["ELEM"] = noptr(elem);
- print_template(f, "prs_pointer.tpl", v);
-}
-
function parse_array(f, v, struct_num, elem_num,
LOCAL, elem, type)
{
@@ -80,29 +72,53 @@ function parse_ptr_elem(f, v, struct_num, elem_num,
print_template(f, "ifptr_end.tpl", v);
}
+function parse_scalar(f, v, elnum,
+ LOCAL, elem, type)
+{
+ if (elements[elnum, "type"] == "union") {
+ parse_union(f, v, elnum);
+ } else if (elements[elnum, "array_len"]!="") {
+ parse_array(f, v, elnum);
+ } else {
+
+ }
+ elem = elements[elnum, "elem"];
+ v["ELEM"] = elem;
+ print_template(f, "prs_pointer.tpl", v);
+}
+
+function parse_pointer(f, v, elnum,
+ LOCAL, elem)
+{
+ elem = elements[elnum, "elem"];
+ v["ELEM"] = elem;
+ print_template(f, "prs_pointer.tpl", v);
+}
+
+function parse_scalars(f, v, elnum)
+{
+ if (elements[elnum, "ptr"] == "1") {
+ parse_pointer(f, v, elnum);
+ } else {
+ parse_scalar(f, v, elnum);
+ }
+}
function struct_parser(f, v, struct_num,
LOCAL, i)
{
v["STRUCTNAME"] = structs[struct_num, "name"];
- v["FUNCNAME"] = v["MODULE"] "_io_" v["STRUCTNAME"];
+ v["FUNCNAME"] = "prs_" 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++) {
- if (isaptr(structs[struct_num, i, "elem"])) {
- parse_pointer(f, v, struct_num, i);
- } else if (structs[struct_num, i, "array_len"]) {
- parse_array(f, v, struct_num, i);
- } else {
- parse_elem(f, v, struct_num, i);
- }
+ parse_scalars(f, v, structs[struct_num, i]);
}
- # now the structures
+ # now the buffers
for (i=0;i<structs[struct_num, "num_elems"];i++) {
- if (!isaptr(structs[struct_num, i, "elem"])) continue;
- parse_ptr_elem(f, v, struct_num, i);
+ parse_buffers(f, v, structs[struct_num, i]);
}
print_template(f, "fn_end.tpl", v);
diff --git a/source3/aparser/parser.c b/source3/aparser/parser.c
index 27605dcfec..76e7d91712 100644
--- a/source3/aparser/parser.c
+++ b/source3/aparser/parser.c
@@ -130,7 +130,7 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
Stream a uint32.
********************************************************************/
-BOOL prs_uint32(char *name, prs_struct *ps, int depth, uint32 *data32)
+BOOL prs_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, BOOL scalars)
{
char *q = prs_mem_get(ps, sizeof(uint32));
if (q == NULL)
@@ -267,10 +267,10 @@ void dump_data(int level,char *buf1,int len)
/*******************************************************************
Stream a pointer
********************************************************************/
-BOOL prs_pointer(char *desc, prs_struct *ps, int depth, void **p)
+BOOL prs_pointer(char *desc, prs_struct *ps, int depth, void **p, BOOL scalars)
{
uint32 v = (*p) ? 1 : 0;
- if (!prs_uint32(desc, ps, depth, &v)) return False;
+ if (!prs_uint32(desc, ps, depth, &v, True)) return False;
*p = (void *) (v ? 1 : 0);
return True;
}
@@ -311,7 +311,7 @@ BOOL prs_uint32s(BOOL charmode, char *name, prs_struct *ps, int depth, uint32 *d
Stream a uint16.
********************************************************************/
-BOOL prs_uint16(char *name, prs_struct *ps, int depth, uint16 *data16)
+BOOL prs_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, BOOL scalars)
{
char *q = prs_mem_get(ps, sizeof(uint16));
if (q == NULL)
diff --git a/source3/aparser/parsetree.awk b/source3/aparser/parsetree.awk
index e0f946a663..6f2697ec91 100644
--- a/source3/aparser/parsetree.awk
+++ b/source3/aparser/parsetree.awk
@@ -4,6 +4,8 @@ function start_module(name)
{
module=name;
num_structs=0;
+ num_elements=0;
+ num_unions=0;
}
function start_struct(name)
@@ -21,44 +23,59 @@ function end_struct()
current_struct="";
}
-function add_elem(type, elem,
- LOCAL, elem_num)
+function add_element(type, elem, case,
+ LOCAL, elem_num, i, v)
{
- elem_num=structs[current_struct, "num_elems"];
- structs[current_struct, elem_num, "type"] = type;
- structs[current_struct, elem_num, "elem"] = elem;
- structs[current_struct, elem_num, "array_len"] = "";
- structs[current_struct, "num_elems"]++;
+ elem_num=num_elements;
+
+ if (substr(elem, 1, 1) == "*") {
+ elem=substr(elem, 2);
+ elements[elem_num, "ptr"]=1;
+ }
+
+ i=match(elem,"[[]");
+ if (i != 0) {
+ v = substr(elem, i+1, length(elem)-i-1);
+ elem=substr(elem, 1, i-1);
+ if (type=="union") {
+ elements[elem_num, "switch"] = v;
+ } else {
+ elements[elem_num, "array_len"] = v;
+ }
+ }
+
+ elements[elem_num, "type"] = type;
+ elements[elem_num, "elem"] = elem;
+ elements[elem_num, "case"] = case;
+
+ num_elements++;
return elem_num;
}
-function add_array(array_len, type, elem,
- LOCAL, elem_num)
+function add_struct_elem(type, elem, case,
+ LOCAL, elem_num)
{
- elem_num=add_elem(type, elem);
- structs[current_struct, elem_num, "array_len"] = array_len;
+ elem_num=structs[current_struct, "num_elems"];
+ structs[current_struct, elem_num] = add_element(type, elem, case);
+ structs[current_struct, "num_elems"]++;
+ return structs[current_struct, elem_num];
}
-function start_union(switch, elem)
+function start_union(elem)
{
- current_union=elem;
- add_elem("union", elem);
- structs[current_struct, "unions", current_union, "switch"] = switch;
- structs[current_struct, "unions", current_union, "num_elems"] = 0;
+ current_union = add_struct_elem("union", elem);
+ unions[current_union, "num_elems"] = 0;
}
-function parse_case(value, type, elem,
+function parse_case(case, type, elem,
LOCAL, elem_num)
{
- elem_num =structs[current_struct, "unions", current_union, "num_elems"];
- structs[current_struct, "unions", current_union, elem_num, "type"] = type;
- structs[current_struct, "unions", current_union, elem_num, "elem"] = elem;
- structs[current_struct, "unions", current_union, elem_num, "value"] = value;
- structs[current_struct, "unions", current_union, "num_elems"]++;
+ elem_num = unions[current_union, "num_elems"];
+ unions[current_union, elem_num] = add_element(type, elem, case);
+ unions[current_union, "num_elems"]++;
}
function end_union()
{
current_union="";
}
-
diff --git a/source3/aparser/spool.struct b/source3/aparser/spool.struct
index 3e959e8f44..52b0e3aed9 100644
--- a/source3/aparser/spool.struct
+++ b/source3/aparser/spool.struct
@@ -1,18 +1,16 @@
module spool
-test SPOOL_NOTIFY_INFO
+test PRINTER_DRIVER_INFO_LEVEL_6
struct BUFFER5 {
- .align 4;
uint32 buf_len;
- {buf_len} uint16 buffer;
+ uint16 *buffer[buf_len];
};
struct UNISTR2 {
- .align 4;
uint32 max_len;
uint32 undoc;
uint32 str_len;
- {str_len} uint16 buffer;
+ uint16 *buffer[str_len];
};
struct UINT64_S {
@@ -26,7 +24,6 @@ struct NTTIME {
};
struct PRINTER_DRIVER_INFO_LEVEL_3 {
- .align 4;
uint32 cversion;
UNISTR2 *name;
UNISTR2 *environment;
@@ -41,7 +38,6 @@ struct PRINTER_DRIVER_INFO_LEVEL_3 {
};
struct PRINTER_DRIVER_INFO_LEVEL_6 {
- .align 4;
uint32 dummy1;
uint32 version;
UNISTR2 *name;
@@ -67,41 +63,9 @@ struct PRINTER_DRIVER_INFO_LEVEL_6 {
struct PRINTER_DRIVER_INFO {
- .align 4;
uint32 level;
- union level *info {
+ union *info[level] {
case 3 PRINTER_DRIVER_INFO_LEVEL_3 info_3;
case 6 PRINTER_DRIVER_INFO_LEVEL_6 info_6;
}
};
-
-
-struct NOTIFY_DATA_VALUE {
- uint32 value0;
- uint32 value1;
-};
-
-struct NOTIFY_DATA_STRING {
- uint32 length;
- {length} uint16 string;
-};
-
-struct SPOOL_NOTIFY_INFO_DATA {
- uint16 type;
- uint16 field;
- uint32 reserved;
- uint32 id;
- union enc_type *notify_data {
- case 1 NOTIFY_DATA_VALUE value;
- case 0 NOTIFY_DATA_STRING string;
- }
- uint32 size;
- uint32 enc_type;
-};
-
-struct SPOOL_NOTIFY_INFO {
- uint32 version;
- uint32 flags;
- uint32 count;
- SPOOL_NOTIFY_INFO_DATA *data;
-};
diff --git a/source3/aparser/templates/prs_pointer.tpl b/source3/aparser/templates/prs_pointer.tpl
index f268c259bc..6ad1b99a01 100644
--- a/source3/aparser/templates/prs_pointer.tpl
+++ b/source3/aparser/templates/prs_pointer.tpl
@@ -1 +1,2 @@
- if (!prs_pointer("@ELEM@_ptr", ps, depth+1, (void **)&il->@ELEM@)) goto fail;
+ if (!prs_pointer("@ELEM@_ptr", ps, depth+1,
+ (void **)&il->@ELEM@, True)) goto fail;