Beispiel #1
0
void main()
  {
    _setmbcp( 932 );
    printf( "%#6.4x\n", mb1[0] << 8 | mb1[1] );
    _mbccpy( mb1, mb2 );
    printf( "%#6.4x\n", mb1[0] << 8 | mb1[1] );
  }
Beispiel #2
0
/*
 * Translate  foo/dir1\\dir2" \\"bar"grok  -->  foo\\dir1\\dir2 \\"bargrok.
 */
char *PathConvertWithoutQuotes( const char *path )
/************************************************/
{
    char *              out;
    char *              p;
    bool                backslash = FALSE;  /* true if last char was a '\\' */
    bool                inquote = FALSE;    /* true if inside a quoted string */

    /*** Allocate a buffer for the new string (should be big enough) ***/
    out = AllocMem( 2 * ( strlen(path) + 1 + 2 ) );
    p = out;

    /*** Convert the path one character at a time ***/
    while( *path != '\0' ) {
        if( *path == '"' ) {
            if( inquote ) {
                if( backslash ) {
                    *p++ = '"';         /* handle \" within a string */
                    backslash = FALSE;
                } else {
                    inquote = FALSE;
                }
            } else {
                inquote = TRUE;
            }
        } else if( *path == '\\' ) {
            *p++ = '\\';
            if( backslash ) {
                backslash = FALSE;
            } else {
                backslash = TRUE;
            }
        } else if( *path == '/' ) {
            if( inquote ) {
                *p++ = '/';
            } else {
                *p++ = '\\';
            }
            backslash = FALSE;
        } else {
            /* copy an ordinary character */
            _mbccpy( (unsigned char *)p, (unsigned char *)path );     /* copy an ordinary character */
            p = (char *)_mbsinc( (unsigned char *)p );
            backslash = FALSE;
        }
        path = (char *)_mbsinc( (unsigned char *)path );
    }
    *p++ = '\0';

    return( out );
}
Beispiel #3
0
/*
 * Translate  foo/dir1\\dir2" \\"bar"grok  -->  "foo\\dir1\\dir2 \\"bargrok".
 */
char *PathConvert( const char *pathname, char quote )
/***************************************************/
{
    const unsigned char *path = (const unsigned char *)pathname;
    char                *out;
    unsigned char       *p;
    bool                quoteends = FALSE;  /* quote the whole filename */
    bool                backslash = FALSE;  /* true if last char was a '\\' */
    bool                inquote = FALSE;    /* true if inside a quoted string */

    /*** Allocate a buffer for the new string (should be big enough) ***/
    out = AllocMem( 2 * ( strlen( (char *)path ) + 1 + 2 ) );
    p = (unsigned char *)out;

    /*** Determine if path contains any bizarre characters ***/
    if( _mbschr( path, ' ' )  !=  NULL      ||
        _mbschr( path, '\t' )  !=  NULL     ||
        _mbschr( path, '"' )  !=  NULL      ||
        _mbschr( path, '\'' )  !=  NULL     ||
        _mbschr( path, '`' )  !=  NULL      ||
        _mbschr( path, quote )  !=  NULL ) {
        quoteends = TRUE;
        *p++ = quote;
    }

    /*** Convert the path one character at a time ***/
    while( *path != '\0' ) {
        if( *path == '"' ) {
            if( inquote ) {
                if( backslash ) {
                    *p++ = '"';         /* handle \" within a string */
                    backslash = FALSE;
                } else {
                    inquote = FALSE;
                }
            } else {
                inquote = TRUE;
            }
        } else if( *path == '\\' ) {
            *p++ = '\\';
            if( backslash ) {
                backslash = FALSE;
            } else {
                backslash = TRUE;
            }
        } else if( *path == '/' ) {
            if( inquote ) {
                *p++ = '/';
            } else {
                *p++ = '\\';
            }
            backslash = FALSE;
        } else {
            _mbccpy( p, path );         /* copy an ordinary character */
            p = _mbsinc( p );
            backslash = FALSE;
        }
        path = _mbsinc( path );
    }
    if( quoteends )  *p++ = quote;
    *p++ = '\0';

    return( out );
}
Beispiel #4
0
/*
 * _AddLine - add a line to the lines data structures
 */
void _AddLine( LPWDATA w, const void *in_data, unsigned len )
{
    int                 i;
    BOOL                hadbreak;
    HWND                hwnd;
    int                 tabcnt = 0;
    int                 nlcnt = 0;
    int                 curbufoff = 0;
    const char          *data;
#ifdef _MBCS
    static char         leadByte;
    static int          leadByteWaiting;
    unsigned char       ch[MB_CUR_MAX+1];
    LPBYTE              p;
#else
    char                ch;
#endif

    data = (const char *)in_data;
    hwnd = w->hwnd;

    _AccessWinLines();
    if( w->LineTail != NULL && !w->LineTail->has_cr ) {
        FARstrcpy( w->tmpbuff->data, w->LineTail->data );
#ifdef _MBCS
        curbufoff = FAR_mbslen( (LPBYTE)w->tmpbuff->data );
#else
        curbufoff = FARstrlen( w->tmpbuff->data );
#endif
        if( curbufoff > w->buffoff ) {
            w->buffoff = curbufoff;
        }
    }
    if( w->no_advance ) {
        curbufoff = 0;
    }
    for( i = 0; i < len; i ++ ) {
        w->no_advance = FALSE;
        do {
            hadbreak = FALSE;
#ifdef _MBCS                        /* MBCS */
            if( tabcnt ) {
                _mbccpy( ch, (unsigned char *)" " );     /* copy the character */
                ch[_mbclen( ch )] = '\0';           /* terminate char with NULL */
                tabcnt--;
            } else if( nlcnt ) {
                _mbccpy( ch, (unsigned char *)"\n" );    /* copy the character */
                ch[_mbclen( ch )] = '\0';           /* terminate char with NULL */
                nlcnt--;
            } else {
                if( !leadByteWaiting ) {
                    if( _ismbblead( *data ) ) {
                        leadByteWaiting = 1;
                        leadByte = *data;
                        ch[0] = '\0';
                    } else {
                        ch[0] = *data;
                        ch[1] = '\0';
                    }
                } else {
                    leadByteWaiting = 0;
                    ch[0] = leadByte;
                    ch[1] = *data;
                    ch[2] = '\0';
                }
                data++;
            }

            if( !_mbccmp( ch, (unsigned char *)"\t" ) ) {
                tabcnt = TAB( curbufoff + 1 );
                continue;
            } else if( !_mbccmp( ch, (unsigned char *)"\f" ) ) {
                nlcnt = w->height;
                continue;
            } else if( !_mbccmp( ch, (unsigned char *)"\r" ) ) {
                curbufoff = 0;
                w->no_advance = TRUE;
                w->tmpbuff->has_cr = TRUE;
                continue;
            } else if( !_mbccmp( ch, (unsigned char *)"\n" ) ) {
                hadbreak = TRUE;
                newLine( w );
                curbufoff = w->buffoff;
            } else if( !_mbccmp( ch, (unsigned char *)"\b" ) ) {
                if( curbufoff > 0 ) {
                    p = FAR_mbsninc( (LPBYTE)w->tmpbuff->data, curbufoff - 1 );
                    if( _ismbblead( *p ) ) {
                        *p = ' ';           /* stomp lead byte */
                        /* char split into 2; don't change curbufoff */
                    } else {
                        curbufoff--;        /* back up one character */
                    }
                }
            } else if( ch[0] != '\0' ) {
                FAR_mbccpy( FAR_mbsninc( (LPBYTE)w->tmpbuff->data, curbufoff ), ch );
                curbufoff++;
                if( curbufoff > w->buffoff ) {
                    w->buffoff = curbufoff;
                }
                if( TOOWIDE( w->buffoff, w ) ) {
                    hadbreak = TRUE;
                    newLine( w );
                    curbufoff = w->buffoff;
                }
            }
#else                               /* SBCS */
            if( tabcnt ) {
                ch = ' ';
                tabcnt--;
            } else if( nlcnt ) {
                ch = '\n';
                nlcnt--;
            } else {
                ch = data[i];
            }

            if( ch == '\t' ) {
                tabcnt = TAB( curbufoff + 1 );
                continue;
            } else if( ch == '\f' ) {
                nlcnt = w->height;
                continue;
            } else if( ch == '\r' ) {
                curbufoff = 0;
                w->no_advance = TRUE;
                w->tmpbuff->has_cr = TRUE;
                continue;
            } else if( ch == '\n' ) {
                hadbreak = TRUE;
                newLine( w );
                curbufoff = w->buffoff;
            } else if( ch == '\b' ) {
                if( curbufoff > 0 ) {
                    curbufoff--;
                }
            } else {
                w->tmpbuff->data[curbufoff++] = ch;
                if( curbufoff > w->buffoff ) {
                    w->buffoff = curbufoff;
                }
                if( TOOWIDE( w->buffoff, w ) ) {
                    hadbreak = TRUE;
                    newLine( w );
                    curbufoff = w->buffoff;
                }
            }
#endif
        } while( tabcnt || nlcnt );
    }
    if( !hadbreak ) {
        updateBuff( w );
    }
    _ReleaseWinLines();

} /* _AddLine */
Beispiel #5
0
    _WCRTLINK wint_t (ungetwc)( wint_t c, FILE *fp )
#endif
    {
        if( c == __F_NAME(EOF,WEOF) ) {   /* cannot push EOF */
            return( c );
        }
        _ValidFile( fp, __F_NAME(EOF,WEOF) );
        _AccessFile( fp );

        /*** Deal with stream orientation ***/
        #ifndef __NETWARE__
            #ifdef __WIDECHAR__
                if( _FP_ORIENTATION(fp) != _WIDE_ORIENTED ) {
                    if( _FP_ORIENTATION(fp) == _NOT_ORIENTED ) {
                        _FP_ORIENTATION(fp) = _WIDE_ORIENTED;
                    } else {
                        _ReleaseFile( fp );
                        return( WEOF );
                    }
                }
            #else
                if( _FP_ORIENTATION(fp) != _BYTE_ORIENTED ) {
                    if( _FP_ORIENTATION(fp) == _NOT_ORIENTED ) {
                        _FP_ORIENTATION(fp) = _BYTE_ORIENTED;
                    } else {
                        _ReleaseFile( fp );
                        return( EOF );
                    }
                }
            #endif
        #endif

        if( fp->_flag & _DIRTY ) {        /* cannot unget after a put */
            _ReleaseFile( fp );
            return( __F_NAME(EOF,WEOF) );
        }
        if(( fp->_flag & _READ ) == 0 ) { /* not open for input */
            _ReleaseFile( fp );
            return( __F_NAME(EOF,WEOF) );
        }
        if( _FP_BASE(fp) == NULL ) {      /* no buffer allocated */
            __ioalloc( fp );
        }
        #ifdef __WIDECHAR__
            if( fp->_flag & _BINARY ) {
                /*** Leave the character in wide form ***/
                if( fp->_cnt == 0 ) {           /* read buffer is empty */
                    fp->_cnt = sizeof(wchar_t);
                    fp->_ptr = _FP_BASE(fp) + fp->_bufsize - sizeof(wchar_t);
                    fp->_flag |= _UNGET;                    /* 10-mar-90 */
                    memcpy( fp->_ptr, &c, sizeof(wchar_t) );
                } else if( fp->_ptr != _FP_BASE(fp) ) {
                    fp->_cnt += sizeof(wchar_t);
                    fp->_ptr -= sizeof(wchar_t);
                    fp->_flag |= _UNGET;
                    memcpy( fp->_ptr, &c, sizeof(wchar_t) );
                } else {                        /* read buffer is full */
                    _ReleaseFile( fp );
                    return( WEOF );
                }
            } else {
                char    mbc[MB_CUR_MAX];
                int     mbcLen;

                /*** Convert the character to multibyte form ***/
                if( wctomb( mbc, c ) == -1 ) {
                    __set_errno( EILSEQ );
                    return( WEOF );
                }
                mbcLen = _mbclen( mbc );

                /*** Store the converted character ***/
                if( fp->_cnt == 0 ) {           /* read buffer is empty */
                    fp->_cnt = mbcLen;
                    fp->_ptr = _FP_BASE(fp) + fp->_bufsize - mbcLen;
                    fp->_flag |= _UNGET;                    /* 10-mar-90 */
                    _mbccpy( fp->_ptr, mbc );
                } else if( fp->_ptr != _FP_BASE(fp) ) {
                    fp->_cnt += mbcLen;
                    fp->_ptr -= mbcLen;
                    fp->_flag |= _UNGET;
                    _mbccpy( fp->_ptr, mbc );
                } else {                        /* read buffer is full */
                    _ReleaseFile( fp );
                    return( WEOF );
                }
            }
        #else
            if( fp->_cnt == 0 ) {               /* read buffer is empty */
                fp->_cnt = CHARSIZE;
                fp->_ptr = _FP_BASE(fp) + fp->_bufsize - CHARSIZE;
                fp->_flag |= _UNGET;                                 /* 10-mar-90 */
                *(CHAR_TYPE*)(fp->_ptr) = c;
            } else if( fp->_ptr != _FP_BASE(fp) ) {
                fp->_cnt += CHARSIZE;
                fp->_ptr -= CHARSIZE;
                if( *(CHAR_TYPE*)(fp->_ptr) != c )  fp->_flag |= _UNGET; /* 10-mar-90 */
                *(CHAR_TYPE*)(fp->_ptr) = c;
            } else {                            /* read buffer is full */
                _ReleaseFile( fp );
                return( EOF );
            }
        #endif
        fp->_flag &= ~ _EOF;

        _ReleaseFile( fp );
        return( (UCHAR_TYPE) c );
    }
Beispiel #6
0
_WCRTLINK INTCHAR_TYPE __F_NAME(ungetc,ungetwc)( INTCHAR_TYPE c, FILE *fp )
{
    if( c == INTCHAR_EOF ) {    /* cannot push EOF */
        return( c );
    }
    _ValidFile( fp, INTCHAR_EOF );
    _AccessFile( fp );

    /*** Deal with stream orientation ***/
    ORIENT_STREAM( fp, INTCHAR_EOF );

    if( fp->_flag & _DIRTY ) {        /* cannot unget after a put */
        _ReleaseFile( fp );
        return( INTCHAR_EOF );
    }
    if(( fp->_flag & _READ ) == 0 ) { /* not open for input */
        _ReleaseFile( fp );
        return( INTCHAR_EOF );
    }
    if( _FP_BASE( fp ) == NULL ) {      /* no buffer allocated */
        __ioalloc( fp );
    }
#ifdef __WIDECHAR__
    if( fp->_flag & _BINARY ) {
        /*** Leave the character in wide form ***/
        if( fp->_cnt == 0 ) {           /* read buffer is empty */
            fp->_cnt = sizeof( wchar_t );
            fp->_ptr = _FP_BASE( fp ) + fp->_bufsize - sizeof( wchar_t );
            fp->_flag |= _UNGET;                    /* 10-mar-90 */
            memcpy( fp->_ptr, &c, sizeof( wchar_t ) );
        } else if( fp->_ptr != _FP_BASE( fp ) ) {
            fp->_cnt += sizeof( wchar_t );
            fp->_ptr -= sizeof( wchar_t );
            fp->_flag |= _UNGET;
            memcpy( fp->_ptr, &c, sizeof( wchar_t ) );
        } else {                        /* read buffer is full */
            _ReleaseFile( fp );
            return( WEOF );
        }
    } else {
        unsigned char   mbc[MB_CUR_MAX];
        int             mbcLen;

        /*** Convert the character to multibyte form ***/
        if( wctomb( (char *)mbc, c ) == -1 ) {
            _RWD_errno = EILSEQ;
            return( WEOF );
        }
        mbcLen = _mbclen( mbc );

        /*** Store the converted character ***/
        if( fp->_cnt == 0 ) {           /* read buffer is empty */
            fp->_cnt = mbcLen;
            fp->_ptr = _FP_BASE( fp ) + fp->_bufsize - mbcLen;
            fp->_flag |= _UNGET;                            /* 10-mar-90 */
            _mbccpy( fp->_ptr, mbc );
        } else if( fp->_ptr != _FP_BASE( fp ) ) {
            fp->_cnt += mbcLen;
            fp->_ptr -= mbcLen;
            fp->_flag |= _UNGET;
            _mbccpy( fp->_ptr, mbc );
        } else {                        /* read buffer is full */
            _ReleaseFile( fp );
            return( WEOF );
        }
    }
#else
    if( fp->_cnt == 0 ) {               /* read buffer is empty */
        fp->_cnt = 1;
        fp->_ptr = _FP_BASE( fp ) + fp->_bufsize - 1;
        fp->_flag |= _UNGET;                                /* 10-mar-90 */
        *fp->_ptr = c;
    } else if( fp->_ptr != _FP_BASE( fp ) ) {
        fp->_cnt++;
        fp->_ptr--;
        if( *fp->_ptr != c ) {
            fp->_flag |= _UNGET;                            /* 10-mar-90 */
        }
        *fp->_ptr = c;
    } else {                            /* read buffer is full */
        _ReleaseFile( fp );
        return( EOF );
    }
#endif
    fp->_flag &= ~ _EOF;

    _ReleaseFile( fp );
    return( (UCHAR_TYPE)c );
}
Beispiel #7
0
/*
 * _GetString - read in a string, return the length
 */
int _GetString( LPWDATA w, char *str, int maxbuff )
{
    HWND        hwnd;
    int         buff_end = 0;
    int         curr_pos = 0;
    BOOL        escape = FALSE;
    BOOL        insert_flag = FALSE;
    int         maxlen = maxbuff;
    LPSTR       res;
    int         wt;
    int         len;
    int         i;
    int         scan;
#ifdef _MBCS
    unsigned char *p;
    int         expectingTrailByte = 0;
    int         overwrote = 0;
    unsigned char   ci;
    unsigned char   cx;
#else
    char        ci;
    char        cx;
#endif

#ifdef _MBCS
    res = _MemAlloc( MB_CUR_MAX * ( maxbuff + 1 ) );
#else
    res = _MemAlloc( maxbuff + 1 );
#endif
    if( res == NULL)
        return( 0 );

    hwnd = w->hwnd;

    _MoveToLine( w, _GetLastLineNumber( w ), FALSE );
    _NewCursor( w, SMALL_CURSOR );
    _SetInputMode( w, TRUE );
    _GotEOF = FALSE;
    str[0] = 0;

    while( 1 ) {

        w->curr_pos = curr_pos;
        _DisplayCursor( w );
        while( !_KeyboardHit( TRUE ) );
        ci = _GetKeyboard( &scan );
#if defined( __OS2__ )
        WinShowCursor( hwnd, FALSE );
#else
        HideCaret( hwnd );
#endif

        if( escape ) {
#ifdef _MBCS
            p = __mbsninc( (unsigned char *)str, curr_pos++ );
            *p = ci;
#else
            str[curr_pos++] = ci;
#endif
            escape = FALSE;
        } else if( (ci == CTRL_V) || (scan != 0xFF) ) {
            if( ci == CTRL_V ) {
                escape = TRUE;      /* This is a VI thing - */
                ci = '^';           /* it permits insertion of any key */
            }
            if( insert_flag ) {
                if( buff_end < maxlen && !TOOWIDE( buff_end, w ) ) {
#ifdef _MBCS
                    if( !expectingTrailByte ) {     /* shift over two bytes */
                        if( _ismbblead( ci ) ) {
                            expectingTrailByte = 1;
                            p = __mbsninc( (unsigned char *)str, curr_pos );
                            for( i = strlen( (char *)p ); i >= 0; i-- )
                                p[i + 2] = p[i];
                            p[0] = ci;
                        } else {                    /* shift over one byte */
                            p = __mbsninc( (unsigned char *)str, curr_pos );
                            for( i = strlen( (char *)p ); i >= 0; i-- )
                                p[i + 1] = p[i];
                            p[0] = ci;
                        }
                    } else {
                        expectingTrailByte = 0;
                        p = __mbsninc( (unsigned char *)str, curr_pos );
                        p[1] = ci;
                    }
                    overwrote = 0;
#else
                    for( i = buff_end; i >= curr_pos; i-- )
                        str[i + 1] = str[i];
                    buff_end++;
                    str[curr_pos] = ci;
#endif
                } else {
                    continue;
                }
            } else if( curr_pos == buff_end ) {
                if( buff_end < maxlen ) {
#ifdef _MBCS
                    if( !expectingTrailByte ) {
                        if( _ismbblead( ci ) ) {
                            expectingTrailByte = 1;
                            p = __mbsninc( (unsigned char *)str, buff_end );
                        } else {
                            p = __mbsninc( (unsigned char *)str, buff_end );
                        }
                        p[0] = ci;
                        p[1] = p[2] = 0;
                    } else {
                        expectingTrailByte = 0;
                        p = __mbsninc( (unsigned char *)str, buff_end );
                        p[1] = ci;
                        p[2] = 0;
                    }
                    overwrote = 0;
#else
                    str[buff_end++] = ci;
                    str[buff_end] = 0;
#endif
                } else {
                    continue;
                }
            } else {
#ifdef _MBCS
                p = __mbsninc( (unsigned char *)str, curr_pos );
                if( !expectingTrailByte ) {
                    if( _ismbblead( ci ) ) {
                        expectingTrailByte = 1;
                        if( !_ismbblead( *p ) ) {
                            for( i = strlen( (char *)p + 1 ); i >= 0; i-- ) {
                                p[i + 2] = p[i + 1];    /* shift over one byte */
                            }
                        }
                        p[0] = ci;
                    } else {
                        if( _ismbblead( *p ) ) {   /* shift over one byte */
                            for( i = 1; i <= strlen( (char *)p + 1 ); i++ ) {
                                p[i] = p[i + 1];
                            }
                        }
                        p[0] = ci;
                    }
                } else {
                    expectingTrailByte = 0;
                    p[1] = ci;
                }
                overwrote = 1;
#else
                str[curr_pos] = ci;
#endif
            }
#ifdef _MBCS
            if( !escape && !expectingTrailByte ) {
                curr_pos++;
                if( !overwrote ) {
                    buff_end++;
                }
            }
#else
            if( !escape ) {
                curr_pos++;
            }
#endif
        } else {
            cx = ci;
            if( cx >= 0x80 )
                cx -= 0x80;
            switch( cx ) {
            case VK_HOME:
                curr_pos = 0;
                break;
            case VK_END:
                curr_pos = buff_end;
                break;
            case VK_RETURN:
#ifdef __OS2__
            case VK_ENTER:
#endif
#ifdef _MBCS
                p = __mbsninc( (unsigned char *)str, buff_end );
                *p = '\0';
#else
                str[buff_end] = 0;
#endif
                _NewCursor( w, ORIGINAL_CURSOR );
#ifdef _MBCS
                _UpdateInputLine( w, str, __mbslen( (unsigned char *)str ), TRUE );
#else
                _UpdateInputLine( w, str, strlen( str ), TRUE );
#endif
                _SetInputMode( w, FALSE );
                FARstrcat( res, str );
                FARstrcpy( str, res );
                _MemFree( res );
                /* return number of bytes */
                return( strlen( str ) );
            case VK_LEFT:
                if( curr_pos > 0 )
                    curr_pos--;
                break;
            case VK_RIGHT:
                if( curr_pos < buff_end )
                    curr_pos++;
                break;
            case VK_DELETE:
                if( curr_pos == buff_end )
                    break;  /* DEL, not BS */
                if( curr_pos < buff_end )
                    curr_pos++;
                /* fall through to VK_BACK... */
            case VK_BACK:
                if( curr_pos > 0 ) {
#ifdef _MBCS
                    p = __mbsninc( (unsigned char *)str, curr_pos - 1 );
                    for( i = curr_pos; i < buff_end; i++ ) {
                        _mbccpy( __mbsninc( p, i - curr_pos ), __mbsninc( p, i - curr_pos + 1 ) );
                    }
                    p = __mbsninc( (unsigned char *)str, i - 1 );
                    *p = '\0';
#else
                    for( i = curr_pos; i <= buff_end; i++ )
                        str[i - 1] = str[i];
#endif
                    buff_end--;
                    curr_pos--;
                }
                break;
            case VK_INSERT:
                if( insert_flag ) {
                    insert_flag = FALSE;
                    _NewCursor( w, SMALL_CURSOR );
                } else {
                    insert_flag = TRUE;
                    _NewCursor( w, FAT_CURSOR );
                }
                break;
            default:
                continue;
            }
        }

        /*
         * update line.  if line was split, then we must reset
         * the current line info.
         */
#ifdef _MBCS
        wt = _UpdateInputLine( w, str, expectingTrailByte ? __mbslen( (unsigned char *)str ) - 1 : __mbslen( (unsigned char *)str ), FALSE );
#else
        wt = _UpdateInputLine( w, str, strlen( str ), FALSE );
#endif

        if( wt >= 0 ) {
#ifdef _MBCS
            len = __mbslen( (unsigned char *)str );
            p = __mbsninc( (unsigned char *)str, len - wt );
            ci = *p;
            *p = '\0';
            FARstrcat( res, str );
            *p = ci;
            for( i = 0; i <= wt; i++ )
                str[i] = str[len - wt + i];
#else
            len = strlen( str );
            ci = str[ len - wt ];
            str[ len - wt ] = 0;
            FARstrcat( res, str );
            str[ len - wt ] = ci;
            for( i = 0; i <= wt; i++ )
                str[i] = str[len - wt + i];
#endif
            curr_pos = wt;
            buff_end = wt;
            maxlen -= len + 1;
        }
    }

} /* _GetString */
Beispiel #8
0
static void test_mbcp(void)
{
    int mb_orig_max = *p__mb_cur_max;
    int curr_mbcp = _getmbcp();
    unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
    unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
    unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
    unsigned char buf[16];
    int step;

    /* _mbtype tests */

    /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
     * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
     * CP1252 (or the ACP?) so we test only a few ASCII characters */
    _setmbcp(1252);
    expect_eq(p_mbctype[10], 0, char, "%x");
    expect_eq(p_mbctype[50], 0, char, "%x");
    expect_eq(p_mbctype[66], _SBUP, char, "%x");
    expect_eq(p_mbctype[100], _SBLOW, char, "%x");
    expect_eq(p_mbctype[128], 0, char, "%x");
    _setmbcp(1250);
    expect_eq(p_mbctype[10], 0, char, "%x");
    expect_eq(p_mbctype[50], 0, char, "%x");
    expect_eq(p_mbctype[66], _SBUP, char, "%x");
    expect_eq(p_mbctype[100], _SBLOW, char, "%x");
    expect_eq(p_mbctype[128], 0, char, "%x");

    /* double byte code pages */
    test_codepage(932);
    test_codepage(936);
    test_codepage(949);
    test_codepage(950);

    _setmbcp(936);
    ok(*p__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", *p__mb_cur_max, mb_orig_max);
    ok(_ismbblead('\354'), "\354 should be a lead byte\n");
    ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
    ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
    ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
    ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
    ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");

    /* _ismbslead */
    expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
    expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");

    expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
    expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
    expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");

    /* _ismbstrail */
    expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");

    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
    expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");

    /* _mbsbtype */
    expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
    expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
    expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
    expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
    expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
    expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
    expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
    expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
    expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");

    expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
    expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
    expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
    expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
    expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
    expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");

    /* _mbsnextc */
    expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
    expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x");  /* lead + invalid tail */
    expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x");    /* single char */

    /* _mbclen/_mbslen */
    expect_eq(_mbclen(mbstring), 2, int, "%d");
    expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
    expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
    expect_eq(_mbslen(mbstring2), 4, int, "%d");
    expect_eq(_mbslen(mbsonlylead), 0, int, "%d");          /* lead + NUL not counted as character */
    expect_eq(_mbslen(mbstring), 4, int, "%d");             /* lead + invalid trail counted */

    /* _mbccpy/_mbsncpy */
    memset(buf, 0xff, sizeof(buf));
    _mbccpy(buf, mbstring);
    expect_bin(buf, "\xb0\xb1\xff", 3);

    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbstring, 1);
    expect_bin(buf, "\xb0\xb1\xff", 3);
    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbstring, 2);
    expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbstring, 3);
    expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbstring, 4);
    expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbstring, 5);
    expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
    memset(buf, 0xff, sizeof(buf));
    _mbsncpy(buf, mbsonlylead, 6);
    expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);

    memset(buf, 0xff, sizeof(buf));
    _mbsnbcpy(buf, mbstring2, 2);
    expect_bin(buf, "\xb0\xb1\xff", 3);
    _mbsnbcpy(buf, mbstring2, 3);
    expect_bin(buf, "\xb0\xb1\0\xff", 4);
    _mbsnbcpy(buf, mbstring2, 4);
    expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
    memset(buf, 0xff, sizeof(buf));
    _mbsnbcpy(buf, mbsonlylead, 5);
    expect_bin(buf, "\0\0\0\0\0\xff", 6);

    /* _mbsinc/mbsdec */
    step = _mbsinc(mbstring) - mbstring;
    ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
    step = _mbsinc(&mbstring[2]) - &mbstring[2];  /* lead + invalid tail */
    ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);

    step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
    ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
    step = _mbsninc(mbsonlylead, 2) - mbsonlylead;  /* lead + NUL byte + lead + char */
    ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
    step = _mbsninc(mbstring2, 0) - mbstring2;
    ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
    step = _mbsninc(mbstring2, 1) - mbstring2;
    ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
    step = _mbsninc(mbstring2, 2) - mbstring2;
    ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
    step = _mbsninc(mbstring2, 3) - mbstring2;
    ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
    step = _mbsninc(mbstring2, 4) - mbstring2;
    ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
    step = _mbsninc(mbstring2, 5) - mbstring2;
    ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
    step = _mbsninc(mbstring2, 17) - mbstring2;
    ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);

    /* functions that depend on locale codepage, not mbcp.
     * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
     * (as of Wine 0.9.43)
     */
    if (*p__mb_cur_max == 1)
    {
        expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
        expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
    }