diff options
author | Tim Potter <tpot@samba.org> | 2005-08-07 22:14:30 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:31:30 -0500 |
commit | febfcd33ec150bcb815fd950afe407d14264f263 (patch) | |
tree | 49171e96fa0dfac16176874a3b507b82b4784e19 /source4/script | |
parent | 7dfaea15b35d9c25cd9079dfc985b54176d0204d (diff) | |
download | samba-febfcd33ec150bcb815fd950afe407d14264f263.tar.gz samba-febfcd33ec150bcb815fd950afe407d14264f263.tar.bz2 samba-febfcd33ec150bcb815fd950afe407d14264f263.zip |
r9202: OK now we are getting somewhere. Generate js stubs for top level structs
and each arm of top level unions. Don't generate a header file (duh) as
the namespace stuff is done in the module init.
(This used to be commit dde7f8be97f1a85b2f8221a98eb2edd357eb8cf2)
Diffstat (limited to 'source4/script')
-rwxr-xr-x | source4/script/build_smb_interfaces.pl | 245 |
1 files changed, 38 insertions, 207 deletions
diff --git a/source4/script/build_smb_interfaces.pl b/source4/script/build_smb_interfaces.pl index b4fa70f4f0..e06f05b25d 100755 --- a/source4/script/build_smb_interfaces.pl +++ b/source4/script/build_smb_interfaces.pl @@ -19,8 +19,6 @@ $header = $parser->parse($file); # Make second pass over tree to make it easier to process. # -my @structs; - sub flatten_structs($) { my $obj = shift; my $s = { %$obj }; @@ -37,10 +35,13 @@ sub flatten_structs($) { delete $s->{UNION_NAME}; } + # Create a new list of structure fields with flattened names + foreach my $elt (@{$obj->{DATA}}) { foreach my $name (@{$elt->{NAME}}) { my $new_elt = { %$elt }; $new_elt->{NAME} = $name; + $new_elt->{PARENT} = $s; push(@{$s->{FIELDS}}, flatten_structs($new_elt)); } } @@ -50,111 +51,7 @@ sub flatten_structs($) { return $s; } -foreach my $s (@{$header}) { # For each parsed structure - print Dumper(flatten_structs($s)); -} - -print Dumper(@structs); -exit; - -# -# Generate header -# - -my $basename = basename($file, ".h"); -stat "libcli/gen_raw" || mkdir("libcli/gen_raw") || die("mkdir"); - -open(FILE, ">libcli/gen_raw/ejs_${basename}.h"); - -print FILE "/* header auto-generated by build_smb_interfaces.pl */\n\n"; - -print FILE "#ifndef _ejs_${basename}_h\n"; -print FILE "#define _ejs_${basename}_h\n\n"; - - -# Generate a push/pull prototype for every top level structure, as -# well as every non-anonymous nested structure (i.e TYPE_NAME element -# is undefined. - -foreach my $s (@{$header}) { - - # Top level - - print FILE "NTSTATUS ejs_push_$s->{TYPE_NAME}(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - print FILE "NTSTATUS ejs_pull_$s->{TYPE_NAME}(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - - sub header_for($$) { - my $prefix = shift; - my $obj = shift; - - return if !($obj->{TYPE} eq "struct" or $obj->{TYPE} eq "union"); - return if ($obj->{NAME} eq "in" or $obj->{NAME} eq "out"); - - print FILE "NTSTATUS ejs_push_${prefix}_$obj->{NAME}(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - print FILE "NTSTATUS ejs_pull_${prefix}_$obj->{NAME}(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - - foreach my $key (%{$obj->{FIELDS}}) { - header_for("${prefix}.$obj->{TYPE_NAME}", $obj->{FIELDS}{$key}); - } - } -} - -exit; - -sub struct_name($) -{ - my $obj = shift; - return defined($obj->{STRUCT_NAE}) ? $obj->{STRUCT_NAME} : $obj->{UNION_NAME}; -} - -sub prototypes_for($) -{ - my $obj = shift; - my $name = struct_name($obj); - - print FILE "NTSTATUS ejs_push_$name(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - print FILE "NTSTATUS ejs_pull_$name(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; -} - -foreach my $x (@{$header}) { - - # Prototypes for top level structures and unions - - prototypes_for($x); - - foreach my $e1 (@{$x->{DATA}}) { - foreach my $e2 (@{$e1->{DATA}}) { - - # Prototypes for non-anonymous nested structures and unions: - # - # e.g struct foo {...}; - - if (defined($e2->{STRUCT_NAME}) or defined($e2->{UNION_NAME})) { - prototypes_for($e2); - } - - # We also would like to push/pull nested structures and unions: - # - # e.g struct foo { - # struct {...} bar; - # }; - - if ($e2->{TYPE} eq "struct") { - if (defined($e2->{NAME}) and !defined($e2->{STRUCT_NAME})) { - foreach my $x (@{$e2->{NAME}}) { - $name = "$e1->{NAME}[0]_$x"; - print FILE "NTSTATUS ejs_push_$name(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - print FILE "NTSTATUS ejs_pull_$name(struct ejs_rpc *, struct MprVar *, const char *, const uint32_t *);\n"; - } - } - } - } - } -} - -print FILE "#endif\n"; - -close(FILE); +@newheader = map { flatten_structs($_) } @{$header}; # # Generate implementation @@ -169,106 +66,59 @@ print FILE "#include \"lib/appweb/ejs/ejs.h\"\n"; print FILE "#include \"scripting/ejs/ejsrpc.h\"\n"; # TODO: remove this print FILE "\n"; -# Top level push/pull functions - -sub print_field($$) { - my $f = shift; - my $suffix = shift; - - my $type = $f->{TYPE}; - - if ($f->{TYPE} eq "char" and $f->{POINTERS} == 1) { - $type = "string"; - } - - if ($f->{TYPE} =~ /_t$/) { - $type = $f->{TYPE}; - $type =~ s/_t$//; - } +# Top level call functions - my $deref = "&"; - if ($f->{POINTERS} == 1 && $type ne "string") { - $deref = ""; - } +foreach my $s (@newheader) { - foreach my $x (@{$f->{NAME}}) { - if ($f->{POINTERS} > 0) { - print FILE "\t// alloc $x?\n"; - } + if ($s->{TYPE} eq "struct") { - if ($f->{TYPE} eq "struct") { - $type = $f->{STRUCT_NAME}; - } - - print FILE "\tNDR_CHECK(ejs_pull_$type(ejs, v, \"$x\", ${deref}r->$suffix.$x));\n"; - } -} + # Top level struct -foreach my $x (@{$header}) { + print FILE "static NTSTATUS ejs_$s->{TYPE_DEFINED}(int eid, int argc, struct MprVar **argv)\n"; + print FILE "{\n"; + print FILE "\treturn NT_STATUS_OK;\n"; + print FILE "}\n\n"; - next, if $x->{STRUCT_NAME} eq ""; + } else { - # Pull in to struct.in + # Top level union - print FILE "static NTSTATUS ejs_pull_$x->{STRUCT_NAME}(struct ejs_rpc *ejs, struct MprVar *v, struct $x->{STRUCT_NAME} *r)\n"; - print FILE "{\n"; - print FILE "\tNDR_CHECK(ejs_pull_struct_start(ejs, &v, \"input\"));\n"; + foreach my $arm (@{$s->{FIELDS}}) { - foreach my $e (@{$x->{DATA}}) { - next, if $e->{NAME}[0] ne 'in'; - foreach my $f (@{$e->{DATA}}) { - print_field($f, "in"); + print FILE "static NTSTATUS ejs_$s->{TYPE_DEFINED}_$arm->{NAME}(int eid, int argc, struct MprVar **argv)\n"; + print FILE "{\n"; + print FILE "\treturn NT_STATUS_OK;\n"; + print FILE "}\n\n"; } } +} - print FILE "\n\treturn NT_STATUS_OK;\n"; - print FILE "}\n\n"; - - # Push from struct.out +# Module initialisation - print FILE "static NTSTATUS ejs_push_$x->{STRUCT_NAME}(struct ejs_rpc *ejs, struct MprVar *v, struct $x->{STRUCT_NAME} *r)\n\n"; - print FILE "{\n"; - print FILE "\tNDR_CHECK(ejs_push_struct_start(ejs, &v, \"output\"));\n"; +print FILE "static int ejs_${basename}_init(int eid, int argc, struct MprVar **argv)\n"; +print FILE "{\n"; +print FILE "\tstruct MprVar *obj = mprInitObject(eid, \"${basename}\", argc, argv);\n\n"; - foreach my $e (@{$x->{DATA}}) { - next, if $e->{NAME}[0] ne 'out'; - foreach my $f (@{$e->{DATA}}) { - print_field($f, "out"); +foreach my $s (@newheader) { + if ($s->{TYPE} eq "struct") { + print FILE "\tmprSetCFunction(obj, \"$s->{TYPE_DEFINED}\", ejs_$s->{TYPE_DEFINED});\n"; + } else { + foreach my $arm (@{$s->{FIELDS}}) { + print FILE "\tmprSetCFunction(obj, \"$s->{TYPE_DEFINED}_$arm->{NAME}\", ejs_$s->{TYPE_DEFINED});\n"; } } - - print FILE "\n\treturn NT_STATUS_OK;\n"; - print FILE "}\n\n"; } -# Nested anonymous structures +print FILE "}\n\n"; -foreach my $x (@{$header}) { - foreach my $e1 (@{$x->{DATA}}) { - foreach my $e2 (@{$e1->{DATA}}) { - if ($e2->{TYPE} eq "struct") { - if (defined($e2->{NAME}) and !defined($e2->{STRUCT_NAME})) { - foreach my $x (@{$e2->{NAME}}) { - - $name = "$e1->{NAME}[0]_$x"; - - print FILE "static NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const uint32_t *r)\n"; - print FILE "{\n"; - print FILE "\treturn NT_STATUS_OK;\n"; - print FILE "}\n\n"; - - print FILE "static NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const uint32_t *r)\n"; - print FILE "{\n"; - print FILE "\treturn NT_STATUS_OK;\n"; - print FILE "}\n\n"; - } - } - } - } - } -} +print FILE "NTSTATUS ejs_init_${basename}(void)\n"; +print FILE "{\n"; +print FILE "\treturn smbcalls_register_ejs(\"${basename}_init\", ejs_${basename}_init);\n"; +print FILE "}\n"; -# Top level call functions +close(FILE); + +exit; foreach my $x (@{$header}) { next, if $x->{STRUCT_NAME} eq ""; @@ -309,22 +159,3 @@ __HERE__ print FILE "}\n\n"; } -# Module initialisation - -print FILE "static int ejs_${basename}_init(int eid, int argc, struct MprVar **argv)\n"; -print FILE "{\n"; -print FILE "\tstruct MprVar *obj = mprInitObject(eid, \"${basename}\", argc, argv);\n\n"; - -foreach my $x (@{$header}) { - next, if $x->{STRUCT_NAME} eq ""; - print FILE "\tmprSetCFunction(obj, \"$x->{STRUCT_NAME}\", ejs_$x->{STRUCT_NAME});\n"; -} - -print FILE "}\n\n"; - -print FILE "NTSTATUS ejs_init_${basename}(void)\n"; -print FILE "{\n"; -print FILE "\treturn smbcalls_register_ejs(\"${basename}_init\", ejs_${basename}_init);\n"; -print FILE "}\n"; - -close(FILE); |