2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/kernel.h>
26 #include <sys/malloc.h>
27 #include <sys/queue.h>
28 #include <sys/utfconv.h>
33 lck_grp_t
* encodinglst_lck_grp
;
34 lck_grp_attr_t
* encodinglst_lck_grp_attr
;
35 lck_attr_t
* encodinglst_lck_attr
;
38 /* hfs encoding converter list */
39 SLIST_HEAD(encodinglst
, hfs_encoding
) hfs_encoding_list
= {0};
41 lck_mtx_t encodinglst_mutex
;
45 /* hfs encoding converter entry */
47 SLIST_ENTRY(hfs_encoding
) link
;
51 hfs_to_unicode_func_t get_unicode_func
;
52 unicode_to_hfs_func_t get_hfsname_func
;
55 /* XXX We should use an "official" interface! */
56 extern kern_return_t
kmod_destroy(host_priv_t host_priv
, kmod_t id
);
57 extern struct host realhost
;
59 #define MAX_HFS_UNICODE_CHARS (15*5)
61 int mac_roman_to_unicode(const Str31 hfs_str
, UniChar
*uni_str
, UInt32 maxCharLen
, UInt32
*usedCharLen
);
63 static int unicode_to_mac_roman(UniChar
*uni_str
, UInt32 unicodeChars
, Str31 hfs_str
);
67 hfs_converterinit(void)
69 SLIST_INIT(&hfs_encoding_list
);
71 encodinglst_lck_grp_attr
= lck_grp_attr_alloc_init();
72 encodinglst_lck_grp
= lck_grp_alloc_init("cnode_hash", encodinglst_lck_grp_attr
);
73 encodinglst_lck_attr
= lck_attr_alloc_init();
75 lck_mtx_init(&encodinglst_mutex
, encodinglst_lck_grp
, encodinglst_lck_attr
);
78 * add resident MacRoman converter and take a reference
79 * since its always "loaded".
81 hfs_addconverter(0, kTextEncodingMacRoman
, mac_roman_to_unicode
, unicode_to_mac_roman
);
82 SLIST_FIRST(&hfs_encoding_list
)->refcount
++;
87 * hfs_addconverter - add an HFS encoding converter
89 * This is called exclusivly by kernel loadable modules
90 * (like HFS_Japanese.kmod) to register hfs encoding
91 * conversion routines.
95 hfs_addconverter(int id
, UInt32 encoding
, hfs_to_unicode_func_t get_unicode
, unicode_to_hfs_func_t get_hfsname
)
97 struct hfs_encoding
*encp
;
99 MALLOC(encp
, struct hfs_encoding
*, sizeof(struct hfs_encoding
), M_TEMP
, M_WAITOK
);
101 lck_mtx_lock(&encodinglst_mutex
);
103 encp
->link
.sle_next
= NULL
;
105 encp
->encoding
= encoding
;
106 encp
->get_unicode_func
= get_unicode
;
107 encp
->get_hfsname_func
= get_hfsname
;
109 SLIST_INSERT_HEAD(&hfs_encoding_list
, encp
, link
);
111 lck_mtx_unlock(&encodinglst_mutex
);
117 * hfs_remconverter - remove an HFS encoding converter
119 * Can be called by a kernel loadable module's finalize
120 * routine to remove an encoding converter so that the
121 * module (i.e. the code) can be unloaded.
123 * However, in the normal case, the removing and unloading
124 * of these converters is done in hfs_relconverter.
125 * The call is initiated from within the kernel during the unmounting of an hfs voulume.
128 hfs_remconverter(int id
, UInt32 encoding
)
130 struct hfs_encoding
*encp
;
132 lck_mtx_lock(&encodinglst_mutex
);
133 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
134 if (encp
->encoding
== encoding
&& encp
->kmod_id
== id
) {
137 /* if converter is no longer in use, release it */
138 if (encp
->refcount
<= 0 && encp
->kmod_id
!= 0) {
139 SLIST_REMOVE(&hfs_encoding_list
, encp
, hfs_encoding
, link
);
140 lck_mtx_unlock(&encodinglst_mutex
);
144 lck_mtx_unlock(&encodinglst_mutex
);
145 return (1); /* busy */
150 lck_mtx_unlock(&encodinglst_mutex
);
157 * hfs_getconverter - get HFS encoding converters
159 * Normally called during the mounting of an hfs voulume.
162 hfs_getconverter(UInt32 encoding
, hfs_to_unicode_func_t
*get_unicode
, unicode_to_hfs_func_t
*get_hfsname
)
164 struct hfs_encoding
*encp
;
167 lck_mtx_lock(&encodinglst_mutex
);
168 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
169 if (encp
->encoding
== encoding
) {
171 *get_unicode
= encp
->get_unicode_func
;
172 *get_hfsname
= encp
->get_hfsname_func
;
177 lck_mtx_unlock(&encodinglst_mutex
);
190 * hfs_relconverter - release interest in an HFS encoding converter
192 * Normally called during the unmounting of an hfs voulume.
195 hfs_relconverter(UInt32 encoding
)
197 struct hfs_encoding
*encp
;
199 lck_mtx_lock(&encodinglst_mutex
);
200 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
201 if (encp
->encoding
== encoding
) {
204 /* if converter is no longer in use, release it */
205 if (encp
->refcount
<= 0 && encp
->kmod_id
!= 0) {
206 int id
= encp
->kmod_id
;
208 SLIST_REMOVE(&hfs_encoding_list
, encp
, hfs_encoding
, link
);
209 lck_mtx_unlock(&encodinglst_mutex
);
212 kmod_destroy((host_priv_t
) host_priv_self(), id
);
215 lck_mtx_unlock(&encodinglst_mutex
);
219 lck_mtx_unlock(&encodinglst_mutex
);
226 * Convert HFS encoded string into UTF-8
228 * Unicode output is fully decomposed
229 * '/' chars are converted to ':'
232 hfs_to_utf8(ExtendedVCB
*vcb
, Str31 hfs_str
, ByteCount maxDstLen
, ByteCount
*actualDstLen
, unsigned char* dstStr
)
235 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
238 hfs_to_unicode_func_t hfs_get_unicode
= VCBTOHFS(vcb
)->hfs_get_unicode
;
240 error
= hfs_get_unicode(hfs_str
, uniStr
, MAX_HFS_UNICODE_CHARS
, &uniCount
);
246 error
= utf8_encodestr(uniStr
, uniCount
* sizeof(UniChar
), dstStr
, &utf8len
, maxDstLen
, ':', 0);
247 if (error
== ENAMETOOLONG
)
248 *actualDstLen
= utf8_encodelen(uniStr
, uniCount
* sizeof(UniChar
), ':', 0);
250 *actualDstLen
= utf8len
;
258 * When an HFS name cannot be encoded with the current
259 * volume encoding then MacRoman is used as a fallback.
262 mac_roman_to_utf8(Str31 hfs_str
, ByteCount maxDstLen
, ByteCount
*actualDstLen
, unsigned char* dstStr
)
265 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
269 error
= mac_roman_to_unicode(hfs_str
, uniStr
, MAX_HFS_UNICODE_CHARS
, &uniCount
);
275 error
= utf8_encodestr(uniStr
, uniCount
* sizeof(UniChar
), dstStr
, &utf8len
, maxDstLen
, ':', 0);
276 if (error
== ENAMETOOLONG
)
277 *actualDstLen
= utf8_encodelen(uniStr
, uniCount
* sizeof(UniChar
), ':', 0);
279 *actualDstLen
= utf8len
;
287 * Convert Unicode string into HFS encoding
289 * ':' chars are converted to '/'
290 * Assumes input represents fully decomposed Unicode
293 unicode_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, u_int16_t
* srcStr
, Str31 dstStr
, int retry
)
296 unicode_to_hfs_func_t hfs_get_hfsname
= VCBTOHFS(vcb
)->hfs_get_hfsname
;
298 error
= hfs_get_hfsname(srcStr
, srcLen
/sizeof(UniChar
), dstStr
);
299 if (error
&& retry
) {
300 error
= unicode_to_mac_roman(srcStr
, srcLen
/sizeof(UniChar
), dstStr
);
306 * Convert UTF-8 string into HFS encoding
308 * ':' chars are converted to '/'
309 * Assumes input represents fully decomposed Unicode
312 utf8_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, const unsigned char* srcStr
, Str31 dstStr
/*, int retry*/)
315 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
318 error
= utf8_decodestr(srcStr
, srcLen
, uniStr
, &ucslen
, sizeof(uniStr
), ':', 0);
320 error
= unicode_to_hfs(vcb
, ucslen
, uniStr
, dstStr
, 1);
326 utf8_to_mac_roman(ByteCount srcLen
, const unsigned char* srcStr
, Str31 dstStr
)
329 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
332 error
= utf8_decodestr(srcStr
, srcLen
, uniStr
, &ucslen
, sizeof(uniStr
), ':', 0);
334 error
= unicode_to_mac_roman(uniStr
, ucslen
/sizeof(UniChar
), dstStr
);
340 * HFS MacRoman to/from Unicode conversions are built into the kernel
341 * All others hfs encodings are loadable.
344 /* 0x00A0 - 0x00FF = Latin 1 Supplement (30 total) */
345 static UInt8 gLatin1Table
[] = {
346 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
347 /* 0x00A0 */ 0xCA, 0xC1, 0xA2, 0xA3, 0xDB, 0xB4, '?', 0xA4, 0xAC, 0xA9, 0xBB, 0xC7, 0xC2, '?', 0xA8, 0xF8,
348 /* 0x00B0 */ 0xA1, 0XB1, '?', '?', 0xAB, 0xB5, 0xA6, 0xe1, 0xFC, '?', 0xBC, 0xC8, '?', '?', '?', 0xC0,
349 /* 0x00C0 */ '?', '?', '?', '?', '?', '?', 0xAE, '?', '?', '?', '?', '?', '?', '?', '?', '?',
350 /* 0x00D0 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xAF, '?', '?', '?', '?', '?', '?', 0xA7,
351 /* 0x00E0 */ '?', '?', '?', '?', '?', '?', 0xBE, '?', '?', '?', '?', '?', '?', '?', '?', '?',
352 /* 0x00F0 */ '?', '?', '?', '?', '?', '?', '?', 0xD6, 0xBF, '?', '?', '?', '?', '?', '?', '?'
355 /* 0x02C0 - 0x02DF = Spacing Modifiers (8 total) */
356 static UInt8 gSpaceModsTable
[] = {
357 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
358 /* 0x02C0 */ '?', '?', '?', '?', '?', '?', 0xF6, 0xFF, '?', '?', '?', '?', '?', '?', '?', '?',
359 /* 0x02D0 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xF9, 0xFA, 0xFB, 0xFE, 0xF7, 0xFD, '?', '?'
362 /* 0x2010 - 0x20AF = General Punctuation (17 total) */
363 static UInt8 gPunctTable
[] = {
364 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
365 /* 0x2010 */ '?', '?', '?', 0xd0, 0xd1, '?', '?', '?', 0xd4, 0xd5, 0xe2, '?', 0xd2, 0xd3, 0xe3, '?',
366 /* 0x2020 */ 0xa0, 0xe0, 0xa5, '?', '?', '?', 0xc9, '?', '?', '?', '?', '?', '?', '?', '?', '?',
367 /* 0x2030 */ 0xe4, '?', '?', '?', '?', '?', '?', '?', '?', 0xdc, 0xdd, '?', '?', '?', '?', '?',
368 /* 0x2040 */ '?', '?', '?', '?', 0xda, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
369 /* 0x2050 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
370 /* 0x2060 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
371 /* 0x2070 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
372 /* 0x2080 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
373 /* 0x2090 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
374 /* 0x20A0 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0xdb, '?', '?', '?'
377 /* 0x22xx = Mathematical Operators (11 total) */
378 static UInt8 gMathTable
[] = {
379 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
380 /* 0x2200 */ '?', '?', 0xb6, '?', '?', '?', 0xc6, '?', '?', '?', '?', '?', '?', '?', '?', 0xb8,
381 /* 0x2210 */ '?', 0xb7, '?', '?', '?', '?', '?', '?', '?', '?', 0xc3, '?', '?', '?', 0xb0, '?',
382 /* 0x2220 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0xba, '?', '?', '?', '?',
383 /* 0x2230 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
384 /* 0x2240 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xc5, '?', '?', '?', '?', '?', '?', '?',
385 /* 0x2250 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
386 /* 0x2260 */ 0xad, '?', '?', '?', 0xb2, 0xb3, '?', '?'
390 static UInt8 gReverseCombTable
[] = {
391 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
392 /* 0x40 */ 0xDA, 0x40, 0xDA, 0xDA, 0xDA, 0x56, 0xDA, 0xDA, 0xDA, 0x6C, 0xDA, 0xDA, 0xDA, 0xDA, 0x82, 0x98,
393 /* 0x50 */ 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xAE, 0xDA, 0xDA, 0xDA, 0xC4, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA,
394 /* 0x60 */ 0xDA, 0x4B, 0xDA, 0xDA, 0xDA, 0x61, 0xDA, 0xDA, 0xDA, 0x77, 0xDA, 0xDA, 0xDA, 0xDA, 0x8D, 0xA3,
395 /* 0x70 */ 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xB9, 0xDA, 0xDA, 0xDA, 0xCF, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA,
397 /* Combining Diacritical Marks (0x0300 - 0x030A) */
398 /* 0 1 2 3 4 5 6 7 8 9 A */
400 /* 0x0300 */ 0xCB, 0xE7, 0xE5, 0xCC, '?', '?', '?', '?', 0x80, '?', 0x81,
403 /* 0x0300 */ 0x88, 0x87, 0x89, 0x8B, '?', '?', '?', '?', 0x8A, '?', 0x8C,
406 /* 0x0300 */ 0xE9, 0x83, 0xE6, '?', '?', '?', '?', '?', 0xE8, '?', '?',
409 /* 0x0300 */ 0x8F, 0x8E, 0x90, '?', '?', '?', '?', '?', 0x91, '?', '?',
412 /* 0x0300 */ 0xED, 0xEA, 0xEB, '?', '?', '?', '?', '?', 0xEC, '?', '?',
415 /* 0x0300 */ 0x93, 0x92, 0x94, '?', '?', '?', '?', '?', 0x95, '?', '?',
418 /* 0x0300 */ '?', '?', '?', 0x84, '?', '?', '?', '?', '?', '?', '?',
421 /* 0x0300 */ '?', '?', '?', 0x96, '?', '?', '?', '?', '?', '?', '?',
424 /* 0x0300 */ 0xF1, 0xEE, 0xEF, 0xCD, '?', '?', '?', '?', 0x85, '?', '?',
427 /* 0x0300 */ 0x98, 0x97, 0x99, 0x9B, '?', '?', '?', '?', 0x9A, '?', '?',
430 /* 0x0300 */ 0xF4, 0xF2, 0xF3, '?', '?', '?', '?', '?', 0x86, '?', '?',
433 /* 0x0300 */ 0x9D, 0x9C, 0x9E, '?', '?', '?', '?', '?', 0x9F, '?', '?',
436 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xD9, '?', '?',
439 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xD8, '?', '?',
442 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'
447 * Convert Unicode string into HFS MacRoman encoding
449 * Assumes Unicode input is fully decomposed
451 static int unicode_to_mac_roman(UniChar
*uni_str
, UInt32 unicodeChars
, Str31 hfs_str
)
459 OSErr result
= noErr
;
464 mask
= (UniChar
) 0xFF80;
467 inputChars
= unicodeChars
;
468 pascalChars
= prevChar
= 0;
475 * If its not 7-bit ascii, then we need to map it
479 switch (c
& 0xFF00) {
482 mc
= gLatin1Table
[lsb
- 0xA0];
486 if (lsb
>= 0xC0 && lsb
<= 0xDF)
487 mc
= gSpaceModsTable
[lsb
- 0xC0];
491 if (lsb
>= 0x10 && lsb
<= 0xAF)
492 mc
= gPunctTable
[lsb
- 0x10];
497 mc
= gMathTable
[lsb
];
502 if (prevChar
>= 'A' && prevChar
< 'z') {
503 mc
= gReverseCombTable
[gReverseCombTable
[prevChar
- 0x40] + lsb
];
504 --p
; /* backup over base char */
509 case 0x0327: /* combining cedilla */
512 else if (prevChar
== 'c')
516 --p
; /* backup over base char */
520 case 0x03A9: mc
= 0xBD; break; /* omega */
522 case 0x03C0: mc
= 0xB9; break; /* pi */
529 case 0x0131: mc
= 0xf5; break; /* dotless i */
531 case 0x0152: mc
= 0xce; break; /* OE */
533 case 0x0153: mc
= 0xcf; break; /* oe */
535 case 0x0192: mc
= 0xc4; break; /* Ä */
537 case 0x2122: mc
= 0xaa; break; /* TM */
539 case 0x25ca: mc
= 0xd7; break; /* diamond */
541 case 0xf8ff: mc
= 0xf0; break; /* apple logo */
543 case 0xfb01: mc
= 0xde; break; /* fi */
545 case 0xfb02: mc
= 0xdf; break; /* fl */
547 } /* end switch (c & 0xFF00) */
550 * If we have an unmapped character then we need to mangle the name...
553 result
= kTECUsedFallbacksStatus
;
562 if (pascalChars
>= 31)
571 hfs_str
[0] = pascalChars
;
574 result
= ENAMETOOLONG
; /* ran out of room! */
580 static UniChar gHiBitBaseUnicode
[128] = {
581 /* 0x80 */ 0x0041, 0x0041, 0x0043, 0x0045, 0x004e, 0x004f, 0x0055, 0x0061,
582 /* 0x88 */ 0x0061, 0x0061, 0x0061, 0x0061, 0x0061, 0x0063, 0x0065, 0x0065,
583 /* 0x90 */ 0x0065, 0x0065, 0x0069, 0x0069, 0x0069, 0x0069, 0x006e, 0x006f,
584 /* 0x98 */ 0x006f, 0x006f, 0x006f, 0x006f, 0x0075, 0x0075, 0x0075, 0x0075,
585 /* 0xa0 */ 0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df,
586 /* 0xa8 */ 0x00ae, 0x00a9, 0x2122, 0x00b4, 0x00a8, 0x2260, 0x00c6, 0x00d8,
587 /* 0xb0 */ 0x221e, 0x00b1, 0x2264, 0x2265, 0x00a5, 0x00b5, 0x2202, 0x2211,
588 /* 0xb8 */ 0x220f, 0x03c0, 0x222b, 0x00aa, 0x00ba, 0x03a9, 0x00e6, 0x00f8,
589 /* 0xc0 */ 0x00bf, 0x00a1, 0x00ac, 0x221a, 0x0192, 0x2248, 0x2206, 0x00ab,
590 /* 0xc8 */ 0x00bb, 0x2026, 0x00a0, 0x0041, 0x0041, 0x004f, 0x0152, 0x0153,
591 /* 0xd0 */ 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x25ca,
592 /* 0xd8 */ 0x0079, 0x0059, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02,
593 /* 0xe0 */ 0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x0041, 0x0045, 0x0041,
594 /* 0xe8 */ 0x0045, 0x0045, 0x0049, 0x0049, 0x0049, 0x0049, 0x004f, 0x004f,
595 /* 0xf0 */ 0xf8ff, 0x004f, 0x0055, 0x0055, 0x0055, 0x0131, 0x02c6, 0x02dc,
596 /* 0xf8 */ 0x00af, 0x02d8, 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7
599 static UniChar gHiBitCombUnicode
[128] = {
600 /* 0x80 */ 0x0308, 0x030a, 0x0327, 0x0301, 0x0303, 0x0308, 0x0308, 0x0301,
601 /* 0x88 */ 0x0300, 0x0302, 0x0308, 0x0303, 0x030a, 0x0327, 0x0301, 0x0300,
602 /* 0x90 */ 0x0302, 0x0308, 0x0301, 0x0300, 0x0302, 0x0308, 0x0303, 0x0301,
603 /* 0x98 */ 0x0300, 0x0302, 0x0308, 0x0303, 0x0301, 0x0300, 0x0302, 0x0308,
604 /* 0xa0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
605 /* 0xa8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
606 /* 0xb0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
607 /* 0xb8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
608 /* 0xc0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
609 /* 0xc8 */ 0x0000, 0x0000, 0x0000, 0x0300, 0x0303, 0x0303, 0x0000, 0x0000,
610 /* 0xd0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
611 /* 0xd8 */ 0x0308, 0x0308, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
612 /* 0xe0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0302, 0x0302, 0x0301,
613 /* 0xe8 */ 0x0308, 0x0300, 0x0301, 0x0302, 0x0308, 0x0300, 0x0301, 0x0302,
614 /* 0xf0 */ 0x0000, 0x0300, 0x0301, 0x0302, 0x0300, 0x0000, 0x0000, 0x0000,
615 /* 0xf8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
620 * Convert HFS MacRoman encoded string into Unicode
622 * Unicode output is fully decomposed
625 mac_roman_to_unicode(const Str31 hfs_str
, UniChar
*uni_str
,
626 UInt32 maxCharLen
, UInt32
*unicodeChars
)
636 *unicodeChars
= pascalChars
= *(p
++); /* pick up length byte */
638 while (pascalChars
--) {
641 if ( (SInt8
) c
>= 0 ) { /* check if seven bit ascii */
642 *(u
++) = (UniChar
) c
; /* just pad high byte with zero */
643 } else { /* its a hi bit character */
647 *(u
++) = uc
= gHiBitBaseUnicode
[c
];
650 * if the unicode character we get back is an alpha char
651 * then we must have an additional combining character
653 if ((uc
<= (UniChar
) 'z') && (uc
>= (UniChar
) 'A')) {
654 *(u
++) = gHiBitCombUnicode
[c
];