-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkfldpm32.pl
executable file
·127 lines (113 loc) · 3.19 KB
/
mkfldpm32.pl
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
#! perl -Iblib/arch -Iblib/lib
use Endurox;
$numargs = @ARGV;
if ( $numargs == 0 )
{
$ARGV[0] = "fld.tbl";
$numargs = 1;
}
$index = 0;
while ( $index < $numargs )
{
$fldtbl = $ARGV[$index];
$fldpm = ( $fldtbl . ".pm" );
# check the file exists
unless ( -e $fldtbl ) {
die( "CMDUBF_CAT:2:ERROR: Cannot find file " . $fldtbl . "\n" );
}
# open the fldtbl for reading
unless ( open( FLDTBL, $fldtbl ) ) {
die( "Cannot open file " . $fldtbl . " for reading.\n" );
}
# open the fldpm for writing
unless ( open( FLDPM, ">" . $fldpm ) ) {
die( "Cannot open file " . $fldpm . " for writing.\n" );
}
$base = 0;
$fields;
while ( $line = <FLDTBL> )
{
if ( $line =~ /^\s*[\#\$]/ || $line =~ /^\s*$/ )
{
# this is a comment, so ignore this line
next;
}
if ( $line =~ /^\s*\*base\s+(\d+)/ )
{
$base = $1;
}
else
{
# line should be in the format...
# <FLDNAME> <FLDNUM> <BFLDTYPE> [# comment]
@words = split( /\s+/, $line );
if ( @words < 3 )
{
print $line . "WARNING: invalid line.\n";
next;
}
$fldname = $words[0];
$fldnum = $words[1];
$type = $words[2];
$bfldtype = 0;
if ( $type eq "short" ) {
$bfldtype = BFLD_SHORT;
}
elsif ( $type eq "long" ) {
$bfldtype = BFLD_LONG;
}
elsif ( $type eq "char" ) {
$bfldtype = BFLD_CHAR;
}
elsif ( $type eq "float" ) {
$bfldtype = BFLD_FLOAT;
}
elsif ( $type eq "double" ) {
$bfldtype = BFLD_DOUBLE;
}
elsif ( $type eq "string" ) {
$bfldtype = BFLD_STRING;
}
elsif ( $type eq "carray" ) {
$bfldtype = BFLD_CARRAY;
}
elsif ( $type eq "ptr" ) {
$bfldtype = FLD_PTR;
}
elsif ( $type eq "ubf" ) {
$bfldtype = FLD_UBF;
}
elsif ( $type eq "view32" ) {
$bfldtype = FLD_VIEW32;
}
else {
# something is wrong, skip this line
next;
}
$fldnum += $base;
$bfldid = Bmkfldid( $bfldtype, $fldnum );
$fields{$fldname} = $bfldid;
}
}
print FLDPM "package " . $fldtbl . ";\n\n";
print FLDPM "use strict;\n";
print FLDPM "use vars qw(\$VERSION \@ISA \@EXPORT);\n";
print FLDPM "require Exporter;\n\n";
print FLDPM "\$VERSION = 1.00;\n\n";
print FLDPM "\@ISA = qw(Exporter);\n";
print FLDPM "\@EXPORT = qw(\n";
foreach $fldname ( keys( %fields ) )
{
print FLDPM ( "\t$fldname\n" );
}
print FLDPM ( ");\n\n" );
print FLDPM "# subs\n";
foreach $fldname ( keys( %fields ) )
{
print FLDPM ( "sub $fldname { $fields{$fldname}; }\n" );
}
print FLDPM "\n1; #\n";
close( FLDTBL );
close( FLDPM );
$index++;
}