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