1 | /* $Id: heapstring.cpp,v 1.34 2000-10-23 19:35:11 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
5 | *
|
---|
6 | * Win32 compatibility string functions for OS/2
|
---|
7 | *
|
---|
8 | * NOTE: lstrcpyn* always appends a terminating 0 (unlike strncpy)!
|
---|
9 | *
|
---|
10 | * Copyright 1999 Patrick Haller
|
---|
11 | */
|
---|
12 |
|
---|
13 | /*****************************************************************************
|
---|
14 | * Includes *
|
---|
15 | *****************************************************************************/
|
---|
16 |
|
---|
17 | #include <odin.h>
|
---|
18 | #include <odinwrap.h>
|
---|
19 | #include <os2sel.h>
|
---|
20 |
|
---|
21 | #include <os2win.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <stdio.h>
|
---|
25 | #include <winnls.h>
|
---|
26 | #include <unicode.h>
|
---|
27 | #include <ctype.h>
|
---|
28 | #include <wcstr.h>
|
---|
29 | #include "heap.h"
|
---|
30 | #include <heapstring.h>
|
---|
31 | #include "misc.h"
|
---|
32 | #include "codepage.h"
|
---|
33 |
|
---|
34 | #define DBG_LOCALLOG DBG_heapstring
|
---|
35 | #include "dbglocal.h"
|
---|
36 |
|
---|
37 | /*****************************************************************************
|
---|
38 | * Defines *
|
---|
39 | *****************************************************************************/
|
---|
40 |
|
---|
41 | ODINDEBUGCHANNEL(KERNEL32-HEAPSTRING)
|
---|
42 |
|
---|
43 | /*****************************************************************************
|
---|
44 | * Name :
|
---|
45 | * Purpose :
|
---|
46 | * Parameters:
|
---|
47 | * Variables :
|
---|
48 | * Result :
|
---|
49 | * Remark :
|
---|
50 | * Status :
|
---|
51 | *
|
---|
52 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
53 | *****************************************************************************/
|
---|
54 |
|
---|
55 | int WIN32API lstrlenA(LPCSTR arg1)
|
---|
56 | {
|
---|
57 | dprintf2(("KERNEL32: lstrlenA(%s)\n",
|
---|
58 | arg1));
|
---|
59 |
|
---|
60 | return O32_lstrlen(arg1);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /*****************************************************************************
|
---|
65 | * Name :
|
---|
66 | * Purpose :
|
---|
67 | * Parameters:
|
---|
68 | * Variables :
|
---|
69 | * Result :
|
---|
70 | * Remark :
|
---|
71 | * Status :
|
---|
72 | *
|
---|
73 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
74 | *****************************************************************************/
|
---|
75 |
|
---|
76 | int WIN32API lstrlenW(LPCWSTR arg1)
|
---|
77 | {
|
---|
78 | int rc;
|
---|
79 |
|
---|
80 | rc = UniStrlen( (UniChar*)arg1);
|
---|
81 | dprintf2(("KERNEL32: lstrlenW(%08xh) returns %d\n",
|
---|
82 | arg1,
|
---|
83 | rc));
|
---|
84 | return rc;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | /*****************************************************************************
|
---|
89 | * Name :
|
---|
90 | * Purpose :
|
---|
91 | * Parameters:
|
---|
92 | * Variables :
|
---|
93 | * Result :
|
---|
94 | * Remark :
|
---|
95 | * Status :
|
---|
96 | *
|
---|
97 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
98 | *****************************************************************************/
|
---|
99 |
|
---|
100 | LPSTR WIN32API lstrcatA(LPSTR arg1, LPCSTR arg2)
|
---|
101 | {
|
---|
102 | dprintf2(("KERNEL32: lstrcat(%s,%s)\n",
|
---|
103 | arg1,
|
---|
104 | arg2));
|
---|
105 |
|
---|
106 | if(arg2 == NULL)
|
---|
107 | return arg1;
|
---|
108 | strcat(arg1, arg2);
|
---|
109 | return arg1;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | /*****************************************************************************
|
---|
114 | * Name :
|
---|
115 | * Purpose :
|
---|
116 | * Parameters:
|
---|
117 | * Variables :
|
---|
118 | * Result :
|
---|
119 | * Remark :
|
---|
120 | * Status :
|
---|
121 | *
|
---|
122 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
123 | *****************************************************************************/
|
---|
124 |
|
---|
125 | LPWSTR WIN32API lstrcatW(LPWSTR arg1, LPCWSTR arg2)
|
---|
126 | {
|
---|
127 | dprintf2(("KERNEL32: OS2lstrcatW(%08xh,%08xh)\n",
|
---|
128 | arg1,
|
---|
129 | arg2));
|
---|
130 |
|
---|
131 | if(arg2 == NULL)
|
---|
132 | return arg1;
|
---|
133 |
|
---|
134 | UniStrcat( (UniChar*) arg1, (UniChar*) arg2 );
|
---|
135 | return arg1;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /*****************************************************************************
|
---|
140 | * Name :
|
---|
141 | * Purpose :
|
---|
142 | * Parameters:
|
---|
143 | * Variables :
|
---|
144 | * Result :
|
---|
145 | * Remark :
|
---|
146 | * Status :
|
---|
147 | *
|
---|
148 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
149 | *****************************************************************************/
|
---|
150 |
|
---|
151 | int WIN32API lstrcmpA(LPCSTR arg1, LPCSTR arg2)
|
---|
152 | {
|
---|
153 | dprintf2(("KERNEL32: OS2lstrcmpA(%s,%s)\n",
|
---|
154 | arg1,
|
---|
155 | arg2));
|
---|
156 |
|
---|
157 | if(arg1 == NULL)
|
---|
158 | return -1;
|
---|
159 | if(arg2 == NULL)
|
---|
160 | return 1;
|
---|
161 |
|
---|
162 | return O32_lstrcmp(arg1, arg2);
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | /*****************************************************************************
|
---|
167 | * Name :
|
---|
168 | * Purpose :
|
---|
169 | * Parameters:
|
---|
170 | * Variables :
|
---|
171 | * Result :
|
---|
172 | * Remark :
|
---|
173 | * Status :
|
---|
174 | *
|
---|
175 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
176 | *****************************************************************************/
|
---|
177 |
|
---|
178 | int WIN32API lstrncmpA(LPCSTR arg1, LPCSTR arg2, int l)
|
---|
179 | {
|
---|
180 | dprintf2(("KERNEL32: OS2lstrncmpA(%s,%s,%d)\n",
|
---|
181 | arg1,
|
---|
182 | arg2,
|
---|
183 | l));
|
---|
184 |
|
---|
185 | return strncmp(arg1, arg2, l);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*****************************************************************************
|
---|
189 | * Name : lstrncmpiA
|
---|
190 | * Purpose :
|
---|
191 | * Parameters:
|
---|
192 | * Variables :
|
---|
193 | * Result :
|
---|
194 | * Remark :
|
---|
195 | * Status :
|
---|
196 | *
|
---|
197 | * Author : Przemyslaw Dobrowolski
|
---|
198 | *****************************************************************************/
|
---|
199 | INT WINAPI lstrncmpiA( LPCSTR str1, LPCSTR str2, INT n )
|
---|
200 | {
|
---|
201 | INT firstch,lastch;
|
---|
202 | INT result = 0;
|
---|
203 |
|
---|
204 | if (n)
|
---|
205 | {
|
---|
206 | do
|
---|
207 | {
|
---|
208 | firstch = tolower(*str1);
|
---|
209 | lastch = tolower(*str2);
|
---|
210 | str1++;
|
---|
211 | str2++;
|
---|
212 | } while (--n && str1 && str2 && firstch == lastch);
|
---|
213 |
|
---|
214 | result = firstch - lastch;
|
---|
215 | }
|
---|
216 |
|
---|
217 | return(result);
|
---|
218 | }
|
---|
219 | //TODO: Don't know if this is completely correct
|
---|
220 | int WIN32API lstrncmpiW(LPCWSTR str1, LPCWSTR str2, int n)
|
---|
221 | {
|
---|
222 | INT firstch,lastch;
|
---|
223 | INT result = 0;
|
---|
224 |
|
---|
225 | if (n)
|
---|
226 | {
|
---|
227 | do
|
---|
228 | {
|
---|
229 | firstch = tolower((char)*str1);
|
---|
230 | lastch = tolower((char)*str2);
|
---|
231 | str1++;
|
---|
232 | str2++;
|
---|
233 | } while (--n && str1 && str2 && firstch == lastch);
|
---|
234 |
|
---|
235 | result = firstch - lastch;
|
---|
236 | }
|
---|
237 |
|
---|
238 | return(result);
|
---|
239 | }
|
---|
240 |
|
---|
241 | /*****************************************************************************
|
---|
242 | * Name :
|
---|
243 | * Purpose :
|
---|
244 | * Parameters:
|
---|
245 | * Variables :
|
---|
246 | * Result :
|
---|
247 | * Remark :
|
---|
248 | * Status :
|
---|
249 | *
|
---|
250 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
251 | *****************************************************************************/
|
---|
252 |
|
---|
253 | int WIN32API lstrcmpW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
254 | {
|
---|
255 | dprintf2(("KERNEL32: lstrcmpW (%08xh, %08xh)\n",
|
---|
256 | arg1,
|
---|
257 | arg2));
|
---|
258 |
|
---|
259 | if(arg1 == NULL)
|
---|
260 | return -1;
|
---|
261 | if(arg2 == NULL)
|
---|
262 | return 1;
|
---|
263 |
|
---|
264 | return wcscmp( (wchar_t*)arg1,
|
---|
265 | (wchar_t*)arg2 );
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | /*****************************************************************************
|
---|
270 | * Name :
|
---|
271 | * Purpose :
|
---|
272 | * Parameters:
|
---|
273 | * Variables :
|
---|
274 | * Result :
|
---|
275 | * Remark :
|
---|
276 | * Status :
|
---|
277 | *
|
---|
278 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
279 | *****************************************************************************/
|
---|
280 |
|
---|
281 | int WIN32API lstrncmpW(LPCWSTR arg1, LPCWSTR arg2, int l)
|
---|
282 | {
|
---|
283 | dprintf2(("KERNEL32: OS2lstrncmpW(%08xh,%08xh,%d)\n",
|
---|
284 | arg1,
|
---|
285 | arg2,
|
---|
286 | l));
|
---|
287 |
|
---|
288 | return wcsncmp((wchar_t*)arg1,
|
---|
289 | (wchar_t*)arg2,
|
---|
290 | l);
|
---|
291 | }
|
---|
292 |
|
---|
293 | /*****************************************************************************
|
---|
294 | * Name :
|
---|
295 | * Purpose :
|
---|
296 | * Parameters:
|
---|
297 | * Variables :
|
---|
298 | * Result :
|
---|
299 | * Remark :
|
---|
300 | * Status :
|
---|
301 | *
|
---|
302 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
303 | *****************************************************************************/
|
---|
304 |
|
---|
305 | LPSTR WIN32API lstrcpyA(LPSTR dest, LPCSTR src)
|
---|
306 | {
|
---|
307 | if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
|
---|
308 | return NULL;
|
---|
309 |
|
---|
310 | return O32_lstrcpy(dest, src);
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 | /*****************************************************************************
|
---|
315 | * Name :
|
---|
316 | * Purpose :
|
---|
317 | * Parameters:
|
---|
318 | * Variables :
|
---|
319 | * Result :
|
---|
320 | * Remark :
|
---|
321 | * Status :
|
---|
322 | *
|
---|
323 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
324 | *****************************************************************************/
|
---|
325 |
|
---|
326 | LPWSTR WIN32API lstrcpyW(LPWSTR dest, LPCWSTR src)
|
---|
327 | {
|
---|
328 | if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
|
---|
329 | return NULL;
|
---|
330 |
|
---|
331 | UniStrcpy( (UniChar*)dest,
|
---|
332 | (UniChar*)src );
|
---|
333 | return dest;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | /*****************************************************************************
|
---|
338 | * Name :
|
---|
339 | * Purpose :
|
---|
340 | * Parameters:
|
---|
341 | * Variables :
|
---|
342 | * Result :
|
---|
343 | * Remark :
|
---|
344 | * Status :
|
---|
345 | *
|
---|
346 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
347 | *****************************************************************************/
|
---|
348 |
|
---|
349 | LPSTR WIN32API lstrcpynA(LPSTR arg1, LPCSTR arg2, int arg3)
|
---|
350 | {
|
---|
351 | register LPSTR p1 = arg1;
|
---|
352 | register LPSTR p2 = (LPSTR)arg2;
|
---|
353 |
|
---|
354 | dprintf2(("KERNEL32: OS2lstrcpyA(%08xh, %08xh, %08xh)\n",
|
---|
355 | arg1,
|
---|
356 | arg2,
|
---|
357 | arg3));
|
---|
358 |
|
---|
359 | //PH: looks like either \0 or arg3 terminate the copy
|
---|
360 | //return strncpy(arg1, arg2, arg3);
|
---|
361 | arg3--; // pre-decrement to avoid exceeding buffer length
|
---|
362 | // results in better code than (arg1 > 1)
|
---|
363 |
|
---|
364 | for (;*p2 && arg3; arg3--)
|
---|
365 | *p1++ = *p2++;
|
---|
366 |
|
---|
367 | *p1 = 0; //CB: copy arg-1, set end 0
|
---|
368 |
|
---|
369 | return arg1;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /*****************************************************************************
|
---|
374 | * Name :
|
---|
375 | * Purpose :
|
---|
376 | * Parameters:
|
---|
377 | * Variables :
|
---|
378 | * Result :
|
---|
379 | * Remark :
|
---|
380 | * Status :
|
---|
381 | *
|
---|
382 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
383 | *****************************************************************************/
|
---|
384 |
|
---|
385 | LPWSTR WIN32API lstrcpynW(LPWSTR dest, LPCWSTR src, int arg3)
|
---|
386 | {
|
---|
387 | dprintf2(("KERNEL32: lstrcpynW(%08xh,%08xh,%08xh)",
|
---|
388 | dest,
|
---|
389 | src,
|
---|
390 | arg3));
|
---|
391 |
|
---|
392 | if (arg3 == 0)
|
---|
393 | return NULL;
|
---|
394 |
|
---|
395 | UniStrncpy( (UniChar*)dest,
|
---|
396 | (UniChar*)src,
|
---|
397 | arg3-1); //CB: copy arg3-1 characters
|
---|
398 | dest[arg3-1] = 0; //CB: set end
|
---|
399 | return dest;
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | /*****************************************************************************
|
---|
404 | * Name :
|
---|
405 | * Purpose :
|
---|
406 | * Parameters:
|
---|
407 | * Variables :
|
---|
408 | * Result :
|
---|
409 | * Remark :
|
---|
410 | * Status :
|
---|
411 | *
|
---|
412 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
413 | *****************************************************************************/
|
---|
414 |
|
---|
415 | int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
|
---|
416 | {
|
---|
417 | dprintf2(("KERNEL32: lstrcmpiA(%s,%s)\n",
|
---|
418 | arg1,
|
---|
419 | arg2));
|
---|
420 |
|
---|
421 | if(arg1 == NULL)
|
---|
422 | return -1;
|
---|
423 |
|
---|
424 | if(arg2 == NULL)
|
---|
425 | return 1;
|
---|
426 |
|
---|
427 | return O32_lstrcmpi(arg1, arg2);
|
---|
428 | }
|
---|
429 |
|
---|
430 |
|
---|
431 | /*****************************************************************************
|
---|
432 | * Name :
|
---|
433 | * Purpose :
|
---|
434 | * Parameters:
|
---|
435 | * Variables :
|
---|
436 | * Result :
|
---|
437 | * Remark :
|
---|
438 | * Status :
|
---|
439 | *
|
---|
440 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
441 | *****************************************************************************/
|
---|
442 |
|
---|
443 | int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
444 | {
|
---|
445 | char *astr1, *astr2;
|
---|
446 | int rc;
|
---|
447 |
|
---|
448 | dprintf2(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
|
---|
449 | arg1,
|
---|
450 | arg2));
|
---|
451 |
|
---|
452 | if(arg1 == NULL)
|
---|
453 | return -1;
|
---|
454 |
|
---|
455 | if(arg2 == NULL)
|
---|
456 | return 1;
|
---|
457 |
|
---|
458 | // NOTE: This function has no equivalent in uunidef.h
|
---|
459 | astr1 = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
460 | astr2 = UnicodeToAsciiString((LPWSTR)arg2);
|
---|
461 | rc = lstrcmpiA(astr1, astr2);
|
---|
462 | FreeAsciiString(astr2);
|
---|
463 | FreeAsciiString(astr1);
|
---|
464 | return(rc);
|
---|
465 | }
|
---|
466 |
|
---|
467 |
|
---|
468 | /*****************************************************************************
|
---|
469 | * Name :
|
---|
470 | * Purpose :
|
---|
471 | * Parameters:
|
---|
472 | * Variables :
|
---|
473 | * Result :
|
---|
474 | * Remark :
|
---|
475 | * Status :
|
---|
476 | *
|
---|
477 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
478 | *****************************************************************************/
|
---|
479 |
|
---|
480 | // unilen: length of astring buffer (including 0 terminator)
|
---|
481 | // returns string length
|
---|
482 |
|
---|
483 | int WIN32API lstrcpynCtoA(LPSTR astring,
|
---|
484 | LPCWSTR ustring,
|
---|
485 | int unilen,
|
---|
486 | UconvObject uconv_object)
|
---|
487 | {
|
---|
488 | int i;
|
---|
489 | int rc;
|
---|
490 | size_t uni_chars_left;
|
---|
491 | size_t out_bytes_left;
|
---|
492 | size_t num_subs;
|
---|
493 | UniChar* in_buf;
|
---|
494 | char* out_buf;
|
---|
495 |
|
---|
496 | dprintf2(("KERNEL32: HeapString: lstrcpynWtoA(%08x,%08xh,%d)\n",
|
---|
497 | astring,
|
---|
498 | ustring,
|
---|
499 | unilen));
|
---|
500 |
|
---|
501 | if (ustring == NULL)
|
---|
502 | {
|
---|
503 | if (astring != NULL && unilen > 0)
|
---|
504 | astring[0] = 0;
|
---|
505 | return 0;
|
---|
506 | }
|
---|
507 |
|
---|
508 | if (astring == NULL || unilen <= 0)
|
---|
509 | return 0;
|
---|
510 |
|
---|
511 | if (uconv_object)
|
---|
512 | {
|
---|
513 | if (unilen == 1)
|
---|
514 | {
|
---|
515 | astring[0] = 0;
|
---|
516 | return 0; //no data
|
---|
517 | }
|
---|
518 |
|
---|
519 | //SvL: Determine length of unicode string
|
---|
520 | uni_chars_left = UniStrlen((UniChar*)ustring)+1;
|
---|
521 | uni_chars_left = min(uni_chars_left, unilen);
|
---|
522 | unilen = uni_chars_left;
|
---|
523 |
|
---|
524 | out_bytes_left = uni_chars_left; //size in bytes == elements
|
---|
525 | in_buf = (UniChar*)ustring;
|
---|
526 | out_buf = astring;
|
---|
527 | rc = UniUconvFromUcs(uconv_object,
|
---|
528 | &in_buf, &uni_chars_left,
|
---|
529 | (void**)&out_buf, &out_bytes_left,
|
---|
530 | &num_subs);
|
---|
531 |
|
---|
532 | /* @@@PH 2000/08/10
|
---|
533 | * this causes the last character in the converted
|
---|
534 | * target string to be chopped off. I.e. causes CMD.EXE
|
---|
535 | * to loose the CRLF functionality.
|
---|
536 | */
|
---|
537 | /*
|
---|
538 | unilen -= 1+out_bytes_left; //end + left bytes
|
---|
539 | astring[unilen] = 0; //terminate
|
---|
540 | */
|
---|
541 |
|
---|
542 | return unilen; //length of string (excluding terminator)
|
---|
543 | }
|
---|
544 | else
|
---|
545 | {
|
---|
546 | /* idiots unicode conversion :) */
|
---|
547 | for (i = 0; i < unilen-1; i++)
|
---|
548 | {
|
---|
549 | astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
|
---|
550 | if (ustring[i] == 0) return i; //asta la vista, baby
|
---|
551 | }
|
---|
552 |
|
---|
553 | astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
|
---|
554 |
|
---|
555 | return(unilen-1);
|
---|
556 | }
|
---|
557 | }
|
---|
558 |
|
---|
559 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
560 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
561 | int WIN32API lstrcpynWtoA(LPSTR astring,
|
---|
562 | LPCWSTR ustring,
|
---|
563 | int unilen)
|
---|
564 | {
|
---|
565 | int ret;
|
---|
566 |
|
---|
567 | ret = lstrcpynCtoA(astring, ustring, unilen, GetWindowsUconvObject());
|
---|
568 | astring[unilen-1] = 0;
|
---|
569 | return ret;
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | /*****************************************************************************
|
---|
574 | * Name :
|
---|
575 | * Purpose :
|
---|
576 | * Parameters:
|
---|
577 | * Variables :
|
---|
578 | * Result :
|
---|
579 | * Remark :
|
---|
580 | * Status :
|
---|
581 | *
|
---|
582 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
583 | *****************************************************************************/
|
---|
584 |
|
---|
585 | // asciilen: max length of unicode buffer (including end 0)
|
---|
586 | // @@@PH 0 termination is NOT necessarily included !
|
---|
587 | int lstrcpynAtoC(LPWSTR unicode,
|
---|
588 | LPCSTR ascii,
|
---|
589 | int asciilen,
|
---|
590 | UconvObject uconv_object)
|
---|
591 | {
|
---|
592 | int rc;
|
---|
593 | int i;
|
---|
594 | size_t uni_chars_left;
|
---|
595 | size_t in_bytes_left;
|
---|
596 | size_t num_subs;
|
---|
597 | UniChar* out_buf;
|
---|
598 | char* in_buf;
|
---|
599 |
|
---|
600 | dprintf2(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
|
---|
601 | ascii,
|
---|
602 | unicode,
|
---|
603 | asciilen));
|
---|
604 |
|
---|
605 | //CB: no input, set at least terminator
|
---|
606 | if (ascii == NULL)
|
---|
607 | {
|
---|
608 | if (unicode != NULL && asciilen > 0) unicode[0] = 0;
|
---|
609 | return 0;
|
---|
610 | }
|
---|
611 |
|
---|
612 | if (unicode == NULL || asciilen <= 0)
|
---|
613 | return 0; //nothing to do
|
---|
614 |
|
---|
615 | if (uconv_object)
|
---|
616 | {
|
---|
617 | //@@@PH what's this?
|
---|
618 | if ((asciilen == 1) && (*ascii == '\0') )
|
---|
619 | {
|
---|
620 | unicode[0] = 0;
|
---|
621 | return 0;
|
---|
622 | }
|
---|
623 |
|
---|
624 | in_buf = (LPSTR)ascii;
|
---|
625 |
|
---|
626 | //@@@PH what's this?
|
---|
627 | //in_bytes_left = asciilen-1; //buffer size in bytes
|
---|
628 |
|
---|
629 | //SvL: Determine length of ascii string
|
---|
630 | in_bytes_left = strlen(in_buf)+1;
|
---|
631 | in_bytes_left = asciilen = min(in_bytes_left, asciilen); //buffer size in bytes
|
---|
632 |
|
---|
633 | out_buf = (UniChar*)unicode;
|
---|
634 |
|
---|
635 | uni_chars_left = in_bytes_left; //elements
|
---|
636 |
|
---|
637 | rc = UniUconvToUcs( uconv_object,
|
---|
638 | (void**)&in_buf, &in_bytes_left,
|
---|
639 | &out_buf, &uni_chars_left,
|
---|
640 | &num_subs );
|
---|
641 |
|
---|
642 | /* @@@PH 2000/08/10
|
---|
643 | * this causes the last character in the converted
|
---|
644 | * target string to be chopped off. I.e. causes CMD.EXE
|
---|
645 | * to enter command correctly.
|
---|
646 | */
|
---|
647 | /*
|
---|
648 | asciilen -= 1+uni_chars_left; //end + left bytes
|
---|
649 |
|
---|
650 | unicode[asciilen] = 0; // always terminate string
|
---|
651 | */
|
---|
652 |
|
---|
653 | return asciilen; //length of string (excluding terminator)
|
---|
654 | }
|
---|
655 | else
|
---|
656 | { //poor man's conversion
|
---|
657 |
|
---|
658 | // for(i = 0;i < asciilen-1;i++)
|
---|
659 | for(i = 0;i < asciilen;i++)
|
---|
660 | {
|
---|
661 | unicode[i] = ascii[i];
|
---|
662 | if (ascii[i] == 0)
|
---|
663 | //return i-1; //work done
|
---|
664 | return i; //work done
|
---|
665 | }
|
---|
666 |
|
---|
667 | // unicode[asciilen-1] = 0;
|
---|
668 | // return asciilen-1;
|
---|
669 | return asciilen;
|
---|
670 | }
|
---|
671 | }
|
---|
672 |
|
---|
673 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
674 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
675 | int WIN32API lstrcpynAtoW(LPWSTR unicode,
|
---|
676 | LPCSTR ascii,
|
---|
677 | int asciilen)
|
---|
678 | {
|
---|
679 | int ret;
|
---|
680 |
|
---|
681 | ret = lstrcpynAtoC(unicode, ascii, asciilen, GetWindowsUconvObject());
|
---|
682 | unicode[asciilen-1] = 0;
|
---|
683 | return ret;
|
---|
684 | }
|
---|
685 |
|
---|
686 | /*****************************************************************************
|
---|
687 | * Name :
|
---|
688 | * Purpose : Converts unicode string to ascii string
|
---|
689 | * Parameters:
|
---|
690 | * Variables :
|
---|
691 | * Result : returns length of ascii string
|
---|
692 | * Remark :
|
---|
693 | * Status :
|
---|
694 | *
|
---|
695 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
696 | *****************************************************************************/
|
---|
697 |
|
---|
698 | LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
|
---|
699 | {
|
---|
700 | //@@@PH huh? wuz dat?
|
---|
701 | if (unicode == NULL)
|
---|
702 | {
|
---|
703 | if (unicode != NULL) ((LPWSTR)unicode)[0] = 0; //CB: set at least end
|
---|
704 | return NULL;
|
---|
705 | }
|
---|
706 |
|
---|
707 | if (unicode == NULL)
|
---|
708 | return NULL; /* garbage in, garbage out ! */
|
---|
709 |
|
---|
710 | /* forward to function with len parameter */
|
---|
711 | lstrcpynWtoA(ascii,
|
---|
712 | unicode,
|
---|
713 | UniStrlen((UniChar*)unicode)+1); //end included
|
---|
714 |
|
---|
715 | return ascii;
|
---|
716 | }
|
---|
717 |
|
---|
718 |
|
---|
719 | /*****************************************************************************
|
---|
720 | * Name :
|
---|
721 | * Purpose : Copies the full string from ascii to unicode
|
---|
722 | * Parameters:
|
---|
723 | * Variables :
|
---|
724 | * Result :
|
---|
725 | * Remark :
|
---|
726 | * Status :
|
---|
727 | *
|
---|
728 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
729 | *****************************************************************************/
|
---|
730 |
|
---|
731 | LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
|
---|
732 | {
|
---|
733 | /* achimha for security, strlen might trap if garbage in */
|
---|
734 | /* @@@PH 98/06/07 */
|
---|
735 | if (ascii == NULL)
|
---|
736 | {
|
---|
737 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
738 | return NULL;
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (unicode == NULL)
|
---|
742 | return NULL; /* garbage in, garbage out ! */
|
---|
743 |
|
---|
744 | /* forward to call with length parameter */
|
---|
745 | lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
|
---|
746 | return (unicode);
|
---|
747 | }
|
---|
748 |
|
---|
749 |
|
---|
750 |
|
---|
751 |
|
---|
752 | /*****************************************************************************
|
---|
753 | * Name :
|
---|
754 | * Purpose :
|
---|
755 | * Parameters:
|
---|
756 | * Variables :
|
---|
757 | * Result :
|
---|
758 | * Remark :
|
---|
759 | * Status :
|
---|
760 | *
|
---|
761 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
762 | *****************************************************************************/
|
---|
763 |
|
---|
764 | LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
|
---|
765 | {
|
---|
766 | LPVOID p = HeapAlloc( heap, flags, size );
|
---|
767 | if (!p)
|
---|
768 | {
|
---|
769 | dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
|
---|
770 | heap,
|
---|
771 | flags,
|
---|
772 | size));
|
---|
773 | }
|
---|
774 | return p;
|
---|
775 | }
|
---|
776 |
|
---|
777 |
|
---|
778 | /*****************************************************************************
|
---|
779 | * Name :
|
---|
780 | * Purpose :
|
---|
781 | * Parameters:
|
---|
782 | * Variables :
|
---|
783 | * Result :
|
---|
784 | * Remark :
|
---|
785 | * Status :
|
---|
786 | *
|
---|
787 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
788 | *****************************************************************************/
|
---|
789 |
|
---|
790 | LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
|
---|
791 | {
|
---|
792 | LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
|
---|
793 | if (!p)
|
---|
794 | {
|
---|
795 | dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
|
---|
796 | heap,
|
---|
797 | flags,
|
---|
798 | lpMem,
|
---|
799 | size));
|
---|
800 | }
|
---|
801 | return p;
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | /*****************************************************************************
|
---|
806 | * Name :
|
---|
807 | * Purpose :
|
---|
808 | * Parameters:
|
---|
809 | * Variables :
|
---|
810 | * Result :
|
---|
811 | * Remark :
|
---|
812 | * Status :
|
---|
813 | *
|
---|
814 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
815 | *****************************************************************************/
|
---|
816 |
|
---|
817 | LPVOID WIN32API HEAP_malloc(DWORD size )
|
---|
818 | {
|
---|
819 | LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
|
---|
820 | if (!p)
|
---|
821 | {
|
---|
822 | dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
|
---|
823 | size));
|
---|
824 | }
|
---|
825 | return p;
|
---|
826 | }
|
---|
827 |
|
---|
828 |
|
---|
829 | /*****************************************************************************
|
---|
830 | * Name :
|
---|
831 | * Purpose :
|
---|
832 | * Parameters:
|
---|
833 | * Variables :
|
---|
834 | * Result :
|
---|
835 | * Remark :
|
---|
836 | * Status :
|
---|
837 | *
|
---|
838 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
839 | *****************************************************************************/
|
---|
840 |
|
---|
841 | DWORD WIN32API HEAP_size(LPVOID lpMem)
|
---|
842 | {
|
---|
843 | return HeapSize( GetProcessHeap(), 0, lpMem );
|
---|
844 | }
|
---|
845 |
|
---|
846 |
|
---|
847 | /*****************************************************************************
|
---|
848 | * Name :
|
---|
849 | * Purpose :
|
---|
850 | * Parameters:
|
---|
851 | * Variables :
|
---|
852 | * Result :
|
---|
853 | * Remark :
|
---|
854 | * Status :
|
---|
855 | *
|
---|
856 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
857 | *****************************************************************************/
|
---|
858 |
|
---|
859 | LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
|
---|
860 | {
|
---|
861 | LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
|
---|
862 | if (!p)
|
---|
863 | {
|
---|
864 | dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
|
---|
865 | lpMem,
|
---|
866 | size));
|
---|
867 | }
|
---|
868 | return p;
|
---|
869 | }
|
---|
870 |
|
---|
871 |
|
---|
872 | /*****************************************************************************
|
---|
873 | * Name :
|
---|
874 | * Purpose :
|
---|
875 | * Parameters:
|
---|
876 | * Variables :
|
---|
877 | * Result :
|
---|
878 | * Remark :
|
---|
879 | * Status :
|
---|
880 | *
|
---|
881 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
882 | *****************************************************************************/
|
---|
883 |
|
---|
884 | VOID WIN32API HEAP_free(LPVOID lpMem)
|
---|
885 | {
|
---|
886 | dprintf2(("KERNEL32: HEAP_free(%08xh)\n",
|
---|
887 | lpMem));
|
---|
888 |
|
---|
889 | HeapFree( GetProcessHeap(), 0, lpMem);
|
---|
890 | }
|
---|
891 |
|
---|
892 |
|
---|
893 | /*****************************************************************************
|
---|
894 | * Name :
|
---|
895 | * Purpose :
|
---|
896 | * Parameters:
|
---|
897 | * Variables :
|
---|
898 | * Result :
|
---|
899 | * Remark :
|
---|
900 | * Status :
|
---|
901 | *
|
---|
902 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
903 | *****************************************************************************/
|
---|
904 |
|
---|
905 | LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
906 | {
|
---|
907 | LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
|
---|
908 | strcpy( p, str );
|
---|
909 | return p;
|
---|
910 | }
|
---|
911 |
|
---|
912 |
|
---|
913 | /*****************************************************************************
|
---|
914 | * Name :
|
---|
915 | * Purpose :
|
---|
916 | * Parameters:
|
---|
917 | * Variables :
|
---|
918 | * Result :
|
---|
919 | * Remark :
|
---|
920 | * Status :
|
---|
921 | *
|
---|
922 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
923 | *****************************************************************************/
|
---|
924 |
|
---|
925 | LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
926 | {
|
---|
927 | INT len = lstrlenW(str) + 1;
|
---|
928 | LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
|
---|
929 | lstrcpyW( p, str );
|
---|
930 | return p;
|
---|
931 | }
|
---|
932 |
|
---|
933 |
|
---|
934 | /*****************************************************************************
|
---|
935 | * Name :
|
---|
936 | * Purpose :
|
---|
937 | * Parameters:
|
---|
938 | * Variables :
|
---|
939 | * Result :
|
---|
940 | * Remark :
|
---|
941 | * Status :
|
---|
942 | *
|
---|
943 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
944 | *****************************************************************************/
|
---|
945 |
|
---|
946 | LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
947 | {
|
---|
948 | LPWSTR ret;
|
---|
949 |
|
---|
950 | if (!str) return NULL;
|
---|
951 | ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
|
---|
952 | lstrcpyAtoW( ret, (LPSTR)str );
|
---|
953 | return ret;
|
---|
954 | }
|
---|
955 |
|
---|
956 |
|
---|
957 | /*****************************************************************************
|
---|
958 | * Name :
|
---|
959 | * Purpose :
|
---|
960 | * Parameters:
|
---|
961 | * Variables :
|
---|
962 | * Result :
|
---|
963 | * Remark :
|
---|
964 | * Status :
|
---|
965 | *
|
---|
966 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
967 | *****************************************************************************/
|
---|
968 |
|
---|
969 | LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
970 | {
|
---|
971 | LPSTR ret;
|
---|
972 |
|
---|
973 | if (!str) return NULL;
|
---|
974 | ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
|
---|
975 | lstrcpyWtoA( ret, (LPWSTR)str );
|
---|
976 | return ret;
|
---|
977 | }
|
---|
978 |
|
---|
979 |
|
---|
980 | /*****************************************************************************
|
---|
981 | * Name : WideCharToLocal
|
---|
982 | * Purpose : similar lstrcpyWtoA, should handle codepages properly
|
---|
983 | * Parameters:
|
---|
984 | * Variables :
|
---|
985 | * Result : strlen of the destination string
|
---|
986 | * Remark :
|
---|
987 | * Status :
|
---|
988 | *
|
---|
989 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
990 | *****************************************************************************/
|
---|
991 |
|
---|
992 | INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
|
---|
993 | {
|
---|
994 | dprintf2(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
|
---|
995 | pLocal,
|
---|
996 | pWide,
|
---|
997 | dwChars));
|
---|
998 |
|
---|
999 | *pLocal = 0;
|
---|
1000 | WideCharToMultiByte(CP_ACP,
|
---|
1001 | 0,
|
---|
1002 | pWide,
|
---|
1003 | -1,
|
---|
1004 | pLocal,
|
---|
1005 | dwChars,
|
---|
1006 | NULL,
|
---|
1007 | NULL);
|
---|
1008 |
|
---|
1009 | return strlen(pLocal);
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 |
|
---|
1013 | /*****************************************************************************
|
---|
1014 | * Name : LocalToWideChar
|
---|
1015 | * Purpose : similar lstrcpyAtoW, should handle codepages properly
|
---|
1016 | * Parameters:
|
---|
1017 | * Variables :
|
---|
1018 | * Result : strlen of the destination string
|
---|
1019 | * Remark :
|
---|
1020 | * Status :
|
---|
1021 | *
|
---|
1022 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1023 | *****************************************************************************/
|
---|
1024 |
|
---|
1025 | INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
|
---|
1026 | {
|
---|
1027 | *pWide = 0;
|
---|
1028 |
|
---|
1029 | dprintf2(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
|
---|
1030 | pLocal,
|
---|
1031 | pWide,
|
---|
1032 | dwChars));
|
---|
1033 |
|
---|
1034 | MultiByteToWideChar(CP_ACP,
|
---|
1035 | 0,
|
---|
1036 | pLocal,
|
---|
1037 | -1,
|
---|
1038 | pWide,
|
---|
1039 | dwChars);
|
---|
1040 |
|
---|
1041 | return lstrlenW(pWide);
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 |
|
---|
1045 |
|
---|
1046 |
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | #if 0
|
---|
1050 |
|
---|
1051 |
|
---|
1052 | /*****************************************************************************
|
---|
1053 | * Name :
|
---|
1054 | * Purpose :
|
---|
1055 | * Parameters:
|
---|
1056 | * Variables :
|
---|
1057 | * Result :
|
---|
1058 | * Remark :
|
---|
1059 | * Status :
|
---|
1060 | *
|
---|
1061 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1062 | *****************************************************************************/
|
---|
1063 |
|
---|
1064 | // Converts unicode string to ascii string
|
---|
1065 | // returns pointer to ascii string
|
---|
1066 | char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
|
---|
1067 | {
|
---|
1068 | char *astring;
|
---|
1069 |
|
---|
1070 | if(ustring == NULL) return(NULL);
|
---|
1071 |
|
---|
1072 | astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
|
---|
1073 | UnicodeToAscii( ustring, astring );
|
---|
1074 | return(astring);
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 |
|
---|
1078 | /*****************************************************************************
|
---|
1079 | * Name :
|
---|
1080 | * Purpose :
|
---|
1081 | * Parameters:
|
---|
1082 | * Variables :
|
---|
1083 | * Result :
|
---|
1084 | * Remark :
|
---|
1085 | * Status :
|
---|
1086 | *
|
---|
1087 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1088 | *****************************************************************************/
|
---|
1089 |
|
---|
1090 | // Converts ascii string to unicode string
|
---|
1091 | // returns pointer to unicode string
|
---|
1092 | WCHAR * WIN32API AsciiToUnicodeString(char *astring)
|
---|
1093 | {
|
---|
1094 | WCHAR *ustring;
|
---|
1095 |
|
---|
1096 | if(astring == NULL)
|
---|
1097 | return(NULL);
|
---|
1098 |
|
---|
1099 | ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
|
---|
1100 | AsciiToUnicode( astring, ustring );
|
---|
1101 | return(ustring);
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | #endif
|
---|
1105 |
|
---|
1106 |
|
---|
1107 |
|
---|
1108 | /**************************************************************************
|
---|
1109 | * This function is used just locally !
|
---|
1110 | * Description: Inverts a string.
|
---|
1111 | */
|
---|
1112 | static void OLE_InvertString(char* string)
|
---|
1113 | {
|
---|
1114 | char sTmpArray[128];
|
---|
1115 | INT counter, i = 0;
|
---|
1116 |
|
---|
1117 | for (counter = strlen(string); counter > 0; counter--)
|
---|
1118 | {
|
---|
1119 | memcpy(sTmpArray + i, string + counter-1, 1);
|
---|
1120 | i++;
|
---|
1121 | }
|
---|
1122 | memcpy(sTmpArray + i, "\0", 1);
|
---|
1123 | strcpy(string, sTmpArray);
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | /***************************************************************************************
|
---|
1127 | * This function is used just locally !
|
---|
1128 | * Description: Test if the given string (psNumber) is valid or not.
|
---|
1129 | * The valid characters are the following:
|
---|
1130 | * - Characters '0' through '9'.
|
---|
1131 | * - One decimal point (dot) if the number is a floating-point value.
|
---|
1132 | * - A minus sign in the first character position if the number is
|
---|
1133 | * a negative value.
|
---|
1134 | * If the function succeeds, psBefore/psAfter will point to the string
|
---|
1135 | * on the right/left of the decimal symbol. pbNegative indicates if the
|
---|
1136 | * number is negative.
|
---|
1137 | */
|
---|
1138 | static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
|
---|
1139 | {
|
---|
1140 | char sNumberSet[] = "0123456789";
|
---|
1141 | BOOL bInDecimal = FALSE;
|
---|
1142 |
|
---|
1143 | /* Test if we do have a minus sign */
|
---|
1144 | if ( *pInput == '-' )
|
---|
1145 | {
|
---|
1146 | *pbNegative = TRUE;
|
---|
1147 | pInput++; /* Jump to the next character. */
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | while(*pInput != '\0')
|
---|
1151 | {
|
---|
1152 | /* Do we have a valid numeric character */
|
---|
1153 | if ( strchr(sNumberSet, *pInput) != NULL )
|
---|
1154 | {
|
---|
1155 | if (bInDecimal == TRUE)
|
---|
1156 | *psAfter++ = *pInput;
|
---|
1157 | else
|
---|
1158 | *psBefore++ = *pInput;
|
---|
1159 | }
|
---|
1160 | else
|
---|
1161 | {
|
---|
1162 | /* Is this a decimal point (dot) */
|
---|
1163 | if ( *pInput == '.' )
|
---|
1164 | {
|
---|
1165 | /* Is it the first time we find it */
|
---|
1166 | if ((bInDecimal == FALSE))
|
---|
1167 | bInDecimal = TRUE;
|
---|
1168 | else
|
---|
1169 | return -1; /* ERROR: Invalid parameter */
|
---|
1170 | }
|
---|
1171 | else
|
---|
1172 | {
|
---|
1173 | /* It's neither a numeric character, nor a decimal point.
|
---|
1174 | * Thus, return an error.
|
---|
1175 | */
|
---|
1176 | return -1;
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 | pInput++;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | /* Add an End of Line character to the output buffers */
|
---|
1183 | *psBefore = '\0';
|
---|
1184 | *psAfter = '\0';
|
---|
1185 |
|
---|
1186 | return 0;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | /**************************************************************************
|
---|
1190 | * This function is used just locally !
|
---|
1191 | * Description: A number could be formatted using different numbers
|
---|
1192 | * of "digits in group" (example: 4;3;2;0).
|
---|
1193 | * The first parameter of this function is an array
|
---|
1194 | * containing the rule to be used. It's format is the following:
|
---|
1195 | * |NDG|DG1|DG2|...|0|
|
---|
1196 | * where NDG is the number of used "digits in group" and DG1, DG2,
|
---|
1197 | * are the corresponding "digits in group".
|
---|
1198 | * Thus, this function returns the grouping value in the array
|
---|
1199 | * pointed by the second parameter.
|
---|
1200 | */
|
---|
1201 | static INT OLE_GetGrouping(char* sRule, INT index)
|
---|
1202 | {
|
---|
1203 | char sData[2], sRuleSize[2];
|
---|
1204 | INT nData, nRuleSize;
|
---|
1205 |
|
---|
1206 | memcpy(sRuleSize, sRule, 1);
|
---|
1207 | memcpy(sRuleSize+1, "\0", 1);
|
---|
1208 | nRuleSize = atoi(sRuleSize);
|
---|
1209 |
|
---|
1210 | if (index > 0 && index < nRuleSize)
|
---|
1211 | {
|
---|
1212 | memcpy(sData, sRule+index, 1);
|
---|
1213 | memcpy(sData+1, "\0", 1);
|
---|
1214 | nData = atoi(sData);
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | else
|
---|
1218 | {
|
---|
1219 | memcpy(sData, sRule+nRuleSize-1, 1);
|
---|
1220 | memcpy(sData+1, "\0", 1);
|
---|
1221 | nData = atoi(sData);
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | return nData;
|
---|
1225 | }
|
---|