- Add several mbcs and CP 932 functions, fix some existing calls

- Bug fixes, -W warnings and winapi_check updates.
- Don't be so strict setting default locale, store codepage
This commit is contained in:
Jon Griffiths 2000-12-19 23:29:15 +00:00 committed by Alexandre Julliard
parent 335b9e3be3
commit 5d4cf0679a
10 changed files with 606 additions and 115 deletions

View File

@ -306,8 +306,8 @@ INT __cdecl CRTDLL__kbhit(VOID)
{
/* FIXME: There has to be a faster way than this in Win32.. */
INPUT_RECORD *ir;
DWORD count = 0;
int retVal = 0, i;
DWORD count = 0, i;
int retVal = 0;
GetNumberOfConsoleInputEvents(__CRTDLL_console_in, &count);
if (!count)
@ -316,19 +316,17 @@ INT __cdecl CRTDLL__kbhit(VOID)
if (!(ir = CRTDLL_malloc(count * sizeof(INPUT_RECORD))))
return 0;
if (!PeekConsoleInputA(__CRTDLL_console_in, ir, count, &count))
return 0;
for(i = 0; i < count - 1; i++)
{
if (ir[i].EventType == KEY_EVENT &&
ir[i].Event.KeyEvent.bKeyDown &&
ir[i].Event.KeyEvent.uChar.AsciiChar)
if (PeekConsoleInputA(__CRTDLL_console_in, ir, count, &count))
for(i = 0; i < count - 1; i++)
{
retVal = 1;
break;
if (ir[i].EventType == KEY_EVENT &&
ir[i].Event.KeyEvent.bKeyDown &&
ir[i].Event.KeyEvent.uChar.AsciiChar)
{
retVal = 1;
break;
}
}
}
CRTDLL_free(ir);
return retVal;
}

View File

@ -325,8 +325,8 @@ LPSTR __cdecl CRTDLL_gets( LPSTR buf );
INT __cdecl CRTDLL_fclose( CRTDLL_FILE* file );
INT __cdecl CTRDLL__creat( LPCSTR path, INT flags );
INT __cdecl CRTDLL__eof( INT fd );
LONG __cdecl CRTDLL__tell(INT fd);
INT __cdecl CRTDLL__umask(INT umask);
LONG __cdecl CRTDLL__tell( INT fd );
INT __cdecl CRTDLL__umask( INT umask );
INT __cdecl CRTDLL__utime( LPCSTR path, struct _utimbuf *t );
INT __cdecl CRTDLL__unlink( LPCSTR pathname );
INT __cdecl CRTDLL_scanf( LPCSTR format, ... );
@ -350,7 +350,7 @@ VOID __cdecl CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr );
INT __cdecl CRTDLL__setjmp( LPDWORD *jmpbuf );
VOID __cdecl CRTDLL_srand( DWORD seed );
INT __cdecl CRTDLL__getw( CRTDLL_FILE* file );
INT __cdecl CRTDLL__isatty(INT fd);
INT __cdecl CRTDLL__isatty( INT fd );
VOID __cdecl CRTDLL__beep( UINT freq, UINT duration );
INT __cdecl CRTDLL_rand( VOID );
UINT __cdecl CRTDLL__rotl( UINT x,INT shift );
@ -359,13 +359,12 @@ DWORD __cdecl CRTDLL__lrotl( DWORD x,INT shift );
DWORD __cdecl CRTDLL__lrotr( DWORD x,INT shift );
DWORD __cdecl CRTDLL__rotr( UINT x,INT shift );
double __cdecl CRTDLL__scalb( double x, LONG y );
INT __cdecl CRTDLL__mbsicmp( unsigned char *x,unsigned char *y );
INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args );
VOID __cdecl CRTDLL_longjmp( jmp_buf env, int val );
LPSTR __cdecl CRTDLL_setlocale( INT category,LPCSTR locale );
INT __cdecl CRTDLL__isctype( INT c, UINT type );
LPSTR __cdecl CRTDLL__fullpath( LPSTR buf, LPCSTR name, INT size );
VOID __cdecl CRTDLL__splitpath(LPCSTR inpath, LPSTR drv, LPSTR dir,
VOID __cdecl CRTDLL__splitpath( LPCSTR inpath, LPSTR drv, LPSTR dir,
LPSTR fname, LPSTR ext );
INT __cdecl CRTDLL__matherr( struct _exception *e );
VOID __cdecl CRTDLL__makepath( LPSTR path, LPCSTR drive,
@ -396,7 +395,6 @@ INT __cdecl CRTDLL_isupper( INT c);
INT __cdecl CRTDLL_isxdigit( INT c );
INT __cdecl CRTDLL_isleadbyte( UCHAR c );
double __cdecl CRTDLL_ldexp( double x, LONG y );
LPSTR __cdecl CRTDLL__mbsrchr( LPSTR s,CHAR x );
VOID __cdecl CRTDLL___dllonexit ( VOID );
VOID __cdecl CRTDLL__mbccpy( LPSTR dest, LPSTR src );
INT __cdecl CRTDLL___isascii( INT c );
@ -485,6 +483,30 @@ LPWSTR __cdecl CRTDLL__wcsset( LPWSTR str, WCHAR c );
DWORD __cdecl CRTDLL_wcscoll( LPCWSTR str1, LPCWSTR str2 );
LPWSTR __cdecl CRTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept );
INT __cdecl CRTDLL_wctomb( LPSTR dst, WCHAR ch );
LPSTR __cdecl CRTDLL__mbsdec( LPCSTR start, LPCSTR cur );
LPSTR __cdecl CRTDLL__mbsninc( LPCSTR str, INT num );
INT __cdecl CRTDLL__mbscmp( LPCSTR str, LPCSTR cmp );
INT __cdecl CRTDLL__mbsicmp( LPCSTR str, LPCSTR cmp );
INT __cdecl CRTDLL__mbsncmp( LPCSTR str, LPCSTR cmp, UINT len );
INT __cdecl CRTDLL__mbsnicmp( LPCSTR str, LPCSTR cmp, UINT len );
LPSTR __cdecl CRTDLL__mbsrchr( LPCSTR s,CHAR x );
USHORT __cdecl CRTDLL__mbbtombc( USHORT c );
INT __cdecl CRTDLL__mbclen( LPCSTR str );
INT __cdecl CRTDLL__ismbbkana( UINT c );
INT __cdecl CRTDLL__ismbckata( UINT c );
INT __cdecl CRTDLL__ismbchira( UINT c );
INT __cdecl CRTDLL__ismbblead( UINT c );
INT __cdecl CRTDLL__ismbslead( LPCSTR start, LPCSTR str);
INT __cdecl CRTDLL__ismbbtrail( UINT c );
INT __cdecl CRTDLL__ismbstrail( LPCSTR start, LPCSTR str );
LPSTR __cdecl CRTDLL__mbsset( LPSTR str, UINT c );
LPSTR __cdecl CRTDLL__mbsnset( LPSTR str, UINT c, UINT len );
INT __cdecl CRTDLL__mbstrlen( LPCSTR str );
UINT __cdecl CRTDLL__mbsnextc( LPCSTR str );
LPSTR __cdecl CRTDLL__mbsncpy( LPSTR dst, LPCSTR src, UINT len );
LPSTR __cdecl CRTDLL__mbschr( LPCSTR str, UINT c );
UINT __cdecl CRTDLL__mbsnccnt( LPCSTR str, UINT len );
LPSTR __cdecl CRTDLL__mbsncat( LPSTR dst, LPCSTR src, UINT len );
/* wcstring.c */
INT __cdecl CRTDLL_iswalnum( WCHAR wc );
@ -519,9 +541,11 @@ VOID __CRTDLL_init_console(VOID);
VOID __CRTDLL_free_console(VOID);
extern WORD CRTDLL_ctype [257];
extern UCHAR CRTDLL_mbctype[257];
extern WORD __CRTDLL_current_ctype[257];
extern WORD* CRTDLL_pctype_dll;
extern INT CRTDLL__mb_cur_max_dll;
extern LCID __CRTDLL_current_lc_all_lcid;
extern UINT __CRTDLL_current_lc_all_cp;
#endif /* __WINE_CRTDLL_H */

View File

@ -1,6 +1,6 @@
# C RunTime DLL. All functions use cdecl!
name crtdll
type win32
name crtdll
type win32
init CRTDLL_Init
import kernel32.dll
@ -150,16 +150,16 @@ debug_channels (crtdll)
@ stub _ismbbalpha
@ stub _ismbbgraph
@ stub _ismbbkalnum
@ stub _ismbbkana
@ cdecl _ismbbkana(long) CRTDLL__ismbbkana
@ stub _ismbbkpunct
@ stub _ismbblead
@ cdecl _ismbblead(long) CRTDLL__ismbblead
@ stub _ismbbprint
@ stub _ismbbpunct
@ stub _ismbbtrail
@ cdecl _ismbbtrail(long) CRTDLL__ismbbtrail
@ stub _ismbcalpha
@ stub _ismbcdigit
@ stub _ismbchira
@ stub _ismbckata
@ cdecl _ismbchira(long) CRTDLL__ismbchira
@ cdecl _ismbckata(long) CRTDLL__ismbckata
@ stub _ismbcl0
@ stub _ismbcl1
@ stub _ismbcl2
@ -169,11 +169,10 @@ debug_channels (crtdll)
@ stub _ismbcspace
@ stub _ismbcsymbol
@ stub _ismbcupper
@ stub _ismbslead
@ stub _ismbstrail
@ cdecl _ismbslead(ptr ptr) CRTDLL__ismbslead
@ cdecl _ismbstrail(ptr ptr) CRTDLL__ismbstrail
@ cdecl _isnan(double) CRTDLL__isnan
@ forward _itoa ntdll._itoa
@ cdecl _itow(long str long) CRTDLL__itow
@ cdecl _j0(double) j0
@ cdecl _j1(double) j1
@ cdecl _jn(long double) jn
@ -188,28 +187,27 @@ debug_channels (crtdll)
@ cdecl _lsearch(ptr ptr long long ptr) CRTDLL__lsearch
@ cdecl _lseek(long long long) CRTDLL__lseek
@ forward _ltoa ntdll._ltoa
@ cdecl _ltow(long str long) CRTDLL__ltow
@ cdecl _makepath (ptr str str str str) CRTDLL__makepath
@ cdecl _matherr(ptr) CRTDLL__matherr
@ stub _mbbtombc
@ cdecl _mbbtombc(long) CRTDLL__mbbtombc
@ stub _mbbtype
@ cdecl _mbccpy (str str) CRTDLL__mbccpy
@ cdecl _mbccpy (str str) strcpy
@ stub _mbcjistojms
@ stub _mbcjmstojis
@ stub _mbclen
@ cdecl _mbclen(long) CRTDLL__mbclen
@ stub _mbctohira
@ stub _mbctokata
@ stub _mbctolower
@ stub _mbctombb
@ stub _mbctoupper
@ stub _mbctype
@ extern _mbctype CRTDLL_mbctype
@ stub _mbsbtype
@ cdecl _mbscat(str str) strcat
@ stub _mbschr
@ stub _mbscmp
@ cdecl _mbschr(str long) CRTDLL__mbschr
@ cdecl _mbscmp(str str) CRTDLL__mbscmp
@ cdecl _mbscpy(ptr str) strcpy
@ stub _mbscspn
@ stub _mbsdec
@ cdecl _mbsdec(str str) CRTDLL__mbsdec
@ cdecl _mbsdup(str) CRTDLL__strdup
@ cdecl _mbsicmp(str str) CRTDLL__mbsicmp
@ cdecl _mbsinc(str) CRTDLL__mbsinc
@ -221,23 +219,23 @@ debug_channels (crtdll)
@ stub _mbsnbcpy
@ stub _mbsnbicmp
@ stub _mbsnbset
@ stub _mbsncat
@ stub _mbsnccnt
@ stub _mbsncmp
@ stub _mbsncpy
@ stub _mbsnextc
@ stub _mbsnicmp
@ stub _mbsninc
@ stub _mbsnset
@ cdecl _mbsncat(str str long) CRTDLL__mbsncat
@ cdecl _mbsnccnt(str long) CRTDLL__mbsnccnt
@ cdecl _mbsncmp(str str long) CRTDLL__mbsncmp
@ cdecl _mbsncpy(str str long) CRTDLL__mbsncpy
@ cdecl _mbsnextc(str) CRTDLL__mbsnextc
@ cdecl _mbsnicmp(str str long) CRTDLL__mbsncmp
@ cdecl _mbsninc(str long) CRTDLL__mbsninc
@ cdecl _mbsnset(str long long) CRTDLL__mbsnset
@ stub _mbspbrk
@ cdecl _mbsrchr(str long) CRTDLL__mbsrchr
@ stub _mbsrev
@ stub _mbsset
@ cdecl _mbsset(str long) CRTDLL__mbsset
@ stub _mbsspn
@ stub _mbsspnp
@ stub _mbsstr
@ cdecl _mbsstr(str str) strstr
@ stub _mbstok
@ stub _mbstrlen
@ cdecl _mbstrlen(str) CRTDLL__mbstrlen
@ stub _mbsupr
@ cdecl _memccpy(ptr ptr long long) memccpy
@ forward _memicmp ntdll._memicmp
@ -534,3 +532,5 @@ debug_channels (crtdll)
@ cdecl wctomb(ptr long) CRTDLL_wctomb
@ stub wprintf
@ stub wscanf
#@ cdecl _itow(long str long) CRTDLL__itow
#@ cdecl _ltow(long str long) CRTDLL__ltow

View File

@ -67,7 +67,7 @@ UINT CRTDLL_osminor_dll; /* CRTDLL.242 */
UINT CRTDLL_osmode_dll; /* CRTDLL.243 */
UINT CRTDLL_osver_dll; /* CRTDLL.244 */
UINT CRTDLL_osversion_dll; /* CRTDLL.245 */
LONG CRTDLL_timezone_dll = 1; /* CRTDLL.245 */
LONG CRTDLL_timezone_dll = 0; /* CRTDLL.304 */
UINT CRTDLL_winmajor_dll; /* CRTDLL.329 */
UINT CRTDLL_winminor_dll; /* CRTDLL.330 */
UINT CRTDLL_winver_dll; /* CRTDLL.331 */
@ -840,7 +840,7 @@ LPSTR __cdecl CRTDLL__fullpath(LPSTR absPath, LPCSTR relPath, INT size)
fln_fix(res);
len = strlen(res);
if (len >= MAX_PATH || len >= size)
if (len >= MAX_PATH || len >= (size_t)size)
return NULL; /* FIXME: errno? */
if (!absPath)
@ -1724,7 +1724,7 @@ INT __cdecl CRTDLL__isnan(double d)
*/
VOID __cdecl CRTDLL__purecall(VOID)
{
CRTDLL__amsg_exit( 6025 );
CRTDLL__amsg_exit( 25 );
}
@ -1771,11 +1771,11 @@ div_t __cdecl CRTDLL_div(INT x, INT y)
* [i386] Windows binary compatible - returns the struct in eax/edx.
*/
#ifdef __i386__
LONGLONG __cdecl CRTDLL_ldiv(LONG x, LONG y)
ULONGLONG __cdecl CRTDLL_ldiv(LONG x, LONG y)
{
LONGLONG retVal;
ULONGLONG retVal;
ldiv_t ldt = ldiv(x,y);
retVal = ((LONGLONG)ldt.rem << 32) | ldt.quot;
retVal = ((ULONGLONG)ldt.rem << 32) | (ULONG)ldt.quot;
return retVal;
}
#endif /* defined(__i386__) */

View File

@ -177,8 +177,7 @@ INT __cdecl CRTDLL__findnext(DWORD hand, find_t * ft)
if (!FindNextFileA(hand, &find_data))
{
SetLastError(ERROR_INVALID_DRIVE);
__CRTDLL__set_errno(GetLastError());
CRTDLL_errno = ENOENT;
return -1;
}

View File

@ -80,7 +80,10 @@ INT __cdecl CRTDLL__abnormal_termination(VOID)
*/
VOID __cdecl CRTDLL__amsg_exit(INT err)
{
CRTDLL_fprintf(CRTDLL_stderr,"\nrun-time error:\nError Code %d\n",err);
/* FIXME: Should be a popup for msvcrt gui executables, and should have
* text for the error number.
*/
CRTDLL_fprintf(CRTDLL_stderr,"\nruntime error R60%d\n",err);
CRTDLL__exit(255);
}

View File

@ -888,9 +888,9 @@ INT __cdecl CRTDLL__putw(INT val, CRTDLL_FILE* file)
*/
INT __cdecl CRTDLL__rmtmp(void)
{
int num_removed = 0, i = 3;
int num_removed = 0, i;
while(i < __CRTDLL_fdend)
for (i = 3; i < __CRTDLL_fdend; i++)
if (__CRTDLL_tempfiles[i])
{
CRTDLL__close(i);
@ -1281,7 +1281,7 @@ WCHAR __cdecl CRTDLL_fputwc( WCHAR wc, CRTDLL_FILE* file)
*/
INT __cdecl CRTDLL_fputs( LPCSTR s, CRTDLL_FILE* file )
{
return CRTDLL_fwrite(s,strlen(s),1,file);
return CRTDLL_fwrite(s,strlen(s),1,file) == 1 ? 0 : CRTDLL_EOF;
}

View File

@ -36,15 +36,12 @@
* a table for a supported Wine locale, mail it to me and
* I will add the needed support (jon_p_griffiths@yahoo.com).
*/
#include "crtdll.h"
#include "winnt.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "winnt.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
@ -55,6 +52,7 @@ DEFAULT_DEBUG_CHANNEL(crtdll);
*/
char __CRTDLL_current_lc_all[MAX_LOCALE_LENGTH];
LCID __CRTDLL_current_lc_all_lcid;
UINT __CRTDLL_current_lc_all_cp;
/* Friendly country strings & iso codes for synonym support.
* Based on MS documentation for setlocale().
@ -80,7 +78,7 @@ static const char* _country_synonyms[] =
/* INTERNAL: Map a synonym to an ISO code */
static void remap_synonym(char *name)
{
int i;
size_t i;
for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
{
if (!strcasecmp(_country_synonyms[i],name))
@ -271,6 +269,7 @@ static void __CRTDLL_set_ctype(UINT codepage, LCID lcid)
unsigned char *traverse = (unsigned char *)cp.LeadByte;
memset(__CRTDLL_current_ctype, 0, sizeof(CRTDLL_ctype));
__CRTDLL_current_lc_all_cp = codepage;
/* Switch ctype macros to MBCS if needed */
CRTDLL__mb_cur_max_dll = cp.MaxCharSize;
@ -330,29 +329,28 @@ LPSTR __cdecl CRTDLL_setlocale(INT category, LPCSTR locale)
/* Default Locale: Special case handling */
if (!strlen(locale) || ((toupper(locale[0]) == 'C') && !locale[1]))
{
if ((toupper(__CRTDLL_current_lc_all[0]) != 'C')
|| __CRTDLL_current_lc_all[1])
{
__CRTDLL_current_lc_all[0] = 'C';
__CRTDLL_current_lc_all[1] = 0;
switch (category) {
case CRTDLL_LC_ALL:
lc_all = 1; /* Fall through all cases ... */
case CRTDLL_LC_COLLATE:
if (!lc_all) break;
case CRTDLL_LC_CTYPE:
/* Restore C locale ctype info */
CRTDLL__mb_cur_max_dll = 1;
memcpy(__CRTDLL_current_ctype, CRTDLL_ctype, sizeof(CRTDLL_ctype));
if (!lc_all) break;
case CRTDLL_LC_MONETARY:
if (!lc_all) break;
case CRTDLL_LC_NUMERIC:
if (!lc_all) break;
case CRTDLL_LC_TIME:
}
return __CRTDLL_current_lc_all;
__CRTDLL_current_lc_all[0] = 'C';
__CRTDLL_current_lc_all[1] = '\0';
__CRTDLL_current_lc_all_cp = GetACP();
switch (category) {
case CRTDLL_LC_ALL:
lc_all = 1; /* Fall through all cases ... */
case CRTDLL_LC_COLLATE:
if (!lc_all) break;
case CRTDLL_LC_CTYPE:
/* Restore C locale ctype info */
CRTDLL__mb_cur_max_dll = 1;
memcpy(__CRTDLL_current_ctype, CRTDLL_ctype, sizeof(CRTDLL_ctype));
memset(CRTDLL_mbctype, 0, sizeof(CRTDLL_mbctype));
if (!lc_all) break;
case CRTDLL_LC_MONETARY:
if (!lc_all) break;
case CRTDLL_LC_NUMERIC:
if (!lc_all) break;
case CRTDLL_LC_TIME:
}
return __CRTDLL_current_lc_all;
}
/* Get locale elements */

View File

@ -2,59 +2,180 @@
* CRTDLL multi-byte string functions
*
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
* NOTES
* See msdn.microsoft.com
* /library/devprods/vs6/visualc/vccore/_crt__ismbb_routines.htm
* For details and CP 932 information.
*
* This code assumes that MB_LEN_MAX is 2 and that [0,0] is an
* invalid MB char. If that changes, this will need to too.
*
* CRTDLL reports valid CP 932 multibyte chars when the current
* code page is not 932. MSVCRT fixes this bug - we implement
* MSVCRT's behaviour, since its correct. However, MSVCRT fails
* to set the code page correctly when the locale is changed, so
* it must be explicitly set to get matching results.
*
* FIXME
* Not currently binary compatable with win32. CRTDLL_mbctype must be
* populated correctly and the ismb* functions should reference it.
*/
#include "crtdll.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
UCHAR CRTDLL_mbctype[257];
/*********************************************************************
* _mbsicmp (CRTDLL.204)
* _mbscmp (CRTDLL.??)
*
* Compare two multibyte strings.
*/
int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
INT __cdecl CRTDLL__mbscmp( LPCSTR str, LPCSTR cmp )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT strc, cmpc;
do {
if (!*x)
return !!*y;
if (!*y)
return !!*x;
/* FIXME: MBCS handling... */
if (*x!=*y)
return 1;
x++;
y++;
if (!*str)
return *cmp ? -1 : 0;
if (!*cmp)
return 1;
strc = CRTDLL__mbsnextc(str);
cmpc = CRTDLL__mbsnextc(cmp);
if (strc != cmpc)
return strc < cmpc ? -1 : 1;
str += (strc > 255) ? 2 : 1;
cmp += (strc > 255) ? 2 : 1; /* equal, use same increment */
} while (1);
}
return strcmp(str, cmp); /* ASCII CP */
}
/*********************************************************************
* CRTDLL__mbsinc (CRTDLL.205)
* _mbsicmp (CRTDLL.??)
*
* Compare two multibyte strings case insensitively.
*/
INT __cdecl CRTDLL__mbsicmp( LPCSTR str, LPCSTR cmp )
{
/* FIXME: No tolower() for mb strings yet */
if (CRTDLL__mb_cur_max_dll > 1)
return CRTDLL__mbscmp( str, cmp );
return strcasecmp( str, cmp ); /* ASCII CP */
}
/*********************************************************************
* _mbsncmp (CRTDLL.??)
*
* Compare two multibyte strings to 'len' characters.
*/
INT __cdecl CRTDLL__mbsncmp( LPCSTR str, LPCSTR cmp, UINT len )
{
if (!len)
return 0;
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT strc, cmpc;
while (len--)
{
if (!*str)
return *cmp ? -1 : 0;
if (!*cmp)
return 1;
strc = CRTDLL__mbsnextc(str);
cmpc = CRTDLL__mbsnextc(cmp);
if (strc != cmpc)
return strc < cmpc ? -1 : 1;
str += (strc > 255) ? 2 : 1;
cmp += (strc > 255) ? 2 : 1; /* Equal, use same increment */
}
return 0; /* Matched len chars */
}
return strncmp(str, cmp, len); /* ASCII CP */
}
/*********************************************************************
* _mbsnicmp (CRTDLL.??)
*
* Compare two multibyte strings case insensitively to 'len' characters.
*/
INT __cdecl CRTDLL__mbsnicmp( LPCSTR str, LPCSTR cmp, UINT len )
{
/* FIXME: No tolower() for mb strings yet */
if (CRTDLL__mb_cur_max_dll > 1)
return CRTDLL__mbsncmp( str, cmp, len );
return strncasecmp( str, cmp, len ); /* ASCII CP */
}
/*********************************************************************
* _mbsinc (CRTDLL.205)
*
* Return the next character of a string.
*/
LPSTR __cdecl CRTDLL__mbsinc( LPCSTR str )
{
if (IsDBCSLeadByte( *str )) str++;
return (LPSTR)(str + 1);
if (CRTDLL__mb_cur_max_dll > 1 &&
CRTDLL_isleadbyte(*str))
return (LPSTR)str + 2; /* MB char */
return (LPSTR)str + 1; /* ASCII CP or SB char */
}
/*********************************************************************
* CRTDLL__mbslen (CRTDLL.206)
* _mbsninc (CRTDLL.??)
*
* Return the 'num'th character of a string.
*/
LPSTR CRTDLL__mbsninc( LPCSTR str, INT num )
{
if (!str || num < 1)
return NULL;
if (CRTDLL__mb_cur_max_dll > 1)
{
while(num--)
str = CRTDLL__mbsinc( str );
return (LPSTR)str;
}
return (LPSTR)str + num; /* ASCII CP */
}
/*********************************************************************
* _mbslen (CRTDLL.206)
*
* Get the length of a string.
*/
INT __cdecl CRTDLL__mbslen( LPCSTR str )
{
INT len;
for (len = 0; *str; len++, str++) if (IsDBCSLeadByte(str[0]) && str[1]) str++;
if (CRTDLL__mb_cur_max_dll > 1)
{
INT len = 0;
while (*str)
{
str += CRTDLL_isleadbyte( *str ) ? 2 : 1;
len++;
}
return len;
}
return strlen( str ); /* ASCII CP */
}
/*********************************************************************
* _mbsrchr (CRTDLL.223)
*/
LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x)
LPSTR __cdecl CRTDLL__mbsrchr(LPCSTR s,CHAR x)
{
/* FIXME: handle multibyte strings */
return strrchr(s,x);
@ -62,7 +183,7 @@ LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x)
/*********************************************************************
* CRTDLL_mbtowc (CRTDLL.430)
* mbtowc (CRTDLL.430)
*/
INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
{
@ -71,7 +192,7 @@ INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
if (!MultiByteToWideChar( CP_ACP, 0, str, n, dst, 1 )) return 0;
/* return the number of bytes from src that have been used */
if (!*str) return 0;
if (n >= 2 && IsDBCSLeadByte(*str) && str[1]) return 2;
if (n >= 2 && CRTDLL_isleadbyte(*str) && str[1]) return 2;
return 1;
}
@ -83,7 +204,355 @@ INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
*/
VOID __cdecl CRTDLL__mbccpy(LPSTR dest, LPSTR src)
{
FIXME("MBCS copy treated as ASCII\n");
*dest = *src;
*dest++ = *src;
if (CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte(*src))
*dest = *++src; /* MB char */
}
/*********************************************************************
* _mbsdec (CRTDLL.??)
*
* Return the character before 'cur'.
*/
LPSTR __cdecl CRTDLL__mbsdec( LPCSTR start, LPCSTR cur )
{
if (CRTDLL__mb_cur_max_dll > 1)
return (LPSTR)(CRTDLL__ismbstrail(start,cur-1) ? cur - 2 : cur -1);
return (LPSTR)cur - 1; /* ASCII CP or SB char */
}
/*********************************************************************
* _mbbtombc (CRTDLL.??)
*
* Convert a single byte character to a multi byte character.
*/
USHORT __cdecl CRTDLL__mbbtombc( USHORT c )
{
if (CRTDLL__mb_cur_max_dll > 1 &&
((c >= 0x20 && c <=0x7e) || (c >= 0xa1 && c <= 0xdf)))
{
/* FIXME: I can't get this function to return anything
* different to what I pass it...
*/
}
return c; /* ASCII CP or no MB char */
}
/*********************************************************************
* _mbclen (CRTDLL.??)
*
* Get the length of a multibyte character.
*/
INT __cdecl CRTDLL__mbclen( LPCSTR str )
{
return CRTDLL_isleadbyte( *str ) ? 2 : 1;
}
/*********************************************************************
* _ismbbkana (CRTDLL.??)
*
* Is the given single byte character Katakana?
*/
INT __cdecl CRTDLL__ismbbkana( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
/* Japanese/Katakana, CP 932 */
return (c >= 0xa1 && c <= 0xdf);
}
return 0;
}
/*********************************************************************
* _ismbchira (CRTDLL.??)
*
* Is the given character Hiragana?
*/
INT __cdecl CRTDLL__ismbchira( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
/* Japanese/Hiragana, CP 932 */
return (c >= 0x829f && c <= 0x82f1);
}
return 0;
}
/*********************************************************************
* _ismbckata (CRTDLL.??)
*
* Is the given double byte character Katakana?
*/
INT __cdecl CRTDLL__ismbckata( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
if ( c < 256)
return CRTDLL__ismbbkana( c );
/* Japanese/Katakana, CP 932 */
return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
}
return 0;
}
/*********************************************************************
* _ismbblead (CRTDLL.??)
*
* Is the given single byte character a lead byte?
*/
INT __cdecl CRTDLL__ismbblead( UINT c )
{
/* FIXME: should reference CRTDLL_mbctype */
return CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte( c );
}
/*********************************************************************
* _ismbbtrail (CRTDLL.??)
*
* Is the given single byte character a trail byte?
*/
INT __cdecl CRTDLL__ismbbtrail( UINT c )
{
/* FIXME: should reference CRTDLL_mbctype */
return !CRTDLL__ismbblead( c );
}
/*********************************************************************
* _ismbslead (CRTDLL.??)
*
* Is the character pointed to 'str' a lead byte?
*/
INT __cdecl CRTDLL__ismbslead( LPCSTR start, LPCSTR str )
{
/* Lead bytes can also be trail bytes if caller messed up
* iterating through the string...
*/
if (CRTDLL__mb_cur_max_dll > 1)
{
while (start < str)
start += CRTDLL_isleadbyte ( *str ) ? 2 : 1;
if (start == str)
return CRTDLL_isleadbyte( *str );
}
return 0; /* Must have been a trail, we skipped it */
}
/*********************************************************************
* _ismbstrail (CRTDLL.??)
*
* Is the character pointed to 'str' a trail byte?
*/
INT __cdecl CRTDLL__ismbstrail( LPCSTR start, LPCSTR str )
{
/* Must not be a lead, and must be preceeded by one */
return !CRTDLL__ismbslead( start, str ) && CRTDLL_isleadbyte(str[-1]);
}
/*********************************************************************
* _mbsset (CRTDLL.??)
*
* Fill a multibyte string with a value.
*/
LPSTR __cdecl CRTDLL__mbsset( LPSTR str, UINT c )
{
LPSTR ret = str;
if (CRTDLL__mb_cur_max_dll == 1 || c < 256)
return CRTDLL__strset( str, c ); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */
while (str[0] && str[1])
{
*str++ = c >> 8;
*str++ = c & 0xff;
}
if (str[0])
str[0] = '\0'; /* FIXME: OK to shorten? */
return ret;
}
/*********************************************************************
* _mbsnset (CRTDLL.??)
*
* Fill a multibyte string with a value up to 'len' characters.
*/
LPSTR __cdecl CRTDLL__mbsnset( LPSTR str, UINT c, UINT len )
{
LPSTR ret = str;
if (!len)
return ret;
if (CRTDLL__mb_cur_max_dll == 1 || c < 256)
return CRTDLL__strnset( str, c, len ); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */
while (str[0] && str[1] && len--)
{
*str++ = c >> 8;
*str++ = c & 0xff;
}
if (len && str[0])
str[0] = '\0'; /* FIXME: OK to shorten? */
return ret;
}
/*********************************************************************
* _mbstrlen (CRTDLL.??)
*
* Get the length of a multibyte string.
*/
INT __cdecl CRTDLL__mbstrlen( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
INT len = 0;
while (*str)
{
str += CRTDLL_isleadbyte ( *str ) ? 2 : 1;
len++;
}
return len;
}
return strlen( str ); /* ASCII CP */
}
/*********************************************************************
* _mbsnextc (CRTDLL.??)
*
* Get the next character from a multibyte string.
*/
UINT __cdecl CRTDLL__mbsnextc( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte( *str ))
return *str << 8 | str[1];
return *str; /* ASCII CP or SB char */
}
/*********************************************************************
* _mbsncpy (CRTDLL.??)
*
* Copy one multibyte string to another up to 'len' characters.
*/
LPSTR __cdecl CRTDLL__mbsncpy( LPSTR dst, LPCSTR src, UINT len )
{
if (!len)
return dst;
if (CRTDLL__mb_cur_max_dll > 1)
{
LPSTR ret = dst;
while (src[0] && src[1] && len--)
{
*dst++ = *src++;
*dst++ = *src++;
}
if (len--)
{
*dst++ = *src++; /* Last char or '\0' */
while(len--)
*dst++ = '\0';
}
return ret;
}
return strncpy( dst, src, len ); /* ASCII CP */
}
/*********************************************************************
* _mbschr (CRTDLL.??)
*
* Find a multibyte character in a multibyte string.
*/
LPSTR __cdecl CRTDLL__mbschr( LPCSTR str, UINT c )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT next;
while((next = CRTDLL__mbsnextc( str )))
{
if (next == c)
return (LPSTR)str;
str += next > 255 ? 2 : 1;
}
return c ? NULL : (LPSTR)str;
}
return strchr( str, c ); /* ASCII CP */
}
/*********************************************************************
* _mbsnccnt (CRTDLL.??)
*
* Return the number of mutibyte characters in 'len' bytes of a string.
*/
UINT __cdecl CRTDLL__mbsnccnt( LPCSTR str, UINT len )
{
int ret = 0;
if (CRTDLL__mb_cur_max_dll > 1)
{
while(*str && len-- > 0)
{
if (CRTDLL_isleadbyte ( *str ))
{
str++;
len--;
}
ret++;
str++;
}
return ret;
}
return min( strlen( str ), len ); /* ASCII CP */
}
/*********************************************************************
* _mbsncat (CRTDLL.??)
*
* Add 'len' characters from one multibyte string to another.
*/
LPSTR __cdecl CRTDLL__mbsncat( LPSTR dst, LPCSTR src, UINT len )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
LPSTR res = dst;
dst += CRTDLL__mbslen( dst );
while (*src && len--)
{
*dst = *src;
if (CRTDLL_isleadbyte( *src ))
*++dst = *++src;
dst++;
src++;
}
*dst++ = '\0';
return res;
}
return strncat( dst, src, len ); /* ASCII CP */
}

View File

@ -9,6 +9,7 @@ CHAR
DWORD
HANDLE
INT
USHORT
LONG
ULONG
UINT
@ -17,7 +18,6 @@ UCHAR
clock_t
size_t
time_t
unsigned char
%long # --forbidden
@ -28,13 +28,12 @@ unsigned long
%longlong
LONGLONG
ULONGLONG
%ptr
CHAR *
CRTDLL_FILE *
CRTDLL_fpos_t *
LPCSTR *
LPCVOID
LPDWORD
LPDWORD *
@ -42,12 +41,12 @@ LPINT
LPUINT
LPSTR *
LPSTR **
LPCSTR *
LPVOID
PCONTEXT
PEXCEPTION_FRAME
PEXCEPTION_FRAME *
PEXCEPTION_RECORD
PINT
VOID *
WCHAR *
_INITTERMFUN *
@ -60,6 +59,7 @@ time_t *
struct _heapinfo *
struct _utimbuf *
struct _exception *
CRTDLL_fpos_t *
diskfree_t *
unsigned char *
va_list