128 fclose(f); 129 strcpy(ret, "GB18030"); 130 } 131 } 132 } 133 } 134 135 return ret; 136 } 137 138 static char* getConsoleEncoding() 139 { 140 char* buf = malloc(16); 141 int cp; 142 if (buf == NULL) { 143 return NULL; 144 } 145 cp = GetConsoleCP(); 146 if (cp >= 874 && cp <= 950) 147 sprintf(buf, "ms%d", cp); 148 else 149 sprintf(buf, "cp%d", cp); 150 return buf; 151 } 152 153 // Exported entries for AWT 154 DllExport const char * 155 getEncodingFromLangID(LANGID langID) 156 { 157 return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT)); 158 } 159 160 // Returns BCP47 Language Tag 161 DllExport const char * 162 getJavaIDFromLangID(LANGID langID) 163 { 164 char * elems[5]; // lang, script, ctry, variant, encoding 165 char * ret; 166 int index; 167 671 &sprops.display_language, 672 &sprops.display_script, 673 &sprops.display_country, 674 &sprops.display_variant, 675 &display_encoding); 676 677 sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID); 678 if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) { 679 // MS claims "Vista has built-in support for HKSCS-2004. 680 // All of the HKSCS-2004 characters have Unicode 4.1. 681 // PUA code point assignments". But what it really means 682 // is that the HKSCS-2004 is ONLY supported in Unicode. 683 // Test indicates the MS950 in its zh_HK locale is a 684 // "regular" MS950 which does not handle HKSCS-2004 at 685 // all. Set encoding to MS950_HKSCS. 686 sprops.encoding = "MS950_HKSCS"; 687 sprops.sun_jnu_encoding = "MS950_HKSCS"; 688 } 689 690 hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE); 691 if (hStdOutErr != INVALID_HANDLE_VALUE && 692 GetFileType(hStdOutErr) == FILE_TYPE_CHAR) { 693 sprops.sun_stdout_encoding = getConsoleEncoding(); 694 } 695 hStdOutErr = GetStdHandle(STD_ERROR_HANDLE); 696 if (hStdOutErr != INVALID_HANDLE_VALUE && 697 GetFileType(hStdOutErr) == FILE_TYPE_CHAR) { 698 if (sprops.sun_stdout_encoding != NULL) 699 sprops.sun_stderr_encoding = sprops.sun_stdout_encoding; 700 else 701 sprops.sun_stderr_encoding = getConsoleEncoding(); 702 } 703 } 704 } 705 706 sprops.unicode_encoding = "UnicodeLittle"; 707 /* User TIMEZONE */ 708 { 709 /* 710 * We defer setting up timezone until it's actually necessary. 711 * Refer to TimeZone.getDefault(). However, the system 712 * property is necessary to be able to be set by the command 713 * line interface -D. Here temporarily set a null string to 714 * timezone. 715 */ 716 sprops.timezone = ""; 717 } 718 719 /* Current directory */ 720 { 721 WCHAR buf[MAX_PATH]; | 128 fclose(f); 129 strcpy(ret, "GB18030"); 130 } 131 } 132 } 133 } 134 135 return ret; 136 } 137 138 static char* getConsoleEncoding() 139 { 140 char* buf = malloc(16); 141 int cp; 142 if (buf == NULL) { 143 return NULL; 144 } 145 cp = GetConsoleCP(); 146 if (cp >= 874 && cp <= 950) 147 sprintf(buf, "ms%d", cp); 148 else if (cp == 65001) 149 sprintf(buf, "UTF-8"); 150 else 151 sprintf(buf, "cp%d", cp); 152 return buf; 153 } 154 155 // Exported entries for AWT 156 DllExport const char * 157 getEncodingFromLangID(LANGID langID) 158 { 159 return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT)); 160 } 161 162 // Returns BCP47 Language Tag 163 DllExport const char * 164 getJavaIDFromLangID(LANGID langID) 165 { 166 char * elems[5]; // lang, script, ctry, variant, encoding 167 char * ret; 168 int index; 169 673 &sprops.display_language, 674 &sprops.display_script, 675 &sprops.display_country, 676 &sprops.display_variant, 677 &display_encoding); 678 679 sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID); 680 if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) { 681 // MS claims "Vista has built-in support for HKSCS-2004. 682 // All of the HKSCS-2004 characters have Unicode 4.1. 683 // PUA code point assignments". But what it really means 684 // is that the HKSCS-2004 is ONLY supported in Unicode. 685 // Test indicates the MS950 in its zh_HK locale is a 686 // "regular" MS950 which does not handle HKSCS-2004 at 687 // all. Set encoding to MS950_HKSCS. 688 sprops.encoding = "MS950_HKSCS"; 689 sprops.sun_jnu_encoding = "MS950_HKSCS"; 690 } 691 692 hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE); 693 if (hStdOutErr != INVALID_HANDLE_VALUE) { 694 switch(GetFileType(hStdOutErr)) { 695 case FILE_TYPE_DISK: 696 case FILE_TYPE_CHAR: 697 case FILE_TYPE_PIPE: 698 sprops.sun_stdout_encoding = getConsoleEncoding(); 699 break; 700 } 701 } 702 hStdOutErr = GetStdHandle(STD_ERROR_HANDLE); 703 if (hStdOutErr != INVALID_HANDLE_VALUE) { 704 switch (GetFileType(hStdOutErr)) { 705 case FILE_TYPE_DISK: 706 case FILE_TYPE_CHAR: 707 case FILE_TYPE_PIPE: 708 if (sprops.sun_stdout_encoding != NULL) 709 sprops.sun_stderr_encoding = sprops.sun_stdout_encoding; 710 else 711 sprops.sun_stderr_encoding = getConsoleEncoding(); 712 break; 713 } 714 } 715 } 716 } 717 718 sprops.unicode_encoding = "UnicodeLittle"; 719 /* User TIMEZONE */ 720 { 721 /* 722 * We defer setting up timezone until it's actually necessary. 723 * Refer to TimeZone.getDefault(). However, the system 724 * property is necessary to be able to be set by the command 725 * line interface -D. Here temporarily set a null string to 726 * timezone. 727 */ 728 sprops.timezone = ""; 729 } 730 731 /* Current directory */ 732 { 733 WCHAR buf[MAX_PATH]; |