michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include "nsICharsetConverterManager.h" michael@0: #include michael@0: #include "nsISupports.h" michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIUnicodeDecoder.h" michael@0: #include "nsIUnicodeEncoder.h" michael@0: #include "nsCRT.h" michael@0: #include michael@0: #include michael@0: #if defined(XP_WIN) michael@0: #include michael@0: #endif michael@0: #ifdef XP_UNIX michael@0: #include michael@0: #endif michael@0: michael@0: //--------------------------------------------------------------------------- michael@0: void header() michael@0: { michael@0: char *header= michael@0: "#ifndef nsCyrillicClass_h__\n" michael@0: "#define nsCyrillicClass_h__\n" michael@0: "/* PLEASE DO NOT EDIT THIS FILE DIRECTLY. THIS FILE IS GENERATED BY \n" michael@0: " GenCyrllicClass found in mozilla/intl/chardet/tools\n" michael@0: " */\n"; michael@0: printf(header); michael@0: } michael@0: //--------------------------------------------------------------------------- michael@0: void footer() michael@0: { michael@0: printf("#endif\n"); michael@0: } michael@0: //--------------------------------------------------------------------------- michael@0: void npl() michael@0: { michael@0: char *npl= michael@0: "/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\n" michael@0: "/* This Source Code Form is subject to the terms of the Mozilla Public\n" michael@0: " * License, v. 2.0. If a copy of the MPL was not distributed with this\n" michael@0: " * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n"; michael@0: printf(npl); michael@0: } michael@0: //--------------------------------------------------------------------------- michael@0: static nsIUnicodeEncoder* gKOI8REncoder = nullptr; michael@0: static nsICharsetConverterManager* gCCM = nullptr; michael@0: michael@0: //--------------------------------------------------------------------------- michael@0: uint8_t CyrillicClass(nsIUnicodeDecoder* decoder, uint8_t byte) michael@0: { michael@0: char16_t ubuf[2]; michael@0: uint8_t bbuf[2]; michael@0: michael@0: int32_t blen = 1; michael@0: int32_t ulen = 1; michael@0: nsresult res = decoder->Convert((char*)&byte, &blen, ubuf, &ulen); michael@0: if(NS_SUCCEEDED(res) && (1 == ulen )) michael@0: { michael@0: ubuf[0] = nsCRT::ToUpper(ubuf[0]); michael@0: blen=1; michael@0: res = gKOI8REncoder->Convert(ubuf,&ulen,(char*)bbuf,&blen); michael@0: if(NS_SUCCEEDED(res) && (1 == blen)) michael@0: { michael@0: if(0xe0 <= bbuf[0]) michael@0: { michael@0: return bbuf[0] - (uint8_t)0xdf; michael@0: } michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: //--------------------------------------------------------------------------- michael@0: void genCyrillicClass(const char* name, const char* charset) michael@0: { michael@0: nsIUnicodeDecoder *decoder = nullptr; michael@0: nsresult res = NS_OK; michael@0: nsAutoString str(charset); michael@0: res = gCCM->GetUnicodeDecoder(&str, &decoder); michael@0: if(NS_FAILED(res)) michael@0: { michael@0: printf("cannot locate %s Decoder\n", charset); michael@0: return; michael@0: } michael@0: printf("static const uint8_t %sMap [128] = {\n",name); michael@0: uint8_t i,j; michael@0: for(i=0x80;i!=0x00;i+=0x10) michael@0: { michael@0: for(j=0;j<=0x0f;j++) michael@0: { michael@0: uint8_t cls = CyrillicClass(decoder, i+j); michael@0: printf(" %2d, ",cls); michael@0: } michael@0: printf("\n"); michael@0: } michael@0: printf("};\n"); michael@0: NS_IF_RELEASE(decoder); michael@0: } michael@0: //--------------------------------------------------------------------------- michael@0: michael@0: michael@0: int main(int argc, char** argv) { michael@0: nsresult res = nullptr; michael@0: michael@0: nsCOMPtr gCCM = do_GetService(kCharsetConverterManagerCID, &res); michael@0: michael@0: if(NS_FAILED(res) && (nullptr != gCCM)) michael@0: { michael@0: printf("cannot locate CharsetConverterManager\n"); michael@0: return(-1); michael@0: } michael@0: nsAutoString koi8r("KOI8-R"); michael@0: res = gCCM->GetUnicodeEncoder(&koi8r,&gKOI8REncoder); michael@0: if(NS_FAILED(res) && (nullptr != gKOI8REncoder)) michael@0: { michael@0: printf("cannot locate KOI8-R Encoder\n"); michael@0: return(-1); michael@0: } michael@0: michael@0: michael@0: npl(); michael@0: header(); michael@0: michael@0: genCyrillicClass("KOI8", "KOI8-R"); michael@0: genCyrillicClass("CP1251", "windows-1251"); michael@0: genCyrillicClass("IBM866", "IBM866"); michael@0: genCyrillicClass("ISO88595", "ISO-8859-5"); michael@0: genCyrillicClass("MacCyrillic", "x-mac-cyrillic"); michael@0: footer(); michael@0: NS_IF_RELEASE(gKOI8REncoder); michael@0: return(0); michael@0: };