1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/usr/bin/perl
#
# Create ejs interfaces for structures in a C header file
#
use File::Basename;
my $file = shift;
my $basename = basename($file, ".h");
require smb_interfaces;
my $parser = new smb_interfaces;
$header = $parser->parse($file);
use Data::Dumper;
#print Dumper($header);
# Create header
open(FILE, ">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";
sub struct_name($)
{
my $obj = shift;
return defined($obj->{STRUCT_NAME}) ? $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";
}
sub pushpull_for($)
{
my $obj = shift;
my $name = struct_name($obj);
print FILE "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const uint32_t *r)\n";
print FILE "{\n";
print FILE "\tNDR_CHECK(ejs_push_struct_start(ejs, &v, name));\n";
print FILE "\n\treturn NT_STATUS_OK;\n";
print FILE "}\n\n";
print FILE "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";
}
foreach my $x (@{$header}) {
# Prototypes for top level structures and unions
prototypes_for($x);
# Prototypes for non-anonymous nested structures and unions
foreach my $e1 (@{$x->{DATA}}) {
foreach my $e2 (@{$e1->{DATA}}) {
if (defined($e2->{STRUCT_NAME}) or defined($e2->{UNION_NAME})) {
prototypes_for($e2);
}
}
}
}
print FILE "#endif\n";
close(FILE);
# Create file
open(FILE, ">ejs_${basename}.c");
print FILE "/* EJS wrapper functions auto-generated by build_smb_interfaces.pl */\n\n";
# Top level functions
foreach my $x (@{$header}) {
pushpull_for($x);
}
close(FILE);
|