1 | /* $Id: crt_mb.cpp,v 1.1 2000-02-03 21:37:47 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * The C RunTime DLL
|
---|
5 | *
|
---|
6 | * Implements C run-time functionality as known from UNIX.
|
---|
7 | *
|
---|
8 | * Partialy based on Wine
|
---|
9 | *
|
---|
10 | * Copyright 1996,1998 Marcus Meissner
|
---|
11 | * Copyright 1996 Jukka Iivonen
|
---|
12 | * Copyright 1997 Uwe Bonnes
|
---|
13 | * Copyright 1999-2000 Jens Wiessner
|
---|
14 | *
|
---|
15 | * CRTDLL - multibyte functions
|
---|
16 | *
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <odin.h>
|
---|
20 | #include <os2win.h>
|
---|
21 | #include <ctype.h>
|
---|
22 | #include <heapstring.h>
|
---|
23 | #include <string.h>
|
---|
24 |
|
---|
25 | #define MB_LEN_MAX 2
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************
|
---|
29 | * _mbscat (CRTDLL.195)
|
---|
30 | */
|
---|
31 | unsigned char * CDECL CRTDLL__mbscat( unsigned char *dst, const unsigned char *src )
|
---|
32 | {
|
---|
33 | dprintf2(("CRTDLL: _mbscat\n"));
|
---|
34 | return (unsigned char*)strcat((char*)dst,(char*)src);
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************
|
---|
39 | * _mbschr (CRTDLL.196)
|
---|
40 | */
|
---|
41 | unsigned char * CDECL CRTDLL__mbschr( const unsigned char *str, unsigned int c )
|
---|
42 | {
|
---|
43 | dprintf2(("CRTDLL: _mbschr\n"));
|
---|
44 | return (unsigned char*)strchr((char*)str,c);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | /*********************************************************************
|
---|
49 | * _mbscmp (CRTDLL.197)
|
---|
50 | */
|
---|
51 | int CDECL CRTDLL__mbscmp( const unsigned char *s1, const unsigned char *s2 )
|
---|
52 | {
|
---|
53 | dprintf2(("CRTDLL: _mbscmp\n"));
|
---|
54 | return strcmp((char*)s1,(char*)s2);
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | /*********************************************************************
|
---|
59 | * _mbscpy (CRTDLL.198)
|
---|
60 | */
|
---|
61 | unsigned char * CDECL CRTDLL__mbscpy( unsigned char *s1, const unsigned char *s2 )
|
---|
62 | {
|
---|
63 | dprintf2(("CRTDLL: _mbscpy\n"));
|
---|
64 | return (unsigned char*)strcpy((char*)s1,(char*)s2);
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | /*********************************************************************
|
---|
69 | * _mbsdup (CRTDLL.201)
|
---|
70 | */
|
---|
71 | unsigned char * CDECL CRTDLL__mbsdup( unsigned char *s1 )
|
---|
72 | {
|
---|
73 | dprintf2(("CRTDLL: _mbsdup\n"));
|
---|
74 | return (unsigned char*)strdup((const char*)s1);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | /*********************************************************************
|
---|
79 | * CRTDLL__mbsicmp (CRTDLL.202)
|
---|
80 | */
|
---|
81 | int CDECL CRTDLL__mbsicmp( const unsigned char *x, const unsigned char *y )
|
---|
82 | {
|
---|
83 | dprintf2(("CRTDLL: _mbsicmp\n"));
|
---|
84 | do {
|
---|
85 | if (!*x)
|
---|
86 | return !!*y;
|
---|
87 | if (!*y)
|
---|
88 | return !!*x;
|
---|
89 | /* FIXME: MBCS handling... */
|
---|
90 | if (*x!=*y)
|
---|
91 | return 1;
|
---|
92 | x++;
|
---|
93 | y++;
|
---|
94 | } while (1);
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | /*********************************************************************
|
---|
99 | * _mbsinc (CRTDLL.203)
|
---|
100 | */
|
---|
101 | LPSTR CDECL CRTDLL__mbsinc( LPCSTR str )
|
---|
102 | {
|
---|
103 | dprintf2(("CRTDLL: _mbsinc\n"));
|
---|
104 | int len = mblen( str, MB_LEN_MAX );
|
---|
105 | if (len < 1) len = 1;
|
---|
106 | return (LPSTR)(str + len);
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | /*********************************************************************
|
---|
111 | * _mbslen (CRTDLL.204)
|
---|
112 | */
|
---|
113 | INT CDECL CRTDLL__mbslen( LPCSTR str )
|
---|
114 | {
|
---|
115 | dprintf2(("CRTDLL: _mbslen\n"));
|
---|
116 | INT len, total = 0;
|
---|
117 | while ((len = mblen( str, MB_LEN_MAX )) > 0)
|
---|
118 | {
|
---|
119 | str += len;
|
---|
120 | total++;
|
---|
121 | }
|
---|
122 | return total;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /*********************************************************************
|
---|
127 | * _mbsrchr (CRTDLL.221)
|
---|
128 | */
|
---|
129 | LPSTR CDECL CRTDLL__mbsrchr(LPSTR s,CHAR x)
|
---|
130 | {
|
---|
131 | dprintf2(("CRTDLL: _mbsrchr\n"));
|
---|
132 | /* FIXME: handle multibyte strings */
|
---|
133 | return strrchr(s,x);
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /*********************************************************************
|
---|
138 | * _mbsstr (CRTDLL.226)
|
---|
139 | */
|
---|
140 | unsigned char * CDECL CRTDLL__mbsstr( const unsigned char *s1, const unsigned char *s2 )
|
---|
141 | {
|
---|
142 | dprintf2(("CRTDLL: _mbsstr\n"));
|
---|
143 | return (unsigned char*)strstr((const char*)s1,(const char*)s2);
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | /*********************************************************************
|
---|
148 | * mblen (CRTDLL.425)
|
---|
149 | */
|
---|
150 | INT CDECL CRTDLL_mblen( const char *s, size_t n )
|
---|
151 | {
|
---|
152 | dprintf2(("CRTDLL: mblen\n"));
|
---|
153 | return (mblen(s, n));
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /*********************************************************************
|
---|
158 | * mbstowcs (CRTDLL.426)
|
---|
159 | */
|
---|
160 | size_t CDECL CRTDLL_mbstowcs( wchar_t *pwcs, const char *s, size_t n )
|
---|
161 | {
|
---|
162 | dprintf2(("CRTDLL: mbstowcs(%08xh, %08xh, %08xh)\n", pwcs, s, n));
|
---|
163 | return (mbstowcs(pwcs, s, n));
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | /*********************************************************************
|
---|
168 | * mbtowc (CRTDLL.427)
|
---|
169 | */
|
---|
170 | INT CDECL CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
|
---|
171 | {
|
---|
172 | dprintf2(("CRTDLL: mbtowc\n"));
|
---|
173 | wchar_t res;
|
---|
174 | int ret = mbtowc( &res, str, n );
|
---|
175 | if (dst) *dst = (WCHAR)res;
|
---|
176 | return ret;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|