Bug 468575 - Scrape some gunk off the config/ grout, r=ted
[wine-gecko.git] / intl / chardet / tools / GenCyrillicClass.cpp
blob97d77b0f2c22d671a552b0ade33f93be77288a91
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #include "nsICharsetConverterManager.h"
39 #include <iostream.h>
40 #include "nsISupports.h"
41 #include "nsIComponentManager.h"
42 #include "nsIServiceManager.h"
43 #include "nsIUnicodeDecoder.h"
44 #include "nsIUnicodeEncoder.h"
45 #include "nsCRT.h"
46 #include <stdio.h>
47 #include <stdlib.h>
48 #if defined(XP_WIN) || defined(XP_OS2)
49 #include <io.h>
50 #endif
51 #ifdef XP_UNIX
52 #include <unistd.h>
53 #endif
55 //---------------------------------------------------------------------------
56 void header()
58 char *header=
59 "#ifndef nsCyrillicClass_h__\n"
60 "#define nsCyrillicClass_h__\n"
61 "/* PLEASE DO NOT EDIT THIS FILE DIRECTLY. THIS FILE IS GENERATED BY \n"
62 " GenCyrllicClass found in mozilla/intl/chardet/tools\n"
63 " */\n";
64 printf(header);
66 //---------------------------------------------------------------------------
67 void footer()
69 printf("#endif\n");
71 //---------------------------------------------------------------------------
72 void npl()
74 char *npl=
75 "/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\n"
76 "/* ***** BEGIN LICENSE BLOCK *****\n"
77 " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n"
78 " *\n"
79 " * The contents of this file are subject to the Mozilla Public License Version\n"
80 " * 1.1 (the \"License\"); you may not use this file except in compliance with\n"
81 " * the License. You may obtain a copy of the License at\n"
82 " * http://www.mozilla.org/MPL/\n"
83 " *\n"
84 " * Software distributed under the License is distributed on an \"AS IS\" basis,\n"
85 " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n"
86 " * for the specific language governing rights and limitations under the\n"
87 " * License.\n"
88 " *\n"
89 " * The Original Code is mozilla.org code.\n"
90 " *\n"
91 " * The Initial Developer of the Original Code is\n"
92 " * Netscape Communications Corporation.\n"
93 " * Portions created by the Initial Developer are Copyright (C) 2001\n"
94 " * the Initial Developer. All Rights Reserved.\n"
95 " *\n"
96 " * Contributor(s):\n"
97 " *\n"
98 " * Alternatively, the contents of this file may be used under the terms of\n"
99 " * either the GNU General Public License Version 2 or later (the \"GPL\"), or\n"
100 " * the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n"
101 " * in which case the provisions of the GPL or the LGPL are applicable instead\n"
102 " * of those above. If you wish to allow use of your version of this file only\n"
103 " * under the terms of either the GPL or the LGPL, and not to allow others to\n"
104 " * use your version of this file under the terms of the MPL, indicate your\n"
105 " * decision by deleting the provisions above and replace them with the notice\n"
106 " * and other provisions required by the GPL or the LGPL. If you do not delete\n"
107 " * the provisions above, a recipient may use your version of this file under\n"
108 " * the terms of any one of the MPL, the GPL or the LGPL.\n"
109 " *\n"
110 " * ***** END LICENSE BLOCK ***** */\n";
111 printf(npl);
113 //---------------------------------------------------------------------------
114 static nsIUnicodeEncoder* gKOI8REncoder = nsnull;
115 static nsICharsetConverterManager* gCCM = nsnull;
117 //---------------------------------------------------------------------------
118 PRUint8 CyrillicClass(nsIUnicodeDecoder* decoder, PRUint8 byte)
120 PRUnichar ubuf[2];
121 PRUint8 bbuf[2];
123 PRInt32 blen = 1;
124 PRInt32 ulen = 1;
125 nsresult res = decoder->Convert((char*)&byte, &blen, ubuf, &ulen);
126 if(NS_SUCCEEDED(res) && (1 == ulen ))
128 ubuf[0] = nsCRT::ToUpper(ubuf[0]);
129 blen=1;
130 res = gKOI8REncoder->Convert(ubuf,&ulen,(char*)bbuf,&blen);
131 if(NS_SUCCEEDED(res) && (1 == blen))
133 if(0xe0 <= bbuf[0])
135 return bbuf[0] - (PRUint8)0xdf;
139 return 0;
141 //---------------------------------------------------------------------------
142 void genCyrillicClass(const char* name, const char* charset)
144 nsIUnicodeDecoder *decoder = nsnull;
145 nsresult res = NS_OK;
146 nsAutoString str(charset);
147 res = gCCM->GetUnicodeDecoder(&str, &decoder);
148 if(NS_FAILED(res))
150 printf("cannot locate %s Decoder\n", charset);
151 return;
153 printf("static const PRUint8 %sMap [128] = {\n",name);
154 PRUint8 i,j;
155 for(i=0x80;i!=0x00;i+=0x10)
157 for(j=0;j<=0x0f;j++)
159 PRUint8 cls = CyrillicClass(decoder, i+j);
160 printf(" %2d, ",cls);
162 printf("\n");
164 printf("};\n");
165 NS_IF_RELEASE(decoder);
167 //---------------------------------------------------------------------------
170 int main(int argc, char** argv) {
171 nsresult res = nsnull;
173 nsCOMPtr<nsICharsetConverterManager> gCCM = do_GetService(kCharsetConverterManagerCID, &res);
175 if(NS_FAILED(res) && (nsnull != gCCM))
177 printf("cannot locate CharsetConverterManager\n");
178 return(-1);
180 nsAutoString koi8r("KOI8-R");
181 res = gCCM->GetUnicodeEncoder(&koi8r,&gKOI8REncoder);
182 if(NS_FAILED(res) && (nsnull != gKOI8REncoder))
184 printf("cannot locate KOI8-R Encoder\n");
185 return(-1);
189 npl();
190 header();
192 genCyrillicClass("KOI8", "KOI8-R");
193 genCyrillicClass("CP1251", "windows-1251");
194 genCyrillicClass("IBM866", "IBM866");
195 genCyrillicClass("ISO88595", "ISO-8859-5");
196 genCyrillicClass("MacCyrillic", "x-mac-cyrillic");
197 footer();
198 NS_IF_RELEASE(gKOI8REncoder);
199 return(0);