summaryrefslogtreecommitdiff
path: root/source4/build/pidl/tables.pl
blob: 8d43dff1461585e4f25625ad62cac5ba6cf68cfd (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w

###################################################
# package to produce a table of all idl parsers
# Copyright tridge@samba.org 2003
# released under the GNU GPL

use strict;

use Getopt::Long;
use File::Basename;

my($opt_output);
my($opt_help) = 0;


#########################################
# display help text
sub ShowHelp()
{
    print "
           perl IDL table generator
           Copyright (C) tridge\@samba.org

           Usage: tables.pl [options] <idlfile>

           Options:
             --output OUTNAME      put output in OUTNAME.*
           \n";
    exit(0);
}

# main program
GetOptions (
	    'help|h|?' => \$opt_help, 
	    'output=s' => \$opt_output,
	    );

if ($opt_help) {
    ShowHelp();
    exit(0);
}


###################################
# add include lines to tables.c
sub process_include($)
{
	my $name = shift;
	print TABLEC "#include \"$name\"\n";
}

###################################
# extract table entries from 1 file
sub process_file($)
{
	my $filename = shift;
	open(FILE, $filename) || die "unable to open $filename\n";

	while (my $line = <FILE>) {
		if ($line =~ /extern const struct dcerpc_interface_table dcerpc_table_(\w+);/) {
			print TABLEC "\t&dcerpc_table_$1,\n";
			print TABLEH "NTSTATUS dcerpc_$1\_init(void);\n";
		}
	}

	close(FILE);
}

print "Creating $opt_output.[ch]\n";
open(TABLEH, ">$opt_output.h") || die "failed to open $opt_output.h\n";
open(TABLEC, ">$opt_output.c") || die "failed to open $opt_output.c\n";

#include "includes.h"

#define NDR_BASE_MARSHALL_SIZE 1024

print TABLEC "
#include \"includes.h\"
";

foreach my $filename (@ARGV) {
	process_include($filename);
}


print TABLEC "
/*
  generated by pidl IDL table generator
*/
const struct dcerpc_interface_table * const dcerpc_pipes[] = {
";

print TABLEH "
/*
   table headers generated by pidl IDL table generator
*/

extern const struct dcerpc_interface_table * const dcerpc_pipes[];

";

foreach my $filename (@ARGV) {
	process_file($filename);
}


print TABLEC "\tNULL\n};\n";

close(TABLEH);
close(TABLEC);