1 | /* $Id: heapstring.cpp,v 1.21 1999-12-06 20:39:38 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;
|
---|
555 |
|
---|
556 | }
|
---|
557 | else
|
---|
558 | {
|
---|
559 | /* idiots unicode conversion :) */
|
---|
560 | for (i = 0; i < unilen-1; i++)
|
---|
561 | {
|
---|
562 | astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
|
---|
563 | if (ustring[i] == 0) return i; //asta la vista, baby
|
---|
564 | }
|
---|
565 |
|
---|
566 | astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
|
---|
567 |
|
---|
568 | return(unilen-1);
|
---|
569 | }
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | /*****************************************************************************
|
---|
574 | * Name :
|
---|
575 | * Purpose :
|
---|
576 | * Parameters:
|
---|
577 | * Variables :
|
---|
578 | * Result :
|
---|
579 | * Remark :
|
---|
580 | * Status :
|
---|
581 | *
|
---|
582 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
583 | *****************************************************************************/
|
---|
584 |
|
---|
585 | // asciilen: max length of unicode buffer (including end 0)
|
---|
586 | // @@@PH 0 termination is NOT necessarily included !
|
---|
587 | int WIN32API lstrcpynAtoW(LPWSTR unicode,
|
---|
588 | LPCSTR ascii,
|
---|
589 | int asciilen)
|
---|
590 | {
|
---|
591 | int rc;
|
---|
592 | int i;
|
---|
593 | size_t uni_chars_left;
|
---|
594 | size_t in_bytes_left;
|
---|
595 | size_t num_subs;
|
---|
596 | UniChar* out_buf;
|
---|
597 | char* in_buf;
|
---|
598 |
|
---|
599 | dprintf2(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
|
---|
600 | ascii,
|
---|
601 | unicode,
|
---|
602 | asciilen));
|
---|
603 |
|
---|
604 | //CB: no input, set at least terminator
|
---|
605 | if (ascii == NULL)
|
---|
606 | {
|
---|
607 | if (unicode != NULL && asciilen > 0) unicode[0] = 0;
|
---|
608 | return 0;
|
---|
609 | }
|
---|
610 |
|
---|
611 | if (unicode == NULL || asciilen <= 0)
|
---|
612 | return 0; //nothing to do
|
---|
613 |
|
---|
614 | if (getUconvObject())
|
---|
615 | {
|
---|
616 | //@@@PH what's this?
|
---|
617 | if ((asciilen == 1) && (*ascii == '\0') )
|
---|
618 | {
|
---|
619 | unicode[0] = 0;
|
---|
620 | return 0;
|
---|
621 | }
|
---|
622 |
|
---|
623 | in_buf = (LPSTR)ascii;
|
---|
624 |
|
---|
625 | //@@@PH what's this?
|
---|
626 | //in_bytes_left = asciilen-1; //buffer size in bytes
|
---|
627 |
|
---|
628 | //SvL: Determine length of ascii string
|
---|
629 | in_bytes_left = strlen(in_buf)+1;
|
---|
630 | in_bytes_left = min(in_bytes_left, asciilen); //buffer size in bytes
|
---|
631 |
|
---|
632 | out_buf = (UniChar*)unicode;
|
---|
633 |
|
---|
634 | uni_chars_left = in_bytes_left; //elements
|
---|
635 |
|
---|
636 | rc = UniUconvToUcs( uconv_object,
|
---|
637 | (void**)&in_buf, &in_bytes_left,
|
---|
638 | &out_buf, &uni_chars_left,
|
---|
639 | &num_subs );
|
---|
640 |
|
---|
641 | //@@@PH what's this?
|
---|
642 | //unicode[asciilen-1-in_bytes_left] = 0;
|
---|
643 |
|
---|
644 | //@@@PH what's this?
|
---|
645 | //return asciilen - 1;
|
---|
646 | return asciilen;
|
---|
647 | }
|
---|
648 | else
|
---|
649 | { //poor man's conversion
|
---|
650 |
|
---|
651 | // for(i = 0;i < asciilen-1;i++)
|
---|
652 | for(i = 0;i < asciilen;i++)
|
---|
653 | {
|
---|
654 | unicode[i] = ascii[i];
|
---|
655 | if (ascii[i] == 0)
|
---|
656 | //return i-1; //work done
|
---|
657 | return i; //work done
|
---|
658 | }
|
---|
659 |
|
---|
660 | // unicode[asciilen-1] = 0;
|
---|
661 | // return asciilen-1;
|
---|
662 | return asciilen;
|
---|
663 | }
|
---|
664 | }
|
---|
665 |
|
---|
666 |
|
---|
667 | /*****************************************************************************
|
---|
668 | * Name :
|
---|
669 | * Purpose : Converts unicode string to ascii string
|
---|
670 | * Parameters:
|
---|
671 | * Variables :
|
---|
672 | * Result : returns length of ascii string
|
---|
673 | * Remark :
|
---|
674 | * Status :
|
---|
675 | *
|
---|
676 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
677 | *****************************************************************************/
|
---|
678 |
|
---|
679 | LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
|
---|
680 | {
|
---|
681 | //@@@PH huh? wuz dat?
|
---|
682 | if (unicode == NULL)
|
---|
683 | {
|
---|
684 | if (unicode != NULL) ((LPWSTR)unicode)[0] = 0; //CB: set at least end
|
---|
685 | return NULL;
|
---|
686 | }
|
---|
687 |
|
---|
688 | if (unicode == NULL)
|
---|
689 | return NULL; /* garbage in, garbage out ! */
|
---|
690 |
|
---|
691 | /* forward to function with len parameter */
|
---|
692 | lstrcpynWtoA(ascii,
|
---|
693 | unicode,
|
---|
694 | UniStrlen((UniChar*)unicode)+1); //end included
|
---|
695 |
|
---|
696 | return ascii;
|
---|
697 | }
|
---|
698 |
|
---|
699 |
|
---|
700 | /*****************************************************************************
|
---|
701 | * Name :
|
---|
702 | * Purpose : Copies the full string from ascii to unicode
|
---|
703 | * Parameters:
|
---|
704 | * Variables :
|
---|
705 | * Result :
|
---|
706 | * Remark :
|
---|
707 | * Status :
|
---|
708 | *
|
---|
709 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
710 | *****************************************************************************/
|
---|
711 |
|
---|
712 | LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
|
---|
713 | {
|
---|
714 | /* achimha for security, strlen might trap if garbage in */
|
---|
715 | /* @@@PH 98/06/07 */
|
---|
716 | if (ascii == NULL)
|
---|
717 | {
|
---|
718 | if (unicode != NULL) unicode[0] = 0; //CB: set at least end
|
---|
719 | return NULL;
|
---|
720 | }
|
---|
721 |
|
---|
722 | if (unicode == NULL)
|
---|
723 | return NULL; /* garbage in, garbage out ! */
|
---|
724 |
|
---|
725 | /* forward to call with length parameter */
|
---|
726 | lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
|
---|
727 | return (unicode);
|
---|
728 | }
|
---|
729 |
|
---|
730 |
|
---|
731 |
|
---|
732 |
|
---|
733 | /*****************************************************************************
|
---|
734 | * Name :
|
---|
735 | * Purpose :
|
---|
736 | * Parameters:
|
---|
737 | * Variables :
|
---|
738 | * Result :
|
---|
739 | * Remark :
|
---|
740 | * Status :
|
---|
741 | *
|
---|
742 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
743 | *****************************************************************************/
|
---|
744 |
|
---|
745 | LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
|
---|
746 | {
|
---|
747 | LPVOID p = HeapAlloc( heap, flags, size );
|
---|
748 | if (!p)
|
---|
749 | {
|
---|
750 | dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
|
---|
751 | heap,
|
---|
752 | flags,
|
---|
753 | size));
|
---|
754 | }
|
---|
755 | return p;
|
---|
756 | }
|
---|
757 |
|
---|
758 |
|
---|
759 | /*****************************************************************************
|
---|
760 | * Name :
|
---|
761 | * Purpose :
|
---|
762 | * Parameters:
|
---|
763 | * Variables :
|
---|
764 | * Result :
|
---|
765 | * Remark :
|
---|
766 | * Status :
|
---|
767 | *
|
---|
768 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
769 | *****************************************************************************/
|
---|
770 |
|
---|
771 | LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
|
---|
772 | {
|
---|
773 | LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
|
---|
774 | if (!p)
|
---|
775 | {
|
---|
776 | dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
|
---|
777 | heap,
|
---|
778 | flags,
|
---|
779 | lpMem,
|
---|
780 | size));
|
---|
781 | }
|
---|
782 | return p;
|
---|
783 | }
|
---|
784 |
|
---|
785 |
|
---|
786 | /*****************************************************************************
|
---|
787 | * Name :
|
---|
788 | * Purpose :
|
---|
789 | * Parameters:
|
---|
790 | * Variables :
|
---|
791 | * Result :
|
---|
792 | * Remark :
|
---|
793 | * Status :
|
---|
794 | *
|
---|
795 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
796 | *****************************************************************************/
|
---|
797 |
|
---|
798 | LPVOID WIN32API HEAP_malloc(DWORD size )
|
---|
799 | {
|
---|
800 | LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
|
---|
801 | if (!p)
|
---|
802 | {
|
---|
803 | dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
|
---|
804 | size));
|
---|
805 | }
|
---|
806 | return p;
|
---|
807 | }
|
---|
808 |
|
---|
809 |
|
---|
810 | /*****************************************************************************
|
---|
811 | * Name :
|
---|
812 | * Purpose :
|
---|
813 | * Parameters:
|
---|
814 | * Variables :
|
---|
815 | * Result :
|
---|
816 | * Remark :
|
---|
817 | * Status :
|
---|
818 | *
|
---|
819 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
820 | *****************************************************************************/
|
---|
821 |
|
---|
822 | LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
|
---|
823 | {
|
---|
824 | LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
|
---|
825 | if (!p)
|
---|
826 | {
|
---|
827 | dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
|
---|
828 | lpMem,
|
---|
829 | size));
|
---|
830 | }
|
---|
831 | return p;
|
---|
832 | }
|
---|
833 |
|
---|
834 |
|
---|
835 | /*****************************************************************************
|
---|
836 | * Name :
|
---|
837 | * Purpose :
|
---|
838 | * Parameters:
|
---|
839 | * Variables :
|
---|
840 | * Result :
|
---|
841 | * Remark :
|
---|
842 | * Status :
|
---|
843 | *
|
---|
844 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
845 | *****************************************************************************/
|
---|
846 |
|
---|
847 | VOID WIN32API HEAP_free(LPVOID lpMem)
|
---|
848 | {
|
---|
849 | dprintf2(("KERNEL32: HEAP_free(%08xh)\n",
|
---|
850 | lpMem));
|
---|
851 |
|
---|
852 | HeapFree( GetProcessHeap(), 0, lpMem);
|
---|
853 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | /*****************************************************************************
|
---|
857 | * Name :
|
---|
858 | * Purpose :
|
---|
859 | * Parameters:
|
---|
860 | * Variables :
|
---|
861 | * Result :
|
---|
862 | * Remark :
|
---|
863 | * Status :
|
---|
864 | *
|
---|
865 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
866 | *****************************************************************************/
|
---|
867 |
|
---|
868 | LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
869 | {
|
---|
870 | LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
|
---|
871 | strcpy( p, str );
|
---|
872 | return p;
|
---|
873 | }
|
---|
874 |
|
---|
875 |
|
---|
876 | /*****************************************************************************
|
---|
877 | * Name :
|
---|
878 | * Purpose :
|
---|
879 | * Parameters:
|
---|
880 | * Variables :
|
---|
881 | * Result :
|
---|
882 | * Remark :
|
---|
883 | * Status :
|
---|
884 | *
|
---|
885 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
886 | *****************************************************************************/
|
---|
887 |
|
---|
888 | LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
889 | {
|
---|
890 | INT len = lstrlenW(str) + 1;
|
---|
891 | LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
|
---|
892 | lstrcpyW( p, str );
|
---|
893 | return p;
|
---|
894 | }
|
---|
895 |
|
---|
896 |
|
---|
897 | /*****************************************************************************
|
---|
898 | * Name :
|
---|
899 | * Purpose :
|
---|
900 | * Parameters:
|
---|
901 | * Variables :
|
---|
902 | * Result :
|
---|
903 | * Remark :
|
---|
904 | * Status :
|
---|
905 | *
|
---|
906 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
907 | *****************************************************************************/
|
---|
908 |
|
---|
909 | LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
|
---|
910 | {
|
---|
911 | LPWSTR ret;
|
---|
912 |
|
---|
913 | if (!str) return NULL;
|
---|
914 | ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
|
---|
915 | lstrcpyAtoW( ret, (LPSTR)str );
|
---|
916 | return ret;
|
---|
917 | }
|
---|
918 |
|
---|
919 |
|
---|
920 | /*****************************************************************************
|
---|
921 | * Name :
|
---|
922 | * Purpose :
|
---|
923 | * Parameters:
|
---|
924 | * Variables :
|
---|
925 | * Result :
|
---|
926 | * Remark :
|
---|
927 | * Status :
|
---|
928 | *
|
---|
929 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
930 | *****************************************************************************/
|
---|
931 |
|
---|
932 | LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
|
---|
933 | {
|
---|
934 | LPSTR ret;
|
---|
935 |
|
---|
936 | if (!str) return NULL;
|
---|
937 | ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
|
---|
938 | lstrcpyWtoA( ret, (LPWSTR)str );
|
---|
939 | return ret;
|
---|
940 | }
|
---|
941 |
|
---|
942 |
|
---|
943 | /*****************************************************************************
|
---|
944 | * Name : WideCharToLocal
|
---|
945 | * Purpose : similar lstrcpyWtoA, should handle codepages properly
|
---|
946 | * Parameters:
|
---|
947 | * Variables :
|
---|
948 | * Result : strlen of the destination string
|
---|
949 | * Remark :
|
---|
950 | * Status :
|
---|
951 | *
|
---|
952 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
953 | *****************************************************************************/
|
---|
954 |
|
---|
955 | INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
|
---|
956 | {
|
---|
957 | dprintf2(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
|
---|
958 | pLocal,
|
---|
959 | pWide,
|
---|
960 | dwChars));
|
---|
961 |
|
---|
962 | *pLocal = 0;
|
---|
963 | WideCharToMultiByte(CP_ACP,
|
---|
964 | 0,
|
---|
965 | pWide,
|
---|
966 | -1,
|
---|
967 | pLocal,
|
---|
968 | dwChars,
|
---|
969 | NULL,
|
---|
970 | NULL);
|
---|
971 |
|
---|
972 | return strlen(pLocal);
|
---|
973 | }
|
---|
974 |
|
---|
975 |
|
---|
976 | /*****************************************************************************
|
---|
977 | * Name : LocalToWideChar
|
---|
978 | * Purpose : similar lstrcpyAtoW, should handle codepages properly
|
---|
979 | * Parameters:
|
---|
980 | * Variables :
|
---|
981 | * Result : strlen of the destination string
|
---|
982 | * Remark :
|
---|
983 | * Status :
|
---|
984 | *
|
---|
985 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
986 | *****************************************************************************/
|
---|
987 |
|
---|
988 | INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
|
---|
989 | {
|
---|
990 | *pWide = 0;
|
---|
991 |
|
---|
992 | dprintf2(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
|
---|
993 | pLocal,
|
---|
994 | pWide,
|
---|
995 | dwChars));
|
---|
996 |
|
---|
997 | MultiByteToWideChar(CP_ACP,
|
---|
998 | 0,
|
---|
999 | pLocal,
|
---|
1000 | -1,
|
---|
1001 | pWide,
|
---|
1002 | dwChars);
|
---|
1003 |
|
---|
1004 | return lstrlenW(pWide);
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 |
|
---|
1008 |
|
---|
1009 |
|
---|
1010 |
|
---|
1011 |
|
---|
1012 | #if 0
|
---|
1013 |
|
---|
1014 |
|
---|
1015 | /*****************************************************************************
|
---|
1016 | * Name :
|
---|
1017 | * Purpose :
|
---|
1018 | * Parameters:
|
---|
1019 | * Variables :
|
---|
1020 | * Result :
|
---|
1021 | * Remark :
|
---|
1022 | * Status :
|
---|
1023 | *
|
---|
1024 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1025 | *****************************************************************************/
|
---|
1026 |
|
---|
1027 | // Converts unicode string to ascii string
|
---|
1028 | // returns pointer to ascii string
|
---|
1029 | char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
|
---|
1030 | {
|
---|
1031 | char *astring;
|
---|
1032 |
|
---|
1033 | if(ustring == NULL) return(NULL);
|
---|
1034 |
|
---|
1035 | astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
|
---|
1036 | UnicodeToAscii( ustring, astring );
|
---|
1037 | return(astring);
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 |
|
---|
1041 | /*****************************************************************************
|
---|
1042 | * Name :
|
---|
1043 | * Purpose :
|
---|
1044 | * Parameters:
|
---|
1045 | * Variables :
|
---|
1046 | * Result :
|
---|
1047 | * Remark :
|
---|
1048 | * Status :
|
---|
1049 | *
|
---|
1050 | * Author : Patrick Haller [Thu, 1999/08/05 20:46]
|
---|
1051 | *****************************************************************************/
|
---|
1052 |
|
---|
1053 | // Converts ascii string to unicode string
|
---|
1054 | // returns pointer to unicode string
|
---|
1055 | WCHAR * WIN32API AsciiToUnicodeString(char *astring)
|
---|
1056 | {
|
---|
1057 | WCHAR *ustring;
|
---|
1058 |
|
---|
1059 | if(astring == NULL)
|
---|
1060 | return(NULL);
|
---|
1061 |
|
---|
1062 | ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
|
---|
1063 | AsciiToUnicode( astring, ustring );
|
---|
1064 | return(ustring);
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | #endif
|
---|
1068 |
|
---|
1069 |
|
---|
1070 |
|
---|