| 1 | /* $Id: mbstring.c,v 1.1 2000-11-21 23:48:52 phaller 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 1999 Alexandre Julliard
|
|---|
| 11 | *
|
|---|
| 12 | * CRTDLL multi-byte string functions
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | //#include <odin.h>
|
|---|
| 17 | //#include <os2win.h>
|
|---|
| 18 | //#include <ctype.h>
|
|---|
| 19 | //#include <heapstring.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 |
|
|---|
| 22 | #define MB_LEN_MAX 2
|
|---|
| 23 |
|
|---|
| 24 | #include "crtdll.h"
|
|---|
| 25 |
|
|---|
| 26 | DEFAULT_DEBUG_CHANNEL(crtdll);
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | /*********************************************************************
|
|---|
| 30 | * _mbsicmp (CRTDLL.204)
|
|---|
| 31 | */
|
|---|
| 32 | int CDECL CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
|
|---|
| 33 | {
|
|---|
| 34 | do {
|
|---|
| 35 | if (!*x)
|
|---|
| 36 | return !!*y;
|
|---|
| 37 | if (!*y)
|
|---|
| 38 | return !!*x;
|
|---|
| 39 | /* FIXME: MBCS handling... */
|
|---|
| 40 | if (*x!=*y)
|
|---|
| 41 | return 1;
|
|---|
| 42 | x++;
|
|---|
| 43 | y++;
|
|---|
| 44 | } while (1);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | /*********************************************************************
|
|---|
| 49 | * CRTDLL__mbsinc (CRTDLL.205)
|
|---|
| 50 | */
|
|---|
| 51 | LPSTR CDECL CRTDLL__mbsinc( LPCSTR str )
|
|---|
| 52 | {
|
|---|
| 53 | // int len = mblen( str, MB_LEN_MAX );
|
|---|
| 54 | // if (len < 1) len = 1;
|
|---|
| 55 | // return (LPSTR)(str + len);
|
|---|
| 56 |
|
|---|
| 57 | if (IsDBCSLeadByte( *str )) str++;
|
|---|
| 58 | return (LPSTR)(str + 1);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | /*********************************************************************
|
|---|
| 63 | * CRTDLL__mbslen (CRTDLL.206)
|
|---|
| 64 | */
|
|---|
| 65 | INT CDECL CRTDLL__mbslen( LPCSTR str )
|
|---|
| 66 | {
|
|---|
| 67 | INT len;
|
|---|
| 68 |
|
|---|
| 69 | // INT len, total = 0;
|
|---|
| 70 | // while ((len = mblen( str, MB_LEN_MAX )) > 0)
|
|---|
| 71 | // {
|
|---|
| 72 | // str += len;
|
|---|
| 73 | // total++;
|
|---|
| 74 | // }
|
|---|
| 75 | // return total;
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | for (len = 0; *str; len++, str++)
|
|---|
| 79 | if (IsDBCSLeadByte(str[0]) && str[1])
|
|---|
| 80 | str++;
|
|---|
| 81 |
|
|---|
| 82 | return len;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | /*********************************************************************
|
|---|
| 88 | * _mbsrchr (CRTDLL.223)
|
|---|
| 89 | */
|
|---|
| 90 | LPSTR CDECL CRTDLL__mbsrchr(LPSTR s,CHAR x)
|
|---|
| 91 | {
|
|---|
| 92 | /* FIXME: handle multibyte strings */
|
|---|
| 93 | return strrchr(s,x);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | /*********************************************************************
|
|---|
| 98 | * CRTDLL_mbtowc (CRTDLL.430)
|
|---|
| 99 | */
|
|---|
| 100 | INT CDECL CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
|
|---|
| 101 | {
|
|---|
| 102 | // wchar_t res;
|
|---|
| 103 | // int ret = mbtowc( &res, str, n );
|
|---|
| 104 | // if (dst) *dst = (WCHAR)res;
|
|---|
| 105 | // return ret;
|
|---|
| 106 |
|
|---|
| 107 | if (n <= 0) return 0;
|
|---|
| 108 | if (!str) return 0;
|
|---|
| 109 | if (!MultiByteToWideChar( CP_ACP, 0, str, n, dst, 1 )) return 0;
|
|---|
| 110 | /* return the number of bytes from src that have been used */
|
|---|
| 111 | if (!*str) return 0;
|
|---|
| 112 | if (n >= 2 && IsDBCSLeadByte(*str) && str[1]) return 2;
|
|---|
| 113 | return 1;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | /*********************************************************************
|
|---|
| 118 | * _mbccpy (CRTDLL.??)
|
|---|
| 119 | *
|
|---|
| 120 | * Copy one multibyte character to another
|
|---|
| 121 | */
|
|---|
| 122 | VOID CDECL CRTDLL__mbccpy(LPSTR dest, LPSTR src)
|
|---|
| 123 | {
|
|---|
| 124 | // @@@PH looks very good, indeed ... .beg.
|
|---|
| 125 | FIXME("MBCS copy treated as ASCII\n");
|
|---|
| 126 | *dest = *src;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | /*********************************************************************
|
|---|
| 131 | * _mbscat (CRTDLL.195)
|
|---|
| 132 | */
|
|---|
| 133 | unsigned char * CDECL CRTDLL__mbscat( unsigned char *dst, const unsigned char *src )
|
|---|
| 134 | {
|
|---|
| 135 | dprintf2(("CRTDLL: _mbscat\n"));
|
|---|
| 136 | return (unsigned char*)strcat((char*)dst,(char*)src);
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | /*********************************************************************
|
|---|
| 141 | * _mbschr (CRTDLL.196)
|
|---|
| 142 | */
|
|---|
| 143 | unsigned char * CDECL CRTDLL__mbschr( const unsigned char *str, unsigned int c )
|
|---|
| 144 | {
|
|---|
| 145 | dprintf2(("CRTDLL: _mbschr\n"));
|
|---|
| 146 | return (unsigned char*)strchr((char*)str,c);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | /*********************************************************************
|
|---|
| 151 | * _mbscmp (CRTDLL.197)
|
|---|
| 152 | */
|
|---|
| 153 | int CDECL CRTDLL__mbscmp( const unsigned char *s1, const unsigned char *s2 )
|
|---|
| 154 | {
|
|---|
| 155 | dprintf2(("CRTDLL: _mbscmp\n"));
|
|---|
| 156 | return strcmp((char*)s1,(char*)s2);
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | /*********************************************************************
|
|---|
| 161 | * _mbscpy (CRTDLL.198)
|
|---|
| 162 | */
|
|---|
| 163 | unsigned char * CDECL CRTDLL__mbscpy( unsigned char *s1, const unsigned char *s2 )
|
|---|
| 164 | {
|
|---|
| 165 | dprintf2(("CRTDLL: _mbscpy\n"));
|
|---|
| 166 | return (unsigned char*)strcpy((char*)s1,(char*)s2);
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 | /*********************************************************************
|
|---|
| 171 | * _mbsdup (CRTDLL.201)
|
|---|
| 172 | */
|
|---|
| 173 | unsigned char * CDECL CRTDLL__mbsdup( unsigned char *s1 )
|
|---|
| 174 | {
|
|---|
| 175 | dprintf2(("CRTDLL: _mbsdup\n"));
|
|---|
| 176 | return (unsigned char*)strdup((const char*)s1);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | /*********************************************************************
|
|---|
| 181 | * _mbsstr (CRTDLL.226)
|
|---|
| 182 | */
|
|---|
| 183 | unsigned char * CDECL CRTDLL__mbsstr( const unsigned char *s1, const unsigned char *s2 )
|
|---|
| 184 | {
|
|---|
| 185 | dprintf2(("CRTDLL: _mbsstr\n"));
|
|---|
| 186 | return (unsigned char*)strstr((const char*)s1,(const char*)s2);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | /*********************************************************************
|
|---|
| 191 | * mblen (CRTDLL.425)
|
|---|
| 192 | */
|
|---|
| 193 | INT CDECL CRTDLL_mblen( const char *s, size_t n )
|
|---|
| 194 | {
|
|---|
| 195 | dprintf2(("CRTDLL: mblen\n"));
|
|---|
| 196 | return (mblen(s, n));
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 | /*********************************************************************
|
|---|
| 201 | * mbstowcs (CRTDLL.426)
|
|---|
| 202 | */
|
|---|
| 203 | size_t CDECL CRTDLL_mbstowcs( wchar_t *pwcs, const char *s, size_t n )
|
|---|
| 204 | {
|
|---|
| 205 | dprintf2(("CRTDLL: mbstowcs(%08xh, %08xh, %08xh)\n", pwcs, s, n));
|
|---|
| 206 | return (mbstowcs(pwcs, s, n));
|
|---|
| 207 | }
|
|---|