Ejemplo n.º 1
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbsnbset,_fmbsnbset)( unsigned char _FFAR *string, unsigned int ch, size_t n )
{
    size_t                  char_size;
    unsigned char _FFAR *   string_start;
    unsigned char           mbc[MB_LEN_MAX+1];

//    if( !__IsDBCS && !ch&0xFF00 )  return( strnset( string, ch, n ) );

    /*** Set every character in the string to 'ch' ***/
    _NEARFAR(_mbvtop,_fmbvtop)( ch, mbc );  /* convert from unsigned int */
    char_size = _NEARFAR(_mbclen,_fmbclen)( mbc );    /* get char size */
    string_start = string;                            /* save string start */
    while( n >= char_size ) {
        _NEARFAR(_mbccpy,_fmbccpy)( string, mbc );    /* copy the character */
        string = _NEARFAR(_mbsinc,_fmbsinc)( string );/* point to next spot */
        n -= char_size;                               /* update counter */
    }

    /*** Pad any remaining bytes with blanks ***/
    while( n-- > 0 ) {
        *(string++) = ' ';
    }

    return( string_start );
}
Ejemplo n.º 2
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbstok_r,_fmbstok_r)( unsigned char _FFAR *str, const unsigned char _FFAR *delim, unsigned char _FFAR **ptr )
{
    unsigned char _FFAR *   string_start;
    int                     count;
    int                     char_len;

//    if( !__IsDBCS )  return( strtok( str, delim ) );

    if( str == NULL ) {
        str = *ptr;
        if( str == NULL )
            return( NULL );
    }

    /*** Skip characters until we reach one not in 'delim' ***/
    #ifdef __FARFUNC__
        while( !_fmbterm(str) && _fmbschr(delim,_fmbsnextc(str))!=NULL )
            str = _fmbsinc( str );
    #else
        while( !_mbterm(str) && _mbschr(delim,_mbsnextc(str))!=NULL )
            str = _mbsinc( str );
    #endif
    if( _NEARFAR(_mbterm,_fmbterm)(str) )  return( NULL );
    string_start = str;

    /*** Skip characters until we reach one in 'delim' ***/
    #ifdef __FARFUNC__
        while( !_fmbterm(str) && _fmbschr(delim,_fmbsnextc(str))==NULL )
            str = _fmbsinc( str );
    #else
        while( !_mbterm(str) && _mbschr(delim,_mbsnextc(str))==NULL )
            str = _mbsinc( str );
    #endif

    /*** Handle the next token ***/
    if( !_NEARFAR(_mbterm,_fmbterm)(str) ) {
        char_len = _NEARFAR(_mbclen,_fmbclen)( str ); /* get char length */
        for( count=0; count<char_len; count++ )
            str[count] = '\0';                  /* replace delim with NULL */
        str += char_len;                        /* start of next token */
        *ptr = str; /* save next start */
        return( string_start );                 /* return next token start */
    } else {
        *ptr = NULL;/* no more tokens */
        return( string_start );                 /* return same token */
    }
}
Ejemplo n.º 3
0
_WCRTLINK int _NEARFAR(_mbsnicmp,_fmbsnicmp)( const unsigned char _FFAR *s1, const unsigned char _FFAR *s2, size_t n )
{
    int                 status = 0;

//    if( !__IsDBCS )  return( strnicmp( s1, s2, n ) );

    /*** Compare characters, one by one ***/
    while( n>0 && !_NEARFAR(_mbterm,_fmbterm)(s1) && !_NEARFAR(_mbterm,_fmbterm)(s2) ) {
        status = _NEARFAR((_mbcicmp),(_fmbcicmp))( s1, s2 ); /* compare chars */
        if( status != 0 )  return( status );    /* if error, break from loop */
        s1 = _NEARFAR(_mbsinc,_fmbsinc)( s1 );  /* skip over character */
        s2 = _NEARFAR(_mbsinc,_fmbsinc)( s2 );  /* skip over character */
        n--;                                    /* update counter */
    }

    if( n > 0 ) /* implies that at least one of the strings terminated */
        return( *s1 - *s2 );
    else
        return( status );
}
Ejemplo n.º 4
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbsrchr,_fmbsrchr)( const unsigned char _FFAR *string, unsigned int ch )
{
    unsigned char _FFAR *   p = NULL;
    unsigned int            chTemp;

//    if( !__IsDBCS && !ch&0xFF00 )  return( strrchr( string, ch ) );

    /*** Search for the specified character ***/
    while( !_NEARFAR(_mbterm,_fmbterm)(string) ) {
        chTemp = _NEARFAR(_mbsnextc,_fmbsnextc)( string ); /* get character */
        if( chTemp == ch )                      /* is it the search char? */
            p = (unsigned char _FFAR*) string;  /* yes, store this address */
        string = _NEARFAR(_mbsinc,_fmbsinc)( string );  /* skip character */
    }

    if( ch != 0 )                               /* looking for NULL? */
        return( p );                            /* no, return last address */
    else
        return( (unsigned char _FFAR*) string );/* yes, return its address */
}
Ejemplo n.º 5
0
_WCRTLINK size_t _NEARFAR(__mbslen,__fmbslen)( unsigned char const _FFAR *s )
{
    size_t              count = 0;

    if( __IsDBCS ) {
        while( *s != '\0' ) {
            s += _ismbblead(*s) ? 2 : 1;/* point to next char */
            count++;                    /* update count */
        }
        return( count );
    } else {
        return( _NEARFAR(strlen,_fstrlen)( s ) );
    }
}
Ejemplo n.º 6
0
_WCRTLINK int _NEARFAR(mbtowc,_fmbtowc)( wchar_t _FFAR *pwc, const char _FFAR *ch, size_t n )
{
#ifdef __NT__
    int                 rc;
    int                 len;
    wchar_t             wch;
#endif

    /*** Catch special cases ***/
    if( ch == NULL )  return( 0 );
    if( n == 0 )  return( -1 );
    if( *ch == '\0' ) {
        if( pwc != NULL )  *pwc = L'\0';
        return( 0 );
    }
    if( _ismbblead( ch[0] )  &&  ch[1] == '\0' )  return( -1 ); /* invalid */

    /*** Convert the character ***/
    #ifdef __NT__
        len = _NEARFAR(_mbclen,_fmbclen)( (unsigned char _FFAR *)ch );
        rc = MultiByteToWideChar( __MBCodePage, MB_ERR_INVALID_CHARS,
                                  (LPCSTR)ch, min(n,len), (LPWSTR)&wch, 1 );
        if( rc != 0 ) {
            if( pwc != NULL )  *pwc = wch;
            return( len );                      /* return mbchar size */
        } else {
            return( -1 );                       /* cannot convert */
        }
    #else
        if( _ismbblead(*ch) && n>=2 ) {         /* lead byte present? */
            if( pwc != NULL ) {
                *pwc = (((wchar_t)ch[0])<<8) |  /* convert to lead:trail */
                        (wchar_t)ch[1];
            }
            return( 2 );                        /* return char size */
        } else if( !_ismbblead(*ch) ) {
            if( pwc != NULL ) {
                *pwc = (wchar_t)ch[0];          /* convert to 00:byte */
            }
            return( 1 );                        /* return char size */
        } else {
            return( -1 );                       /* n==1, but char 2 bytes */
        }
    #endif
}
Ejemplo n.º 7
0
_WCRTLINK int _NEARFAR(mbrtowc,_fmbrtowc)( wchar_t _FFAR *pwc, const char _FFAR *s, size_t n, mbstate_t _FFAR *ps )
{
    int                 rc;

    /*** Check the simple cases ***/
    if( s == NULL )  return( 0 );           /* always in initial state */
    if( n == 0 )  return( -2 );             /* can't process nothing */

    /*** Check for a valid multibyte character ***/
    rc = _NEARFAR(mbtowc,_fmbtowc)( pwc, s, n );
    if( rc != -1 ) {
        return( rc );
    } else if( n < MB_LEN_MAX && _ismbblead( (unsigned char)*s ) ) {
        return( -2 );                       /* incomplete, possibly valid */
    } else {
        _RWD_errno = EILSEQ;                /* encoding error */
        return( -1 );
    }
}
Ejemplo n.º 8
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbschr,_fmbschr)( const unsigned char _FFAR *string, unsigned int ch )
{
    char                mbc[MB_LEN_MAX+1];

//    if( !__IsDBCS && !ch&0xFF00 )  return( strchr( string, ch ) );

    /*** Search for the specified character ***/
    _mbvtop( ch, mbc );
    mbc[_mbclen(mbc)] = '\0';
    #ifdef __FARFUNC__
        while( !_fmbterm(string) && _fmbccmp(string,mbc)!=0 )
            string = _fmbsinc( string );        /* skip over character */
    #else
        while( !_mbterm(string) && _mbccmp(string,mbc)!=0 )
            string = _mbsinc( string );         /* skip over character */
    #endif

    /*** Return character address, or NULL if not found ***/
    if( !_NEARFAR(_mbterm,_fmbterm)(string) || ch==0 )
        return( (unsigned char _FFAR*) string );
    else
        return( NULL );
}
Ejemplo n.º 9
0
_WCRTLINK int _NEARFAR(_mbsnbicmp,_fmbsnbicmp)( const unsigned char _FFAR *s1, const unsigned char _FFAR *s2, size_t n )
{
    int                 status = 0;
    size_t              bytes;

//    if( !__IsDBCS )  return( strnicmp( s1, s2, n ) );

    /*** Compare characters, one by one ***/
    while( n>0 && !_NEARFAR(_mbterm,_fmbterm)(s1) && !_NEARFAR(_mbterm,_fmbterm)(s2) ) {
        if( n >= MB_LEN_MAX ) {
            status = _NEARFAR(_mbcicmp,_fmbcicmp)( s1, s2 );    /* compare */
        } else {
            status = _NEARFAR(strnicmp,_fstrnicmp)( s1, s2, n );/* compare */
        }
        if( status != 0 )  break;                   /* if error, exit loop */
        bytes = _NEARFAR(_mbclen,_fmbclen)( s1 );   /* char size in bytes */
        n = n>bytes ? n-bytes : 0;                  /* update counter */
        s1 = _NEARFAR(_mbsinc,_fmbsinc)( s1 );      /* skip over character */
        s2 = _NEARFAR(_mbsinc,_fmbsinc)( s2 );      /* skip over character */
    }

    return( status );
}
Ejemplo n.º 10
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbsupr,_fmbsupr)( unsigned char _FFAR *string )
{
#if defined(__NT__) && !defined(__FARFUNC__)
    CharUpper( (char _FFAR *)string );    // call the Win32 API
#else
    unsigned int            ch;
    unsigned char _FFAR     *p;
    unsigned char           mbc[MB_LEN_MAX+1];

    p = string;
    while( !_NEARFAR(_mbterm,_fmbterm)( p ) ) {
        ch = _mbctoupper( _NEARFAR(_mbsnextc,_fmbsnextc)( p ) );
        _NEARFAR(_mbvtop,_fmbvtop)( ch, mbc );
        mbc[_NEARFAR(_mbclen,_fmbclen)( mbc )] = '\0';
        _NEARFAR(_mbccpy,_fmbccpy)( p, mbc );
        p = _NEARFAR(_mbsinc,_fmbsinc)( p );
    }
#endif
    return( string );
}
Ejemplo n.º 11
0
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbscat,_fmbscat)( unsigned char _FFAR *s1, const unsigned char _FFAR *s2 )
{
    return( (unsigned char _FFAR *)_NEARFAR(strcat,_fstrcat)( (char _FFAR *)s1, (const char _FFAR *)s2 ) );
}