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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#!/usr/bin/perl
# $Header$
$usage = "Usage: xvar [-a] [-c] typemap file.xv\n";
die $usage unless (@ARGV >= 2 && @ARGV <= 4);
SWITCH: while ($ARGV[0] =~ /^-/) {
$flag = shift @ARGV;
$aflag = 1, next SWITCH if $flag =~ /^-a$/;
$cflag = 1, next SWITCH if $flag =~ /^-c$/;
die $usage;
}
$typemap = shift @ARGV;
open(TYPEMAP, $typemap) || die "cannot open $typemap\n";
while (<TYPEMAP>) {
next if /^\s*$/ || /^#/;
chop;
($typename, $kind) = split(/\t+/);
$type_kind{$typename} = $kind;
}
close(TYPEMAP);
$uvfile = shift @ARGV;
open(F, $uvfile) || die "cannot open $uvfile\n";
#($uvoutfile = $uvfile) =~ s|^.*/([^/]*).us$|\1.c| ;
#print "uvoutfile is $uvoutfile\n";
#open(FOUT, ">$uvoutfile") || die "cannot open $uvoutfile\n";
#select(FOUT);
while (<F>) {
last if ($Module, $foo, $Package, $foo1, $Prefix) =
/^MODULE\s*=\s*(\w+)(\s+PACKAGE\s*=\s*(\w+))?(\s+PREFIX\s*=\s*(\w+))?/;
print $_;
}
$Package .= "::" if defined $Package && $Package ne "";
print <<EOF;
static struct varinfo varinfo [] = {
EOF
while (<F>) {
next if /^s*$/ || /^#/;
if (/^MODULE\s*=\s*(\w+)(\s+PACKAGE\s*=\s*(\w+))?(\s+PREFIX\s*=\s*(\w+))?/) {
$Module = $1;
$foo = $2;
$Package = $3;
$foo1 = $4;
$Prefix = $5;
$Package .= "'" if defined $Package && $Package ne "";
next;
}
chop;
$func = undef;
($var, $kind, $store, $read) = split(/\t+/);
die "$kind not defined in typemap\n" if !defined($type_kind{$kind});
$flags = "0";
if ($store =~ /FUNC=(.*)/) {
$flags .= "|VI_FUNC";
$func = $1;
} elsif ($store eq "VAR") {
$flags .= "|VI_VARIABLE";
} elsif ($store ne "VAL") {
die "$var storage class not VAL, VAR or FUNC\n";
}
if ($read eq "READWRITE") {
$flags .= "|VI_READWRITE";
} elsif ($read ne "READONLY") {
die "$var access class not READONLY or READWRITE\n";
}
SIZE: {
$type_kind = $type_kind{$kind};
$size = 0;
do {$size = "sizeof(int)"; last SIZE; }
if ($type_kind eq "T_INT");
do {$size = "sizeof($kind)"; last SIZE; }
if ($type_kind eq "T_ENUM");
do {$size = "sizeof(unsigned int)"; last SIZE; }
if ($type_kind eq "T_U_INT");
do {$size = "sizeof(short)"; last SIZE; }
if ($type_kind eq "T_SHORT");
do {$size = "sizeof(unsigned short)"; last SIZE; }
if ($type_kind eq "T_U_SHORT");
do {$size = "sizeof(long)"; last SIZE; }
if ($type_kind eq "T_LONG");
do {$size = "sizeof(unsigned long)"; last SIZE; }
if ($type_kind eq "T_U_LONG");
do {$size = "sizeof(char)"; last SIZE; }
if ($type_kind eq "T_CHAR");
do {$size = "sizeof(unsigned char)"; last SIZE; }
if ($type_kind eq "T_U_CHAR");
do {$size = "0"; last SIZE; }
if ($type_kind eq "T_STRING");
do {$size = "sizeof(char *)"; last SIZE; }
if ($type_kind eq "T_PTR");
do {$size = "sizeof($kind)"; last SIZE; }
if ($type_kind eq "T_OPAQUE");
}
($name = $var) =~ s/^$Prefix//;
print " { \"$Package$name\", $type_kind, $flags, $size, ";
if ($store =~ /FUNC/) {
print "(char *)$func, 0.0 },\n";
} elsif ($store eq "VAR") {
print "(char *)&$var, 0.0 },\n";
} elsif ($type_kind eq "T_FLOAT" || $type_kind eq "T_DOUBLE") {
print "0, $var },\n";
} else {
print "(char *)$var, 0.0 },\n";
}
}
print <<EOF if $aflag;
};
static unsigned long varinfolen = sizeof(varinfo)/sizeof(*varinfo);
static int UV_val(int ix, SV *sv)
{
return common_UV_val(varinfo, varinfolen, ix, sv);
}
static int UV_set(int ix, SV *sv)
{
return common_UV_set(varinfo, varinfolen, ix, sv);
}
EOF
print <<EOF if !$aflag;
};
static unsigned long varinfolen = sizeof(varinfo)/sizeof(*varinfo);
static int UV_val(ix, sv)
int ix;
SV *sv;
{
return common_UV_val(varinfo, varinfolen, ix, sv);
}
static int UV_set(ix, sv)
int ix;
SV *sv;
{
return common_UV_set(varinfo, varinfolen, ix, sv);
}
EOF
print qq/extern "C"\n/ if $cflag;
print <<EOF;
void init_$Module()
{
int i;
struct ufuncs uf;
uf.uf_set = UV_set;
uf.uf_val = UV_val;
for (i = 0; i < varinfolen; i++) {
uf.uf_index = i;
magicname(varinfo[i].vname, (char *)&uf, sizeof uf);
}
}
EOF
|