Bug 790132 - Add a test to make sure media sniffing occurs only when we want. r=bz
[gecko.git] / intl / chardet / tools / genverifier.pm
blobb9e7b9583263fff2bb5794fbf3f7c334ffaf6665
1 #!/usr/local/bin/perl
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 package genverifier;
8 use strict;
9 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
11 use Exporter;
12 $VERSION = 1.00;
13 @ISA = qw(Exporter);
15 @EXPORT = qw(
16 GenVerifier
18 @EXPORT_OK = qw();
20 sub GenNPL {
21 my($ret) = << "END_MPL";
22 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
23 /* This Source Code Form is subject to the terms of the Mozilla Public
24 * License, v. 2.0. If a copy of the MPL was not distributed with this
25 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
26 END_MPL
28 return $ret;
31 ##--------------------------------------------------------------
32 sub GetClass {
33 my($char, $clstbl) = @_;
34 my($l);
35 for($l =0; $l <= @$clstbl; $l++) {
36 if(($clstbl->[$l][0] <= $char) && ($char <= $clstbl->[$l][1]))
38 return $clstbl->[$l][2];
41 print "WARNING- there are no class for $char\n";
43 ##--------------------------------------------------------------
44 sub GenClassPkg {
45 my($name, $bits) = @_;
46 return GenPkg($name, $bits, "_cls");
48 ##--------------------------------------------------------------
49 sub GenStatePkg {
50 my($name, $bits) = @_;
51 return GenPkg($name, $bits, "_st");
53 ##--------------------------------------------------------------
54 sub GenPkg {
55 my($name, $bits, $tbl) = @_;
56 my($ret);
57 $ret = " {\n" .
58 " eIdxSft" . $bits . "bits, \n" .
59 " eSftMsk" . $bits . "bits, \n" .
60 " eBitSft" . $bits . "bits, \n" .
61 " eUnitMsk" . $bits . "bits, \n" .
62 " " . $name . $tbl . " \n" .
63 " }";
64 return $ret;
66 ##--------------------------------------------------------------
67 sub Gen4BitsClass {
68 my($name, $clstbl) = @_;
69 my($i,$j);
70 my($cls);
71 my($ret);
72 $ret = "";
73 $ret .= "static const uint32_t " . $name . "_cls [ 256 / 8 ] = {\n";
74 for($i = 0; $i < 0x100; $i+= 8) {
75 $ret .= "PCK4BITS(";
76 for($j = $i; $j < $i + 8; $j++) {
77 $cls = &GetClass($j,$clstbl);
78 $ret .= sprintf("%d", $cls) ;
79 if($j != ($i+7)) {
80 $ret .= ",";
83 if( $i+8 >= 0x100) {
84 $ret .= ") ";
85 } else {
86 $ret .= "),";
88 $ret .= sprintf(" // %02x - %02x \n", $i, ($i+7));
90 $ret .= "};\n";
91 return $ret;
93 ##--------------------------------------------------------------
94 sub GenVerifier {
95 my($name, $charset, $cls, $numcls, $st) = @_;
96 my($ret);
97 $ret = GenNPL();
98 $ret .= GenNote();
99 $ret .= GenHeader();
100 $ret .= Gen4BitsClass($name, $cls);
101 $ret .= "\n\n";
102 $ret .= Gen4BitsState($name, $st);
103 $ret .= "\n\n";
104 $ret .= "static nsVerifier ns" . $name . "Verifier = {\n";
105 $ret .= ' "' . $charset . '",' . "\n";
106 $ret .= GenClassPkg($name, 4);
107 $ret .= ",\n";
108 $ret .= " " . $numcls;
109 $ret .= ",\n";
110 $ret .= GenStatePkg($name, 4);
111 $ret .= "\n};\n";
112 return $ret;
115 ##--------------------------------------------------------------
116 sub Gen4BitsState {
117 my($name, $sttbl) = @_;
118 my($lenafterpad) = (((@$sttbl-1) >> 3) + 1) << 3;
119 my($i,$j);
120 my($ret);
121 $ret = "";
122 $ret .= "static const uint32_t " . $name . "_st [ " . ($lenafterpad >> 3) . "] = {\n";
123 for($i = 0; $i < $lenafterpad ; $i+= 8) {
124 $ret .= "PCK4BITS(";
125 for($j = $i; $j < $i + 8; $j++) {
126 if(0 == $sttbl->[$j]) {
127 $ret .= "eStart";
128 } else { if(1 == $sttbl->[$j]) {
129 $ret .= "eError";
130 } else { if(2 == $sttbl->[$j]) {
131 $ret .= "eItsMe";
132 } else {
133 $ret .= sprintf(" %d", $sttbl->[$j]) ;
135 if($j != ($i+7)) {
136 $ret .= ",";
139 if( $i+8 >= $lenafterpad ) {
140 $ret .= ") ";
141 } else {
142 $ret .= "),";
144 $ret .= sprintf("//%02x-%02x \n", $i, ($i+7));
146 $ret .= "};\n";
147 return $ret;
149 ##--------------------------------------------------------------
151 sub GenNote {
152 my($ret) = << "END_NOTE";
154 * DO NOT EDIT THIS DOCUMENT MANUALLY !!!
155 * THIS FILE IS AUTOMATICALLY GENERATED BY THE TOOLS UNDER
156 * mozilla/intl/chardet/tools/
157 * Please contact ftang\@netscape.com or mozilla-i18n\@mozilla.org
158 * if you have any question. Thanks
160 END_NOTE
161 return $ret;
164 ##--------------------------------------------------------------
165 sub GenHeader {
166 my($ret) = << "END_HEADER";
167 #include "nsVerifier.h"
168 END_HEADER
170 return $ret;
172 ##--------------------------------------------------------------
173 1; # this should be the last line