/*
- * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2001-2003 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
+#if HFS
#include <sys/param.h>
#include <hfs/hfs_macos_defs.h>
+#include <hfs/hfs.h>
/* CJK Mac Encoding Bits */
#define CJK_CHINESE_SIMP 0x8
#define CJK_ALL 0xF
-#define CJK_CHINESE (CJK_CHINESE_TRAD | CJK_CHINESE_SIMP)
-#define CJK_KATAKANA (CJK_JAPAN | CJK_CHINESE_SIMP | CJK_KOREAN)
+#define CJK_CHINESE (CJK_CHINESE_TRAD | CJK_CHINESE_SIMP)
+#define CJK_KATAKANA (CJK_JAPAN)
/* Remember the last unique CJK bit */
u_int8_t cjk_lastunique = 0;
-/* CJK encoding bias */
+/* Encoding bias */
u_int32_t hfs_encodingbias = 0;
+int hfs_islatinbias = 0;
+
+extern lck_mtx_t encodinglst_mutex;
/* Map CJK bits to Mac encoding */
cjkstate = CJK_ALL;
continue;
}
+ if (hfs_islatinbias && ch >= 0x0300 && ch <= 0x0329) {
+ guess = hfs_encodingbias;
+ continue;
+ }
+ if (ch <= 0x03CE && ch >= 0x0384) {
+ guess = kTextEncodingMacGreek;
+ continue;
+ }
if (ch <= 0x0491 && ch >= 0x0401) {
guess = kTextEncodingMacCyrillic;
continue;
if (ch >= 0x0E00 && ch <= 0x0E5B) {
return kTextEncodingMacThai;
}
+ /* Catch a few Shift-JIS strays */
+ if (guess == 0 || guess == kTextEncodingMacUnicode) {
+ if (ch == 0x2010 || ch == 0x2014 || ch == 0x2015 || ch == 0x2016) {
+ guess = kTextEncodingMacJapanese;
+ if ((cjkstate == 0) || (cjkstate & CJK_JAPAN))
+ cjkstate = CJK_JAPAN;
+ else
+ cjkstate |= CJK_JAPAN;
+ continue;
+ }
+ if ((hfs_encodingbias == kTextEncodingMacJapanese) &&
+ (ch == 0x00A2 || ch == 0x00A3 || ch == 0x00AC)) {
+ guess = kTextEncodingMacJapanese;
+ continue;
+ }
+ /* TM char depends on the Mac encoding used. */
+ if (ch == 0x2122) {
+ switch(hfs_encodingbias) {
+ case kTextEncodingMacJapanese:
+ case kTextEncodingMacChineseTrad:
+ case kTextEncodingMacKorean:
+ case kTextEncodingMacGreek:
+ case kTextEncodingMacThai:
+ case kTextEncodingMacChineseSimp:
+ guess = hfs_encodingbias;
+ break;
+ }
+ }
+ }
if (guess == 0 && ch > 0x2122) {
guess = kTextEncodingMacUnicode;
}
}
+__private_extern__
+u_int32_t
+hfs_getencodingbias(void)
+{
+ return (hfs_encodingbias);
+}
+
+
+__private_extern__
+void
+hfs_setencodingbias(u_int32_t bias)
+{
+ lck_mtx_lock(&encodinglst_mutex);
+
+ hfs_encodingbias = bias;
+
+ switch (bias) {
+ case kTextEncodingMacRoman:
+ case kTextEncodingMacCentralEurRoman:
+ case kTextEncodingMacTurkish:
+ case kTextEncodingMacCroatian:
+ case kTextEncodingMacIcelandic:
+ case kTextEncodingMacRomanian:
+ hfs_islatinbias = 1;
+ break;
+ default:
+ hfs_islatinbias = 0;
+ break;
+ }
+
+ lck_mtx_unlock(&encodinglst_mutex);
+}
+
+#else /* not HFS - temp workaround until 4277828 is fixed */
+/* stubs for exported routines that aren't present when we build kernel without HFS */
+
+#include <sys/types.h>
+
+u_int32_t hfs_pickencoding(u_int16_t *src, int len);
+
+u_int32_t hfs_pickencoding(__unused u_int16_t *src, __unused int len)
+{
+ return(0);
+}
+
+#endif /* HFS */
+