unsigned char * __cdecl _mbslwr(
    unsigned char *string
    )
{
        unsigned char *cp;

        _mlock(_MB_CP_LOCK);

        for (cp=string; *cp; cp++)
        {
            if (_ISLEADBYTE(*cp))
            {

#if defined (_WIN32)

                int retval;
                unsigned char ret[4];

                if ((retval = __crtLCMapStringA(__mblcid,
                                                LCMAP_LOWERCASE,
                                                cp,
                                                2,
                                                ret,
                                                2,
                                                __mbcodepage,
                                                TRUE)) == 0)
                {
                    _munlock(_MB_CP_LOCK);
                    return NULL;
                }

                *cp = ret[0];

                if (retval > 1)
                    *(++cp) = ret[1];

#else  /* defined (_WIN32) */

                int mbval = ((*cp) << 8) + *(cp+1);

                cp++;
                if (     mbval >= _MBUPPERLOW1
                    &&   mbval <= _MBUPPERHIGH1 )
                    *cp += _MBCASEDIFF1;

                else if (mbval >= _MBUPPERLOW2
                    &&   mbval <= _MBUPPERHIGH2 )
                    *cp += _MBCASEDIFF2;
#endif  /* defined (_WIN32) */

            }
            else
                /* single byte, macro version */
                *cp = (unsigned char) _mbbtolower(*cp);
        }

        _munlock(_MB_CP_LOCK);
        return string ;
}
Exemple #2
0
int __cdecl _mbsicmp (const unsigned char *s1, const unsigned char *s2)
{
        unsigned short c1, c2;
#if defined (_WIN32)
        int    retval;
        unsigned char szResult[4];
#endif  /* defined (_WIN32) */

        if ( _ISNOTMBCP )
            return _stricmp(s1, s2);

        _mlock(_MB_CP_LOCK);

        for (;;)
        {
            c1 = *s1++;
            if (_ISLEADBYTE(c1))
            {
                if (*s1 == '\0')
                    c1 = 0;
                else
                {
#if defined (_WIN32)
                    retval = __crtLCMapStringA(__mblcid, LCMAP_UPPERCASE,
                                               s1 - 1, 2, szResult, 2,
                                               __mbcodepage, TRUE);
                    if (retval == 1)
                        c1 = szResult[0];
                    else if (retval == 2)
                        c1 = (szResult[0] << 8) + szResult[1];
                    else
                    {
                        _munlock(_MB_CP_LOCK);
                        return _NLSCMPERROR;
                    }
                    s1++;
#else  /* defined (_WIN32) */
                    c1 = ((c1 << 8) | *s1++);
                    if (c1 >= _MBUPPERLOW1 && c1 <= _MBUPPERHIGH1)
                        c1 += _MBCASEDIFF1;
                    else if (c1 >= _MBUPPERLOW2 && c1 <= _MBUPPERHIGH2)
                        c1 += _MBCASEDIFF2;
#endif  /* defined (_WIN32) */
                }
            }
            else
                c1 = _mbbtolower(c1);

            c2 = *s2++;
            if (_ISLEADBYTE(c2))
            {
                if (*s2 == '\0')
                    c2 = 0;
                else
                {
#if defined (_WIN32)
                    retval = __crtLCMapStringA(__mblcid, LCMAP_UPPERCASE,
                                               s2 - 1, 2, szResult, 2,
                                               __mbcodepage, TRUE);
                    if (retval == 1)
                        c2 = szResult[0];
                    else if (retval == 2)
                        c2 = (szResult[0] << 8) + szResult[1];
                    else
                    {
                        _munlock(_MB_CP_LOCK);
                        return _NLSCMPERROR;
                    }
                    s2++;
#else  /* defined (_WIN32) */
                    c2 = ((c2 << 8) | *s2++);
                    if (c2 >= _MBUPPERLOW1 && c2 <= _MBUPPERHIGH1)
                        c2 += _MBCASEDIFF1;
                    else if (c2 >= _MBUPPERLOW2 && c2 <= _MBUPPERHIGH2)
                        c2 += _MBCASEDIFF2;
#endif  /* defined (_WIN32) */
                }
            }
            else
                c2 = _mbbtolower(c2);

            if (c1 != c2)
            {
                _munlock(_MB_CP_LOCK);
                return( (c1 > c2) ? 1 : -1 );
            }

            if (c1 == 0)
            {
                _munlock(_MB_CP_LOCK);
                return(0);
            }
        }
}
Exemple #3
0
int __cdecl _mbsicmp(
    const unsigned char *s1,
    const unsigned char *s2
    )
{
	unsigned short c1, c2;

        if (0 == __mbcodepage)
            return _stricmp(s1, s2);

        _mlock(_MB_CP_LOCK);

        for (;;) {

            c1 = *s1++;
            if (_ISLEADBYTE(c1)) {
                if (*s1 == '\0')
                    c1 = 0;
                else {
                    c1 = ((c1<<8) | *s1++);

                    if ( ((c1 >= _MBUPPERLOW1) && (c1 <= _MBUPPERHIGH1)) )
                        c1 += _MBCASEDIFF1;

                    else if ( ((c1 >= _MBUPPERLOW2) && (c1 <= _MBUPPERHIGH2)) )
                        c1 += _MBCASEDIFF2;
			}
		}
		else
                c1 = _mbbtolower(c1);

            c2 = *s2++;
            if (_ISLEADBYTE(c2)) {
                if (*s2 == '\0')
                    c2 = 0;
                else {
				c2 = ((c2<<8) | *s2++);

                    if ( ((c2 >= _MBUPPERLOW1) && (c2 <= _MBUPPERHIGH1)) )
                        c2 += _MBCASEDIFF1;

                    else if ( ((c2 >= _MBUPPERLOW2) && (c2 <= _MBUPPERHIGH2)) )
                        c2 += _MBCASEDIFF2;
                }
            }
		else
                c2 = _mbbtolower(c2);

            if (c1 != c2)
            {
                _munlock(_MB_CP_LOCK);
                return( (c1 > c2) ? 1 : -1 );
            }

            if (c1 == 0)
            {
                _munlock(_MB_CP_LOCK);
                return(0);
            }

        }
}
Exemple #4
0
int __cdecl _mbsnbicmp(
        const unsigned char *s1,
        const unsigned char *s2,
        size_t n
        )
{
        unsigned short c1, c2;

        if (n==0)
                return(0);

        if ( _ISNOTMBCP )
            return _strnicmp(s1, s2, n);

        _mlock(_MB_CP_LOCK);

        while (n--) {

                c1 = *s1++;
                if (_ISLEADBYTE(c1)) {
                        if (n==0)
                {
                    c1 = 0; /* 'naked' lead - end of string */
                    c2 = _ISLEADBYTE(*s2) ? 0 : *s2;
                    goto test;
                }
                        if (*s1 == '\0')
                                c1 = 0;
                        else {
                                c1 = ((c1<<8) | *s1++);

                    if ( ((c1 >= _MBUPPERLOW1) && (c1 <= _MBUPPERHIGH1)) )
                        c1 += _MBCASEDIFF1;

                    else if ( ((c1 >= _MBUPPERLOW2) && (c1 <= _MBUPPERHIGH2)) )
                        c1 += _MBCASEDIFF2;
                        }
                }
                else
                c1 = _mbbtolower(c1);

                c2 = *s2++;
                if (_ISLEADBYTE(c2)) {
                        if (n==0)
                {
                    c2 = 0; /* 'naked' lead - end of string */
                    goto test;
                }
                n--;
                        if (*s2 == '\0')
                                c2 = 0;
                        else {
                                c2 = ((c2<<8) | *s2++);

                    if ( ((c2 >= _MBUPPERLOW1) && (c2 <= _MBUPPERHIGH1)) )
                        c2 += _MBCASEDIFF1;

                    else if ( ((c2 >= _MBUPPERLOW2) && (c2 <= _MBUPPERHIGH2)) )
                        c2 += _MBCASEDIFF2;
                        }
                }
                else
                c2 = _mbbtolower(c2);

test:
            if (c1 != c2)
            {
                _munlock(_MB_CP_LOCK);
                        return( (c1 > c2) ? 1 : -1);
            }

            if (c1 == 0)
            {
                _munlock(_MB_CP_LOCK);
                        return(0);
            }
        }

        _munlock(_MB_CP_LOCK);
        return(0);
}