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

📄 winlines.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#define WIN32_NICE_AND_FAT
#include "variety.h"
#if defined( __OS2__ )
  #define INCL_WIN
  #include <wos2.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define INCLUDE_COMMDLG_H
#include "mbdefwin.h"
#include "win.h"

#if defined(__WINDOWS__) && !defined(__386__)
#pragma library("commdlg");
#endif

/*
 * createNewEntry - build a new line number entry
 */
static LPLDATA createNewEntry( LPWDATA w )
{
    LPLDATA             ld;

    #ifdef _MBCS
        char _WCI86FAR *        p;
        p = FAR_mbsninc( w->tmpbuff->data, w->buffoff);
        *p = '\0';
        ld = _MemAlloc( sizeof(line_data) + FAR_mbsnbcnt(w->tmpbuff->data,w->buffoff) );
    #else
        w->tmpbuff->data[ w->buffoff ] = 0;
        ld = _MemAlloc( sizeof(line_data) + w->buffoff );
    #endif
    w->buffoff = 0;
    FARstrcpy( ld->data, w->tmpbuff->data );
    if( w->LineTail == NULL ) {
        w->LineHead = w->LineTail = ld;
    } else {
        w->LineTail->next = ld;
        ld->prev = w->LineTail;
        w->LineTail = ld;
    }
    return( ld );

} /* createNewEntry */

/*
 * incrementLastLineNumber - guess!
 */
static void incrementLastLineNumber( LPWDATA w )
{
    int diff;

    w->LastLineNumber++;
    if( w->LastLineNumber > _AutoClearLines ) {
        _FreeAllLines( w );
        return;
    }
    diff = w->LastLineNumber - w->TopLineNumber;
    if( diff < w->height ) {
        w->CurrentLineNumber++;
        if( diff == w->height-1 ) {
            w->TopLineNumber++;
            _ShiftWindow( w, 1 );
            /* We must clear the bottom line which NT cannot do when it
             * Scrolls up near the bottom, in this case this is the
             * simplest thing to do.
             */
            _DisplayLineInWindow( w, w->height - 1, (LPSTR)" " );
        }
    }
    _PositionScrollThumb( w );

} /* incrementLastLineNumber */

/*
 * replaceTail - replace tail line data
 */
static void replaceTail( LPWDATA w )
{
    LPLDATA             tmp;

    #ifdef _MBCS
        * (FAR_mbsninc( w->tmpbuff->data, w->buffoff )) = '\0';
    #else
        w->tmpbuff->data[ w->buffoff ] = 0;
    #endif

    tmp = w->LineTail->prev;
    _MemFree( w->LineTail );

    #ifdef _MBCS
        w->LineTail = _MemAlloc( sizeof(line_data) + w->buffoff*MB_CUR_MAX );
    #else
        w->LineTail = _MemAlloc( sizeof(line_data) + w->buffoff );
    #endif

    FARstrcpy( w->LineTail->data, w->tmpbuff->data );
    w->LineTail->prev = tmp;
    if( tmp != NULL ) {
        tmp->next = w->LineTail;
    } else {
        w->LineHead = w->LineTail;
    }
    _DisplayLineInWindow( w, w->LastLineNumber-w->TopLineNumber+1,
                    w->LineTail->data );

} /* replaceTail */

/*
 * addBuff - add current working buffer to line data structures
 */
static void addBuff( LPWDATA w )
{
    LPLDATA     ld;

    ld = createNewEntry( w );
    ld->has_cr = TRUE;
    _DisplayLineInWindow( w, w->LastLineNumber-w->TopLineNumber+1, ld->data );

} /* addBuff */

/*
 * updateBuff - update current line with tmpbuff
 */
static void updateBuff( LPWDATA w )
{
    int oldbuff;

    if( w->LineHead == NULL || w->LineTail->has_cr ) {
        oldbuff = w->buffoff;
        addBuff( w );
        w->buffoff = oldbuff;
    } else {
        replaceTail( w );
    }
    w->LineTail->has_cr = FALSE;

} /* updateBuff */

/*
 * newLine - add a new line to the bottom
 */
static void newLine( LPWDATA w )
{
    if( w->LineTail != NULL && !w->LineTail->has_cr ) {
        replaceTail( w );
        w->buffoff = 0;
        w->LineTail->has_cr = TRUE;
    } else {
        addBuff( w );
    }
    w->lineinprogress = FALSE;
    incrementLastLineNumber( w );

} /* newLine */

/*
 * _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;
    char                ch[MB_CUR_MAX+1];
    char _WCI86FAR *    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( 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, " " );         /* copy the character */
                    ch[_mbclen(ch)] = '\0';     /* terminate char with NULL */
                    tabcnt--;
                } else if( nlcnt ) {
                    _mbccpy( ch, "\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,"\t") ) {
                    tabcnt = TAB( curbufoff + 1 );
                    continue;
                } else if( !_mbccmp(ch,"\f") ) {
                    nlcnt = w->height;
                    continue;
                } else if( !_mbccmp(ch,"\r") ) {
                    curbufoff = 0;
                    w->no_advance = TRUE;
                    w->tmpbuff->has_cr = TRUE;
                    continue;
                } else if( !_mbccmp(ch,"\n") ) {
                    hadbreak = TRUE;
                    newLine( w );
                    curbufoff = w->buffoff;
                } else if( !_mbccmp(ch,"\b") ) {
                    if( curbufoff > 0 ) {
                        p = FAR_mbsninc( 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(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--;

⌨️ 快捷键说明

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