1 | /* $Id: heapstring.cpp,v 1.36 2001-01-18 18:14:16 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 | if(arg3 == 0) {
|
---|
360 | return NULL;
|
---|
361 | }
|
---|
362 |
|
---|
363 | //PH: looks like either \0 or arg3 terminate the copy
|
---|
364 | //return strncpy(arg1, arg2, arg3);
|
---|
365 | arg3--; // pre-decrement to avoid exceeding buffer length
|
---|
366 | // results in better code than (arg1 > 1)
|
---|
367 |
|
---|
368 | for (;*p2 && arg3; arg3--)
|
---|
369 | *p1++ = *p2++;
|
---|
370 |
|
---|
371 | *p1 = 0; //CB: copy arg-1, set end 0
|
---|
372 |
|
---|
373 | return arg1;
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | /*****************************************************************************
|
---|
378 | * Name :
|
---|
379 | * Purpose :
|
---|
380 | * Parameters:
|
---|
381 | * Variables :
|
---|
382 | * Result :
|
---|
383 | * Remark :
|
---|
384 | * Status :
|
---|
385 | *
|
---|
386 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
387 | *****************************************************************************/
|
---|
388 |
|
---|
389 | LPWSTR WIN32API lstrcpynW(LPWSTR dest, LPCWSTR src, int arg3)
|
---|
390 | {
|
---|
391 | dprintf2(("KERNEL32: lstrcpynW(%08xh,%08xh,%08xh)",
|
---|
392 | dest,
|
---|
393 | src,
|
---|
394 | arg3));
|
---|
395 |
|
---|
396 | if (arg3 == 0)
|
---|
397 | return NULL;
|
---|
398 |
|
---|
399 | UniStrncpy( (UniChar*)dest,
|
---|
400 | (UniChar*)src,
|
---|
401 | arg3-1); //CB: copy arg3-1 characters
|
---|
402 | dest[arg3-1] = 0; //CB: set end
|
---|
403 | return dest;
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 | /*****************************************************************************
|
---|
408 | * Name :
|
---|
409 | * Purpose :
|
---|
410 | * Parameters:
|
---|
411 | * Variables :
|
---|
412 | * Result :
|
---|
413 | * Remark :
|
---|
414 | * Status :
|
---|
415 | *
|
---|
416 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
417 | *****************************************************************************/
|
---|
418 |
|
---|
419 | int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
|
---|
420 | {
|
---|
421 | dprintf2(("KERNEL32: lstrcmpiA(%s,%s)\n",
|
---|
422 | arg1,
|
---|
423 | arg2));
|
---|
424 |
|
---|
425 | if(arg1 == NULL)
|
---|
426 | return -1;
|
---|
427 |
|
---|
428 | if(arg2 == NULL)
|
---|
429 | return 1;
|
---|
430 |
|
---|
431 | return O32_lstrcmpi(arg1, arg2);
|
---|
432 | }
|
---|
433 |
|
---|
434 |
|
---|
435 | /*****************************************************************************
|
---|
436 | * Name :
|
---|
437 | * Purpose :
|
---|
438 | * Parameters:
|
---|
439 | * Variables :
|
---|
440 | * Result :
|
---|
441 | * Remark :
|
---|
442 | * Status :
|
---|
443 | *
|
---|
444 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
445 | *****************************************************************************/
|
---|
446 |
|
---|
447 | int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
|
---|
448 | {
|
---|
449 | char *astr1, *astr2;
|
---|
450 | int rc;
|
---|
451 |
|
---|
452 | dprintf2(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
|
---|
453 | arg1,
|
---|
454 | arg2));
|
---|
455 |
|
---|
456 | if(arg1 == NULL)
|
---|
457 | return -1;
|
---|
458 |
|
---|
459 | if(arg2 == NULL)
|
---|
460 | return 1;
|
---|
461 |
|
---|
462 | // NOTE: This function has no equivalent in uunidef.h
|
---|
463 | astr1 = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
464 | astr2 = UnicodeToAsciiString((LPWSTR)arg2);
|
---|
465 | rc = lstrcmpiA(astr1, astr2);
|
---|
466 | FreeAsciiString(astr2);
|
---|
467 | FreeAsciiString(astr1);
|
---|
468 | return(rc);
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | /*****************************************************************************
|
---|
473 | * Name :
|
---|
474 | * Purpose :
|
---|
475 | * Parameters:
|
---|
476 | * Variables :
|
---|
477 | * Result :
|
---|
478 | * Remark :
|
---|
479 | * Status :
|
---|
480 | *
|
---|
481 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
482 | *****************************************************************************/
|
---|
483 |
|
---|
484 | // unilen: length of astring buffer (including 0 terminator)
|
---|
485 | // returns string length
|
---|
486 |
|
---|
487 | int WIN32API lstrcpynCtoA(LPSTR astring,
|
---|
488 | LPCWSTR ustring,
|
---|
489 | int unilen,
|
---|
490 | UconvObject uconv_object)
|
---|
491 | {
|
---|
492 | int i;
|
---|
493 | int rc;
|
---|
494 | size_t uni_chars_left;
|
---|
495 | size_t out_bytes_left;
|
---|
496 | size_t num_subs;
|
---|
497 | UniChar* in_buf;
|
---|
498 | char* out_buf;
|
---|
499 |
|
---|
500 | dprintf2(("KERNEL32: HeapString: lstrcpynWtoA(%08x,%08xh,%d)\n",
|
---|
501 | astring,
|
---|
502 | ustring,
|
---|
503 | unilen));
|
---|
504 |
|
---|
505 | if (ustring == NULL)
|
---|
506 | {
|
---|
507 | if (astring != NULL && unilen > 0)
|
---|
508 | astring[0] = 0;
|
---|
509 | return 0;
|
---|
510 | }
|
---|
511 |
|
---|
512 | if (astring == NULL || unilen <= 0)
|
---|
513 | return 0;
|
---|
514 |
|
---|
515 | if (uconv_object)
|
---|
516 | {
|
---|
517 | if (unilen == 1)
|
---|
518 | {
|
---|
519 | astring[0] = 0;
|
---|
520 | return 0; //no data
|
---|
521 | }
|
---|
522 |
|
---|
523 | //SvL: Determine length of unicode string
|
---|
524 | uni_chars_left = UniStrlen((UniChar*)ustring)+1;
|
---|
525 | uni_chars_left = min(uni_chars_left, unilen);
|
---|
526 | unilen = uni_chars_left;
|
---|
527 |
|
---|
528 | out_bytes_left = uni_chars_left; //size in bytes == elements
|
---|
529 | in_buf = (UniChar*)ustring;
|
---|
530 | out_buf = astring;
|
---|
531 | rc = UniUconvFromUcs(uconv_object,
|
---|
532 | &in_buf, &uni_chars_left,
|
---|
533 | (void**)&out_buf, &out_bytes_left,
|
---|
534 | &num_subs);
|
---|
535 |
|
---|
536 | /* @@@PH 2000/08/10
|
---|
537 | * this causes the last character in the converted
|
---|
538 | * target string to be chopped off. I.e. causes CMD.EXE
|
---|
539 | * to loose the CRLF functionality.
|
---|
540 | */
|
---|
541 | /*
|
---|
542 | unilen -= 1+out_bytes_left; //end + left bytes
|
---|
543 | astring[unilen] = 0; //terminate
|
---|
544 | */
|
---|
545 |
|
---|
546 | return unilen; //length of string (excluding terminator)
|
---|
547 | }
|
---|
548 | else
|
---|
549 | {
|
---|
550 | /* idiots unicode conversion :) */
|
---|
551 | for (i = 0; i < unilen-1; i++)
|
---|
552 | {
|
---|
553 | astring[i] = (ustring[i] > 255) ? (char)0x20 : (char)ustring[i]; //CB: handle invalid characters as space
|
---|
554 | if (ustring[i] == 0) return i; //asta la vista, baby
|
---|
555 | }
|
---|
556 |
|
---|
557 | // astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
|
---|
558 | // return(unilen-1);
|
---|
559 | return unilen;
|
---|
560 | }
|
---|
561 | }
|
---|
562 |
|
---|
563 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
564 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
565 | int WIN32API lstrcpynWtoA(LPSTR astring,
|
---|
566 | LPCWSTR ustring,
|
---|
567 | int unilen)
|
---|
568 | {
|
---|
569 | int ret;
|
---|
570 |
|
---|
571 | ret = lstrcpynCtoA(astring, ustring, unilen, GetWindowsUconvObject());
|
---|
572 | //Must not always set the last character to 0; some apps send the wrong
|
---|
573 | //string size to apis that use this function (i.e. GetMenuStringW (Notes))
|
---|
574 | //-> overwrites stack
|
---|
575 | if(ret == unilen) {
|
---|
576 | astring[unilen-1] = 0;
|
---|
577 | }
|
---|
578 | else astring[ret] = 0;
|
---|
579 |
|
---|
580 | return ret;
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | /*****************************************************************************
|
---|
585 | * Name :
|
---|
586 | * Purpose :
|
---|
587 | * Parameters:
|
---|
588 | * Variables :
|
---|
589 | * Result :
|
---|
590 | * Remark :
|
---|
591 | * Status :
|
---|
592 | *
|
---|
593 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
594 | *****************************************************************************/
|
---|
595 |
|
---|
596 | // asciilen: max length of unicode buffer (including end 0)
|
---|
597 | // @@@PH 0 termination is NOT necessarily included !
|
---|
598 | int lstrcpynAtoC(LPWSTR unicode,
|
---|
599 | LPCSTR ascii,
|
---|
600 | int asciilen,
|
---|
601 | UconvObject uconv_object)
|
---|
602 | {
|
---|
603 | int rc;
|
---|
604 | int i;
|
---|
605 | size_t uni_chars_left;
|
---|
606 | size_t in_bytes_left;
|
---|
607 | size_t num_subs;
|
---|
608 | UniChar* out_buf;
|
---|
609 | char* in_buf;
|
---|
610 |
|
---|
611 | dprintf2(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
|
---|
612 | ascii,
|
---|
613 | unicode,
|
---|
614 | asciilen));
|
---|
615 |
|
---|
616 | //CB: no input, set at least terminator
|
---|
617 | if (ascii == NULL)
|
---|
618 | {
|
---|
619 | if (unicode != NULL && asciilen > 0) unicode[0] = 0;
|
---|
620 | return 0;
|
---|
621 | }
|
---|
622 |
|
---|
623 | if (unicode == NULL || asciilen <= 0)
|
---|
624 | return 0; //nothing to do
|
---|
625 |
|
---|
626 | if (uconv_object)
|
---|
627 | {
|
---|
628 | //@@@PH what's this?
|
---|
629 | if ((asciilen == 1) && (*ascii == '\0') )
|
---|
630 | {
|
---|
631 | unicode[0] = 0;
|
---|
632 | return 0;
|
---|
633 | }
|
---|
634 |
|
---|
635 | in_buf = (LPSTR)ascii;
|
---|
636 |
|
---|
637 | //@@@PH what's this?
|
---|
638 | //in_bytes_left = asciilen-1; //buffer size in bytes
|
---|
639 |
|
---|
640 | //SvL: Determine length of ascii string
|
---|
641 | in_bytes_left = strlen(in_buf)+1;
|
---|
642 | in_bytes_left = asciilen = min(in_bytes_left, asciilen); //buffer size in bytes
|
---|
643 |
|
---|
644 | out_buf = (UniChar*)unicode;
|
---|
645 |
|
---|
646 | uni_chars_left = in_bytes_left; //elements
|
---|
647 |
|
---|
648 | rc = UniUconvToUcs( uconv_object,
|
---|
649 | (void**)&in_buf, &in_bytes_left,
|
---|
650 | &out_buf, &uni_chars_left,
|
---|
651 | &num_subs );
|
---|
652 |
|
---|
653 | /* @@@PH 2000/08/10
|
---|
654 | * this causes the last character in the converted
|
---|
655 | * target string to be chopped off. I.e. causes CMD.EXE
|
---|
656 | * to enter command correctly.
|
---|
657 | */
|
---|
658 | /*
|
---|
659 | asciilen -= 1+uni_chars_left; //end + left bytes
|
---|
660 |
|
---|
661 | unicode[asciilen] = 0; // always terminate string
|
---|
662 | */
|
---|
663 |
|
---|
664 | return asciilen; //length of string (excluding terminator)
|
---|
665 | }
|
---|
666 | else
|
---|
667 | { //poor man's conversion
|
---|
668 |
|
---|
669 | // for(i = 0;i < asciilen-1;i++)
|
---|
670 | for(i = 0;i < asciilen;i++)
|
---|
671 | {
|
---|
672 | unicode[i] = ascii[i];
|
---|
673 | if (ascii[i] == 0)
|
---|
674 | //return i-1; //work done
|
---|
675 | return i; //work done
|
---|
676 | }
|
---|
677 |
|
---|
678 | // unicode[asciilen-1] = 0;
|
---|
679 | // return asciilen-1;
|
---|
680 | return asciilen;
|
---|
681 | }
|
---|
682 | }
|
---|
683 |
|
---|
684 | //lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
|
---|
685 | //because Wine code depends on this behaviour (i.e. comdlg32)
|
---|
686 | int WIN32API lstrcpynAtoW(LPWSTR unicode,
|
---|
687 | LPCSTR ascii,
|
---|
688 | int asciilen)
|
---|
689 | {
|
---|
690 | int ret;
|
---|
691 |
|
---|
692 | ret = lstrcpynAtoC(unicode, ascii, asciilen, GetWindowsUconvObject());
|
---|
693 | //Must not always set the last character to 0; some apps send the wrong
|
---|
694 | //string size to apis that use this function (i.e. GetMenuStringW (Notes))
|
---|
695 | //-> overwrites stack
|
---|
696 | if(ret == asciilen) {
|
---|
697 | unicode[asciilen-1] = 0;
|
---|
698 | }
|
---|
699 | else unicode[ret] = 0;
|
---|
700 | return ret;
|
---|
701 | }
|
---|
702 |
|
---|
703 | /*****************************************************************************
|
---|
704 | * Name :
|
---|
705 | * Purpose : Converts unicode string to ascii string
|
---|
706 | * Parameters:
|
---|
707 | * Variables :
|
---|
708 | * Result : returns length of ascii string
|
---|
709 | * Remark :
|
---|
710 | * Status :
|
---|
711 | *
|
---|
712 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
713 | *****************************************************************************/
|
---|
714 |
|
---|
715 | LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
|
---|
716 | {
|
---|
717 | //@@@PH huh? wuz dat?
|
---|
718 | if (unicode == NULL)
|
---|
719 | {
|
---|
720 | if (unicode != NULL) ((LPWSTR)unicode)[0] = 0; //CB: set at least end
|
---|
721 | return NULL;
|
---|
722 | }
|
---|
723 |
|
---|
724 | if (unicode == NULL)
|
---|
725 | return NULL; /* garbage in, garbage out ! */
|
---|
726 |
|
---|
727 | /* forward to function with len parameter */
|
---|
728 | lstrcpynWtoA(ascii,
|
---|
729 | unicode,
|
---|
730 | UniStrlen((UniChar*)unicode)+1); //end included
|
---|
731 |
|
---|
732 | return ascii;
|
---|
733 | }
|
---|
734 |
|
---|
735 |
|
---|
736 | /*****************************************************************************
|
---|
737 | * Name :
|
---|
738 | * Purpose : Copies the full string from ascii to unicode
|
---|
739 | * Parameters:
|
---|
740 | * Variables :
|
---|
741 | * Result :
|
---|
742 | * Remark :
|
---|
743 | * Status :
|
---|
744 | *
|
---|
745 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
746 | *****************************************************************************/
|
---|
747 |
|
---|
748 | LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
|
---|
749 | {
|
---|
750 | /* achimha for security, strlen might trap if garbage in */
|
---|
751 | /* @@@PH 98/06/07 */
|
---|
752 | if (ascii == NULL)
|
---|
753 | {
|
---|
754 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
755 | return NULL;
|
---|
756 | }
|
---|
757 |
|
---|
758 | if (unicode == NULL)
|
---|
759 | return NULL; /* garbage in, garbage out ! */
|
---|
760 |
|
---|
761 | /* forward to call with length parameter */
|
---|
762 | lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
|
---|
763 | return (unicode);
|
---|
764 | }
|
---|
765 |
|
---|
766 |
|
---|
767 |
|
---|
768 |
|
---|
769 | /*****************************************************************************
|
---|
770 | * Name :
|
---|
771 | * Purpose :
|
---|
772 | * Parameters:
|
---|
773 | * Variables :
|
---|
774 | * Result :
|
---|
775 | * Remark :
|
---|
776 | * Status :
|
---|
777 | *
|
---|
778 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
779 | *****************************************************************************/
|
---|
780 |
|
---|
781 | LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
|
---|
782 | {
|
---|
783 | LPVOID p = HeapAlloc( heap, flags, size );
|
---|
784 | if (!p)
|
---|
785 | {
|
---|
786 | dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
|
---|
787 | heap,
|
---|
788 | flags,
|
---|
789 | size));
|
---|
790 | }
|
---|
791 | return p;
|
---|
792 | }
|
---|
793 |
|
---|
794 |
|
---|
795 | /*****************************************************************************
|
---|
796 | * Name :
|
---|
797 | * Purpose :
|
---|
798 | * Parameters:
|
---|
799 | * Variables :
|
---|
800 | * Result :
|
---|
801 | * Remark :
|
---|
802 | * Status :
|
---|
803 | *
|
---|
804 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
805 | *****************************************************************************/
|
---|
806 |
|
---|
807 | LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
|
---|
808 | {
|
---|
809 | LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
|
---|
810 | if (!p)
|
---|
811 | {
|
---|
812 | dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
|
---|
813 | heap,
|
---|
814 | flags,
|
---|
815 | lpMem,
|
---|
816 | size));
|
---|
817 | }
|
---|
818 | return p;
|
---|
819 | }
|
---|
820 |
|
---|
821 |
|
---|
822 | /*****************************************************************************
|
---|
823 | * Name :
|
---|
824 | * Purpose :
|
---|
825 | * Parameters:
|
---|
826 | * Variables :
|
---|
827 | * Result :
|
---|
828 | * Remark :
|
---|
829 | * Status :
|
---|
830 | *
|
---|
831 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
832 | *****************************************************************************/
|
---|
833 |
|
---|
834 | LPVOID WIN32API HEAP_malloc(DWORD size )
|
---|
835 | {
|
---|
836 | LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
|
---|
837 | if (!p)
|
---|
838 | {
|
---|
839 | dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
|
---|
840 | size));
|
---|
841 | }
|
---|
842 | return p;
|
---|
843 | }
|
---|
844 |
|
---|
845 |
|
---|
846 | /*****************************************************************************
|
---|
847 | * Name :
|
---|
848 | * Purpose :
|
---|
849 | * Parameters:
|
---|
850 | * Variables :
|
---|
851 | * Result :
|
---|
852 | * Remark :
|
---|
853 | * Status :
|
---|
854 | *
|
---|
855 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
856 | *****************************************************************************/
|
---|
857 |
|
---|
858 | DWORD WIN32API HEAP_size(LPVOID lpMem)
|
---|
859 | {
|
---|
860 | return HeapSize( GetProcessHeap(), 0, lpMem );
|
---|
861 | }
|
---|
862 |
|
---|
863 |
|
---|
864 | /*****************************************************************************
|
---|
865 | * Name :
|
---|
866 | * Purpose :
|
---|
867 | * Parameters:
|
---|
868 | * Variables :
|
---|
869 | * Result :
|
---|
870 | * Remark :
|
---|
871 | * Status :
|
---|
872 | *
|
---|
873 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
874 | *****************************************************************************/
|
---|
875 |
|
---|
876 | LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
|
---|
877 | {
|
---|
878 | LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
|
---|
879 | if (!p)
|
---|
880 | {
|
---|
881 | dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
|
---|
882 | lpMem,
|
---|
883 | size));
|
---|
884 | }
|
---|
885 | return p;
|
---|
886 | }
|
---|
887 |
|
---|
888 |
|
---|
889 | /*****************************************************************************
|
---|
890 | * Name :
|
---|
891 | * Purpose :
|
---|
892 | * Parameters:
|
---|
893 | * Variables :
|
---|
894 | * Result :
|
---|
895 | * Remark :
|
---|
896 | * Status :
|
---|
897 | *
|
---|
898 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
899 | *****************************************************************************/
|
---|
900 |
|
---|
901 | VOID WIN32API HEAP_free(LPVOID lpMem)
|
---|
902 | {
|
---|
903 | dprintf2(("KERNEL32: HEAP_free(%08xh)\n",
|
---|
904 | lpMem));
|
---|
905 |
|
---|
906 | HeapFree( GetProcessHeap(), 0, lpMem);
|
---|
907 | }
|
---|
908 |
|
---|
909 |
|
---|
910 | /*****************************************************************************
|
---|
911 | * Name :
|
---|
912 | * Purpose :
|
---|
913 | * Parameters:
|
---|
914 | * Variables :
|
---|
915 | * Result :
|
---|
916 | * Remark :
|
---|
917 | * Status :
|
---|
918 | *
|
---|
919 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
920 | *****************************************************************************/
|
---|
921 |
|
---|
922 | LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
923 | {
|
---|
924 | LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
|
---|
925 | strcpy( p, str );
|
---|
926 | return p;
|
---|
927 | }
|
---|
928 |
|
---|
929 |
|
---|
930 | /*****************************************************************************
|
---|
931 | * Name :
|
---|
932 | * Purpose :
|
---|
933 | * Parameters:
|
---|
934 | * Variables :
|
---|
935 | * Result :
|
---|
936 | * Remark :
|
---|
937 | * Status :
|
---|
938 | *
|
---|
939 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
940 | *****************************************************************************/
|
---|
941 |
|
---|
942 | LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
943 | {
|
---|
944 | INT len = lstrlenW(str) + 1;
|
---|
945 | LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
|
---|
946 | lstrcpyW( p, str );
|
---|
947 | return p;
|
---|
948 | }
|
---|
949 |
|
---|
950 |
|
---|
951 | /*****************************************************************************
|
---|
952 | * Name :
|
---|
953 | * Purpose :
|
---|
954 | * Parameters:
|
---|
955 | * Variables :
|
---|
956 | * Result :
|
---|
957 | * Remark :
|
---|
958 | * Status :
|
---|
959 | *
|
---|
960 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
961 | *****************************************************************************/
|
---|
962 |
|
---|
963 | LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
964 | {
|
---|
965 | LPWSTR ret;
|
---|
966 |
|
---|
967 | if (!str) return NULL;
|
---|
968 | ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
|
---|
969 | lstrcpyAtoW( ret, (LPSTR)str );
|
---|
970 | return ret;
|
---|
971 | }
|
---|
972 |
|
---|
973 |
|
---|
974 | /*****************************************************************************
|
---|
975 | * Name :
|
---|
976 | * Purpose :
|
---|
977 | * Parameters:
|
---|
978 | * Variables :
|
---|
979 | * Result :
|
---|
980 | * Remark :
|
---|
981 | * Status :
|
---|
982 | *
|
---|
983 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
984 | *****************************************************************************/
|
---|
985 |
|
---|
986 | LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
987 | {
|
---|
988 | LPSTR ret;
|
---|
989 |
|
---|
990 | if (!str) return NULL;
|
---|
991 | ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
|
---|
992 | lstrcpyWtoA( ret, (LPWSTR)str );
|
---|
993 | return ret;
|
---|
994 | }
|
---|
995 |
|
---|
996 |
|
---|
997 | /*****************************************************************************
|
---|
998 | * Name : WideCharToLocal
|
---|
999 | * Purpose : similar lstrcpyWtoA, should handle codepages properly
|
---|
1000 | * Parameters:
|
---|
1001 | * Variables :
|
---|
1002 | * Result : strlen of the destination string
|
---|
1003 | * Remark :
|
---|
1004 | * Status :
|
---|
1005 | *
|
---|
1006 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1007 | *****************************************************************************/
|
---|
1008 |
|
---|
1009 | INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
|
---|
1010 | {
|
---|
1011 | dprintf2(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
|
---|
1012 | pLocal,
|
---|
1013 | pWide,
|
---|
1014 | dwChars));
|
---|
1015 |
|
---|
1016 | *pLocal = 0;
|
---|
1017 | WideCharToMultiByte(CP_ACP,
|
---|
1018 | 0,
|
---|
1019 | pWide,
|
---|
1020 | -1,
|
---|
1021 | pLocal,
|
---|
1022 | dwChars,
|
---|
1023 | NULL,
|
---|
1024 | NULL);
|
---|
1025 |
|
---|
1026 | return strlen(pLocal);
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 |
|
---|
1030 | /*****************************************************************************
|
---|
1031 | * Name : LocalToWideChar
|
---|
1032 | * Purpose : similar lstrcpyAtoW, should handle codepages properly
|
---|
1033 | * Parameters:
|
---|
1034 | * Variables :
|
---|
1035 | * Result : strlen of the destination string
|
---|
1036 | * Remark :
|
---|
1037 | * Status :
|
---|
1038 | *
|
---|
1039 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1040 | *****************************************************************************/
|
---|
1041 |
|
---|
1042 | INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
|
---|
1043 | {
|
---|
1044 | *pWide = 0;
|
---|
1045 |
|
---|
1046 | dprintf2(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
|
---|
1047 | pLocal,
|
---|
1048 | pWide,
|
---|
1049 | dwChars));
|
---|
1050 |
|
---|
1051 | MultiByteToWideChar(CP_ACP,
|
---|
1052 | 0,
|
---|
1053 | pLocal,
|
---|
1054 | -1,
|
---|
1055 | pWide,
|
---|
1056 | dwChars);
|
---|
1057 |
|
---|
1058 | return lstrlenW(pWide);
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 |
|
---|
1062 |
|
---|
1063 |
|
---|
1064 |
|
---|
1065 |
|
---|
1066 | #if 0
|
---|
1067 |
|
---|
1068 |
|
---|
1069 | /*****************************************************************************
|
---|
1070 | * Name :
|
---|
1071 | * Purpose :
|
---|
1072 | * Parameters:
|
---|
1073 | * Variables :
|
---|
1074 | * Result :
|
---|
1075 | * Remark :
|
---|
1076 | * Status :
|
---|
1077 | *
|
---|
1078 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1079 | *****************************************************************************/
|
---|
1080 |
|
---|
1081 | // Converts unicode string to ascii string
|
---|
1082 | // returns pointer to ascii string
|
---|
1083 | char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
|
---|
1084 | {
|
---|
1085 | char *astring;
|
---|
1086 |
|
---|
1087 | if(ustring == NULL) return(NULL);
|
---|
1088 |
|
---|
1089 | astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
|
---|
1090 | UnicodeToAscii( ustring, astring );
|
---|
1091 | return(astring);
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 |
|
---|
1095 | /*****************************************************************************
|
---|
1096 | * Name :
|
---|
1097 | * Purpose :
|
---|
1098 | * Parameters:
|
---|
1099 | * Variables :
|
---|
1100 | * Result :
|
---|
1101 | * Remark :
|
---|
1102 | * Status :
|
---|
1103 | *
|
---|
1104 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1105 | *****************************************************************************/
|
---|
1106 |
|
---|
1107 | // Converts ascii string to unicode string
|
---|
1108 | // returns pointer to unicode string
|
---|
1109 | WCHAR * WIN32API AsciiToUnicodeString(char *astring)
|
---|
1110 | {
|
---|
1111 | WCHAR *ustring;
|
---|
1112 |
|
---|
1113 | if(astring == NULL)
|
---|
1114 | return(NULL);
|
---|
1115 |
|
---|
1116 | ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
|
---|
1117 | AsciiToUnicode( astring, ustring );
|
---|
1118 | return(ustring);
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | #endif
|
---|
1122 |
|
---|
1123 |
|
---|
1124 |
|
---|
1125 | /**************************************************************************
|
---|
1126 | * This function is used just locally !
|
---|
1127 | * Description: Inverts a string.
|
---|
1128 | */
|
---|
1129 | static void OLE_InvertString(char* string)
|
---|
1130 | {
|
---|
1131 | char sTmpArray[128];
|
---|
1132 | INT counter, i = 0;
|
---|
1133 |
|
---|
1134 | for (counter = strlen(string); counter > 0; counter--)
|
---|
1135 | {
|
---|
1136 | memcpy(sTmpArray + i, string + counter-1, 1);
|
---|
1137 | i++;
|
---|
1138 | }
|
---|
1139 | memcpy(sTmpArray + i, "\0", 1);
|
---|
1140 | strcpy(string, sTmpArray);
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /***************************************************************************************
|
---|
1144 | * This function is used just locally !
|
---|
1145 | * Description: Test if the given string (psNumber) is valid or not.
|
---|
1146 | * The valid characters are the following:
|
---|
1147 | * - Characters '0' through '9'.
|
---|
1148 | * - One decimal point (dot) if the number is a floating-point value.
|
---|
1149 | * - A minus sign in the first character position if the number is
|
---|
1150 | * a negative value.
|
---|
1151 | * If the function succeeds, psBefore/psAfter will point to the string
|
---|
1152 | * on the right/left of the decimal symbol. pbNegative indicates if the
|
---|
1153 | * number is negative.
|
---|
1154 | */
|
---|
1155 | static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
|
---|
1156 | {
|
---|
1157 | char sNumberSet[] = "0123456789";
|
---|
1158 | BOOL bInDecimal = FALSE;
|
---|
1159 |
|
---|
1160 | /* Test if we do have a minus sign */
|
---|
1161 | if ( *pInput == '-' )
|
---|
1162 | {
|
---|
1163 | *pbNegative = TRUE;
|
---|
1164 | pInput++; /* Jump to the next character. */
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | while(*pInput != '\0')
|
---|
1168 | {
|
---|
1169 | /* Do we have a valid numeric character */
|
---|
1170 | if ( strchr(sNumberSet, *pInput) != NULL )
|
---|
1171 | {
|
---|
1172 | if (bInDecimal == TRUE)
|
---|
1173 | *psAfter++ = *pInput;
|
---|
1174 | else
|
---|
1175 | *psBefore++ = *pInput;
|
---|
1176 | }
|
---|
1177 | else
|
---|
1178 | {
|
---|
1179 | /* Is this a decimal point (dot) */
|
---|
1180 | if ( *pInput == '.' )
|
---|
1181 | {
|
---|
1182 | /* Is it the first time we find it */
|
---|
1183 | if ((bInDecimal == FALSE))
|
---|
1184 | bInDecimal = TRUE;
|
---|
1185 | else
|
---|
1186 | return -1; /* ERROR: Invalid parameter */
|
---|
1187 | }
|
---|
1188 | else
|
---|
1189 | {
|
---|
1190 | /* It's neither a numeric character, nor a decimal point.
|
---|
1191 | * Thus, return an error.
|
---|
1192 | */
|
---|
1193 | return -1;
|
---|
1194 | }
|
---|
1195 | }
|
---|
1196 | pInput++;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | /* Add an End of Line character to the output buffers */
|
---|
1200 | *psBefore = '\0';
|
---|
1201 | *psAfter = '\0';
|
---|
1202 |
|
---|
1203 | return 0;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | /**************************************************************************
|
---|
1207 | * This function is used just locally !
|
---|
1208 | * Description: A number could be formatted using different numbers
|
---|
1209 | * of "digits in group" (example: 4;3;2;0).
|
---|
1210 | * The first parameter of this function is an array
|
---|
1211 | * containing the rule to be used. It's format is the following:
|
---|
1212 | * |NDG|DG1|DG2|...|0|
|
---|
1213 | * where NDG is the number of used "digits in group" and DG1, DG2,
|
---|
1214 | * are the corresponding "digits in group".
|
---|
1215 | * Thus, this function returns the grouping value in the array
|
---|
1216 | * pointed by the second parameter.
|
---|
1217 | */
|
---|
1218 | static INT OLE_GetGrouping(char* sRule, INT index)
|
---|
1219 | {
|
---|
1220 | char sData[2], sRuleSize[2];
|
---|
1221 | INT nData, nRuleSize;
|
---|
1222 |
|
---|
1223 | memcpy(sRuleSize, sRule, 1);
|
---|
1224 | memcpy(sRuleSize+1, "\0", 1);
|
---|
1225 | nRuleSize = atoi(sRuleSize);
|
---|
1226 |
|
---|
1227 | if (index > 0 && index < nRuleSize)
|
---|
1228 | {
|
---|
1229 | memcpy(sData, sRule+index, 1);
|
---|
1230 | memcpy(sData+1, "\0", 1);
|
---|
1231 | nData = atoi(sData);
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | else
|
---|
1235 | {
|
---|
1236 | memcpy(sData, sRule+nRuleSize-1, 1);
|
---|
1237 | memcpy(sData+1, "\0", 1);
|
---|
1238 | nData = atoi(sData);
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | return nData;
|
---|
1242 | }
|
---|