FreeCalypso > hg > tcs211-fcmodem
comparison g23m/condat/ms/src/atb/ATBCommon.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /******************************************************************************* | |
2 | |
3 CONDAT (UK) | |
4 | |
5 ******************************************************************************** | |
6 | |
7 This software product is the property of Condat (UK) Ltd and may not be | |
8 disclosed to any third party without the express permission of the owner. | |
9 | |
10 ******************************************************************************** | |
11 | |
12 $Project name: | |
13 $Project code: | |
14 $Module: | |
15 $File: ATBCommon.c | |
16 $Revision: | |
17 | |
18 $Author: SH - Condat(UK) | |
19 $Date: | |
20 | |
21 ******************************************************************************** | |
22 | |
23 Description: ATB Common functions and definitions. | |
24 | |
25 | |
26 ******************************************************************************** | |
27 | |
28 $History: ATBCommon.c | |
29 | |
30 Mar 30, 2005 REF: CRR 29986 xpradipg | |
31 Description: Optimisation 1: Removal of unused variables and dynamically | |
32 allocate/ deallocate mbndata | |
33 Solution: removed the definition of translation_ascii_2_unicode and added | |
34 the extern declaration | |
35 | |
36 March 24, 2005 REF: CRR MMI-FIX-9828 x0012852 | |
37 Description: BMI having problems with Umlauts ,especially "ü" | |
38 Solution: g_translation_8bit_table[] array is modified . Changed codes 0x80 , 0x81, | |
39 0x82 to ox81, 0x82 ,0x83 respectively. | |
40 | |
41 Jan 05, 2005 REF: CRR MMI-FIX-24757 xnkulkar | |
42 Description: the display doesn´t show special chars correctly; if there is an "@" in the text, the "@" and | |
43 text after is not visible | |
44 Solution: Fix for MMI-SPR-25978 has solved the problem of data loss after '@' symbol. However, some other | |
45 symbols (like ¥ etc.) were not displayed properly. Modified the g_translation_8bit_table[] array | |
46 to take care of all the special GSM character set . | |
47 | |
48 Nov 30, 2004 REF: CRR MMI-SPR-25978 xnkulkar | |
49 Description: Messages:Not able to receive message after @ in the receiver phone (Bug raised in 3.x) | |
50 Solution: in g_translation_8bit_table, the value for '@' symbol was used as 0x00. It has been | |
51 changed to 0x40 now. | |
52 | |
53 26-05-04 CRR 19656 Sandip and Deepa M.D | |
54 Fix for The Dsample doesn't display lines ( <CR> or <LF> ) in the SETUP IDLE | |
55 TEXT command. | |
56 Fix for The idle screen is empty when a SETUP IDLE TEXT command is sent with | |
57 a long text ( 239 characters ). | |
58 | |
59 | |
60 $End | |
61 | |
62 *******************************************************************************/ | |
63 | |
64 /* includes */ | |
65 #include <string.h> | |
66 #include <stdio.h> | |
67 #include <stdlib.h> | |
68 | |
69 #if defined (NEW_FRAME) | |
70 | |
71 #include "typedefs.h" | |
72 #include "vsi.h" | |
73 #include "pei.h" | |
74 #include "custom.h" | |
75 #include "gsm.h" | |
76 | |
77 #else | |
78 | |
79 #include "STDDEFS.H" | |
80 #include "custom.h" | |
81 #include "gsm.h" | |
82 #include "vsi.h" | |
83 | |
84 #endif | |
85 | |
86 #include "mfw_mfw.h" | |
87 #include "mfw_win.h" | |
88 #include "mfw_kbd.h" | |
89 #include "mfw_tim.h" | |
90 #include "mfw_phb.h" | |
91 #include "mfw_sms.h" | |
92 #include "mfw_ss.h" | |
93 #include "mfw_icn.h" | |
94 #include "mfw_mnu.h" | |
95 #include "mfw_lng.h" | |
96 #include "mfw_sat.h" | |
97 #include "mfw_kbd.h" | |
98 #include "mfw_nm.h" | |
99 #include "mfw_cm.h" | |
100 #include "ATBCommon.h" | |
101 | |
102 /*SPR2175, Added macro and tables for string conversion routines*/ | |
103 #define MAX_STRING_LEN (5+MFW_NUM_LEN+MAX_MSG_LEN+4) | |
104 | |
105 /*SPR 1508, changed codes 128, 129 and 130 to 129, 130, and 131 respectively.*/ | |
106 static const char g_translation_ascii_table[128] = { 64, 156, 36, 157, 138, 131, 151, 141, 149, 129, | |
107 10, 2 , 7, 32, 143, 134, 4, 95, 232, 226, 239, 234, 227, 5, 228, | |
108 233, 240, 32, 146, 145, 225, 144, 32, 33, 34, 35, 1, 37, 38, 39, | |
109 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, | |
110 55, 56, 57, 58, 59, 60, 61, 62, 63, 173, 65, 66, 67, 68, 69, | |
111 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, | |
112 85, 86, 87, 88, 89, 90, 142, 153, 165, 154, 168, 06, 97, 98, 99, | |
113 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, | |
114 115, 116, 117, 118, 119, 120, 121, 122, 132, 148, 164, 130, 133}; | |
115 | |
116 | |
117 | |
118 static const int g_translation_unicode[128] = { 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, 0x00F2, 0x00C7, 0x000A, 0x00D8, 0x00F8, | |
119 0x000D, 0x00C5, 0x00E5, 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8, 0x03A3, 0x0398, | |
120 0x039E, 0x03A2, 0x00C6, 0x00E6, 0x00DF, 0x00C9, 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026, | |
121 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, | |
122 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x00A1, | |
123 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, | |
124 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, | |
125 0x00C4, 0x00D6, 0x00D1, 0x00DC, 0x00A7, 0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, | |
126 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, | |
127 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0}; | |
128 | |
129 /*SPR 1508, added conversion table*/ | |
130 // Mar 30, 2005 REF: CRR 29986 xpradipg | |
131 // remove the definition of the table | |
132 #ifdef FF_MMI_OPTIM | |
133 extern const int translation_ascii_2_unicode[]; | |
134 #else | |
135 static const int translation_ascii_2_unicode[256] = { | |
136 0x0000, 0x00A4, 0x00d8, 0xFFFF, 0x0394, 0x03A8, 0x00BF, 0x00F8, 0xFFFF, 0xFFFF, 0x000A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
137 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
138 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026,0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, | |
139 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, | |
140 0x0040,0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, | |
141 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x005F, | |
142 0xFFFF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, | |
143 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
144 | |
145 0xFFFF, 0x00C7, 0x00FC, 0x00E9, 0x00E4, 0x00E0, 0x00E5, 0xFFFF, 0xFFFF, 0xFFFF, 0x00E8, 0xFFFF, 0xFFFF, 0x00EC, 0x00C4, 0x00C5, | |
146 0x00C9, 0x00E6, 0x00C6, 0xFFFF, 0x00F6, 0x00F2, 0xFFFF, 0x00F9, 0xFFFF, 0x00D6, 0x00DC, 0xFFFF, 0x00A3, 0x00A5, 0xFFFF, 0xFFFF, | |
147 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00F1, 0x00D1, 0xFFFF, 0xFFFF, 0x00A7, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00A1, 0xFFFF, 0xFFFF, | |
148 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
149 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
150 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, | |
151 0xFFFF, 0x00DF, 0x0393, 0x03A0, 0x03A3, 0xFFFF, 0xFFFF, 0xFFFF, 0x03A6, 0x0398, 0x03A9, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x039B, | |
152 0x039E, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF | |
153 }; | |
154 #endif | |
155 // MMI_FIX-19656 Using 8 bit table for dispay start | |
156 // Nov 30, 2004 REF: CRR MMI-SPR-25978 xnkulkar | |
157 // Description: Messages:Not able to receive message after @ in the receiver phone (Bug raised in 3.x) | |
158 // Solution: in g_translation_8bit_table, the value for '@' symbol was used as 0x00. It has been | |
159 // changed to 0x40 now. | |
160 | |
161 // Jan 05, 2005 REF: CRR MMI-FIX-24757 xnkulkar | |
162 // Description: the display doesn´t show special chars correctly; if there is an "@" in the text, the "@" and | |
163 // text after is not visible | |
164 // Solution: Fix for MMI-SPR-25978 has solved the problem of data loss after '@' symbol. However, some other | |
165 // symbols (like ¥ etc.) were not displayed properly. Modified the g_translation_8bit_table[] array | |
166 // to take care of all the special GSM character set . | |
167 | |
168 // March 24, 2005 REF: CRR MMI-FIX-9828 x0012852 | |
169 // Description: BMI having problems with Umlauts ,especially "ü" | |
170 // Solution: g_translation_8bit_table[] array is modified . Changed codes 0x80 , 0x81, | |
171 // 0x82 to ox81, 0x82 ,0x83 respectively. | |
172 | |
173 | |
174 static const char g_translation_8bit_table[256] ={ | |
175 0x40, 0x9C, 0x24, 0x9D, 0x8A, 0x83, 0x97, 0x8D, 0x95, 0x81, 0x0A, 0x02, 0x07, 0x20, 0x8F, 0x86, | |
176 0x04, 0x5F, 0xE8, 0xE2, 0xEF, 0xEA, 0xE3, 0x05, 0xE4, 0xE9,0xF0, 0xFF, 0x92, 0x91, 0xE1, 0x90, | |
177 0x20, 0x21, 0x22, 0x23, 0x01, 0x25, 0x26,0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, | |
178 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, | |
179 0xAD,0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, | |
180 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x8E, 0x99, 0xA5, 0x9A, 0xA8, | |
181 0x06, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, | |
182 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x84, 0x94, 0xA4, 0x82, 0x85, | |
183 | |
184 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
185 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
186 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
187 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
188 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
189 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
190 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
191 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | |
192 }; | |
193 //MMI_FIX-19656 Using 8 bit table for dispay start | |
194 | |
195 static char convertUCS2_2_ascii_char(char* ipString); | |
196 static char convertUCS2_2_gsm_char(char* ipString); | |
197 static USHORT ATB_swap_bytes(USHORT character); | |
198 | |
199 /******************************************************************************* | |
200 | |
201 $Function: convertUCS2_2_ascii_char | |
202 | |
203 $Description: convert unicode char to ASCII char. Added for SPR 1508. | |
204 moved here for SPR 2175 | |
205 | |
206 $Returns: ASCII char | |
207 $Arguments: pointer to first byte of unicode char | |
208 *******************************************************************************/ | |
209 static char convertUCS2_2_ascii_char(char* ipString) | |
210 { | |
211 U16 word_code; | |
212 BOOL match_found= FALSE; | |
213 int k; | |
214 char debug[60]; | |
215 | |
216 word_code = ipString[0]*0x100 + ipString[1]; | |
217 sprintf(debug, "Word code: %d", word_code); | |
218 TRACE_EVENT(debug); | |
219 if (word_code <= 0xFF) | |
220 if (translation_ascii_2_unicode[word_code] == word_code) | |
221 return word_code; | |
222 | |
223 | |
224 for (k=0; k < 256; k++) | |
225 { if(translation_ascii_2_unicode[k] == word_code) | |
226 { sprintf(debug, "Match found: %d, %d", word_code, k); | |
227 TRACE_EVENT(debug); | |
228 match_found = TRUE; | |
229 return k; | |
230 } | |
231 | |
232 } | |
233 | |
234 if (!match_found) | |
235 { TRACE_EVENT("No match"); | |
236 | |
237 return 0x3F;/*question mark*/ | |
238 } | |
239 } | |
240 /******************************************************************************* | |
241 | |
242 $Function: convertUCS2_2_ascii_char | |
243 | |
244 $Description: convert unicode char to GSM char. Added for SPR 1508. | |
245 moved here for SPR 2175 | |
246 | |
247 $Returns: GSM char | |
248 $Arguments: pointer to first byte of unicode char | |
249 *******************************************************************************/ | |
250 static char convertUCS2_2_gsm_char(char* ipString) | |
251 { | |
252 U16 word_code; | |
253 BOOL match_found= FALSE; | |
254 int k; | |
255 word_code = ipString[0]*0x100 + ipString[1]; | |
256 | |
257 | |
258 if ( word_code > 0x7F || g_translation_unicode[word_code] != word_code) | |
259 { | |
260 | |
261 for (k=0; k < 256; k++) | |
262 { if(g_translation_unicode[k] == word_code) | |
263 { | |
264 match_found = TRUE; | |
265 return k; | |
266 } | |
267 | |
268 } | |
269 } | |
270 else | |
271 return word_code; | |
272 if (!match_found) | |
273 { return '?'; | |
274 } | |
275 } | |
276 /******************************************************************************* | |
277 | |
278 $Function: ATB_convert_String | |
279 | |
280 $Description: Convert a string into an ascii string with 0x80 as first word if data is unicode | |
281 moved here and renamed for SPR 2175 | |
282 $Returns: execution status | |
283 | |
284 $Arguments: ipString - input byte array | |
285 ipDataType - type of input data | |
286 ipLength - length of input string (in bytes) | |
287 opString - output byte array | |
288 opDataType - type of output data | |
289 opLength - length of output string (in bytes) | |
290 *******************************************************************************/ | |
291 /* MC, SPR 1257, merged in b-sample version of this function*/ | |
292 int ATB_convert_String( char * ipString, UBYTE ipDataType, int ipLength, | |
293 char * opString, UBYTE opDataType, int opLength, UBYTE addNull) | |
294 { | |
295 int i;/*SPR 1946, changed from byte to int*/ | |
296 int j;/*SPR 1946, changed from byte to int*/ | |
297 /*JVJ SPR1298 Converted to dynamic variable */ | |
298 UBYTE* text_8bit = NULL;/*SPR1991, don't alloacte this till it's needed*/ | |
299 int len;/*SPR 1946, changed from byte to int*/ | |
300 | |
301 | |
302 #ifdef TRACE_SMSREAD | |
303 | |
304 char buf[150]; | |
305 sprintf(buf, "opString%x ipString%x ipLength%d opLength%d",opString, ipString, ipLength, opLength); | |
306 TRACE_EVENT(buf); | |
307 #endif | |
308 | |
309 if ((opString == NULL) || (ipString==NULL) || (opLength ==0)) | |
310 return (FALSE); | |
311 if (ipLength>MAX_STRING_LEN) | |
312 { | |
313 TRACE_EVENT("Too long, returning."); | |
314 return; | |
315 } | |
316 opString[0] = 'X'; | |
317 opString[1] = '?'; | |
318 opString[2] = 0x00; | |
319 | |
320 #ifdef TRACE_SMSREAD | |
321 sprintf(buf,"iDT: %d,iL:%d, oDT:%d, oL:%d, A0:%d",ipDataType,ipLength,opDataType,opLength,addNull); | |
322 TRACE_EVENT(buf); | |
323 #endif | |
324 | |
325 | |
326 switch (ipDataType) | |
327 { | |
328 case MFW_DCS_UCS2: | |
329 if (opDataType == MFW_DCS_UCS2) | |
330 { //Copy array and add 0x80, 0x7F as first word | |
331 if (ipLength < opLength) | |
332 len = ipLength; | |
333 else | |
334 len = opLength; | |
335 /*SPR 1507, copy the bytes in pairs*/ | |
336 for (i=0;i<len;i+=2) | |
337 { opString[i] = ipString[i]; | |
338 opString[i+1] = ipString[i+1]; | |
339 } | |
340 if (i+1<opLength) | |
341 { | |
342 opString[i ] = 0x00; | |
343 opString[i+1] = 0x00; | |
344 } | |
345 } | |
346 else if ((opDataType == MFW_DCS_8bits) || | |
347 (opDataType == MFW_ASCII)) | |
348 { | |
349 if ((ipLength/2 ) < opLength) | |
350 len = ipLength/2; | |
351 else | |
352 len = opLength; | |
353 | |
354 for (i=0;i<len;i++) | |
355 { /*SPR 1508, use new functions to convert to ASCII/GSM*/ | |
356 if (opDataType == MFW_ASCII) | |
357 opString[i] = convertUCS2_2_ascii_char(&ipString[i*2]); | |
358 else | |
359 opString[i] = convertUCS2_2_gsm_char(&ipString[i*2]); | |
360 } | |
361 if (len<opLength) | |
362 { | |
363 opString[len ] = 0x00; | |
364 } | |
365 | |
366 } | |
367 else //Output data type is 7 bits - not implemented | |
368 { | |
369 } | |
370 break; | |
371 case MFW_DCS_8bits: | |
372 | |
373 if (opDataType == MFW_DCS_UCS2) | |
374 { //Convert data to unicode | |
375 if (ipLength*2 < opLength) | |
376 len = ipLength; | |
377 else | |
378 len = opLength/2; | |
379 #ifdef TRACE_SMSREAD | |
380 sprintf(buf, "8->UCS2, len:%d", len); | |
381 TRACE_EVENT(buf); | |
382 #endif | |
383 for (i = 0; i < len; i++) | |
384 { /*SPR 1508 use table to convert to Unicode*/ | |
385 opString[i*2] = (g_translation_unicode[ipString[i]]>>8)&0x00FF; | |
386 opString[i*2+1] = (g_translation_unicode[ipString[i]])&0x00FF; | |
387 } | |
388 if (len*2+1 < opLength) | |
389 { | |
390 opString[len*2] = 0x00; | |
391 opString[len*2+1] = 0x00; | |
392 } | |
393 } | |
394 else if (opDataType == MFW_DCS_8bits) | |
395 { //Data already in correct format - copy | |
396 if (ipLength < opLength) | |
397 len = ipLength; | |
398 else | |
399 len = opLength; | |
400 for (i=0;i<len;i++) | |
401 { | |
402 opString[i] = g_translation_8bit_table[ipString[i]]; | |
403 } | |
404 if (len<opLength) | |
405 opString[len] = 0x00; | |
406 } | |
407 else if (opDataType == MFW_ASCII) // SH - translate characters, don't change bit width | |
408 { | |
409 len = ipLength; | |
410 if (len > opLength) | |
411 len = opLength; | |
412 for (i=0;i<len;i++) | |
413 { | |
414 opString[i] = g_translation_8bit_table[ipString[i]]; | |
415 } | |
416 if (len<opLength) | |
417 opString[len] = 0x00; | |
418 | |
419 //MMI_FIX-19656 Using 8 bit table for mapping end | |
420 } | |
421 else // convert data to 7bit | |
422 { | |
423 len = utl_cvt8To7 ((UBYTE *)ipString , ipLength, (UBYTE*)opString, 0); | |
424 } | |
425 break; | |
426 case MFW_DCS_7bits: | |
427 default: | |
428 /*SPR 1991, allocate memory to conversion buffer*/ | |
429 text_8bit = (UBYTE*)mfwAlloc(MAX_STRING_LEN+1); | |
430 | |
431 if (opDataType == MFW_DCS_7bits) //text string is already in this format | |
432 { | |
433 //Data already in correct format - copy | |
434 if (ipLength < opLength) | |
435 len = ipLength; | |
436 else | |
437 len = opLength; | |
438 for (i=0;i<len;i++) | |
439 opString[i] = ipString[i]; | |
440 if (len<opLength) | |
441 opString[len] = 0x00; | |
442 } | |
443 else if (opDataType == MFW_DCS_8bits) | |
444 { | |
445 len = utl_cvt7To8 ((UBYTE *)ipString , ipLength, (UBYTE *)opString, 0 ); | |
446 if (len <opLength) | |
447 opString[len] = 0x00; | |
448 else | |
449 opString[opLength]=0x00; | |
450 } | |
451 else if (opDataType == MFW_ASCII) // SH - expand to 8 bit and convert chars | |
452 { | |
453 len = utl_cvt7To8 ((UBYTE *)ipString , ipLength, text_8bit, 0 ); | |
454 if (len > opLength) | |
455 len = opLength; | |
456 for (i = 0; i < len; i++) | |
457 { | |
458 opString[i] = g_translation_ascii_table[UBYTEToChar(text_8bit[i])]; | |
459 } | |
460 if (len <opLength) | |
461 opString[len] = 0x00; | |
462 } | |
463 else | |
464 { //Convert to unicode | |
465 len = utl_cvt7To8 ((UBYTE *)ipString , ipLength, text_8bit, 0); | |
466 if (len*2 > opLength) | |
467 len = opLength/2; | |
468 for (i = 0; i < len; i++) | |
469 {/*SPR 1508, use new table to convert to Unicode*/ | |
470 opString[i*2] = (g_translation_unicode[ipString[i]]>>8)&0x00FF; | |
471 opString[i*2+1] = g_translation_unicode[UBYTEToChar(text_8bit[i])]; | |
472 } | |
473 if (len*2+1 < opLength) | |
474 { | |
475 opString[len*2] = 0x00; | |
476 opString[len*2+1] = 0x00; | |
477 } | |
478 } | |
479 break; | |
480 | |
481 case MFW_ASCII: | |
482 if (ipLength <=0) | |
483 ipLength = strlen(ipString); //calculate length if not supplied | |
484 if (opDataType == MFW_DCS_UCS2) | |
485 { //Convert data to unicode | |
486 if (ipLength*2 < opLength) | |
487 len = ipLength; | |
488 else | |
489 len = opLength/2; | |
490 for (i = 0; i < len; i++) | |
491 { /*SPR 1508, convert to Unicode using new table*/ | |
492 opString[i*2] = (translation_ascii_2_unicode[ ipString[i]]>>8)&0x00FF; | |
493 opString[i*2+1] = (translation_ascii_2_unicode[ ipString[i]])&0x00FF; | |
494 } | |
495 if (len*2+1 < opLength) | |
496 { | |
497 opString[len*2] = 0x00; | |
498 opString[len*2+1] = 0x00; | |
499 } | |
500 } | |
501 else if (opDataType == MFW_ASCII) | |
502 { //Data already in correct format - copy | |
503 if (ipLength < opLength) | |
504 len = ipLength; | |
505 else | |
506 len = opLength; | |
507 for (i=0;i<len;i++) | |
508 opString[i] = ipString[i]; | |
509 if (len<opLength) | |
510 opString[len] = 0x00; | |
511 } | |
512 else if (opDataType == MFW_DCS_8bits || opDataType == MFW_DCS_7bits) // SH - translate characters, don't change bit width | |
513 { | |
514 | |
515 if (ipLength < opLength) | |
516 len = ipLength; | |
517 else | |
518 len = opLength; | |
519 for (i=0;i<len;i++) | |
520 { | |
521 opString[i] = ipString[i]; | |
522 if (ipString[i]>=128 || g_translation_ascii_table[ipString[i]]!=ipString[i]) | |
523 { | |
524 for (j=0; j<128; j++) // Reverse translation | |
525 { | |
526 if (ipString[i] == g_translation_ascii_table[j]) | |
527 opString[i] = j; | |
528 } | |
529 #ifdef TRACE_SMSREAD | |
530 sprintf(buf, "Converted %x to %x", ipString[i], opString[i]); | |
531 TRACE_EVENT(buf); | |
532 #endif | |
533 } | |
534 } | |
535 if (len<opLength) | |
536 opString[len] = 0x00; | |
537 } | |
538 if (opDataType == MFW_DCS_7bits) // convert data to 7bit | |
539 { | |
540 len = utl_cvt8To7 ((UBYTE *)ipString , ipLength, (UBYTE*)opString, 0); | |
541 } | |
542 break; | |
543 } | |
544 | |
545 if (addNull) | |
546 { //Add 0x00 (or 0x00,0x00) to end of array | |
547 | |
548 /*SPR925 - SH - changed so NULL is in right place for unicode*/ | |
549 if (opDataType == MFW_DCS_UCS2) | |
550 { | |
551 if (len*2+1>opLength) | |
552 len = opLength/2; | |
553 | |
554 opString[len*2] = 0x00; | |
555 opString[len*2+1] = 0x00; | |
556 } | |
557 else | |
558 { | |
559 if (len>opLength) | |
560 len = opLength; | |
561 | |
562 opString[len] = 0x00; | |
563 } | |
564 /* end SPR925 */ | |
565 } | |
566 /*SPR 1991, free memory only if it has been allocated*/ | |
567 if (text_8bit!= NULL) | |
568 mfwFree(text_8bit,MAX_STRING_LEN+1); | |
569 return TRUE; | |
570 } | |
571 | |
572 | |
573 | |
574 /******************************************************************************* | |
575 | |
576 $Function: ATB_mem_Alloc | |
577 | |
578 $Description: ATB memory allocation function. | |
579 | |
580 $Returns: Address if successful, null if not. | |
581 | |
582 $Arguments: Size of memory to be allocated. | |
583 | |
584 *******************************************************************************/ | |
585 | |
586 UBYTE* ATB_mem_Alloc(USHORT size) | |
587 { | |
588 return (UBYTE *)mfwAlloc(size); | |
589 } | |
590 | |
591 | |
592 /******************************************************************************* | |
593 | |
594 $Function: ATB_mem_Free | |
595 | |
596 $Description: Frees memory allocated by the ATB | |
597 | |
598 $Returns: None. | |
599 | |
600 $Arguments: address - Pointer to memory to free | |
601 size - Size of the allocated block | |
602 | |
603 *******************************************************************************/ | |
604 | |
605 void ATB_mem_Free(UBYTE* address, USHORT size) | |
606 { | |
607 mfwFree(address,size); | |
608 return; | |
609 } | |
610 /******************************************************************************* | |
611 | |
612 $Function: ATB_swap_bytes | |
613 | |
614 $Description: Returns a unicode character with the bytes swapped. Added for SPR2175 | |
615 | |
616 $Returns: USHORT | |
617 | |
618 $Arguments: USHORT | |
619 | |
620 *******************************************************************************/ | |
621 static USHORT ATB_swap_bytes(USHORT character) | |
622 { | |
623 return ((UNICODE_NONASCII&character) << 8) + ((UNICODE_ASCII&character) >>8); | |
624 | |
625 } | |
626 | |
627 /******************************************************************************* | |
628 | |
629 $Function: ATB_char_GSM | |
630 | |
631 $Description: Returns the GSM of the provided ascii character.Added for SPR 2175. | |
632 | |
633 $Returns: A GSM character | |
634 | |
635 $Arguments: character - The ascii character | |
636 | |
637 *******************************************************************************/ | |
638 | |
639 char ATB_char_GSM(char ascii_character) | |
640 { int i; | |
641 /*check if GSM and ASCII encoding are the same value*/ | |
642 if (g_translation_ascii_table[ascii_character] == ascii_character) | |
643 return ascii_character; | |
644 | |
645 /*otherwise we have to search for the correct entry in the GSM to ASCII table*/ | |
646 for (i=0; i<128; i++) | |
647 { | |
648 if (g_translation_ascii_table[i] == ascii_character) | |
649 return i; | |
650 | |
651 } | |
652 } | |
653 /******************************************************************************* | |
654 | |
655 $Function: ATB_char_Ascii | |
656 | |
657 $Description: Returns the ascii of the provided unicode character | |
658 | |
659 $Returns: An ascii character | |
660 | |
661 $Arguments: character - The unicode character | |
662 | |
663 *******************************************************************************/ | |
664 | |
665 char ATB_char_Ascii(USHORT character) | |
666 { int i; | |
667 | |
668 /*SPR2175, rewrote function*/ | |
669 /*if the first byte of the character is the same as the ASCII code, return the first byte*/ | |
670 if (translation_ascii_2_unicode[((character & UNICODE_ASCII)>>8)] == ((character & UNICODE_ASCII)>>8)) | |
671 return (char)((character & UNICODE_ASCII)>>8); | |
672 | |
673 /*otherwise we have to search for the correct entry in the ASCII to unicode table*/ | |
674 for (i=0; i<256; i++) | |
675 { | |
676 if (translation_ascii_2_unicode[i] == ATB_swap_bytes(character)) | |
677 return i; | |
678 | |
679 } | |
680 } | |
681 | |
682 | |
683 /******************************************************************************* | |
684 | |
685 $Function: ATB_char_Unicode | |
686 | |
687 $Description: Returns the unicode of the provided ascii character | |
688 | |
689 $Returns: A unicode character | |
690 | |
691 $Arguments: character - The ascii character | |
692 | |
693 *******************************************************************************/ | |
694 | |
695 USHORT ATB_char_Unicode(char character) | |
696 { /*SPR 2175, re-wrote function*/ | |
697 USHORT table_value; | |
698 USHORT return_value = NULL; | |
699 /*look up corresponding Unicode char in table*/ | |
700 table_value= translation_ascii_2_unicode[character]; | |
701 | |
702 /*swap bytes as little-endian*/ | |
703 return_value = ATB_swap_bytes(table_value); | |
704 | |
705 return return_value; | |
706 } | |
707 | |
708 | |
709 /******************************************************************************* | |
710 | |
711 $Function: ATB_char_IsAscii | |
712 | |
713 $Description: Returns TRUE if the unicode character provided is ascii | |
714 | |
715 $Returns: TRUE or FALSE | |
716 | |
717 $Arguments: character - The unicode character | |
718 | |
719 *******************************************************************************/ | |
720 | |
721 BOOL ATB_char_IsAscii(USHORT character) | |
722 { | |
723 BOOL result = FALSE; | |
724 | |
725 if (character & UNICODE_NONASCII) // Make sure character is ASCII | |
726 { | |
727 result = FALSE; | |
728 } | |
729 else | |
730 { | |
731 result = TRUE; | |
732 } | |
733 | |
734 return result; | |
735 } | |
736 | |
737 | |
738 /******************************************************************************* | |
739 | |
740 $Function: ATB_char_IsAlphabetic | |
741 | |
742 $Description: Return TRUE if unicode character is part of latin alphabet | |
743 | |
744 $Returns: TRUE or FALSE | |
745 | |
746 $Arguments: character - The unicode character | |
747 | |
748 *******************************************************************************/ | |
749 | |
750 BOOL ATB_char_IsAlphabetic(USHORT character) | |
751 { | |
752 BOOL result = FALSE; | |
753 UBYTE asciiChar; | |
754 | |
755 if (ATB_char_IsAscii(character)) // Make sure character is ASCII | |
756 { | |
757 asciiChar = ATB_char_Ascii(character); | |
758 if ( (asciiChar >='A') && (asciiChar <='Z') ) | |
759 result = TRUE; | |
760 else if ( (asciiChar >='a') && (asciiChar <='z') ) | |
761 result = TRUE; | |
762 } | |
763 | |
764 return result; | |
765 } | |
766 | |
767 | |
768 /******************************************************************************* | |
769 | |
770 $Function: ATB_char_IsNumierc | |
771 | |
772 $Description: Return TRUE if unicode character is a digit, 0-9 | |
773 | |
774 $Returns: TRUE or FALSE | |
775 | |
776 $Arguments: character - The unicode character | |
777 | |
778 *******************************************************************************/ | |
779 | |
780 BOOL ATB_char_IsNumeric(USHORT character) | |
781 { | |
782 BOOL result = FALSE; | |
783 UBYTE asciiChar; | |
784 | |
785 if (ATB_char_IsAscii(character)) // Make sure character is ASCII | |
786 { | |
787 asciiChar = ATB_char_Ascii(character); | |
788 if ( (asciiChar >='0') && (asciiChar <='9') ) | |
789 result = TRUE; | |
790 } | |
791 | |
792 return result; | |
793 } | |
794 | |
795 /******************************************************************************* | |
796 | |
797 $Function: ATB_char_IsVisible | |
798 | |
799 $Description: Return TRUE if unicode character is visible, i.e. not ascii <32 | |
800 | |
801 $Returns: TRUE or FALSE | |
802 | |
803 $Arguments: character - The unicode character | |
804 | |
805 *******************************************************************************/ | |
806 | |
807 BOOL ATB_char_IsVisible(USHORT character) | |
808 { | |
809 BOOL result = TRUE; | |
810 UBYTE asciiChar; | |
811 | |
812 if (ATB_char_IsAscii(character)) // Make sure character is ASCII | |
813 { | |
814 asciiChar = ATB_char_Ascii(character); | |
815 /*SPR 2175, if ASCII value has no unicode equivalent assume not visible*/ | |
816 if (translation_ascii_2_unicode[asciiChar] == 0xFFFF) | |
817 result = FALSE; | |
818 } | |
819 | |
820 return result; | |
821 } | |
822 | |
823 | |
824 /******************************************************************************* | |
825 | |
826 $Function: ATB_string_Size | |
827 | |
828 $Description: Return the size in bytes of a character in the string | |
829 | |
830 $Returns: No. of bytes per character | |
831 | |
832 $Arguments: text - The text string | |
833 | |
834 *******************************************************************************/ | |
835 | |
836 UBYTE ATB_string_Size(T_ATB_TEXT *text) | |
837 { | |
838 UBYTE size; | |
839 | |
840 switch(text->dcs) | |
841 { | |
842 case ATB_DCS_UNICODE: | |
843 size = 2; | |
844 break; | |
845 | |
846 default: | |
847 size = 1; | |
848 break; | |
849 } | |
850 | |
851 return size; | |
852 } | |
853 | |
854 | |
855 /******************************************************************************* | |
856 | |
857 $Function: ATB_string_SetChar | |
858 | |
859 $Description: Set a character in the string to a value. Use this function rather than | |
860 accessing text data directly; it allows transparent ASCII and Unicode | |
861 handling. | |
862 | |
863 $Returns: None | |
864 | |
865 $Arguments: text - The text string | |
866 textIndex - The position of the character to set | |
867 character - The unicode character to set it to | |
868 | |
869 *******************************************************************************/ | |
870 | |
871 void ATB_string_SetChar(T_ATB_TEXT *text, USHORT textIndex, USHORT character) | |
872 { | |
873 USHORT *unicode; | |
874 | |
875 if (text->dcs==ATB_DCS_UNICODE) | |
876 { | |
877 unicode = (USHORT *)text->data; | |
878 unicode[textIndex] = character; | |
879 } | |
880 else | |
881 text->data[textIndex] = ATB_char_Ascii(character); | |
882 | |
883 return; | |
884 } | |
885 | |
886 | |
887 /******************************************************************************* | |
888 | |
889 $Function: ATB_string_GetChar | |
890 | |
891 $Description: Gets the value of a character in the string. Use this function rather than | |
892 accessing text data directly; it allows transparent ASCII and Unicode | |
893 handling. | |
894 | |
895 $Returns: The unicode character at the required position | |
896 | |
897 $Arguments: text - The text string | |
898 textIndex - The position of the character to get | |
899 | |
900 *******************************************************************************/ | |
901 | |
902 USHORT ATB_string_GetChar(T_ATB_TEXT *text, USHORT textIndex) | |
903 { | |
904 USHORT *unicode; | |
905 USHORT character; | |
906 | |
907 if (text->dcs==ATB_DCS_UNICODE) | |
908 { | |
909 unicode = (USHORT *)text->data; | |
910 character = unicode[textIndex]; | |
911 } | |
912 else | |
913 character = ATB_char_Unicode(text->data[textIndex]); | |
914 | |
915 return character; | |
916 } | |
917 | |
918 | |
919 /******************************************************************************* | |
920 | |
921 $Function: ATB_string_MoveLeft | |
922 | |
923 $Description: Move part of string left by 'offset' characters | |
924 | |
925 $Returns: TRUE if the operation was successful | |
926 | |
927 $Arguments: text - The text string | |
928 textIndex - The place where the newly moved section is to go | |
929 offset - The number of characters to move the section left by | |
930 | |
931 *******************************************************************************/ | |
932 | |
933 BOOL ATB_string_MoveLeft(T_ATB_TEXT *text, USHORT textIndex, USHORT offset) | |
934 { | |
935 BOOL outcome; | |
936 USHORT character; | |
937 | |
938 /* Copy until end of line char reached */ | |
939 | |
940 while ((textIndex+offset)<=text->len) | |
941 { | |
942 character = ATB_string_GetChar(text, textIndex+offset); | |
943 ATB_string_SetChar(text, textIndex, character); | |
944 textIndex++; | |
945 } | |
946 outcome = TRUE; | |
947 text->len -= offset; | |
948 | |
949 return outcome; | |
950 } | |
951 | |
952 | |
953 /******************************************************************************* | |
954 | |
955 $Function: ATB_string_MoveRight | |
956 | |
957 $Description: Move part of string right by 'offset' characters | |
958 | |
959 $Returns: TRUE if the operation was successful | |
960 | |
961 $Arguments: text - The text string | |
962 textIndex - The start of the section to be moved right | |
963 offset - The number of characters to move the section right by | |
964 size - The maximum possible length of the string | |
965 | |
966 *******************************************************************************/ | |
967 | |
968 BOOL ATB_string_MoveRight(T_ATB_TEXT *text, USHORT textStart, USHORT offset, USHORT size) | |
969 { | |
970 int textIndex; | |
971 BOOL outcome; | |
972 USHORT character; | |
973 | |
974 textIndex = text->len; | |
975 | |
976 if ((text->len+ offset) < size) /* SPR#1995 - SH - <= should be < */ | |
977 { | |
978 while (textIndex >= textStart) | |
979 { | |
980 character = ATB_string_GetChar(text, textIndex); | |
981 ATB_string_SetChar(text, textIndex+offset, character); | |
982 textIndex--; | |
983 } | |
984 text->len += offset; | |
985 outcome = TRUE; | |
986 } | |
987 else | |
988 outcome = FALSE; | |
989 | |
990 return outcome; | |
991 } | |
992 | |
993 | |
994 /******************************************************************************* | |
995 | |
996 $Function: ATB_string_Length | |
997 | |
998 $Description: Returns the length of the string, also setting the 'len' parameter of | |
999 the text structure | |
1000 | |
1001 $Returns: Length of the string in characters | |
1002 | |
1003 $Arguments: text - The text string | |
1004 | |
1005 *******************************************************************************/ | |
1006 | |
1007 USHORT ATB_string_Length(T_ATB_TEXT* text) | |
1008 { | |
1009 USHORT length; | |
1010 | |
1011 if (text->dcs==ATB_DCS_UNICODE) | |
1012 { | |
1013 text->len = ATB_string_UCLength((USHORT *)text->data); | |
1014 } | |
1015 else | |
1016 { | |
1017 text->len = strlen((char *)text->data); | |
1018 } | |
1019 | |
1020 return text->len; | |
1021 } | |
1022 | |
1023 | |
1024 /******************************************************************************* | |
1025 | |
1026 $Function: ATB_string_UCLength | |
1027 | |
1028 $Description: Returns the length of the provided unicode string | |
1029 | |
1030 $Returns: Length of the string in characters | |
1031 | |
1032 $Arguments: text - Pointer to the unicode string | |
1033 | |
1034 *******************************************************************************/ | |
1035 | |
1036 USHORT ATB_string_UCLength(USHORT* text) | |
1037 { | |
1038 USHORT length = 0; | |
1039 | |
1040 while (text[length]!=UNICODE_EOLN) | |
1041 { | |
1042 length++; | |
1043 } | |
1044 | |
1045 return (length); | |
1046 } | |
1047 | |
1048 | |
1049 /******************************************************************************* | |
1050 | |
1051 $Function: ATB_string_Copy | |
1052 | |
1053 $Description: Copy 'src' string into 'dest' string. | |
1054 | |
1055 $Returns: None. | |
1056 | |
1057 $Arguments: dest - The destination string (allocated by caller) | |
1058 src - The source string (allocated by caller) | |
1059 | |
1060 *******************************************************************************/ | |
1061 | |
1062 void ATB_string_Copy(T_ATB_TEXT* dest, T_ATB_TEXT* src) | |
1063 { | |
1064 USHORT textIndex; | |
1065 USHORT character; | |
1066 | |
1067 dest->dcs = src->dcs; | |
1068 | |
1069 for (textIndex=0; textIndex<src->len; textIndex++) | |
1070 { | |
1071 character = ATB_string_GetChar(src, textIndex); | |
1072 ATB_string_SetChar(dest, textIndex, character); | |
1073 } | |
1074 | |
1075 ATB_string_SetChar(dest, textIndex, UNICODE_EOLN); | |
1076 dest->len = textIndex; | |
1077 | |
1078 return; | |
1079 } | |
1080 | |
1081 | |
1082 /******************************************************************************* | |
1083 | |
1084 $Function: ATB_string_Concat | |
1085 | |
1086 $Description: Concatenate the second string, adding it to the end of the first. | |
1087 N.B. The strings don't have to have the same DCS. | |
1088 | |
1089 $Returns: None. | |
1090 | |
1091 $Arguments: dest - The destination string (allocated by caller) | |
1092 src - The source string (allocated by caller) | |
1093 | |
1094 *******************************************************************************/ | |
1095 | |
1096 void ATB_string_Concat(T_ATB_TEXT* dest, T_ATB_TEXT* src) | |
1097 { | |
1098 USHORT textIndex; | |
1099 USHORT character; | |
1100 TRACE_EVENT_P4("dest_len:%d, src len:%d, dest dcs: %d, src dcs:%d", dest->len, src->len, dest->dcs, src->dcs); | |
1101 | |
1102 for (textIndex = 0; textIndex<src->len; textIndex++) | |
1103 { | |
1104 character = ATB_string_GetChar(src, textIndex); | |
1105 /*SPR 2512, use destination length */ | |
1106 ATB_string_SetChar(dest, textIndex+dest->len, character); | |
1107 } | |
1108 | |
1109 dest->len += src->len; | |
1110 /*SPR 2512, use destination length to find point to insert termination*/ | |
1111 ATB_string_SetChar(dest, dest->len, UNICODE_EOLN); | |
1112 | |
1113 return; | |
1114 } | |
1115 | |
1116 | |
1117 /******************************************************************************* | |
1118 | |
1119 $Function: ATB_string_Concat | |
1120 | |
1121 $Description: Return position of character in string, or -1 if not found | |
1122 | |
1123 $Returns: Position of character in string | |
1124 | |
1125 $Arguments: text - The text string to search | |
1126 findChar - The character to find | |
1127 | |
1128 *******************************************************************************/ | |
1129 | |
1130 SHORT ATB_string_FindChar(T_ATB_TEXT* text, USHORT findChar) | |
1131 { | |
1132 USHORT textIndex; | |
1133 SHORT foundPos; | |
1134 USHORT character; | |
1135 | |
1136 textIndex = 0; | |
1137 foundPos = -1; | |
1138 | |
1139 character = ATB_string_GetChar(text, 0); | |
1140 | |
1141 while (character!=UNICODE_EOLN && foundPos==-1) | |
1142 { | |
1143 if (character==findChar) | |
1144 foundPos = (int)textIndex; | |
1145 textIndex++; | |
1146 character = ATB_string_GetChar(text, textIndex); | |
1147 } | |
1148 | |
1149 return foundPos; | |
1150 } | |
1151 | |
1152 | |
1153 /******************************************************************************* | |
1154 | |
1155 $Function: ATB_string_ToUnicode | |
1156 | |
1157 $Description: Convert a string to a unicode string. Memory for the unicode | |
1158 string should be allocated before calling. Returns a pointer to the | |
1159 unicode string. | |
1160 | |
1161 $Returns: None. | |
1162 | |
1163 $Arguments: dest - The destination string (allocated by caller) | |
1164 src - The source string (allocated by caller) | |
1165 | |
1166 *******************************************************************************/ | |
1167 | |
1168 void ATB_string_ToUnicode(T_ATB_TEXT *dest, T_ATB_TEXT *src) | |
1169 { | |
1170 USHORT textIndex; | |
1171 USHORT character; | |
1172 | |
1173 dest->dcs = ATB_DCS_UNICODE; | |
1174 | |
1175 for (textIndex=0; textIndex<src->len; textIndex++) | |
1176 { | |
1177 character = ATB_string_GetChar(src, textIndex); | |
1178 ATB_string_SetChar(dest, textIndex, character); | |
1179 } | |
1180 | |
1181 ATB_string_SetChar(dest, textIndex, UNICODE_EOLN); | |
1182 dest->len = textIndex; | |
1183 | |
1184 return; | |
1185 } | |
1186 | |
1187 | |
1188 /******************************************************************************* | |
1189 | |
1190 $Function: ATB_string_ToAscii | |
1191 | |
1192 $Description: Convert a string to an ascii string. Memory for the ascii | |
1193 string should be allocated before calling. Returns a pointer to the | |
1194 ascii string. | |
1195 | |
1196 $Returns: None. | |
1197 | |
1198 $Arguments: dest - The destination string (allocated by caller) | |
1199 src - The source string (allocated by caller) | |
1200 | |
1201 *******************************************************************************/ | |
1202 | |
1203 void ATB_string_ToAscii(T_ATB_TEXT *dest, T_ATB_TEXT *src) | |
1204 { | |
1205 USHORT textIndex; | |
1206 USHORT character; | |
1207 | |
1208 dest->dcs = ATB_DCS_ASCII; | |
1209 | |
1210 for (textIndex = 0; textIndex<src->len; textIndex++) | |
1211 { | |
1212 character = ATB_string_GetChar(src, textIndex); | |
1213 | |
1214 if (ATB_char_IsAscii(character) && ATB_char_IsVisible(character)) // Filter out non-ascii characters | |
1215 { | |
1216 character = ATB_char_Unicode('?'); | |
1217 } | |
1218 | |
1219 ATB_string_SetChar(dest, textIndex, character); | |
1220 } | |
1221 | |
1222 return; | |
1223 } | |
1224 | |
1225 | |
1226 /******************************************************************************* | |
1227 | |
1228 $Function: ATB_string_ToUnicode | |
1229 | |
1230 $Description: Moves index position through text | |
1231 | |
1232 $Returns: The new index. | |
1233 | |
1234 $Arguments: text - The text string | |
1235 textIndex - Current position within the text buffer | |
1236 offset - Negative for backwards movement, positive for forwards | |
1237 movement. | |
1238 | |
1239 *******************************************************************************/ | |
1240 | |
1241 USHORT ATB_string_IndexMove(T_ATB_TEXT *text, USHORT textIndex, SHORT offset) | |
1242 { | |
1243 while (textIndex>0 && offset<0) | |
1244 { | |
1245 textIndex--; | |
1246 offset++; | |
1247 } | |
1248 | |
1249 while (ATB_string_GetChar(text, textIndex)!=UNICODE_EOLN && offset>0) | |
1250 { | |
1251 textIndex++; | |
1252 offset--; | |
1253 } | |
1254 | |
1255 return textIndex; | |
1256 } | |
1257 |