~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/intl/chardet/tools/genverifier.pm

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl
 
2
package genverifier;
 
3
use strict;
 
4
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
 
5
 
 
6
use Exporter;
 
7
$VERSION = 1.00;
 
8
@ISA = qw(Exporter);
 
9
 
 
10
@EXPORT       = qw(
 
11
                   GenVerifier
 
12
                  );
 
13
@EXPORT_OK    = qw();
 
14
 
 
15
sub GenNPL {
 
16
  my($ret) = << "END_NPL";
 
17
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
18
/* ***** BEGIN LICENSE BLOCK *****
 
19
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
20
 *
 
21
 * The contents of this file are subject to the Netscape Public License
 
22
 * Version 1.1 (the "License"); you may not use this file except in
 
23
 * compliance with the License. You may obtain a copy of the License at
 
24
 * http://www.mozilla.org/NPL/
 
25
 *
 
26
 * Software distributed under the License is distributed on an "AS IS" basis,
 
27
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
28
 * for the specific language governing rights and limitations under the
 
29
 * License.
 
30
 *
 
31
 * The Original Code is mozilla.org code.
 
32
 *
 
33
 * The Initial Developer of the Original Code is 
 
34
 * Netscape Communications Corporation.
 
35
 * Portions created by the Initial Developer are Copyright (C) 1998
 
36
 * the Initial Developer. All Rights Reserved.
 
37
 *
 
38
 * Contributor(s):
 
39
 *
 
40
 *
 
41
 * Alternatively, the contents of this file may be used under the terms of
 
42
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
43
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
44
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
45
 * of those above. If you wish to allow use of your version of this file only
 
46
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
47
 * use your version of this file under the terms of the NPL, indicate your
 
48
 * decision by deleting the provisions above and replace them with the notice
 
49
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
50
 * the provisions above, a recipient may use your version of this file under
 
51
 * the terms of any one of the NPL, the GPL or the LGPL.
 
52
 *
 
53
 * ***** END LICENSE BLOCK ***** */
 
54
END_NPL
 
55
 
 
56
  return $ret;
 
57
}
 
58
 
 
59
##--------------------------------------------------------------
 
60
sub GetClass {
 
61
  my($char, $clstbl) = @_;
 
62
  my($l);
 
63
  for($l =0; $l <= @$clstbl; $l++) {
 
64
    if(($clstbl->[$l][0] <= $char) && ($char <= $clstbl->[$l][1]))
 
65
    {
 
66
          return $clstbl->[$l][2];
 
67
    }
 
68
  }
 
69
  print "WARNING- there are no class for $char\n";
 
70
};
 
71
##--------------------------------------------------------------
 
72
sub GenClassPkg {
 
73
  my($name, $bits) = @_;
 
74
  return GenPkg($name, $bits, "_cls");
 
75
}
 
76
##--------------------------------------------------------------
 
77
sub GenStatePkg {
 
78
  my($name, $bits) = @_;
 
79
  return GenPkg($name, $bits, "_st");
 
80
};
 
81
##--------------------------------------------------------------
 
82
sub GenPkg {
 
83
  my($name, $bits, $tbl) = @_;
 
84
  my($ret);
 
85
  $ret = "    {\n" . 
 
86
         "       eIdxSft"  . $bits . "bits, \n" .
 
87
         "       eSftMsk"  . $bits . "bits, \n" . 
 
88
         "       eBitSft"  . $bits . "bits, \n" . 
 
89
         "       eUnitMsk" . $bits . "bits, \n" .
 
90
         "       " . $name . $tbl . " \n" . 
 
91
         "    }";
 
92
  return $ret;
 
93
};
 
94
##--------------------------------------------------------------
 
95
sub Gen4BitsClass {
 
96
  my($name, $clstbl) = @_;
 
97
  my($i,$j);
 
98
  my($cls);
 
99
  my($ret);
 
100
  $ret = "";
 
101
  $ret .= "static const PRUint32 " . $name . "_cls [ 256 / 8 ] = {\n";
 
102
  for($i = 0; $i < 0x100; $i+= 8) {
 
103
     $ret .= "PCK4BITS(";
 
104
     for($j = $i; $j < $i + 8; $j++) {
 
105
         $cls = &GetClass($j,$clstbl);
 
106
         $ret .= sprintf("%d", $cls) ;
 
107
         if($j != ($i+7)) {
 
108
            $ret .= ",";
 
109
         }
 
110
     }
 
111
     if( $i+8 >= 0x100) {
 
112
        $ret .= ") ";
 
113
     } else {
 
114
        $ret .= "),";
 
115
     }
 
116
     $ret .= sprintf("  // %02x - %02x \n", $i, ($i+7));
 
117
  }
 
118
  $ret .= "};\n";
 
119
  return $ret;
 
120
};
 
121
##--------------------------------------------------------------
 
122
sub GenVerifier {
 
123
  my($name, $charset, $cls, $numcls, $st) = @_;
 
124
  my($ret);
 
125
  $ret = GenNPL();
 
126
  $ret .= GenNote();
 
127
  $ret .= GenHeader();
 
128
  $ret .= Gen4BitsClass($name, $cls);
 
129
  $ret .= "\n\n";
 
130
  $ret .= Gen4BitsState($name, $st);
 
131
  $ret .= "\n\n";
 
132
  $ret .= "static nsVerifier ns" . $name . "Verifier = {\n";
 
133
  $ret .= '     "' . $charset . '",' . "\n";
 
134
  $ret .= GenClassPkg($name, 4);
 
135
  $ret .= ",\n";
 
136
  $ret .= "    " . $numcls;
 
137
  $ret .= ",\n";
 
138
  $ret .= GenStatePkg($name, 4);
 
139
  $ret .= "\n};\n";
 
140
  return $ret;
 
141
 
 
142
};
 
143
##--------------------------------------------------------------
 
144
sub Gen4BitsState {
 
145
  my($name, $sttbl) = @_;
 
146
  my($lenafterpad) = (((@$sttbl-1) >> 3) + 1) << 3;
 
147
  my($i,$j);
 
148
  my($ret);
 
149
  $ret = "";
 
150
  $ret .= "static const PRUint32 " . $name . "_st [ " . ($lenafterpad >> 3) . "] = {\n";
 
151
  for($i = 0; $i < $lenafterpad ; $i+= 8) {
 
152
     $ret .= "PCK4BITS(";
 
153
     for($j = $i; $j < $i + 8; $j++) {
 
154
         if(0 == $sttbl->[$j]) {
 
155
              $ret .= "eStart";
 
156
         } else { if(1 == $sttbl->[$j]) {
 
157
              $ret .= "eError";
 
158
         } else { if(2 == $sttbl->[$j]) {
 
159
              $ret .= "eItsMe";
 
160
         } else {
 
161
              $ret .= sprintf("     %d", $sttbl->[$j]) ;
 
162
         }}}
 
163
         if($j != ($i+7)) {
 
164
            $ret .= ",";
 
165
         }
 
166
     }
 
167
     if( $i+8 >= $lenafterpad ) {
 
168
        $ret .= ") ";
 
169
     } else {
 
170
        $ret .= "),";
 
171
     }
 
172
     $ret .= sprintf("//%02x-%02x \n", $i, ($i+7));
 
173
  }
 
174
  $ret .= "};\n";
 
175
  return $ret;
 
176
};
 
177
##--------------------------------------------------------------
 
178
 
 
179
sub GenNote {
 
180
  my($ret) = << "END_NOTE";
 
181
/* 
 
182
 * DO NOT EDIT THIS DOCUMENT MANUALLY !!!
 
183
 * THIS FILE IS AUTOMATICALLY GENERATED BY THE TOOLS UNDER
 
184
 *    mozilla/intl/chardet/tools/
 
185
 * Please contact ftang\@netscape.com or mozilla-i18n\@mozilla.org
 
186
 * if you have any question. Thanks
 
187
 */
 
188
END_NOTE
 
189
  return $ret;
 
190
}
 
191
 
 
192
##--------------------------------------------------------------
 
193
sub GenHeader {
 
194
  my($ret) = << "END_HEADER";
 
195
#include "nsVerifier.h"
 
196
END_HEADER
 
197
 
 
198
  return $ret;
 
199
}
 
200
##--------------------------------------------------------------
 
201
1; # this should be the last line