⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winlines.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                    }
                } 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 */

/*
 * _UpdateInputLine - add data to current line; return number of chars
 *                   on next line if line break was forced
 */
int _UpdateInputLine( LPWDATA w, char *line, unsigned len, BOOL force_add )
{
    int         i,j;
    BOOL        justnew=FALSE;
    BOOL        wassplit=FALSE;

    _AccessWinLines();
    w->lineinprogress = TRUE;
    j = w->buffoff;
    for( i=0;i<len;i++ ) {
        justnew = FALSE;
        if( TOOWIDE( j, w ) ) {
            #ifdef _MBCS
                FAR_mbccpy( FAR_mbsninc(w->tmpbuff->data,j), "" );
            #else
                w->tmpbuff->data[ j ] = 0;
            #endif
            w->buffoff = j;
            newLine( w );
            j = 0;
            justnew = TRUE;
            wassplit = TRUE;
        }
        #ifdef _MBCS
            FAR_mbccpy( FAR_mbsninc(w->tmpbuff->data,j), FAR_mbsninc(line,i) );
        #else
            w->tmpbuff->data[ j ] = line[ i ];
        #endif
        j++;
    }
    #ifdef _MBCS
        FAR_mbccpy( FAR_mbsninc(w->tmpbuff->data,j), "" );
    #else
        w->tmpbuff->data[ j ] = 0;
    #endif

    if( force_add && !justnew ) {
        w->buffoff = j;
        newLine( w );
    } else {
        _DisplayLineInWindow( w, w->LastLineNumber-w->TopLineNumber+1,
                              w->tmpbuff->data );
        if( !wassplit ) j = -1;
    }
    _ReleaseWinLines();

    return( j );
} /* _UpdateInputLine */


#define MAXLNE 32768L
/*
 * _PositionScrollThumb
*/
void _PositionScrollThumb( LPWDATA w )
{
    DWORD       c;
    WORD        curr,end;
    DWORD       ll;

    c = w->TopLineNumber;
    ll = _GetLastLineNumber( w );
    if( ll > MAXLNE ) {
        end = MAXLNE;
        curr = (WORD)(((DWORD) c * MAXLNE)/ll);
    } else {
        end = ll;
        curr = c;
    }
#if defined( __OS2__ )
    if( end > w->height ) {
        end -= w->height;
    }
    WinSendMsg( WinWindowFromID( WinQueryWindow( w->hwnd, QW_PARENT ),
                                FID_VERTSCROLL ),
                SBM_SETSCROLLBAR, MPFROMSHORT( curr ),
                MPFROM2SHORT( 1, end ) );
#else
    SetScrollRange( w->hwnd, SB_VERT, 1, end, FALSE );
    SetScrollPos( w->hwnd, SB_VERT, curr, TRUE );
#endif
} /* _PositionScrollThumb */


/*
 * _GetLineFromThumbPosition - given a thumb position, find line in file
 */
DWORD _GetLineFromThumbPosition( LPWDATA w, WORD n )
{
    DWORD       new;
    DWORD       ll;

    ll = _GetLastLineNumber( w );

    if( ll > MAXLNE ) {
        new = ((DWORD)n*ll)/MAXLNE;
    } else {
        new = (DWORD) n;
    }
    return( new );

} /* _GetLineFromThumbPosition */


/*
 * _GetLineDataPointer - get line data pointer
 */
LPLDATA _GetLineDataPointer( LPWDATA w, DWORD line )
{
    DWORD       cnt;
    LPLDATA     ld;

    _AccessWinLines();
    if( line == w->LastLineNumber ) {
        if( w->lineinprogress ) {
            _ReleaseWinLines();
            return( w->tmpbuff );
        }
    }

    cnt = 1;
    ld =  w->LineHead;
    while( cnt != line && ld != NULL ) {
        ld = ld->next;
        cnt++;
    }
    _ReleaseWinLines();
    return( ld );

} /* _GetLineDataPointer */

/*
 * _FreeAllLines - as it sounds!
 */
void _FreeAllLines( LPWDATA w )
{
    LPLDATA     ld,tmp;

    _AccessWinLines();
    ld = w->LineHead;
    while( ld != NULL ) {
        tmp = ld->next;
        _MemFree( ld );
        ld = tmp;
    }
    w->LineHead = w->LineTail = NULL;
    w->buffoff = 0;
    w->CurrentLineNumber = w->LastLineNumber = w->TopLineNumber = 1;
    _PositionScrollThumb( w );
    _ReleaseWinLines();

} /* _FreeAllLines */

#if !defined( __OS2__ )

static char filterFiles[] = "Result Files (*.TXT)" \
                            "\0" \
                            "*.TXT" \
                            "\0\0";

/*
 * _SaveAllLines - save all lines to a file
 */
void _SaveAllLines( LPWDATA w )
{
    char                fname[_MAX_PATH];
    OPENFILENAME        of;
    BOOL                rc;
    FILE                *f;
    LPLDATA             ld;

    fname[0] = 0;
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = _MainWindow;
    of.lpstrFilter = filterFiles;
    of.nFilterIndex = 1L;
    of.lpstrFile = fname;
    of.nMaxFile = _MAX_PATH;
    of.lpstrTitle = "Save File Name Selection";
    of.Flags = OFN_HIDEREADONLY;
    rc = GetSaveFileName( &of );

    if( !rc ) {
        return;
    }

    /*
     * save lines
     */
    _AccessWinLines();
    f = fopen( fname, "w" );
    if( f == NULL ) {
        MessageBox( NULL, fname,"Error opening file", MB_OK );
        return;
    }
    ld = w->LineHead;
    while( ld != NULL ) {
#if defined(__386__) || defined(__AXP__) || defined(__PPC__)
        fprintf( f,"%s\n", ld->data );
#else
        fprintf( f,"%Fs\n", ld->data );
#endif
        ld = ld->next;
    }
    fclose( f );
    _ReleaseWinLines();
    MessageBox( NULL,fname,"Data saved to file", MB_OK );

} /* _SaveAllLines */

#define MAX_BYTES       0xfffeL
/*
 * _CopyAllLines - copy lines to clipboard
 */
void _CopyAllLines( LPWDATA w )
{
    LPLDATA     ld;
    DWORD       total;
    unsigned    len;
    HANDLE      data;
    unsigned    slen;
    #if defined(__NT__)
        char    *ptr;
    #else
        char    _WCFAR *ptr;
    #endif

    /*
     * get number of bytes
     */
    _AccessWinLines();
    ld = w->LineHead;
    total = 0;
    while( ld != NULL ) {
        total += FARstrlen( ld->data ) + 2;
        ld = ld->next;
    }
    if( total > MAX_BYTES ) len = (unsigned) MAX_BYTES;
    else len = total;

    /*
     * get memory block
     */
    data = GlobalAlloc( GMEM_MOVEABLE, len + 1 );
    if( data == NULL ) {
        MessageBox( NULL, "Out of Memory","Copy to Clipboard", MB_OK );
        _ReleaseWinLines();
        return;
    }
    ptr = MK_FP32( GlobalLock( data ) );

    /*
     * copy data into block
     */
    ld = w->LineHead;
    total = 0;
    while( ld != NULL ) {
        slen = FARstrlen( ld->data ) + 2;
        if( total + slen > MAX_BYTES ) break;
        #if defined(__NT__)
            memcpy( &ptr[total], ld->data, slen - 2 );
        #else
            _fmemcpy( &ptr[total], ld->data, slen - 2 );
        #endif
        ptr[total+slen-2] = 0x0d;
        ptr[total+slen-1] = 0x0a;
        total += slen;
        ld = ld->next;
    }
    ptr[total] = 0;
    GlobalUnlock( data );

    /*
     * dump data to the clipboard
     */
    if( OpenClipboard( w->hwnd ) ) {
        EmptyClipboard();
        SetClipboardData( CF_TEXT, data );
        CloseClipboard();
    }
    _ReleaseWinLines();

} /* _CopyAllLines */
#endif

/*
 * _GetLastLineNumber
 */
DWORD _GetLastLineNumber( LPWDATA w )
{
    DWORD       ll;

    ll = w->LastLineNumber;
    if( w->lineinprogress ) ll++;
    return( ll );

} /* _GetLastLineNumber */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -