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