/[public]/psiconv/trunk/lib/psiconv/unicode.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/unicode.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 181 Revision 196
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 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 2003-2004 Frodo Looijaard <frodol@dds.nl>
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.
43 /* 0x38 */ 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 43 /* 0x38 */ 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
44 /* 0x40 */ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 44 /* 0x40 */ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
45 /* 0x48 */ 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 45 /* 0x48 */ 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
46 /* 0x50 */ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 46 /* 0x50 */ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
47 /* 0x58 */ 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 47 /* 0x58 */ 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
48 /* 0x60 */ 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0067, 48 /* 0x60 */ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
49 /* 0x68 */ 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 49 /* 0x68 */ 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
50 /* 0x70 */ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 50 /* 0x70 */ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
51 /* 0x78 */ 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 51 /* 0x78 */ 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000,
52 /* 0x80 */ 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 52 /* 0x80 */ 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
53 /* 0x88 */ 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000, 53 /* 0x88 */ 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000,
71 71
72/* TODO: Check the charset number, select the correct one */ 72/* TODO: Check the charset number, select the correct one */
73extern int psiconv_unicode_select_characterset(const psiconv_config config, 73extern int psiconv_unicode_select_characterset(const psiconv_config config,
74 int charset) 74 int charset)
75{ 75{
76 memcpy(config->unicode_table,table_cp1252,sizeof(psiconv_ucs2) * 0x100); 76 switch(charset) {
77 case 0: config->unicode = psiconv_bool_true;
78 break;
79 case 1: config->unicode = psiconv_bool_false;
80 memcpy(config->unicode_table,table_cp1252,
81 sizeof(psiconv_ucs2) * 0x100);
82 break;
83 default: return -1;
84 }
77 return 0; 85 return 0;
78} 86}
79 87
80 88
81psiconv_ucs2 psiconv_unicode_from_char(const psiconv_config config, 89psiconv_ucs2 psiconv_unicode_from_char(const psiconv_config config,
101 psiconv_ucs2 **output) 109 psiconv_ucs2 **output)
102{ 110{
103 int i; 111 int i;
104 if (!output) 112 if (!output)
105 return PSICONV_E_NOMEM; 113 return PSICONV_E_NOMEM;
106 if (!(*output = malloc(sizeof(**output) * (1 + strlen(input))))) 114 if (!(*output = malloc(sizeof(**output) * (1 + strlen((const char *) input)))))
107 return PSICONV_E_NOMEM; 115 return PSICONV_E_NOMEM;
108 for (i = 0; i < strlen(input); i++) 116 for (i = 0; i < strlen((const char *) input); i++)
109 (*output)[i] = psiconv_unicode_from_char(config,input[i]); 117 (*output)[i] = psiconv_unicode_from_char(config,input[i]);
110 (*output)[i] = 0x0000; 118 (*output)[i] = 0x0000;
111 return PSICONV_E_OK; 119 return PSICONV_E_OK;
112} 120}
113 121
132 int i = 0; 140 int i = 0;
133 while (input[i]) 141 while (input[i])
134 i++; 142 i++;
135 return i; 143 return i;
136} 144}
145
146psiconv_ucs2 *psiconv_unicode_strdup(const psiconv_ucs2 *input)
147{
148 psiconv_ucs2 *output;
149 int i = 0;
150
151 if (!(output = malloc(sizeof(*output) *
152 (1 + psiconv_unicode_strlen(input)))))
153 return NULL;
154 while ((output[i] = input[i]))
155 i++;
156 return output;
157}
158
159int psiconv_unicode_strcmp(const psiconv_ucs2 *str1, const psiconv_ucs2 *str2)
160{
161 int i = 0;
162 while (str1[i] && str2[i]) {
163 if (str1[i] < str2[i])
164 return -1;
165 if (str1[i] > str2[i])
166 return 1;
167 i++;
168 }
169 if (str1[i] < str2[i])
170 return -1;
171 else if (str1[i] > str2[i])
172 return 1;
173 else
174 return 0;
175}
176

Legend:
Removed from v.181  
changed lines
  Added in v.196

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26