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