diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-05-17 06:53:21 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-05-17 06:53:21 +0000 |
commit | ba2f726efdb97c95c6110b0365a011121e27fce3 (patch) | |
tree | ab61d7cddc2bb615a938505b817cf0fd438999e0 /source3 | |
parent | c560164030c0b842ee06f651a2b019c5596624a2 (diff) | |
download | samba-ba2f726efdb97c95c6110b0365a011121e27fce3.tar.gz samba-ba2f726efdb97c95c6110b0365a011121e27fce3.tar.bz2 samba-ba2f726efdb97c95c6110b0365a011121e27fce3.zip |
- added typedefs
- added parse error checking
- made parser more flexible
(This used to be commit ab0beaf3573471fab1fda3358987b337811f99b7)
Diffstat (limited to 'source3')
-rwxr-xr-x | source3/aparser/build | 8 | ||||
-rw-r--r-- | source3/aparser/main.awk | 51 | ||||
-rw-r--r-- | source3/aparser/parsefn.awk | 2 | ||||
-rw-r--r-- | source3/aparser/parser.h | 1 | ||||
-rw-r--r-- | source3/aparser/parsetree.awk | 16 | ||||
-rw-r--r-- | source3/aparser/srvsvc.struct | 26 | ||||
-rw-r--r-- | source3/aparser/token.awk | 92 |
7 files changed, 131 insertions, 65 deletions
diff --git a/source3/aparser/build b/source3/aparser/build index db4bec057d..a8b49451f6 100755 --- a/source3/aparser/build +++ b/source3/aparser/build @@ -2,6 +2,12 @@ file=$1 -igawk -f main.awk $file +if ! igawk -f main.awk $file; then + echo parse failed; + exit 1; +fi +echo compiling vluke gcc -Wall -g -o vluke parser.c vluke.c +echo done. + diff --git a/source3/aparser/main.awk b/source3/aparser/main.awk index 5d67f123c7..46acfe5c59 100644 --- a/source3/aparser/main.awk +++ b/source3/aparser/main.awk @@ -1,57 +1,22 @@ # the main program @include dump.awk -@include parsetree.awk @include header.awk @include util.awk @include template.awk @include parsefn.awk @include harness.awk - -/^module/ { - start_module($2); - next; -} - -/^test/ { - add_test($2); - next; -} - -/^struct.*\{/ { - start_struct($2); - next; -} - -/^[ \t]*union.*\{/ { - start_union($2); - next; -} - -/^[ \t]*case.*;/ { - split($0,a,"[ \t;]*"); - parse_case(a[3],a[4],a[5]); - next; -} - -/^\};/ { - end_struct(); - next; -} - -/^[ \t]*\}/ { - end_union(); - next; -} - -/.*;/ { - split($0,a,"[ \t;]*"); - add_struct_elem(a[2], a[3]); -} +@include parsetree.awk +@include token.awk END { - dump_structs("debug.out"); + dump_structs("dump.out"); + printf("Producing headers...\n"); produce_headers("prs_"module".h"); + printf("Producing parsers...\n"); produce_parsers("prs_"module".c"); + printf("Producing harness...\n"); produce_harness("test.h"); + printf("Done.\n"); + exit 0; } diff --git a/source3/aparser/parsefn.awk b/source3/aparser/parsefn.awk index 4c88cdeab8..45c41d770b 100644 --- a/source3/aparser/parsefn.awk +++ b/source3/aparser/parsefn.awk @@ -15,7 +15,7 @@ function parse_array(f, v, elnum, flags, v["FLAGS"] = flags; v["ARRAY_LEN"] = elements[elnum, "array_len"]; - if (type == "uint16") { + if (type == "wchar") { print_template(f, "prs_wstring.tpl", v); } else { print_template(f, "prs_array.tpl", v); diff --git a/source3/aparser/parser.h b/source3/aparser/parser.h index 7d4425ed3e..5c3a14c66f 100644 --- a/source3/aparser/parser.h +++ b/source3/aparser/parser.h @@ -25,6 +25,7 @@ typedef int BOOL; typedef unsigned char uint8; typedef unsigned short uint16; +typedef unsigned short wchar; typedef unsigned uint32; #define False 0 diff --git a/source3/aparser/parsetree.awk b/source3/aparser/parsetree.awk index e99793f516..fe0958e7bf 100644 --- a/source3/aparser/parsetree.awk +++ b/source3/aparser/parsetree.awk @@ -9,6 +9,19 @@ function start_module(name) num_tests=0; } +function parse_typedef(type1, type2, + LOCAL, type, i) +{ + type=type2; + if (substr(type,1,1)=="*") type=substr(type,2); + + i=match(type,"[[]"); + if (i != 0) type = substr(type, 1, i-1); + start_struct(type); + add_struct_elem(type1, type2); + end_struct(""); +} + function start_struct(name) { current_struct=num_structs; @@ -18,8 +31,9 @@ function start_struct(name) structs[current_struct, "num_unions"]=0; } -function end_struct() +function end_struct(name) { + if (name!="") structs[num_structs, "name"]=name; printf("struct %s with %d elements\n", structs[num_structs, "name"], structs[num_structs, "num_elems"]); diff --git a/source3/aparser/srvsvc.struct b/source3/aparser/srvsvc.struct index e50fe11a82..aa40c8f15e 100644 --- a/source3/aparser/srvsvc.struct +++ b/source3/aparser/srvsvc.struct @@ -1,28 +1,16 @@ module srvsvc -#define SRV_NETCONNENUM 0x08 -#define SRV_NETFILEENUM 0x09 -#define SRV_NETSESSENUM 0x0c -#define SRV_NETSHAREENUM 0x0f -#define SRV_NET_SHARE_GET_INFO 0x10 -#define SRV_NET_SRV_GET_INFO 0x15 -#define SRV_NET_SRV_SET_INFO 0x16 -#define SRV_NET_REMOTE_TOD 0x1c - -struct UNISTR2 { +typedef uint32 LONG; +typedef uint32 *ENUM_HND; + +typedef struct _UNISTR2 { uint32 max_len; uint32 undoc; uint32 str_len; - uint16 buffer[str_len]; -}; + wchar buffer[str_len]; +} UNISTR2; -struct LPWSTR { - UNISTR2 *str; -}; - -struct ENUM_HND { - uint32 *handle; /* enumeration handle */ -}; +typedef UNISTR2 *LPWSTR; /* function 8 */ struct CONN_INFO_0 { diff --git a/source3/aparser/token.awk b/source3/aparser/token.awk new file mode 100644 index 0000000000..a64700f536 --- /dev/null +++ b/source3/aparser/token.awk @@ -0,0 +1,92 @@ +# tokenise the input file + +function parse_error(msg) { + printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg); + exit 1; +} + +# ignore blank lines +/^[ \t]*$/ { + next; +} + +# ignore comments +/^[ \t]*\#/ { + next; +} + +# ignore C comments +/^[ \t]*\/\*.*\*\// { + next; +} + +/^[ \t]*module/ { + {if (module!="") parse_error("you can only specify one module name");} + start_module($2); + next; +} + +{if (module=="") parse_error("you must specify the module name first");} + +/^[ \t]*typedef struct.*\{/ { + {if (current_struct!="") parse_error("you cannot have nested structures");} + start_struct($3); + next; +} + +/^[ \t]*typedef.*;/ { + {if (current_struct!="") parse_error("typedefs must be global");} + split($0,a,"[ \t;]*"); + parse_typedef(a[2], a[3]); + next; +} + +/^[ \t]*struct.*\{/ { + {if (current_struct!="") parse_error("you cannot have nested structures");} + start_struct($2); + next; +} + +{if (current_struct=="") parse_error("this must appear inside a structure");} + +/^[ \t]*union.*\{/ { + {if (current_union!="") parse_error("you cannot have nested unions");} + start_union($2); + next; +} + +/^[ \t]*case.*;/ { + {if (current_union=="") parse_error("this must appear inide a union");} + split($0,a,"[ \t;]*"); + parse_case(a[3],a[4],a[5]); + next; +} + +/^[ \t]*\}$/ { + {if (current_union=="") parse_error("this must appear inside a union");} + end_union(); + next; +} + +{if (current_union!="") parse_error("this cannot appear inside a union");} + +/^[ \t]*\};/ { + end_struct(""); + next; +} + +/^[ \t]*\} .*;/ { + split($0,a,"[ \t;]*"); + end_struct(a[2]); + next; +} + +/^.*;/ { + split($0,a,"[ \t;]*"); + add_struct_elem(a[2], a[3]); + next; +} + +{ + parse_error("Unknown construct."); +} |