r14542: Remove librpc, libndr and libnbt from includes.h
[mat/samba.git] / source4 / librpc / 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 # Copyright jelmer@samba.org 2005
7 # released under the GNU GPL
8
9 use strict;
10
11 use Getopt::Long;
12 use File::Basename;
13
14 my $opt_output = 'librpc/gen_ndr/tables.c';
15 my $opt_help  = 0;
16
17
18 #########################################
19 # display help text
20 sub ShowHelp()
21 {
22     print "
23            perl DCE/RPC interface table generator
24            Copyright (C) tridge\@samba.org
25
26            Usage: tables.pl [options] <idlfile>
27
28            Options:
29              --output OUTNAME      put output in OUTNAME.*
30            \n";
31     exit(0);
32 }
33
34 # main program
35 GetOptions (
36             'help|h|?' => \$opt_help, 
37             'output=s' => \$opt_output,
38             );
39
40 if ($opt_help) {
41     ShowHelp();
42     exit(0);
43 }
44
45 my $init_fns = "";
46
47 ###################################
48 # extract table entries from 1 file
49 sub process_file($)
50 {
51         my $filename = shift;
52         open(FILE, $filename) || die "unable to open $filename\n";
53         my $found = 0;
54
55         while (my $line = <FILE>) {
56                 if ($line =~ /extern const struct dcerpc_interface_table (\w+);/) {
57                         $found = 1;
58                         $init_fns.="\tstatus = librpc_register_interface(&$1);\n";
59                         $init_fns.="\tif (NT_STATUS_IS_ERR(status)) return status;\n\n";
60                 }
61         }
62
63         if ($found) {
64                 print TABLEC "#include \"$filename\"\n";
65         }
66
67         close(FILE);
68 }
69
70 print "Creating $opt_output\n";
71 open(TABLEC, ">$opt_output") || die "failed to open $opt_output\n";
72
73 print TABLEC <<EOF;
74
75 /* Automatically generated by tables.pl. DO NOT EDIT */
76
77 #include "includes.h"
78 #include "librpc/rpc/dcerpc.h"
79 #include "librpc/rpc/dcerpc_table.h"
80 EOF
81
82 process_file($_) foreach (@ARGV);
83
84 print TABLEC <<EOF;
85
86 NTSTATUS dcerpc_register_builtin_interfaces(void)
87 {
88         NTSTATUS status;
89
90 $init_fns
91         
92         return NT_STATUS_OK;
93 }
94 EOF
95
96 close(TABLEC);