Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / intl / uconv / src / nsOS2Charset.cpp
blob24dac954dbff736d5959b069304576a08a892e36
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Communicator client code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * John Fairhurst
25 * Henry Sobotka
26 * IBM Corp.
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
41 #include "nsIPlatformCharset.h"
42 #include "nsGREResProperties.h"
43 #include "pratom.h"
44 #define INCL_WIN
45 #include <os2.h>
46 #include "nsUConvDll.h"
47 #include "nsIOS2Locale.h"
48 #include "nsCOMPtr.h"
49 #include "nsReadableUtils.h"
50 #include "nsLocaleCID.h"
51 #include "nsIComponentManager.h"
52 #include "nsITimelineService.h"
53 #include "nsPlatformCharset.h"
55 static nsGREResProperties *gInfo = nsnull;
56 static PRInt32 gCnt= 0;
58 NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
60 nsPlatformCharset::nsPlatformCharset()
62 NS_TIMELINE_START_TIMER("nsPlatformCharset()");
64 UINT acp = ::WinQueryCp(HMQ_CURRENT);
65 PRInt32 acpint = (PRInt32)(acp & 0x00FFFF);
66 nsAutoString acpKey(NS_LITERAL_STRING("os2."));
67 acpKey.AppendInt(acpint, 10);
68 nsresult res = MapToCharset(acpKey, mCharset);
70 NS_TIMELINE_STOP_TIMER("nsPlatformCharset()");
71 NS_TIMELINE_MARK_TIMER("nsPlatformCharset()");
73 nsPlatformCharset::~nsPlatformCharset()
75 PR_AtomicDecrement(&gCnt);
76 if ((0 == gCnt) && (nsnull != gInfo)) {
77 delete gInfo;
78 gInfo = nsnull;
82 nsresult
83 nsPlatformCharset::InitInfo()
85 PR_AtomicIncrement(&gCnt); // count for gInfo
87 if (gInfo == nsnull) {
88 nsGREResProperties *info =
89 new nsGREResProperties(NS_LITERAL_CSTRING("os2charset.properties"));
91 NS_ASSERTION(info , "cannot open properties file");
92 NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
93 gInfo = info;
95 return NS_OK;
98 nsresult
99 nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
101 //delay loading os2charset.properties bundle if possible
102 if (inANSICodePage.EqualsLiteral("os2.850")) {
103 outCharset.AssignLiteral("IBM850");
104 return NS_OK;
107 if (inANSICodePage.EqualsLiteral("os2.932")) {
108 outCharset.AssignLiteral("Shift_JIS");
109 return NS_OK;
112 // ensure the .property file is loaded
113 nsresult rv = InitInfo();
114 if (NS_FAILED(rv)) {
115 outCharset.AssignLiteral("IBM850");
116 return rv;
119 nsAutoString charset;
120 rv = gInfo->Get(inANSICodePage, charset);
121 if (NS_FAILED(rv)) {
122 outCharset.AssignLiteral("IBM850");
123 return rv;
126 LossyCopyUTF16toASCII(charset, outCharset);
127 return NS_OK;
130 NS_IMETHODIMP
131 nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
132 nsACString& oResult)
134 if ((selector == kPlatformCharsetSel_4xBookmarkFile) || (selector == kPlatformCharsetSel_4xPrefsJS)) {
135 if ((mCharset.Find("IBM850", IGNORE_CASE) != -1) || (mCharset.Find("IBM437", IGNORE_CASE) != -1))
136 oResult.AssignLiteral("ISO-8859-1");
137 else if (mCharset.Find("IBM852", IGNORE_CASE) != -1)
138 oResult.AssignLiteral("windows-1250");
139 else if ((mCharset.Find("IBM855", IGNORE_CASE) != -1) || (mCharset.Find("IBM866", IGNORE_CASE) != -1))
140 oResult.AssignLiteral("windows-1251");
141 else if ((mCharset.Find("IBM869", IGNORE_CASE) != -1) || (mCharset.Find("IBM813", IGNORE_CASE) != -1))
142 oResult.AssignLiteral("windows-1253");
143 else if (mCharset.Find("IBM857", IGNORE_CASE) != -1)
144 oResult.AssignLiteral("windows-1254");
145 else
146 oResult = mCharset;
147 } else {
148 oResult = mCharset;
150 return NS_OK;
153 NS_IMETHODIMP
154 nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult)
156 nsCOMPtr<nsIOS2Locale> os2Locale;
157 ULONG codepage;
158 char acp_name[6];
161 // convert locale name to a code page
163 nsresult rv;
164 oResult.Truncate();
166 os2Locale = do_CreateInstance(NS_OS2LOCALE_CONTRACTID, &rv);
167 if (NS_FAILED(rv)) { return rv; }
169 rv = os2Locale->GetPlatformLocale(localeName, &codepage);
170 if (NS_FAILED(rv)) { return rv; }
172 nsAutoString os2_key(NS_LITERAL_STRING("os2."));
173 os2_key.AppendInt((PRUint32)codepage);
175 return MapToCharset(os2_key, oResult);
179 NS_IMETHODIMP
180 nsPlatformCharset::Init()
182 return NS_OK;
185 nsresult
186 nsPlatformCharset::MapToCharset(short script, short region, nsACString& outCharset)
188 return NS_OK;
191 nsresult
192 nsPlatformCharset::InitGetCharset(nsACString &oString)
194 return NS_OK;
197 nsresult
198 nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult)
200 return NS_OK;
203 nsresult
204 nsPlatformCharset::VerifyCharset(nsCString &aCharset)
206 return NS_OK;