5 # don't use warnings module as it is not portable enough
11 my $public_file = undef;
12 my $private_file = undef;
13 my $public_define = undef;
14 my $private_define = undef;
15 my $public_fd = \*STDOUT;
16 my $private_fd = \*STDOUT;
19 'public=s' => sub { my ($f,$v) = @_; $public_file = $v; },
20 'private=s' => sub { my ($f,$v) = @_; $private_file = $v; },
24 $private_define = "$v\_PRIVATE";
26 'public-define=s' => \$public_define,
27 'private-define=s' => \$private_define
30 if (not defined($public_define) and defined($public_file)) {
31 $public_define = $public_file;
32 $public_define =~ tr{./}{__};
33 } elsif (not defined($public_define)) {
34 $public_define = '_PROTO_H_';
37 if (not defined($private_define) and defined($private_file)) {
38 $private_define = $private_file;
39 $private_define =~ tr{./}{__};
40 } elsif (not defined($public_define)) {
41 $public_define = '_PROTO_H_';
44 if (defined($public_file)) {
45 open PUBLIC, ">$public_file";
46 $public_fd = \*PUBLIC;
49 if ($private_file eq $public_file) {
50 $private_fd = $public_fd;
51 } elsif (not defined($private_file)) {
52 open PRIVATE, ">$private_file";
53 $private_fd = \*PRIVATE;
58 my ($file, $header_name) = @_;
59 print $file "#ifndef $header_name\n";
60 print $file "#define $header_name\n\n";
61 print $file "/* This file is automatically generated with \"make proto\". DO NOT EDIT */\n\n";
66 my ($file, $header_name) = @_;
67 printf $file "\n#endif /* %s */\n", $header_name;
70 sub handle_loadparm($$)
72 my ($file,$line) = @_;
74 if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|CHAR|INTEGER|LIST)\((\w+),.*\)/o) {
81 "CONST_STRING" => "const char *",
82 "STRING" => "const char *",
85 "LIST" => "const char **",
93 print $file "$tmap{$type}$name($smap{$scope});\n";
99 my ($public_file, $private_file, $filename) = @_;
101 $filename =~ s/\.o$/\.c/g;
103 open(FH, "< $filename") || die "Failed to open $filename";
105 print $private_file "\n/* The following definitions come from $filename */\n\n";
107 while (my $line = <FH>) {
108 my $target = $private_file;
110 # these are ordered for maximum speed
111 next if ($line =~ /^\s/);
113 next unless ($line =~ /\(/);
115 next if ($line =~ /^\/|[;]/);
117 next unless ( $line =~ /
118 ^void|^BOOL|^int|^struct|^char|^const|^\w+_[tT]\s|^uint|^unsigned|^long|
119 ^NTSTATUS|^ADS_STATUS|^enum\s.*\(|^DATA_BLOB|^WERROR|^XFILE|^FILE|^DIR|
120 ^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NTTIME|^FN_|^REG_KEY|^REG_HANDLE|^REG_VAL|
121 ^GtkWidget|^GType|^smb_ucs2_t
124 next if ($line =~ /^int\s*main/);
126 if ($line =~ /^FN_/) {
127 handle_loadparm($public_file, $line);
131 if ($line =~ s/_PUBLIC_//xo) {
132 $target = $public_file;
135 if ( $line =~ /\(.*\)\s*$/o ) {
137 print $target "$line;\n";
143 while ($line = <FH>) {
144 if ($line =~ /\)\s*$/o) {
146 print $target "$line;\n";
156 if ($public_file ne $private_file) {
157 print_header($private_fd, $private_define);
159 print_header($public_fd, $public_define);
160 process_file($public_fd, $private_fd, $_) foreach (@ARGV);
161 print_footer($public_fd, $public_define);
162 if ($public_file ne $private_file) {
163 print_footer($private_fd, $private_define);