harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r801484 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni: shared/luniglob.c unix/helpers.c unix/helpers.h windows/charsetmap.h windows/helpers.c windows/helpers.h
Date Thu, 06 Aug 2009 01:02:30 GMT
Author: regisxu
Date: Thu Aug  6 01:02:29 2009
New Revision: 801484

URL: http://svn.apache.org/viewvc?rev=801484&view=rev
Log:
Apply patch for HARMONY-6279: [classlib][luni] file.encoding is always set to ISO-9959-1 if
using drlvm

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/charsetmap.h
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.h
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.h

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c?rev=801484&r1=801483&r2=801484&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c Thu
Aug  6 01:02:29 2009
@@ -29,6 +29,7 @@
 #include "hyport.h"
 #include "strhelp.h"
 #include "hycomp.h"
+#include "helpers.h"
 
 static UDATA keyInitCount = 0;
 
@@ -52,6 +53,8 @@
   VMInterface *vmInterface;
   char *bootPath = NULL;
   char *propVal = NULL;
+#define CHARSETBUFF 64
+  char charset[CHARSETBUFF];
   vmiError propRes;
 
   /* Query the VM interface */
@@ -156,7 +159,8 @@
        (*vmInterface)->GetSystemProperty (vmInterface, "file.encoding", &propVal);
        if (propVal == NULL) {
            /* FIXME provide appropriate non-dummy value */
-           propRes = (*vmInterface)->SetSystemProperty (vmInterface, "file.encoding",
"8859_1");
+           getOSCharset(charset, CHARSETBUFF);
+           propRes = (*vmInterface)->SetSystemProperty (vmInterface, "file.encoding",
charset);
            if (VMI_ERROR_NONE != propRes) {
                /* goto fail2; */
            }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.c?rev=801484&r1=801483&r2=801484&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.c Thu Aug
 6 01:02:29 2009
@@ -220,3 +220,41 @@
 
   hysock_setopt_bool (socketP, HY_SOL_SOCKET, HY_SO_REUSEADDR, &value);
 }
+
+/* Get charset from the OS */
+inline void getOSCharset(char *locale, const size_t size) {
+  char * codec = NULL;
+  size_t cur = 0;
+  short flag = 0;
+  setlocale(LC_CTYPE, "");
+  codec = setlocale(LC_CTYPE, NULL);
+  // get codeset from language[_territory][.codeset][@modifier]
+  while (*codec) {
+    if (!flag) {
+      if (*codec != '.') {
+        codec++;
+        continue;
+      } else {
+        flag = 1;
+        codec++;
+      }
+    } else {
+      if (*codec == '@') {
+        break;
+      } else {
+        locale[cur++] = (*codec);
+        codec++;
+        if (cur >= size) {
+          // Not enough size
+          cur = 0;
+          break;
+        }
+      }
+    }
+  }
+  locale[cur] = '\0';
+  if (!strlen(locale)) {
+    strcpy(locale, "8859_1");
+  }
+  return;
+}

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.h?rev=801484&r1=801483&r2=801484&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.h (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/helpers.h Thu Aug
 6 01:02:29 2009
@@ -35,4 +35,5 @@
 I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time);
 I_32 setPlatformReadOnly (JNIEnv * env, char *path);
 int portCmp (const void **a, const void **b);
+void getOSCharset(char *locale, const size_t size);
 #endif /* helpers_h */

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/charsetmap.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/charsetmap.h?rev=801484&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/charsetmap.h
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/charsetmap.h
Thu Aug  6 01:02:29 2009
@@ -0,0 +1,123 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Charles Lee
+ * @version $Revision: 1.0$
+ */
+
+#if !defined(charsetmap_h)
+#define charsetmap_h
+typedef struct {
+  const int cp;
+  const char *name;
+} CharsetMap;
+
+static const CharsetMap mapper[] = {
+  37,"IBM037",        437,"IBM437",         500,"IBM500",
+  708,"ASMO-708",     720,"DOS-720",        737,"ibm737",
+  775,"ibm775",       850,"ibm850",         852,"ibm852",
+  855,"IBM855",       857,"ibm857",         858,"IBM00858",
+  860,"IBM860",       861,"ibm861",         862,"DOS-862",
+  863,"IBM863",       864,"IBM864",         865,"IBM865",
+  866,"cp866",        869,"ibm869",         870,"IBM870",
+  874,"windows-874",  875,"cp875",          932,"shift_jis",
+  936,"gb2312",       949,"ks_c_5601-1987", 950,"big5",
+  1026,"IBM1026",     1047,"IBM01047",      1140,"IBM01140",
+  1141,"IBM01141",    1142,"IBM01142",      1143,"IBM01143",
+  1144,"IBM01144",    1145,"IBM01145",      1146,"IBM01146",
+  1147,"IBM01147",    1148,"IBM01148",      1149,"IBM01149",
+  1200,"utf-16",      1201,"unicodeFFFE",   1250,"windows-1250",
+  1251,"windows-1251",                      1252,"windows-1252",
+  1253,"windows-1253",                      1254,"windows-1254",
+  1255,"windows-1255",                      1256,"windows-1256",
+  1257,"windows-1257",                      1258,"windows-1258",
+  1361,"Johab",       10000,"macintosh",    10001,"x-mac-japanese",
+  10002,"x-mac-chinesetrad",                10003,"x-mac-korean",
+  10004,"x-mac-arabic",                     10005,"x-mac-hebrew",
+  10006,"x-mac-greek",                      10007,"x-mac-cyrillic",
+  10008,"x-mac-chinesesimp",                10010,"x-mac-romanian",
+  10017,"x-mac-ukrainian",                  10021,"x-mac-thai",
+  10029,"x-mac-ce",                         10079,"x-mac-icelandic",
+  10081,"x-mac-turkish",                    10082,"x-mac-croatian",
+  12000,"utf-32",     12001,"utf-32BE",     20000,"x-Chinese_CNS",
+  20001,"x-cp20001",  20002,"x_Chinese-Eten",
+  20003,"x-cp20003",  20004,"x-cp20004",    20005,"x-cp20005",
+  20105,"x-IA5",      20106,"x-IA5-German", 20107,"x-IA5-Swedish",
+  20108,"x-IA5-Norwegian",20127,"us-ascii", 20261,"x-cp20261",
+  20269,"x-cp20269",  20273,"IBM273",       20277,"IBM277",
+  20278,"IBM278",     20280,"IBM280",       20284,"IBM284",
+  20285,"IBM285",     20290,"IBM290",       20297,"IBM297",
+  20420,"IBM420",     20423,"IBM423",       20424,"IBM424",
+  20833,"x-EBCDIC-KoreanExtended",          20838,"IBM-Thai",
+  20866,"koi8-r",     20871,"IBM871",       20880,"IBM880",
+  20905,"IBM905",     20924,"IBM00924",     20932,"EUC-JP",
+  20936,"x-cp20936",  20949,"x-cp20949",    21025,"cp1025",
+  21866,"koi8-u",     28591,"iso-8859-1",   28592,"iso-8859-2",
+  28593,"iso-8859-3", 28594,"iso-8859-4",   28595,"iso-8859-5",
+  28596,"iso-8859-6", 28597,"iso-8859-7",   28598,"iso-8859-8",
+  28599,"iso-8859-9", 28603,"iso-8859-13",  28605,"iso-8859-15",
+  29001,"x-Europa",   38598,"iso-8859-8-i", 50220,"iso-2022-jp",
+  50221,"csISO2022JP", 50222,"iso-2022-jp", 50225,"iso-2022-kr",
+  50227,"x-cp50227",  50229,"cp50229",      50930,"cp50930",
+  50931,"cp50229",    50933,"cp50933",      50935,"cp50935",
+  50936,"cp50936",    50937,"cp50937",      50939,"cp50939",
+  51932,"euc-jp",     51936,"EUC-CN",       51949,"euc-kr",
+  51950,"cp51950",    52936,"hz-gb-2312",   54936,"GB18030",
+  57002,"x-iscii-de", 57003,"x-iscii-be",   57004,"x-iscii-ta",
+  57005,"x-iscii-te", 57006,"x-iscii-as",   57007,"x-iscii-or",
+  57008,"x-iscii-ka", 57009,"x-iscii-ma",   57010,"x-iscii-gu",
+  57011,"x-iscii-pa", 65000,"utf-7",        65001,"utf-8"
+};
+
+void getCharset(int cp, char *locale, const size_t size) {
+  int begin, mid, end, cur;
+  int len = sizeof(mapper) / sizeof(CharsetMap);
+  if (cp < mapper[0].cp || cp > mapper[len -1].cp) {
+    strcpy(locale, "windows-1252");
+    return;
+  }
+
+  //searching
+  begin = 0;
+  end = len - 1;
+  cur = -1;
+  while (begin < end) {
+    mid = (begin + end) / 2;
+    if (mapper[mid].cp == cp) {
+      cur = mid;
+      break;
+    }
+    if (mapper[mid].cp < cp) {
+      begin = mid + 1;
+    } else {
+      end = mid - 1;
+    }
+  }
+
+  if (cur < 0) {
+    // Not found
+    strcpy(locale, "windows-1252");
+  } else {
+    if (strlen(mapper[cur].name) >= size) {
+      strcpy(locale, "windows-1252");
+    } else {
+      strcpy(locale, mapper[cur].name);
+    }
+  }
+  return;
+}
+#endif

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.c?rev=801484&r1=801483&r2=801484&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.c Thu
Aug  6 01:02:29 2009
@@ -25,12 +25,14 @@
 #include <windows.h>
 #include <winbase.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <LMCONS.H>
 #include <direct.h>
 
 #include "vmi.h"
 #include "jclprots.h"
 #include "harmonyglob.h"
+#include "charsetmap.h"
 
 #include "hysock.h"
 
@@ -476,3 +478,22 @@
 setDefaultServerSocketOptions (JNIEnv * env, hysocket_t socketP)
 {
 }
+
+/* Get charset from the OS */
+void getOSCharset(char *locale, const size_t size) {
+  size_t cp;
+  DWORD holder;
+#if defined(_WIN32_WCE)
+  LCID localeId = GetUserDefaultLCID();
+#else
+  LCID localeId = GetThreadLocale();
+#endif
+  if (0 < GetLocaleInfo(localeId, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+                        (LPTSTR)&holder, sizeof(holder) / sizeof(TCHAR))) {
+    cp = (size_t)holder;
+  } else {
+    cp = (size_t)GetACP();
+  }
+  getCharset(cp, locale, size);
+  return;
+}

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.h?rev=801484&r1=801483&r2=801484&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.h (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/helpers.h Thu
Aug  6 01:02:29 2009
@@ -34,4 +34,5 @@
 void setPlatformBindOptions (JNIEnv * env, hysocket_t socketP);
 I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time);
 I_32 setPlatformReadOnly (JNIEnv * env, char *path);
+void getOSCharset(char *locale, const size_t size);
 #endif /* helpers_h */



Mime
View raw message