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