1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

started update to handle arbitrary arrays

note: this code is currently broken.
(This used to be commit 15646ebd84)
This commit is contained in:
Andrew Tridgell 2000-05-15 13:41:05 +00:00
parent e2e33eb320
commit 32a7cf9188
8 changed files with 149 additions and 147 deletions

View File

@ -1,39 +1,50 @@
# dump the current parse tree
function dump_union(f, struct_num, union,
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)
{
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);
}
}
function dump_union(f, elnum,
LOCAL, i)
{
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"]);
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_array(f, struct_num, elem_num,
LOCAL, i)
function dump_elem(f, struct_num, elem_num,
LOCAL, enum)
{
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"]);
}
elnum = structs[struct_num, elem_num];
function dump_elem(f, struct_num, elem_num)
{
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);
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");
}

View File

@ -1,37 +1,38 @@
# produce a header file for a parsed struct file
function header_union(f, struct_num, union,
function header_elstring(elnum,
LOCAL, elem)
{
elem=elements[elnum, "elem"];
if (elements[elnum, "ptr"]=="1") elem="*"elem;
if (elements[elnum, "array_len"]!="") elem="*"elem;
return elem;
}
function header_element(f, elnum,
LOCAL, type)
{
type=elements[elnum, "type"];
xprintf(f,"\t%s %s;\n", type, header_elstring(elnum));
}
function header_union(f, elnum,
LOCAL, i)
{
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"]);
for (i=0;i<unions[elnum, "num_elems"];i++) {
header_element(f, unions[elnum, i]);
}
xprintf(f,"\t} %s;\n", union);
xprintf(f,"\t} %s;\n", header_elstring(elnum));
}
function header_array(f, struct_num, elem_num)
function header_elem(f, elnum)
{
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"]);
}
function header_elem(f, struct_num, elem_num)
{
if (structs[struct_num, elem_num, "type"] == ".align") return;
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);
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"]);
}

View File

@ -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 {

View File

@ -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);

View File

@ -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)

View File

@ -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="";
}

View File

@ -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;
};

View File

@ -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;