]> code.delx.au - refind/blob - filesystems/fsw_strfunc.h
Close to finished with debian/copyright revisions.
[refind] / filesystems / fsw_strfunc.h
1 /* fsw_strfunc.h generated by mk_fsw_strfunc.py */
2
3 /*-
4 * Copyright (c) 2006 Christoph Pfisterer
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * * Neither the name of Christoph Pfisterer nor the names of the
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 static int fsw_streq_ISO88591_UTF8(void *s1data, void *s2data, int len)
36 {
37 int i;
38 fsw_u8 *p1 = (fsw_u8 *)s1data;
39 fsw_u8 *p2 = (fsw_u8 *)s2data;
40 fsw_u32 c1, c2;
41
42 for (i = 0; i < len; i++) {
43 c1 = *p1++;
44 c2 = *p2++;
45 if ((c2 & 0xe0) == 0xc0) {
46 c2 = ((c2 & 0x1f) << 6) | (*p2++ & 0x3f);
47 } else if ((c2 & 0xf0) == 0xe0) {
48 c2 = ((c2 & 0x0f) << 12) | ((*p2++ & 0x3f) << 6);
49 c2 |= (*p2++ & 0x3f);
50 } else if ((c2 & 0xf8) == 0xf0) {
51 c2 = ((c2 & 0x07) << 18) | ((*p2++ & 0x3f) << 12);
52 c2 |= ((*p2++ & 0x3f) << 6);
53 c2 |= (*p2++ & 0x3f);
54 }
55 if (c1 != c2)
56 return 0;
57 }
58 return 1;
59 }
60
61 static int fsw_streq_ISO88591_UTF16(void *s1data, void *s2data, int len)
62 {
63 int i;
64 fsw_u8 *p1 = (fsw_u8 *)s1data;
65 fsw_u16 *p2 = (fsw_u16 *)s2data;
66 fsw_u32 c1, c2;
67
68 for (i = 0; i < len; i++) {
69 c1 = *p1++;
70 c2 = *p2++;
71 if (c1 != c2)
72 return 0;
73 }
74 return 1;
75 }
76
77 static int fsw_streq_ISO88591_UTF16_SWAPPED(void *s1data, void *s2data, int len)
78 {
79 int i;
80 fsw_u8 *p1 = (fsw_u8 *)s1data;
81 fsw_u16 *p2 = (fsw_u16 *)s2data;
82 fsw_u32 c1, c2;
83
84 for (i = 0; i < len; i++) {
85 c1 = *p1++;
86 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
87 if (c1 != c2)
88 return 0;
89 }
90 return 1;
91 }
92
93 static int fsw_streq_UTF8_UTF16(void *s1data, void *s2data, int len)
94 {
95 int i;
96 fsw_u8 *p1 = (fsw_u8 *)s1data;
97 fsw_u16 *p2 = (fsw_u16 *)s2data;
98 fsw_u32 c1, c2;
99
100 for (i = 0; i < len; i++) {
101 c1 = *p1++;
102 if ((c1 & 0xe0) == 0xc0) {
103 c1 = ((c1 & 0x1f) << 6) | (*p1++ & 0x3f);
104 } else if ((c1 & 0xf0) == 0xe0) {
105 c1 = ((c1 & 0x0f) << 12) | ((*p1++ & 0x3f) << 6);
106 c1 |= (*p1++ & 0x3f);
107 } else if ((c1 & 0xf8) == 0xf0) {
108 c1 = ((c1 & 0x07) << 18) | ((*p1++ & 0x3f) << 12);
109 c1 |= ((*p1++ & 0x3f) << 6);
110 c1 |= (*p1++ & 0x3f);
111 }
112 c2 = *p2++;
113 if (c1 != c2)
114 return 0;
115 }
116 return 1;
117 }
118
119 static int fsw_streq_UTF8_UTF16_SWAPPED(void *s1data, void *s2data, int len)
120 {
121 int i;
122 fsw_u8 *p1 = (fsw_u8 *)s1data;
123 fsw_u16 *p2 = (fsw_u16 *)s2data;
124 fsw_u32 c1, c2;
125
126 for (i = 0; i < len; i++) {
127 c1 = *p1++;
128 if ((c1 & 0xe0) == 0xc0) {
129 c1 = ((c1 & 0x1f) << 6) | (*p1++ & 0x3f);
130 } else if ((c1 & 0xf0) == 0xe0) {
131 c1 = ((c1 & 0x0f) << 12) | ((*p1++ & 0x3f) << 6);
132 c1 |= (*p1++ & 0x3f);
133 } else if ((c1 & 0xf8) == 0xf0) {
134 c1 = ((c1 & 0x07) << 18) | ((*p1++ & 0x3f) << 12);
135 c1 |= ((*p1++ & 0x3f) << 6);
136 c1 |= (*p1++ & 0x3f);
137 }
138 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
139 if (c1 != c2)
140 return 0;
141 }
142 return 1;
143 }
144
145 static int fsw_streq_UTF16_UTF16_SWAPPED(void *s1data, void *s2data, int len)
146 {
147 int i;
148 fsw_u16 *p1 = (fsw_u16 *)s1data;
149 fsw_u16 *p2 = (fsw_u16 *)s2data;
150 fsw_u32 c1, c2;
151
152 for (i = 0; i < len; i++) {
153 c1 = *p1++;
154 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
155 if (c1 != c2)
156 return 0;
157 }
158 return 1;
159 }
160
161 static fsw_status_t fsw_strcoerce_UTF8_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
162 {
163 fsw_status_t status;
164 int i;
165 fsw_u8 *sp;
166 fsw_u8 *dp;
167 fsw_u32 c;
168
169 dest->type = FSW_STRING_TYPE_ISO88591;
170 dest->len = srclen;
171 dest->size = srclen * sizeof(fsw_u8);
172 status = fsw_alloc(dest->size, &dest->data);
173 if (status)
174 return status;
175
176 sp = (fsw_u8 *)srcdata;
177 dp = (fsw_u8 *)dest->data;
178 for (i = 0; i < srclen; i++) {
179 c = *sp++;
180 if ((c & 0xe0) == 0xc0) {
181 c = ((c & 0x1f) << 6) | (*sp++ & 0x3f);
182 } else if ((c & 0xf0) == 0xe0) {
183 c = ((c & 0x0f) << 12) | ((*sp++ & 0x3f) << 6);
184 c |= (*sp++ & 0x3f);
185 } else if ((c & 0xf8) == 0xf0) {
186 c = ((c & 0x07) << 18) | ((*sp++ & 0x3f) << 12);
187 c |= ((*sp++ & 0x3f) << 6);
188 c |= (*sp++ & 0x3f);
189 }
190 *dp++ = (fsw_u8)c;
191 }
192 return FSW_SUCCESS;
193 }
194
195 static fsw_status_t fsw_strcoerce_UTF16_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
196 {
197 fsw_status_t status;
198 int i;
199 fsw_u16 *sp;
200 fsw_u8 *dp;
201 fsw_u32 c;
202
203 dest->type = FSW_STRING_TYPE_ISO88591;
204 dest->len = srclen;
205 dest->size = srclen * sizeof(fsw_u8);
206 status = fsw_alloc(dest->size, &dest->data);
207 if (status)
208 return status;
209
210 sp = (fsw_u16 *)srcdata;
211 dp = (fsw_u8 *)dest->data;
212 for (i = 0; i < srclen; i++) {
213 c = *sp++;
214 *dp++ = (fsw_u8)c;
215 }
216 return FSW_SUCCESS;
217 }
218
219 static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
220 {
221 fsw_status_t status;
222 int i;
223 fsw_u16 *sp;
224 fsw_u8 *dp;
225 fsw_u32 c;
226
227 dest->type = FSW_STRING_TYPE_ISO88591;
228 dest->len = srclen;
229 dest->size = srclen * sizeof(fsw_u8);
230 status = fsw_alloc(dest->size, &dest->data);
231 if (status)
232 return status;
233
234 sp = (fsw_u16 *)srcdata;
235 dp = (fsw_u8 *)dest->data;
236 for (i = 0; i < srclen; i++) {
237 c = *sp++; c = FSW_SWAPVALUE_U16(c);
238 *dp++ = (fsw_u8)c;
239 }
240 return FSW_SUCCESS;
241 }
242
243 static fsw_status_t fsw_strcoerce_ISO88591_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
244 {
245 fsw_status_t status;
246 int i;
247 fsw_u8 *sp;
248 fsw_u16 *dp;
249 fsw_u32 c;
250
251 dest->type = FSW_STRING_TYPE_UTF16;
252 dest->len = srclen;
253 dest->size = srclen * sizeof(fsw_u16);
254 status = fsw_alloc(dest->size, &dest->data);
255 if (status)
256 return status;
257
258 sp = (fsw_u8 *)srcdata;
259 dp = (fsw_u16 *)dest->data;
260 for (i = 0; i < srclen; i++) {
261 c = *sp++;
262 *dp++ = (fsw_u16)c;
263 }
264 return FSW_SUCCESS;
265 }
266
267 static fsw_status_t fsw_strcoerce_UTF8_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
268 {
269 fsw_status_t status;
270 int i;
271 fsw_u8 *sp;
272 fsw_u16 *dp;
273 fsw_u32 c;
274
275 dest->type = FSW_STRING_TYPE_UTF16;
276 dest->len = srclen;
277 dest->size = srclen * sizeof(fsw_u16);
278 status = fsw_alloc(dest->size, &dest->data);
279 if (status)
280 return status;
281
282 sp = (fsw_u8 *)srcdata;
283 dp = (fsw_u16 *)dest->data;
284 for (i = 0; i < srclen; i++) {
285 c = *sp++;
286 if ((c & 0xe0) == 0xc0) {
287 c = ((c & 0x1f) << 6) | (*sp++ & 0x3f);
288 } else if ((c & 0xf0) == 0xe0) {
289 c = ((c & 0x0f) << 12) | ((*sp++ & 0x3f) << 6);
290 c |= (*sp++ & 0x3f);
291 } else if ((c & 0xf8) == 0xf0) {
292 c = ((c & 0x07) << 18) | ((*sp++ & 0x3f) << 12);
293 c |= ((*sp++ & 0x3f) << 6);
294 c |= (*sp++ & 0x3f);
295 }
296 *dp++ = (fsw_u16)c;
297 }
298 return FSW_SUCCESS;
299 }
300
301 static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
302 {
303 fsw_status_t status;
304 int i;
305 fsw_u16 *sp;
306 fsw_u16 *dp;
307 fsw_u32 c;
308
309 dest->type = FSW_STRING_TYPE_UTF16;
310 dest->len = srclen;
311 dest->size = srclen * sizeof(fsw_u16);
312 status = fsw_alloc(dest->size, &dest->data);
313 if (status)
314 return status;
315
316 sp = (fsw_u16 *)srcdata;
317 dp = (fsw_u16 *)dest->data;
318 for (i = 0; i < srclen; i++) {
319 c = *sp++; c = FSW_SWAPVALUE_U16(c);
320 *dp++ = (fsw_u16)c;
321 }
322 return FSW_SUCCESS;
323 }
324
325 static fsw_status_t fsw_strcoerce_ISO88591_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
326 {
327 fsw_status_t status;
328 int i, destsize;
329 fsw_u8 *sp;
330 fsw_u8 *dp;
331 fsw_u32 c;
332
333 sp = (fsw_u8 *)srcdata;
334 destsize = 0;
335 for (i = 0; i < srclen; i++) {
336 c = *sp++;
337
338 if (c < 0x000080)
339 destsize++;
340 else if (c < 0x000800)
341 destsize += 2;
342 else if (c < 0x010000)
343 destsize += 3;
344 else
345 destsize += 4;
346 }
347
348 dest->type = FSW_STRING_TYPE_UTF8;
349 dest->len = srclen;
350 dest->size = destsize;
351 status = fsw_alloc(dest->size, &dest->data);
352 if (status)
353 return status;
354
355 sp = (fsw_u8 *)srcdata;
356 dp = (fsw_u8 *)dest->data;
357 for (i = 0; i < srclen; i++) {
358 c = *sp++;
359
360 if (c < 0x000080) {
361 *dp++ = (fsw_u8)c;
362 } else if (c < 0x000800) {
363 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
364 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
365 } else if (c < 0x010000) {
366 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
367 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
368 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
369 } else {
370 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
371 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
372 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
373 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
374 }
375 }
376 return FSW_SUCCESS;
377 }
378
379 static fsw_status_t fsw_strcoerce_UTF16_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
380 {
381 fsw_status_t status;
382 int i, destsize;
383 fsw_u16 *sp;
384 fsw_u8 *dp;
385 fsw_u32 c;
386
387 sp = (fsw_u16 *)srcdata;
388 destsize = 0;
389 for (i = 0; i < srclen; i++) {
390 c = *sp++;
391
392 if (c < 0x000080)
393 destsize++;
394 else if (c < 0x000800)
395 destsize += 2;
396 else if (c < 0x010000)
397 destsize += 3;
398 else
399 destsize += 4;
400 }
401
402 dest->type = FSW_STRING_TYPE_UTF8;
403 dest->len = srclen;
404 dest->size = destsize;
405 status = fsw_alloc(dest->size, &dest->data);
406 if (status)
407 return status;
408
409 sp = (fsw_u16 *)srcdata;
410 dp = (fsw_u8 *)dest->data;
411 for (i = 0; i < srclen; i++) {
412 c = *sp++;
413
414 if (c < 0x000080) {
415 *dp++ = (fsw_u8)c;
416 } else if (c < 0x000800) {
417 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
418 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
419 } else if (c < 0x010000) {
420 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
421 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
422 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
423 } else {
424 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
425 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
426 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
427 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
428 }
429 }
430 return FSW_SUCCESS;
431 }
432
433 static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
434 {
435 fsw_status_t status;
436 int i, destsize;
437 fsw_u16 *sp;
438 fsw_u8 *dp;
439 fsw_u32 c;
440
441 sp = (fsw_u16 *)srcdata;
442 destsize = 0;
443 for (i = 0; i < srclen; i++) {
444 c = *sp++; c = FSW_SWAPVALUE_U16(c);
445
446 if (c < 0x000080)
447 destsize++;
448 else if (c < 0x000800)
449 destsize += 2;
450 else if (c < 0x010000)
451 destsize += 3;
452 else
453 destsize += 4;
454 }
455
456 dest->type = FSW_STRING_TYPE_UTF8;
457 dest->len = srclen;
458 dest->size = destsize;
459 status = fsw_alloc(dest->size, &dest->data);
460 if (status)
461 return status;
462
463 sp = (fsw_u16 *)srcdata;
464 dp = (fsw_u8 *)dest->data;
465 for (i = 0; i < srclen; i++) {
466 c = *sp++; c = FSW_SWAPVALUE_U16(c);
467
468 if (c < 0x000080) {
469 *dp++ = (fsw_u8)c;
470 } else if (c < 0x000800) {
471 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
472 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
473 } else if (c < 0x010000) {
474 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
475 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
476 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
477 } else {
478 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
479 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
480 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
481 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
482 }
483 }
484 return FSW_SUCCESS;
485 }