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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#!/usr/local/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package genverifier;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
use Exporter;
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(
GenVerifier
);
@EXPORT_OK = qw();
sub GenNPL {
my($ret) = << "END_MPL";
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
END_MPL
return $ret;
}
##--------------------------------------------------------------
sub GetClass {
my($char, $clstbl) = @_;
my($l);
for($l =0; $l <= @$clstbl; $l++) {
if(($clstbl->[$l][0] <= $char) && ($char <= $clstbl->[$l][1]))
{
return $clstbl->[$l][2];
}
}
print "WARNING- there are no class for $char\n";
};
##--------------------------------------------------------------
sub GenClassPkg {
my($name, $bits) = @_;
return GenPkg($name, $bits, "_cls");
}
##--------------------------------------------------------------
sub GenStatePkg {
my($name, $bits) = @_;
return GenPkg($name, $bits, "_st");
};
##--------------------------------------------------------------
sub GenPkg {
my($name, $bits, $tbl) = @_;
my($ret);
$ret = " {" .
"eIdxSft" . $bits . "bits, " .
"eSftMsk" . $bits . "bits, " .
"eBitSft" . $bits . "bits, " .
"eUnitMsk" . $bits . "bits, " .
$name . $tbl . "" .
" }";
return $ret;
};
##--------------------------------------------------------------
sub Gen4BitsClass {
my($name, $clstbl) = @_;
my($i,$j);
my($cls);
my($ret);
$ret = "";
$ret .= "static const uint32_t " . $name . "_cls [ 256 / 8 ] = {\n";
for($i = 0; $i < 0x100; $i+= 8) {
$ret .= "PCK4BITS(";
for($j = $i; $j < $i + 8; $j++) {
$cls = &GetClass($j,$clstbl);
$ret .= sprintf("%2d", $cls) ;
if($j != ($i+7)) {
$ret .= ",";
}
}
if( $i+8 >= 0x100) {
$ret .= ") ";
} else {
$ret .= "),";
}
$ret .= sprintf(" // %02x - %02x\n", $i, ($i+7));
}
$ret .= "};\n";
return $ret;
};
##--------------------------------------------------------------
sub GenVerifier {
my($name, $charset, $cls, $numcls, $st) = @_;
my($ret);
$ret = GenNPL();
$ret .= GenNote();
$ret .= GenHeader();
$ret .= Gen4BitsClass($name, $cls);
$ret .= "\n\n";
$ret .= Gen4BitsState($name, $st);
$ret .= "\n\n";
$ret .= "const SMModel " . $name . "SMModel = {\n";
$ret .= GenClassPkg($name, 4);
$ret .= ",\n";
$ret .= " " . $numcls;
$ret .= ",\n";
$ret .= GenStatePkg($name, 4);
$ret .= ",\n";
$ret .= " " . "CHAR_LEN_TABLE(" . $name . "CharLenTable),\n";
$ret .= ' "' . $charset . '",' . "\n";
$ret .= "};\n";
return $ret;
};
##--------------------------------------------------------------
sub Gen4BitsState {
my($name, $sttbl) = @_;
my($lenafterpad) = (((@$sttbl-1) >> 3) + 1) << 3;
my($i,$j);
my($ret);
$ret = "";
$ret .= "static const uint32_t " . $name . "_st [ " . ($lenafterpad >> 3) . "] = {\n";
for($i = 0; $i < $lenafterpad ; $i+= 8) {
$ret .= "PCK4BITS(";
for($j = $i; $j < $i + 8; $j++) {
if(0 == $sttbl->[$j]) {
$ret .= "eStart";
} else { if(1 == $sttbl->[$j]) {
$ret .= "eError";
} else { if(2 == $sttbl->[$j]) {
$ret .= "eItsMe";
} else {
$ret .= sprintf(" %d", $sttbl->[$j]) ;
}}}
if($j != ($i+7)) {
$ret .= ",";
}
}
if( $i+8 >= $lenafterpad ) {
$ret .= ") ";
} else {
$ret .= "),";
}
$ret .= sprintf(" // %02x - %02x\n", $i, ($i+7));
}
$ret .= "};\n";
return $ret;
};
##--------------------------------------------------------------
sub GenNote {
my($ret) = << "END_NOTE";
/*
* DO NOT EDIT THIS DOCUMENT MANUALLY !!!
* THIS FILE IS AUTOMATICALLY GENERATED BY THE TOOLS UNDER
* mozilla/intl/chardet/tools/
* Please contact ftang\@netscape.com or mozilla-i18n\@mozilla.org
* if you have any question. Thanks
*/
END_NOTE
return $ret;
}
##--------------------------------------------------------------
sub GenHeader {
my($ret) = << "END_HEADER";
#include "nsVerifier.h"
END_HEADER
return $ret;
}
##--------------------------------------------------------------
1; # this should be the last line
|