r3428: switched to using minimal includes for the auto-generated RPC code.
[samba.git] / source / build / pidl / tables.pl
1 #!/usr/bin/perl -w
2
3 ###################################################
4 # package to produce a table of all idl parsers
5 # Copyright tridge@samba.org 2003
6 # released under the GNU GPL
7
8 use strict;
9
10 use Getopt::Long;
11 use File::Basename;
12
13 my($opt_output);
14 my($opt_help) = 0;
15
16
17 #########################################
18 # display help text
19 sub ShowHelp()
20 {
21     print "
22            perl IDL table generator
23            Copyright (C) tridge\@samba.org
24
25            Usage: tables.pl [options] <idlfile>
26
27            Options:
28              --output OUTNAME      put output in OUTNAME.*
29            \n";
30     exit(0);
31 }
32
33 # main program
34 GetOptions (
35             'help|h|?' => \$opt_help, 
36             'output=s' => \$opt_output,
37             );
38
39 if ($opt_help) {
40     ShowHelp();
41     exit(0);
42 }
43
44
45 ###################################
46 # add include lines to tables.c
47 sub process_include($)
48 {
49         my $name = shift;
50         print TABLEC "#include \"$name\"\n";
51 }
52
53 ###################################
54 # extract table entries from 1 file
55 sub process_file($)
56 {
57         my $filename = shift;
58         open(FILE, $filename) || die "unable to open $filename\n";
59
60         while (my $line = <FILE>) {
61                 if ($line =~ /extern const struct dcerpc_interface_table dcerpc_table_(\w+);/) {
62                         print TABLEC "\t&dcerpc_table_$1,\n";
63                         print TABLEH "NTSTATUS dcerpc_$1\_init(void);\n";
64                 }
65         }
66
67         close(FILE);
68 }
69
70 print "Creating $opt_output.[ch]\n";
71 open(TABLEH, ">$opt_output.h") || die "failed to open $opt_output.h\n";
72 open(TABLEC, ">$opt_output.c") || die "failed to open $opt_output.c\n";
73
74 #include "includes.h"
75
76 #define NDR_BASE_MARSHALL_SIZE 1024
77
78 print TABLEC "
79 #include \"includes.h\"
80 ";
81
82 foreach my $filename (@ARGV) {
83         process_include($filename);
84 }
85
86
87 print TABLEC "
88 /*
89   generated by pidl IDL table generator
90 */
91 const struct dcerpc_interface_table * const dcerpc_pipes[] = {
92 ";
93
94 print TABLEH "
95 /*
96    table headers generated by pidl IDL table generator
97 */
98
99 extern const struct dcerpc_interface_table * const dcerpc_pipes[];
100
101 ";
102
103 foreach my $filename (@ARGV) {
104         process_file($filename);
105 }
106
107
108 print TABLEC "\tNULL\n};\n";
109
110 close(TABLEH);
111 close(TABLEC);