1 | /* |
1 | /* |
2 | unicode.c - Part of psiconv, a PSION 5 file formats converter |
2 | unicode.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 2003-2004 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 2003-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
24 | #include "unicode.h" |
24 | #include "unicode.h" |
25 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
26 | #include "generate_routines.h" |
26 | #include "generate_routines.h" |
27 | |
27 | |
28 | #include <string.h> |
28 | #include <string.h> |
|
|
29 | #include <stdlib.h> |
29 | |
30 | |
30 | #ifdef DMALLOC |
31 | #ifdef DMALLOC |
31 | #include <dmalloc.h> |
32 | #include <dmalloc.h> |
32 | #endif |
33 | #endif |
33 | |
34 | |
… | |
… | |
142 | |
143 | |
143 | int psiconv_unicode_write_char(const psiconv_config config, |
144 | int psiconv_unicode_write_char(const psiconv_config config, |
144 | psiconv_buffer buf, |
145 | psiconv_buffer buf, |
145 | int lev, psiconv_ucs2 value) |
146 | int lev, psiconv_ucs2 value) |
146 | { |
147 | { |
147 | psiconv_u8 byte; |
|
|
148 | int i; |
148 | int i; |
149 | int res=0; |
149 | int res=0; |
150 | |
150 | |
151 | if (config->unicode) { |
151 | if (config->unicode) { |
152 | if (value < 0x80) { |
152 | if (value < 0x80) { |
… | |
… | |
224 | if (result) |
224 | if (result) |
225 | result[0] = 0; |
225 | result[0] = 0; |
226 | return result; |
226 | return result; |
227 | } |
227 | } |
228 | |
228 | |
|
|
229 | |
|
|
230 | psiconv_ucs2 *psiconv_unicode_from_list(psiconv_list input) |
|
|
231 | { |
|
|
232 | psiconv_ucs2 *result; |
|
|
233 | int i; |
|
|
234 | psiconv_ucs2 *character; |
|
|
235 | |
|
|
236 | if (!(result = malloc(sizeof(psiconv_ucs2) * (psiconv_list_length(input)+1)))) |
|
|
237 | goto ERROR1; |
|
|
238 | for (i = 0; i < psiconv_list_length(input); i++) { |
|
|
239 | if (!(character = psiconv_list_get(input,i))) |
|
|
240 | goto ERROR2; |
|
|
241 | result[i] = *character; |
|
|
242 | } |
|
|
243 | result[i] = 0; |
|
|
244 | return result; |
|
|
245 | |
|
|
246 | ERROR2: |
|
|
247 | free(result); |
|
|
248 | ERROR1: |
|
|
249 | return NULL; |
|
|
250 | } |
|
|
251 | |
|
|
252 | |
|
|
253 | psiconv_ucs2 *psiconv_unicode_strstr(const psiconv_ucs2 *haystack, |
|
|
254 | const psiconv_ucs2 *needle) |
|
|
255 | { |
|
|
256 | int i,j,haystack_len,needle_len; |
|
|
257 | haystack_len = psiconv_unicode_strlen(haystack); |
|
|
258 | needle_len = psiconv_unicode_strlen(needle); |
|
|
259 | |
|
|
260 | |
|
|
261 | |
|
|
262 | for (i = 0; i < haystack_len - needle_len + 1; i++) { |
|
|
263 | for (j = 0; j < needle_len; j++) |
|
|
264 | if (haystack[i+j] != needle[j]) |
|
|
265 | break; |
|
|
266 | if (j == needle_len) |
|
|
267 | return (psiconv_ucs2 *) haystack+i; |
|
|
268 | } |
|
|
269 | return NULL; |
|
|
270 | } |