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
|
###################################################
# Python function wrapper generator
# Copyright jelmer@samba.org 2007
# released under the GNU GPL
package Parse::Pidl::Samba4::Python;
use Exporter;
@ISA = qw(Exporter);
use strict;
use Parse::Pidl::Typelist;
use Parse::Pidl::Util qw(has_property ParseExpr);
use vars qw($VERSION);
$VERSION = '0.01';
sub new($) {
my ($class) = @_;
my $self = { res => "", res_hdr => "", tabs => "", constants => {}};
bless($self, $class);
}
sub pidl_hdr ($$)
{
my $self = shift;
$self->{res_hdr} .= shift;
}
sub pidl($$)
{
my ($self, $d) = @_;
if ($d) {
$self->{res} .= $self->{tabs};
$self->{res} .= $d;
}
$self->{res} .= "\n";
}
sub indent($)
{
my ($self) = @_;
$self->{tabs} .= "\t";
}
sub deindent($)
{
my ($self) = @_;
$self->{tabs} = substr($self->{tabs}, 0, -1);
}
sub Parse($$$$)
{
my($self,$basename,$ndr,$hdr) = @_;
my $py_hdr = $hdr;
$py_hdr =~ s/ndr_([^\/]+)$/py_$1/g;
$self->pidl_hdr("/* header auto-generated by pidl */\n\n");
$self->pidl("
/* Python wrapper functions auto-generated by pidl */
#include \"includes.h\"
#include <Python.h>
#include \"$hdr\"
#include \"$py_hdr\"
");
$self->pidl("static PyMethodDef $basename\_methods[] = {");
$self->indent;
$self->pidl("{ NULL, NULL, 0, NULL }");
$self->deindent;
$self->pidl("};");
$self->pidl("");
$self->pidl("void init$basename(void)");
$self->pidl("{");
$self->indent;
$self->pidl("PyObject *m;");
$self->pidl("m = Py_InitModule((char *)\"$basename\", $basename\_methods);");
# FIXME
$self->deindent;
$self->pidl("}");
return ($self->{res_hdr}, $self->{res});
}
1;
|