source: trunk/src/kernel32/heapstring.cpp@ 4363

Last change on this file since 4363 was 4363, checked in by phaller, 25 years ago

Added HEAP_size

File size: 28.6 KB
Line 
1/* $Id: heapstring.cpp,v 1.33 2000-10-02 13:05:37 phaller Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 *
6 * Win32 compatibility string functions for OS/2
7 *
8 * NOTE: lstrcpyn* always appends a terminating 0 (unlike strncpy)!
9 *
10 * Copyright 1999 Patrick Haller
11 */
12
13/*****************************************************************************
14 * Includes *
15 *****************************************************************************/
16
17#include <odin.h>
18#include <odinwrap.h>
19#include <os2sel.h>
20
21#include <os2win.h>
22#include <stdlib.h>
23#include <string.h>
24#include <stdio.h>
25#include <winnls.h>
26#include <unicode.h>
27#include <ctype.h>
28#include <wcstr.h>
29#include "heap.h"
30#include <heapstring.h>
31#include "misc.h"
32#include "codepage.h"
33
34#define DBG_LOCALLOG DBG_heapstring
35#include "dbglocal.h"
36
37/*****************************************************************************
38 * Defines *
39 *****************************************************************************/
40
41ODINDEBUGCHANNEL(KERNEL32-HEAPSTRING)
42
43/*****************************************************************************
44 * Name :
45 * Purpose :
46 * Parameters:
47 * Variables :
48 * Result :
49 * Remark :
50 * Status :
51 *
52 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
53 *****************************************************************************/
54
55int WIN32API lstrlenA(LPCSTR arg1)
56{
57 dprintf2(("KERNEL32: lstrlenA(%s)\n",
58 arg1));
59
60 return O32_lstrlen(arg1);
61}
62
63
64/*****************************************************************************
65 * Name :
66 * Purpose :
67 * Parameters:
68 * Variables :
69 * Result :
70 * Remark :
71 * Status :
72 *
73 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
74 *****************************************************************************/
75
76int WIN32API lstrlenW(LPCWSTR arg1)
77{
78 int rc;
79
80 rc = UniStrlen( (UniChar*)arg1);
81 dprintf2(("KERNEL32: lstrlenW(%08xh) returns %d\n",
82 arg1,
83 rc));
84 return rc;
85}
86
87
88/*****************************************************************************
89 * Name :
90 * Purpose :
91 * Parameters:
92 * Variables :
93 * Result :
94 * Remark :
95 * Status :
96 *
97 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
98 *****************************************************************************/
99
100LPSTR WIN32API lstrcatA(LPSTR arg1, LPCSTR arg2)
101{
102 dprintf2(("KERNEL32: lstrcat(%s,%s)\n",
103 arg1,
104 arg2));
105
106 if(arg2 == NULL)
107 return arg1;
108 strcat(arg1, arg2);
109 return arg1;
110}
111
112
113/*****************************************************************************
114 * Name :
115 * Purpose :
116 * Parameters:
117 * Variables :
118 * Result :
119 * Remark :
120 * Status :
121 *
122 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
123 *****************************************************************************/
124
125LPWSTR WIN32API lstrcatW(LPWSTR arg1, LPCWSTR arg2)
126{
127 dprintf2(("KERNEL32: OS2lstrcatW(%08xh,%08xh)\n",
128 arg1,
129 arg2));
130
131 if(arg2 == NULL)
132 return arg1;
133
134 UniStrcat( (UniChar*) arg1, (UniChar*) arg2 );
135 return arg1;
136}
137
138
139/*****************************************************************************
140 * Name :
141 * Purpose :
142 * Parameters:
143 * Variables :
144 * Result :
145 * Remark :
146 * Status :
147 *
148 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
149 *****************************************************************************/
150
151int WIN32API lstrcmpA(LPCSTR arg1, LPCSTR arg2)
152{
153 dprintf2(("KERNEL32: OS2lstrcmpA(%s,%s)\n",
154 arg1,
155 arg2));
156
157 if(arg1 == NULL)
158 return -1;
159 if(arg2 == NULL)
160 return 1;
161
162 return O32_lstrcmp(arg1, arg2);
163}
164
165
166/*****************************************************************************
167 * Name :
168 * Purpose :
169 * Parameters:
170 * Variables :
171 * Result :
172 * Remark :
173 * Status :
174 *
175 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
176 *****************************************************************************/
177
178int WIN32API lstrncmpA(LPCSTR arg1, LPCSTR arg2, int l)
179{
180 dprintf2(("KERNEL32: OS2lstrncmpA(%s,%s,%d)\n",
181 arg1,
182 arg2,
183 l));
184
185 return strncmp(arg1, arg2, l);
186}
187
188/*****************************************************************************
189 * Name : lstrncmpiA
190 * Purpose :
191 * Parameters:
192 * Variables :
193 * Result :
194 * Remark :
195 * Status :
196 *
197 * Author : Przemyslaw Dobrowolski
198 *****************************************************************************/
199INT WINAPI lstrncmpiA( LPCSTR str1, LPCSTR str2, INT n )
200{
201 INT firstch,lastch;
202 INT result = 0;
203
204 if (n)
205 {
206 do
207 {
208 firstch = tolower(*str1);
209 lastch = tolower(*str2);
210 str1++;
211 str2++;
212 } while (--n && str1 && str2 && firstch == lastch);
213
214 result = firstch - lastch;
215 }
216
217 return(result);
218}
219//TODO: Don't know if this is completely correct
220int WIN32API lstrncmpiW(LPCWSTR str1, LPCWSTR str2, int n)
221{
222 INT firstch,lastch;
223 INT result = 0;
224
225 if (n)
226 {
227 do
228 {
229 firstch = tolower((char)*str1);
230 lastch = tolower((char)*str2);
231 str1++;
232 str2++;
233 } while (--n && str1 && str2 && firstch == lastch);
234
235 result = firstch - lastch;
236 }
237
238 return(result);
239}
240
241/*****************************************************************************
242 * Name :
243 * Purpose :
244 * Parameters:
245 * Variables :
246 * Result :
247 * Remark :
248 * Status :
249 *
250 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
251 *****************************************************************************/
252
253int WIN32API lstrcmpW(LPCWSTR arg1, LPCWSTR arg2)
254{
255 dprintf2(("KERNEL32: lstrcmpW (%08xh, %08xh)\n",
256 arg1,
257 arg2));
258
259 if(arg1 == NULL)
260 return -1;
261 if(arg2 == NULL)
262 return 1;
263
264 return wcscmp( (wchar_t*)arg1,
265 (wchar_t*)arg2 );
266}
267
268
269/*****************************************************************************
270 * Name :
271 * Purpose :
272 * Parameters:
273 * Variables :
274 * Result :
275 * Remark :
276 * Status :
277 *
278 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
279 *****************************************************************************/
280
281int WIN32API lstrncmpW(LPCWSTR arg1, LPCWSTR arg2, int l)
282{
283 dprintf2(("KERNEL32: OS2lstrncmpW(%08xh,%08xh,%d)\n",
284 arg1,
285 arg2,
286 l));
287
288 return wcsncmp((wchar_t*)arg1,
289 (wchar_t*)arg2,
290 l);
291}
292
293/*****************************************************************************
294 * Name :
295 * Purpose :
296 * Parameters:
297 * Variables :
298 * Result :
299 * Remark :
300 * Status :
301 *
302 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
303 *****************************************************************************/
304
305LPSTR WIN32API lstrcpyA(LPSTR dest, LPCSTR src)
306{
307 if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
308 return NULL;
309
310 return O32_lstrcpy(dest, src);
311}
312
313
314/*****************************************************************************
315 * Name :
316 * Purpose :
317 * Parameters:
318 * Variables :
319 * Result :
320 * Remark :
321 * Status :
322 *
323 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
324 *****************************************************************************/
325
326LPWSTR WIN32API lstrcpyW(LPWSTR dest, LPCWSTR src)
327{
328 if ( (src == NULL) || (dest == NULL) ) // stupid parameter checking
329 return NULL;
330
331 UniStrcpy( (UniChar*)dest,
332 (UniChar*)src );
333 return dest;
334}
335
336
337/*****************************************************************************
338 * Name :
339 * Purpose :
340 * Parameters:
341 * Variables :
342 * Result :
343 * Remark :
344 * Status :
345 *
346 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
347 *****************************************************************************/
348
349LPSTR WIN32API lstrcpynA(LPSTR arg1, LPCSTR arg2, int arg3)
350{
351 register LPSTR p1 = arg1;
352 register LPSTR p2 = (LPSTR)arg2;
353
354 dprintf2(("KERNEL32: OS2lstrcpyA(%08xh, %08xh, %08xh)\n",
355 arg1,
356 arg2,
357 arg3));
358
359 //PH: looks like either \0 or arg3 terminate the copy
360 //return strncpy(arg1, arg2, arg3);
361 arg3--; // pre-decrement to avoid exceeding buffer length
362 // results in better code than (arg1 > 1)
363
364 for (;*p2 && arg3; arg3--)
365 *p1++ = *p2++;
366
367 *p1 = 0; //CB: copy arg-1, set end 0
368
369 return arg1;
370}
371
372
373/*****************************************************************************
374 * Name :
375 * Purpose :
376 * Parameters:
377 * Variables :
378 * Result :
379 * Remark :
380 * Status :
381 *
382 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
383 *****************************************************************************/
384
385LPWSTR WIN32API lstrcpynW(LPWSTR dest, LPCWSTR src, int arg3)
386{
387 dprintf2(("KERNEL32: lstrcpynW(%08xh,%08xh,%08xh)",
388 dest,
389 src,
390 arg3));
391
392 if (arg3 == 0)
393 return NULL;
394
395 UniStrncpy( (UniChar*)dest,
396 (UniChar*)src,
397 arg3-1); //CB: copy arg3-1 characters
398 dest[arg3-1] = 0; //CB: set end
399 return dest;
400}
401
402
403/*****************************************************************************
404 * Name :
405 * Purpose :
406 * Parameters:
407 * Variables :
408 * Result :
409 * Remark :
410 * Status :
411 *
412 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
413 *****************************************************************************/
414
415int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
416{
417 dprintf2(("KERNEL32: lstrcmpiA(%s,%s)\n",
418 arg1,
419 arg2));
420
421 if(arg1 == NULL)
422 return -1;
423
424 if(arg2 == NULL)
425 return 1;
426
427 return O32_lstrcmpi(arg1, arg2);
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
443int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
444{
445 char *astr1, *astr2;
446 int rc;
447
448 dprintf2(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
449 arg1,
450 arg2));
451
452 if(arg1 == NULL)
453 return -1;
454
455 if(arg2 == NULL)
456 return 1;
457
458 // NOTE: This function has no equivalent in uunidef.h
459 astr1 = UnicodeToAsciiString((LPWSTR)arg1);
460 astr2 = UnicodeToAsciiString((LPWSTR)arg2);
461 rc = lstrcmpiA(astr1, astr2);
462 FreeAsciiString(astr2);
463 FreeAsciiString(astr1);
464 return(rc);
465}
466
467
468/*****************************************************************************
469 * Name :
470 * Purpose :
471 * Parameters:
472 * Variables :
473 * Result :
474 * Remark :
475 * Status :
476 *
477 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
478 *****************************************************************************/
479
480// unilen: length of astring buffer (including 0 terminator)
481// returns string length
482
483int WIN32API lstrcpynCtoA(LPSTR astring,
484 LPCWSTR ustring,
485 int unilen,
486 UconvObject uconv_object)
487{
488 int i;
489 int rc;
490 size_t uni_chars_left;
491 size_t out_bytes_left;
492 size_t num_subs;
493 UniChar* in_buf;
494 char* out_buf;
495
496 if (ustring == NULL)
497 {
498 if (astring != NULL && unilen > 0)
499 astring[0] = 0;
500 return 0;
501 }
502
503 if (astring == NULL || unilen <= 0)
504 return 0;
505
506 if (uconv_object)
507 {
508 if (unilen == 1)
509 {
510 astring[0] = 0;
511 return 0; //no data
512 }
513
514 //SvL: Determine length of unicode string
515 uni_chars_left = UniStrlen((UniChar*)ustring)+1;
516 uni_chars_left = min(uni_chars_left, unilen);
517 unilen = uni_chars_left;
518
519 out_bytes_left = uni_chars_left; //size in bytes == elements
520 in_buf = (UniChar*)ustring;
521 out_buf = astring;
522 rc = UniUconvFromUcs(uconv_object,
523 &in_buf, &uni_chars_left,
524 (void**)&out_buf, &out_bytes_left,
525 &num_subs);
526
527 /* @@@PH 2000/08/10
528 * this causes the last character in the converted
529 * target string to be chopped off. I.e. causes CMD.EXE
530 * to loose the CRLF functionality.
531 */
532 /*
533 unilen -= 1+out_bytes_left; //end + left bytes
534 astring[unilen] = 0; //terminate
535 */
536
537 return unilen; //length of string (excluding terminator)
538 }
539 else
540 {
541 /* idiots unicode conversion :) */
542 for (i = 0; i < unilen-1; i++)
543 {
544 astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
545 if (ustring[i] == 0) return i; //asta la vista, baby
546 }
547
548 astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
549
550 return(unilen-1);
551 }
552}
553
554int WIN32API lstrcpynWtoA(LPSTR astring,
555 LPCWSTR ustring,
556 int unilen)
557{
558 return lstrcpynCtoA(astring, ustring, unilen, GetWindowsUconvObject());
559}
560
561
562/*****************************************************************************
563 * Name :
564 * Purpose :
565 * Parameters:
566 * Variables :
567 * Result :
568 * Remark :
569 * Status :
570 *
571 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
572 *****************************************************************************/
573
574// asciilen: max length of unicode buffer (including end 0)
575// @@@PH 0 termination is NOT necessarily included !
576int lstrcpynAtoC(LPWSTR unicode,
577 LPCSTR ascii,
578 int asciilen,
579 UconvObject uconv_object)
580{
581 int rc;
582 int i;
583 size_t uni_chars_left;
584 size_t in_bytes_left;
585 size_t num_subs;
586 UniChar* out_buf;
587 char* in_buf;
588
589 dprintf2(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
590 ascii,
591 unicode,
592 asciilen));
593
594 //CB: no input, set at least terminator
595 if (ascii == NULL)
596 {
597 if (unicode != NULL && asciilen > 0) unicode[0] = 0;
598 return 0;
599 }
600
601 if (unicode == NULL || asciilen <= 0)
602 return 0; //nothing to do
603
604 if (uconv_object)
605 {
606 //@@@PH what's this?
607 if ((asciilen == 1) && (*ascii == '\0') )
608 {
609 unicode[0] = 0;
610 return 0;
611 }
612
613 in_buf = (LPSTR)ascii;
614
615 //@@@PH what's this?
616 //in_bytes_left = asciilen-1; //buffer size in bytes
617
618 //SvL: Determine length of ascii string
619 in_bytes_left = strlen(in_buf)+1;
620 in_bytes_left = asciilen = min(in_bytes_left, asciilen); //buffer size in bytes
621
622 out_buf = (UniChar*)unicode;
623
624 uni_chars_left = in_bytes_left; //elements
625
626 rc = UniUconvToUcs( uconv_object,
627 (void**)&in_buf, &in_bytes_left,
628 &out_buf, &uni_chars_left,
629 &num_subs );
630
631 /* @@@PH 2000/08/10
632 * this causes the last character in the converted
633 * target string to be chopped off. I.e. causes CMD.EXE
634 * to enter command correctly.
635 */
636 /*
637 asciilen -= 1+uni_chars_left; //end + left bytes
638
639 unicode[asciilen] = 0; // always terminate string
640 */
641
642 return asciilen; //length of string (excluding terminator)
643 }
644 else
645 { //poor man's conversion
646
647// for(i = 0;i < asciilen-1;i++)
648 for(i = 0;i < asciilen;i++)
649 {
650 unicode[i] = ascii[i];
651 if (ascii[i] == 0)
652 //return i-1; //work done
653 return i; //work done
654 }
655
656// unicode[asciilen-1] = 0;
657// return asciilen-1;
658 return asciilen;
659 }
660}
661
662int WIN32API lstrcpynAtoW(LPWSTR unicode,
663 LPCSTR ascii,
664 int asciilen)
665{
666 return lstrcpynAtoC(unicode, ascii, asciilen, GetWindowsUconvObject());
667}
668
669/*****************************************************************************
670 * Name :
671 * Purpose : Converts unicode string to ascii string
672 * Parameters:
673 * Variables :
674 * Result : returns length of ascii string
675 * Remark :
676 * Status :
677 *
678 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
679 *****************************************************************************/
680
681LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPCWSTR unicode)
682{
683 //@@@PH huh? wuz dat?
684 if (unicode == NULL)
685 {
686 if (unicode != NULL) ((LPWSTR)unicode)[0] = 0; //CB: set at least end
687 return NULL;
688 }
689
690 if (unicode == NULL)
691 return NULL; /* garbage in, garbage out ! */
692
693 /* forward to function with len parameter */
694 lstrcpynWtoA(ascii,
695 unicode,
696 UniStrlen((UniChar*)unicode)+1); //end included
697
698 return ascii;
699}
700
701
702/*****************************************************************************
703 * Name :
704 * Purpose : Copies the full string from ascii to unicode
705 * Parameters:
706 * Variables :
707 * Result :
708 * Remark :
709 * Status :
710 *
711 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
712 *****************************************************************************/
713
714LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPCSTR ascii)
715{
716 /* achimha for security, strlen might trap if garbage in */
717 /* @@@PH 98/06/07 */
718 if (ascii == NULL)
719 {
720 if (unicode != NULL) unicode[0] = 0; //CB: set at least end
721 return NULL;
722 }
723
724 if (unicode == NULL)
725 return NULL; /* garbage in, garbage out ! */
726
727 /* forward to call with length parameter */
728 lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
729 return (unicode);
730}
731
732
733
734
735/*****************************************************************************
736 * Name :
737 * Purpose :
738 * Parameters:
739 * Variables :
740 * Result :
741 * Remark :
742 * Status :
743 *
744 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
745 *****************************************************************************/
746
747LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
748{
749 LPVOID p = HeapAlloc( heap, flags, size );
750 if (!p)
751 {
752 dprintf2(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
753 heap,
754 flags,
755 size));
756 }
757 return p;
758}
759
760
761/*****************************************************************************
762 * Name :
763 * Purpose :
764 * Parameters:
765 * Variables :
766 * Result :
767 * Remark :
768 * Status :
769 *
770 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
771 *****************************************************************************/
772
773LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
774{
775 LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
776 if (!p)
777 {
778 dprintf2(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
779 heap,
780 flags,
781 lpMem,
782 size));
783 }
784 return p;
785}
786
787
788/*****************************************************************************
789 * Name :
790 * Purpose :
791 * Parameters:
792 * Variables :
793 * Result :
794 * Remark :
795 * Status :
796 *
797 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
798 *****************************************************************************/
799
800LPVOID WIN32API HEAP_malloc(DWORD size )
801{
802 LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
803 if (!p)
804 {
805 dprintf2(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
806 size));
807 }
808 return p;
809}
810
811
812/*****************************************************************************
813 * Name :
814 * Purpose :
815 * Parameters:
816 * Variables :
817 * Result :
818 * Remark :
819 * Status :
820 *
821 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
822 *****************************************************************************/
823
824DWORD WIN32API HEAP_size(LPVOID lpMem)
825{
826 return HeapSize( GetProcessHeap(), 0, lpMem );
827}
828
829
830/*****************************************************************************
831 * Name :
832 * Purpose :
833 * Parameters:
834 * Variables :
835 * Result :
836 * Remark :
837 * Status :
838 *
839 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
840 *****************************************************************************/
841
842LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
843{
844 LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
845 if (!p)
846 {
847 dprintf2(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
848 lpMem,
849 size));
850 }
851 return p;
852}
853
854
855/*****************************************************************************
856 * Name :
857 * Purpose :
858 * Parameters:
859 * Variables :
860 * Result :
861 * Remark :
862 * Status :
863 *
864 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
865 *****************************************************************************/
866
867VOID WIN32API HEAP_free(LPVOID lpMem)
868{
869 dprintf2(("KERNEL32: HEAP_free(%08xh)\n",
870 lpMem));
871
872 HeapFree( GetProcessHeap(), 0, lpMem);
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
888LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
889{
890 LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
891 strcpy( p, str );
892 return p;
893}
894
895
896/*****************************************************************************
897 * Name :
898 * Purpose :
899 * Parameters:
900 * Variables :
901 * Result :
902 * Remark :
903 * Status :
904 *
905 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
906 *****************************************************************************/
907
908LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
909{
910 INT len = lstrlenW(str) + 1;
911 LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
912 lstrcpyW( p, str );
913 return p;
914}
915
916
917/*****************************************************************************
918 * Name :
919 * Purpose :
920 * Parameters:
921 * Variables :
922 * Result :
923 * Remark :
924 * Status :
925 *
926 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
927 *****************************************************************************/
928
929LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
930{
931 LPWSTR ret;
932
933 if (!str) return NULL;
934 ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
935 lstrcpyAtoW( ret, (LPSTR)str );
936 return ret;
937}
938
939
940/*****************************************************************************
941 * Name :
942 * Purpose :
943 * Parameters:
944 * Variables :
945 * Result :
946 * Remark :
947 * Status :
948 *
949 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
950 *****************************************************************************/
951
952LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
953{
954 LPSTR ret;
955
956 if (!str) return NULL;
957 ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
958 lstrcpyWtoA( ret, (LPWSTR)str );
959 return ret;
960}
961
962
963/*****************************************************************************
964 * Name : WideCharToLocal
965 * Purpose : similar lstrcpyWtoA, should handle codepages properly
966 * Parameters:
967 * Variables :
968 * Result : strlen of the destination string
969 * Remark :
970 * Status :
971 *
972 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
973 *****************************************************************************/
974
975INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
976{
977 dprintf2(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
978 pLocal,
979 pWide,
980 dwChars));
981
982 *pLocal = 0;
983 WideCharToMultiByte(CP_ACP,
984 0,
985 pWide,
986 -1,
987 pLocal,
988 dwChars,
989 NULL,
990 NULL);
991
992 return strlen(pLocal);
993}
994
995
996/*****************************************************************************
997 * Name : LocalToWideChar
998 * Purpose : similar lstrcpyAtoW, should handle codepages properly
999 * Parameters:
1000 * Variables :
1001 * Result : strlen of the destination string
1002 * Remark :
1003 * Status :
1004 *
1005 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1006 *****************************************************************************/
1007
1008INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
1009{
1010 *pWide = 0;
1011
1012 dprintf2(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
1013 pLocal,
1014 pWide,
1015 dwChars));
1016
1017 MultiByteToWideChar(CP_ACP,
1018 0,
1019 pLocal,
1020 -1,
1021 pWide,
1022 dwChars);
1023
1024 return lstrlenW(pWide);
1025}
1026
1027
1028
1029
1030
1031
1032#if 0
1033
1034
1035/*****************************************************************************
1036 * Name :
1037 * Purpose :
1038 * Parameters:
1039 * Variables :
1040 * Result :
1041 * Remark :
1042 * Status :
1043 *
1044 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1045 *****************************************************************************/
1046
1047// Converts unicode string to ascii string
1048// returns pointer to ascii string
1049char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
1050{
1051 char *astring;
1052
1053 if(ustring == NULL) return(NULL);
1054
1055 astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
1056 UnicodeToAscii( ustring, astring );
1057 return(astring);
1058}
1059
1060
1061/*****************************************************************************
1062 * Name :
1063 * Purpose :
1064 * Parameters:
1065 * Variables :
1066 * Result :
1067 * Remark :
1068 * Status :
1069 *
1070 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1071 *****************************************************************************/
1072
1073// Converts ascii string to unicode string
1074// returns pointer to unicode string
1075WCHAR * WIN32API AsciiToUnicodeString(char *astring)
1076{
1077 WCHAR *ustring;
1078
1079 if(astring == NULL)
1080 return(NULL);
1081
1082 ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
1083 AsciiToUnicode( astring, ustring );
1084 return(ustring);
1085}
1086
1087#endif
1088
1089
1090
1091/**************************************************************************
1092 * This function is used just locally !
1093 * Description: Inverts a string.
1094 */
1095static void OLE_InvertString(char* string)
1096{
1097 char sTmpArray[128];
1098 INT counter, i = 0;
1099
1100 for (counter = strlen(string); counter > 0; counter--)
1101 {
1102 memcpy(sTmpArray + i, string + counter-1, 1);
1103 i++;
1104 }
1105 memcpy(sTmpArray + i, "\0", 1);
1106 strcpy(string, sTmpArray);
1107}
1108
1109/***************************************************************************************
1110 * This function is used just locally !
1111 * Description: Test if the given string (psNumber) is valid or not.
1112 * The valid characters are the following:
1113 * - Characters '0' through '9'.
1114 * - One decimal point (dot) if the number is a floating-point value.
1115 * - A minus sign in the first character position if the number is
1116 * a negative value.
1117 * If the function succeeds, psBefore/psAfter will point to the string
1118 * on the right/left of the decimal symbol. pbNegative indicates if the
1119 * number is negative.
1120 */
1121static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
1122{
1123char sNumberSet[] = "0123456789";
1124BOOL bInDecimal = FALSE;
1125
1126 /* Test if we do have a minus sign */
1127 if ( *pInput == '-' )
1128 {
1129 *pbNegative = TRUE;
1130 pInput++; /* Jump to the next character. */
1131 }
1132
1133 while(*pInput != '\0')
1134 {
1135 /* Do we have a valid numeric character */
1136 if ( strchr(sNumberSet, *pInput) != NULL )
1137 {
1138 if (bInDecimal == TRUE)
1139 *psAfter++ = *pInput;
1140 else
1141 *psBefore++ = *pInput;
1142 }
1143 else
1144 {
1145 /* Is this a decimal point (dot) */
1146 if ( *pInput == '.' )
1147 {
1148 /* Is it the first time we find it */
1149 if ((bInDecimal == FALSE))
1150 bInDecimal = TRUE;
1151 else
1152 return -1; /* ERROR: Invalid parameter */
1153 }
1154 else
1155 {
1156 /* It's neither a numeric character, nor a decimal point.
1157 * Thus, return an error.
1158 */
1159 return -1;
1160 }
1161 }
1162 pInput++;
1163 }
1164
1165 /* Add an End of Line character to the output buffers */
1166 *psBefore = '\0';
1167 *psAfter = '\0';
1168
1169 return 0;
1170}
1171
1172/**************************************************************************
1173 * This function is used just locally !
1174 * Description: A number could be formatted using different numbers
1175 * of "digits in group" (example: 4;3;2;0).
1176 * The first parameter of this function is an array
1177 * containing the rule to be used. It's format is the following:
1178 * |NDG|DG1|DG2|...|0|
1179 * where NDG is the number of used "digits in group" and DG1, DG2,
1180 * are the corresponding "digits in group".
1181 * Thus, this function returns the grouping value in the array
1182 * pointed by the second parameter.
1183 */
1184static INT OLE_GetGrouping(char* sRule, INT index)
1185{
1186 char sData[2], sRuleSize[2];
1187 INT nData, nRuleSize;
1188
1189 memcpy(sRuleSize, sRule, 1);
1190 memcpy(sRuleSize+1, "\0", 1);
1191 nRuleSize = atoi(sRuleSize);
1192
1193 if (index > 0 && index < nRuleSize)
1194 {
1195 memcpy(sData, sRule+index, 1);
1196 memcpy(sData+1, "\0", 1);
1197 nData = atoi(sData);
1198 }
1199
1200 else
1201 {
1202 memcpy(sData, sRule+nRuleSize-1, 1);
1203 memcpy(sData+1, "\0", 1);
1204 nData = atoi(sData);
1205 }
1206
1207 return nData;
1208}
Note: See TracBrowser for help on using the repository browser.