xorriso  1.5.4.pl02
About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.
  Fossies Dox: xorriso-1.5.4.pl02.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

hfsplus_case.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Thomas Schmitt
3  *
4  * This file is part of the libisofs project; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License version 2
6  * or later as published by the Free Software Foundation.
7  * See COPYING file for details.
8  */
9 
10 /**
11  * Maps UTF-16BE double-byte characters to the representative of their
12  * equivalence class under the relation of HFS+ case-insensitivity.
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #include "../config.h"
17 #endif
18 
19 #include "libisofs.h"
20 
21 
22 /* The translation list utf16be_transl was generated by a program which
23  compared input and output of existing example code by Apple Inc.
24  found published on
25  http://developer.apple.com/legacy/mac/library/#technotes/tn/tn1150.html
26 
27  Each deviation was recorded as pair of byte pairs. The first pair gives
28  the input, the second pair gives the output. If a byte pair is not mentioned
29  in this list as input, then it gets mapped to itself.
30  Pairs which get mapped to pair 0,0 shall be ignored with HFS+ comparisons.
31 
32  Another comparison run verified that both implementations yield the same
33  character translation with all 65536 possible input bit patterns.
34 */
35 static uint8_t utf16be_transl[] = {
36  0x00, 0x00, 0xff, 0xff,
37  0x00, 0x41, 0x00, 0x61,
38  0x00, 0x42, 0x00, 0x62,
39  0x00, 0x43, 0x00, 0x63,
40  0x00, 0x44, 0x00, 0x64,
41  0x00, 0x45, 0x00, 0x65,
42  0x00, 0x46, 0x00, 0x66,
43  0x00, 0x47, 0x00, 0x67,
44  0x00, 0x48, 0x00, 0x68,
45  0x00, 0x49, 0x00, 0x69,
46  0x00, 0x4a, 0x00, 0x6a,
47  0x00, 0x4b, 0x00, 0x6b,
48  0x00, 0x4c, 0x00, 0x6c,
49  0x00, 0x4d, 0x00, 0x6d,
50  0x00, 0x4e, 0x00, 0x6e,
51  0x00, 0x4f, 0x00, 0x6f,
52  0x00, 0x50, 0x00, 0x70,
53  0x00, 0x51, 0x00, 0x71,
54  0x00, 0x52, 0x00, 0x72,
55  0x00, 0x53, 0x00, 0x73,
56  0x00, 0x54, 0x00, 0x74,
57  0x00, 0x55, 0x00, 0x75,
58  0x00, 0x56, 0x00, 0x76,
59  0x00, 0x57, 0x00, 0x77,
60  0x00, 0x58, 0x00, 0x78,
61  0x00, 0x59, 0x00, 0x79,
62  0x00, 0x5a, 0x00, 0x7a,
63  0x00, 0xc6, 0x00, 0xe6,
64  0x00, 0xd0, 0x00, 0xf0,
65  0x00, 0xd8, 0x00, 0xf8,
66  0x00, 0xde, 0x00, 0xfe,
67  0x01, 0x10, 0x01, 0x11,
68  0x01, 0x26, 0x01, 0x27,
69  0x01, 0x32, 0x01, 0x33,
70  0x01, 0x3f, 0x01, 0x40,
71  0x01, 0x41, 0x01, 0x42,
72  0x01, 0x4a, 0x01, 0x4b,
73  0x01, 0x52, 0x01, 0x53,
74  0x01, 0x66, 0x01, 0x67,
75  0x01, 0x81, 0x02, 0x53,
76  0x01, 0x82, 0x01, 0x83,
77  0x01, 0x84, 0x01, 0x85,
78  0x01, 0x86, 0x02, 0x54,
79  0x01, 0x87, 0x01, 0x88,
80  0x01, 0x89, 0x02, 0x56,
81  0x01, 0x8a, 0x02, 0x57,
82  0x01, 0x8b, 0x01, 0x8c,
83  0x01, 0x8e, 0x01, 0xdd,
84  0x01, 0x8f, 0x02, 0x59,
85  0x01, 0x90, 0x02, 0x5b,
86  0x01, 0x91, 0x01, 0x92,
87  0x01, 0x93, 0x02, 0x60,
88  0x01, 0x94, 0x02, 0x63,
89  0x01, 0x96, 0x02, 0x69,
90  0x01, 0x97, 0x02, 0x68,
91  0x01, 0x98, 0x01, 0x99,
92  0x01, 0x9c, 0x02, 0x6f,
93  0x01, 0x9d, 0x02, 0x72,
94  0x01, 0x9f, 0x02, 0x75,
95  0x01, 0xa2, 0x01, 0xa3,
96  0x01, 0xa4, 0x01, 0xa5,
97  0x01, 0xa7, 0x01, 0xa8,
98  0x01, 0xa9, 0x02, 0x83,
99  0x01, 0xac, 0x01, 0xad,
100  0x01, 0xae, 0x02, 0x88,
101  0x01, 0xb1, 0x02, 0x8a,
102  0x01, 0xb2, 0x02, 0x8b,
103  0x01, 0xb3, 0x01, 0xb4,
104  0x01, 0xb5, 0x01, 0xb6,
105  0x01, 0xb7, 0x02, 0x92,
106  0x01, 0xb8, 0x01, 0xb9,
107  0x01, 0xbc, 0x01, 0xbd,
108  0x01, 0xc4, 0x01, 0xc6,
109  0x01, 0xc5, 0x01, 0xc6,
110  0x01, 0xc7, 0x01, 0xc9,
111  0x01, 0xc8, 0x01, 0xc9,
112  0x01, 0xca, 0x01, 0xcc,
113  0x01, 0xcb, 0x01, 0xcc,
114  0x01, 0xe4, 0x01, 0xe5,
115  0x01, 0xf1, 0x01, 0xf3,
116  0x01, 0xf2, 0x01, 0xf3,
117  0x03, 0x91, 0x03, 0xb1,
118  0x03, 0x92, 0x03, 0xb2,
119  0x03, 0x93, 0x03, 0xb3,
120  0x03, 0x94, 0x03, 0xb4,
121  0x03, 0x95, 0x03, 0xb5,
122  0x03, 0x96, 0x03, 0xb6,
123  0x03, 0x97, 0x03, 0xb7,
124  0x03, 0x98, 0x03, 0xb8,
125  0x03, 0x99, 0x03, 0xb9,
126  0x03, 0x9a, 0x03, 0xba,
127  0x03, 0x9b, 0x03, 0xbb,
128  0x03, 0x9c, 0x03, 0xbc,
129  0x03, 0x9d, 0x03, 0xbd,
130  0x03, 0x9e, 0x03, 0xbe,
131  0x03, 0x9f, 0x03, 0xbf,
132  0x03, 0xa0, 0x03, 0xc0,
133  0x03, 0xa1, 0x03, 0xc1,
134  0x03, 0xa3, 0x03, 0xc3,
135  0x03, 0xa4, 0x03, 0xc4,
136  0x03, 0xa5, 0x03, 0xc5,
137  0x03, 0xa6, 0x03, 0xc6,
138  0x03, 0xa7, 0x03, 0xc7,
139  0x03, 0xa8, 0x03, 0xc8,
140  0x03, 0xa9, 0x03, 0xc9,
141  0x03, 0xe2, 0x03, 0xe3,
142  0x03, 0xe4, 0x03, 0xe5,
143  0x03, 0xe6, 0x03, 0xe7,
144  0x03, 0xe8, 0x03, 0xe9,
145  0x03, 0xea, 0x03, 0xeb,
146  0x03, 0xec, 0x03, 0xed,
147  0x03, 0xee, 0x03, 0xef,
148  0x04, 0x02, 0x04, 0x52,
149  0x04, 0x04, 0x04, 0x54,
150  0x04, 0x05, 0x04, 0x55,
151  0x04, 0x06, 0x04, 0x56,
152  0x04, 0x08, 0x04, 0x58,
153  0x04, 0x09, 0x04, 0x59,
154  0x04, 0x0a, 0x04, 0x5a,
155  0x04, 0x0b, 0x04, 0x5b,
156  0x04, 0x0f, 0x04, 0x5f,
157  0x04, 0x10, 0x04, 0x30,
158  0x04, 0x11, 0x04, 0x31,
159  0x04, 0x12, 0x04, 0x32,
160  0x04, 0x13, 0x04, 0x33,
161  0x04, 0x14, 0x04, 0x34,
162  0x04, 0x15, 0x04, 0x35,
163  0x04, 0x16, 0x04, 0x36,
164  0x04, 0x17, 0x04, 0x37,
165  0x04, 0x18, 0x04, 0x38,
166  0x04, 0x1a, 0x04, 0x3a,
167  0x04, 0x1b, 0x04, 0x3b,
168  0x04, 0x1c, 0x04, 0x3c,
169  0x04, 0x1d, 0x04, 0x3d,
170  0x04, 0x1e, 0x04, 0x3e,
171  0x04, 0x1f, 0x04, 0x3f,
172  0x04, 0x20, 0x04, 0x40,
173  0x04, 0x21, 0x04, 0x41,
174  0x04, 0x22, 0x04, 0x42,
175  0x04, 0x23, 0x04, 0x43,
176  0x04, 0x24, 0x04, 0x44,
177  0x04, 0x25, 0x04, 0x45,
178  0x04, 0x26, 0x04, 0x46,
179  0x04, 0x27, 0x04, 0x47,
180  0x04, 0x28, 0x04, 0x48,
181  0x04, 0x29, 0x04, 0x49,
182  0x04, 0x2a, 0x04, 0x4a,
183  0x04, 0x2b, 0x04, 0x4b,
184  0x04, 0x2c, 0x04, 0x4c,
185  0x04, 0x2d, 0x04, 0x4d,
186  0x04, 0x2e, 0x04, 0x4e,
187  0x04, 0x2f, 0x04, 0x4f,
188  0x04, 0x60, 0x04, 0x61,
189  0x04, 0x62, 0x04, 0x63,
190  0x04, 0x64, 0x04, 0x65,
191  0x04, 0x66, 0x04, 0x67,
192  0x04, 0x68, 0x04, 0x69,
193  0x04, 0x6a, 0x04, 0x6b,
194  0x04, 0x6c, 0x04, 0x6d,
195  0x04, 0x6e, 0x04, 0x6f,
196  0x04, 0x70, 0x04, 0x71,
197  0x04, 0x72, 0x04, 0x73,
198  0x04, 0x74, 0x04, 0x75,
199  0x04, 0x78, 0x04, 0x79,
200  0x04, 0x7a, 0x04, 0x7b,
201  0x04, 0x7c, 0x04, 0x7d,
202  0x04, 0x7e, 0x04, 0x7f,
203  0x04, 0x80, 0x04, 0x81,
204  0x04, 0x90, 0x04, 0x91,
205  0x04, 0x92, 0x04, 0x93,
206  0x04, 0x94, 0x04, 0x95,
207  0x04, 0x96, 0x04, 0x97,
208  0x04, 0x98, 0x04, 0x99,
209  0x04, 0x9a, 0x04, 0x9b,
210  0x04, 0x9c, 0x04, 0x9d,
211  0x04, 0x9e, 0x04, 0x9f,
212  0x04, 0xa0, 0x04, 0xa1,
213  0x04, 0xa2, 0x04, 0xa3,
214  0x04, 0xa4, 0x04, 0xa5,
215  0x04, 0xa6, 0x04, 0xa7,
216  0x04, 0xa8, 0x04, 0xa9,
217  0x04, 0xaa, 0x04, 0xab,
218  0x04, 0xac, 0x04, 0xad,
219  0x04, 0xae, 0x04, 0xaf,
220  0x04, 0xb0, 0x04, 0xb1,
221  0x04, 0xb2, 0x04, 0xb3,
222  0x04, 0xb4, 0x04, 0xb5,
223  0x04, 0xb6, 0x04, 0xb7,
224  0x04, 0xb8, 0x04, 0xb9,
225  0x04, 0xba, 0x04, 0xbb,
226  0x04, 0xbc, 0x04, 0xbd,
227  0x04, 0xbe, 0x04, 0xbf,
228  0x04, 0xc3, 0x04, 0xc4,
229  0x04, 0xc7, 0x04, 0xc8,
230  0x04, 0xcb, 0x04, 0xcc,
231  0x05, 0x31, 0x05, 0x61,
232  0x05, 0x32, 0x05, 0x62,
233  0x05, 0x33, 0x05, 0x63,
234  0x05, 0x34, 0x05, 0x64,
235  0x05, 0x35, 0x05, 0x65,
236  0x05, 0x36, 0x05, 0x66,
237  0x05, 0x37, 0x05, 0x67,
238  0x05, 0x38, 0x05, 0x68,
239  0x05, 0x39, 0x05, 0x69,
240  0x05, 0x3a, 0x05, 0x6a,
241  0x05, 0x3b, 0x05, 0x6b,
242  0x05, 0x3c, 0x05, 0x6c,
243  0x05, 0x3d, 0x05, 0x6d,
244  0x05, 0x3e, 0x05, 0x6e,
245  0x05, 0x3f, 0x05, 0x6f,
246  0x05, 0x40, 0x05, 0x70,
247  0x05, 0x41, 0x05, 0x71,
248  0x05, 0x42, 0x05, 0x72,
249  0x05, 0x43, 0x05, 0x73,
250  0x05, 0x44, 0x05, 0x74,
251  0x05, 0x45, 0x05, 0x75,
252  0x05, 0x46, 0x05, 0x76,
253  0x05, 0x47, 0x05, 0x77,
254  0x05, 0x48, 0x05, 0x78,
255  0x05, 0x49, 0x05, 0x79,
256  0x05, 0x4a, 0x05, 0x7a,
257  0x05, 0x4b, 0x05, 0x7b,
258  0x05, 0x4c, 0x05, 0x7c,
259  0x05, 0x4d, 0x05, 0x7d,
260  0x05, 0x4e, 0x05, 0x7e,
261  0x05, 0x4f, 0x05, 0x7f,
262  0x05, 0x50, 0x05, 0x80,
263  0x05, 0x51, 0x05, 0x81,
264  0x05, 0x52, 0x05, 0x82,
265  0x05, 0x53, 0x05, 0x83,
266  0x05, 0x54, 0x05, 0x84,
267  0x05, 0x55, 0x05, 0x85,
268  0x05, 0x56, 0x05, 0x86,
269  0x10, 0xa0, 0x10, 0xd0,
270  0x10, 0xa1, 0x10, 0xd1,
271  0x10, 0xa2, 0x10, 0xd2,
272  0x10, 0xa3, 0x10, 0xd3,
273  0x10, 0xa4, 0x10, 0xd4,
274  0x10, 0xa5, 0x10, 0xd5,
275  0x10, 0xa6, 0x10, 0xd6,
276  0x10, 0xa7, 0x10, 0xd7,
277  0x10, 0xa8, 0x10, 0xd8,
278  0x10, 0xa9, 0x10, 0xd9,
279  0x10, 0xaa, 0x10, 0xda,
280  0x10, 0xab, 0x10, 0xdb,
281  0x10, 0xac, 0x10, 0xdc,
282  0x10, 0xad, 0x10, 0xdd,
283  0x10, 0xae, 0x10, 0xde,
284  0x10, 0xaf, 0x10, 0xdf,
285  0x10, 0xb0, 0x10, 0xe0,
286  0x10, 0xb1, 0x10, 0xe1,
287  0x10, 0xb2, 0x10, 0xe2,
288  0x10, 0xb3, 0x10, 0xe3,
289  0x10, 0xb4, 0x10, 0xe4,
290  0x10, 0xb5, 0x10, 0xe5,
291  0x10, 0xb6, 0x10, 0xe6,
292  0x10, 0xb7, 0x10, 0xe7,
293  0x10, 0xb8, 0x10, 0xe8,
294  0x10, 0xb9, 0x10, 0xe9,
295  0x10, 0xba, 0x10, 0xea,
296  0x10, 0xbb, 0x10, 0xeb,
297  0x10, 0xbc, 0x10, 0xec,
298  0x10, 0xbd, 0x10, 0xed,
299  0x10, 0xbe, 0x10, 0xee,
300  0x10, 0xbf, 0x10, 0xef,
301  0x10, 0xc0, 0x10, 0xf0,
302  0x10, 0xc1, 0x10, 0xf1,
303  0x10, 0xc2, 0x10, 0xf2,
304  0x10, 0xc3, 0x10, 0xf3,
305  0x10, 0xc4, 0x10, 0xf4,
306  0x10, 0xc5, 0x10, 0xf5,
307  0x20, 0x0c, 0x00, 0x00,
308  0x20, 0x0d, 0x00, 0x00,
309  0x20, 0x0e, 0x00, 0x00,
310  0x20, 0x0f, 0x00, 0x00,
311  0x20, 0x2a, 0x00, 0x00,
312  0x20, 0x2b, 0x00, 0x00,
313  0x20, 0x2c, 0x00, 0x00,
314  0x20, 0x2d, 0x00, 0x00,
315  0x20, 0x2e, 0x00, 0x00,
316  0x20, 0x6a, 0x00, 0x00,
317  0x20, 0x6b, 0x00, 0x00,
318  0x20, 0x6c, 0x00, 0x00,
319  0x20, 0x6d, 0x00, 0x00,
320  0x20, 0x6e, 0x00, 0x00,
321  0x20, 0x6f, 0x00, 0x00,
322  0x21, 0x60, 0x21, 0x70,
323  0x21, 0x61, 0x21, 0x71,
324  0x21, 0x62, 0x21, 0x72,
325  0x21, 0x63, 0x21, 0x73,
326  0x21, 0x64, 0x21, 0x74,
327  0x21, 0x65, 0x21, 0x75,
328  0x21, 0x66, 0x21, 0x76,
329  0x21, 0x67, 0x21, 0x77,
330  0x21, 0x68, 0x21, 0x78,
331  0x21, 0x69, 0x21, 0x79,
332  0x21, 0x6a, 0x21, 0x7a,
333  0x21, 0x6b, 0x21, 0x7b,
334  0x21, 0x6c, 0x21, 0x7c,
335  0x21, 0x6d, 0x21, 0x7d,
336  0x21, 0x6e, 0x21, 0x7e,
337  0x21, 0x6f, 0x21, 0x7f,
338  0xfe, 0xff, 0x00, 0x00,
339  0xff, 0x21, 0xff, 0x41,
340  0xff, 0x22, 0xff, 0x42,
341  0xff, 0x23, 0xff, 0x43,
342  0xff, 0x24, 0xff, 0x44,
343  0xff, 0x25, 0xff, 0x45,
344  0xff, 0x26, 0xff, 0x46,
345  0xff, 0x27, 0xff, 0x47,
346  0xff, 0x28, 0xff, 0x48,
347  0xff, 0x29, 0xff, 0x49,
348  0xff, 0x2a, 0xff, 0x4a,
349  0xff, 0x2b, 0xff, 0x4b,
350  0xff, 0x2c, 0xff, 0x4c,
351  0xff, 0x2d, 0xff, 0x4d,
352  0xff, 0x2e, 0xff, 0x4e,
353  0xff, 0x2f, 0xff, 0x4f,
354  0xff, 0x30, 0xff, 0x50,
355  0xff, 0x31, 0xff, 0x51,
356  0xff, 0x32, 0xff, 0x52,
357  0xff, 0x33, 0xff, 0x53,
358  0xff, 0x34, 0xff, 0x54,
359  0xff, 0x35, 0xff, 0x55,
360  0xff, 0x36, 0xff, 0x56,
361  0xff, 0x37, 0xff, 0x57,
362  0xff, 0x38, 0xff, 0x58,
363  0xff, 0x39, 0xff, 0x59,
364  0xff, 0x3a, 0xff, 0x5a,
365  0x00
366 };
367 static int utf16be_transl_count = 329;
368 
369 /* These are the start indice in utf16be_transl[] for the page numbers 0 to 9
370  as classified by function what_page().
371  As soon as the first byte of the input pair in utf16be_transl[] changes,
372  the search can be ended and output is equal to input.
373  If page -1 is returned by what_page(), then input is equal to output.
374 */
375 static int utf16be_transl_starts[] = {
376  0, 31, 81, 112, 195, 233, 271, 286, 302, 303
377 };
378 
379 
380 static int what_page(uint16_t x)
381 {
382  switch(((uint8_t *) &x)[0]) {
383  case 0:
384  return 0;
385  case 1:
386  return 1;
387  case 3:
388  return 2;
389  case 4:
390  return 3;
391  case 5:
392  return 4;
393  case 16:
394  return 5;
395  case 32:
396  return 6;
397  case 33:
398  return 7;
399  case 254:
400  return 8;
401  case 255:
402  return 9;
403  default:
404  return -1; /* no mapping */
405  }
406 }
407 
408 
409 /* Accelerator for the ASCII subset which is expected to be the most
410  frequently used one.
411 */
412 static uint16_t cmp_name_page0(uint16_t x)
413 {
414  uint8_t *low;
415 
416  low = ((uint8_t *) &x) + 1;
417 
418  if (x == 0)
419  return 0xffff;
420  if (*low <= 0x40)
421  ;
422  else if (*low <= 0x5a)
423  *low = *low + 0x20;
424  else if (*low < 0xc6)
425  ;
426  else if (*low == 0xc6)
427  *low = 0xe6;
428  else if (*low == 0xd0)
429  *low = 0xf0;
430  else if (*low == 0xd8)
431  *low = 0xf8;
432  else if (*low == 0xde)
433  *low = 0xfe;
434  return x;
435 }
436 
437 
438 /* Converts a character into the representative of its HFS+ equivalence
439  class.
440  @param x The UTF-16BE character to be converted.
441  @return 0 = ignore character with comparisons
442  else the case-insensitive character.
443 */
444 uint16_t iso_hfsplus_cichar(uint16_t x)
445 {
446  int page, i;
447  uint16_t ret;
448  uint8_t low, high;
449 
450  high = ((uint8_t *) &x)[0];
451  low = ((uint8_t *) &x)[1];
452 
453  page = what_page(x);
454  if (page < 0)
455  return x; /* No translation needed */
456  if (page == 0)
457  return cmp_name_page0(x); /* Accelerator for ASCII subset */
458 
459  for (i = utf16be_transl_starts[page] * 4; i < utf16be_transl_count * 4;
460  i += 4) {
461  if (utf16be_transl[i] != high)
462  break;
463  if (utf16be_transl[i + 1] == low) {
464  ((uint8_t *) &ret)[0] = utf16be_transl[i + 2];
465  ((uint8_t *) &ret)[1] = utf16be_transl[i + 3];
466  return ret;
467  }
468  }
469  return x;
470 }
471 
472 
static int what_page(uint16_t x)
Definition: hfsplus_case.c:380
static uint8_t utf16be_transl[]
Definition: hfsplus_case.c:35
uint16_t iso_hfsplus_cichar(uint16_t x)
Definition: hfsplus_case.c:444
static int utf16be_transl_count
Definition: hfsplus_case.c:367
static uint16_t cmp_name_page0(uint16_t x)
Definition: hfsplus_case.c:412
static int utf16be_transl_starts[]
Definition: hfsplus_case.c:375