Пример #1
0
/*
 * ReplaceCurrentLine - replace current line with work line
 */
vi_rc ReplaceCurrentLine( void )
{
    int         extra;
    line        *tmp;

    /*
     * add extra space to fcb
     */
    FetchFcb( CurrentFcb );
    extra = WorkLine->len - CurrentLine->len;
    CurrentFcb->byte_cnt += extra;
    CurrentFcb->nullfcb = false;

    /*
     * copy new data in
     */
    tmp = LineAlloc( WorkLine->data, WorkLine->len );
    tmp->u.ld.mark = CurrentLine->u.ld.mark;
    ReplaceLLItem( (ss **)&CurrentFcb->lines.head, (ss **)&CurrentFcb->lines.tail,
                   (ss *)CurrentLine, (ss *)tmp );
    MemFree( CurrentLine );
    CurrentLine = tmp;

    WorkLine->len = -1;

    return( CheckCurrentFcbCapacity() );

} /* ReplaceCurrentLine */
Пример #2
0
/*
 * AddNewLineAroundCurrent - put a new line on either side of the current line
 */
void AddNewLineAroundCurrent( char *data, int copylen, insert_dir dir )
{
    bool        wasnull;
    /*
     * if inserting into a null fcb, clean it up
     */
    FetchFcb( CurrentFcb );
    wasnull = CurrentFcb->nullfcb;
    if( wasnull ) {
        MemFree( CurrentFcb->lines.head );
        CurrentFcb->lines.head = CurrentFcb->lines.tail = NULL;
        CurrentFcb->nullfcb = FALSE;
        CurrentFcb->byte_cnt = 0;
        CurrentFcb->end_line = 0;
    }

    /*
     * add the line
     */
    InsertNewLine( CurrentLine, &CurrentFcb->lines, data, copylen,dir );
    CurrentFcb->byte_cnt += copylen + 1;
    CurrentFcb->end_line += 1;

    /*
     * update line info
     */
    if( wasnull ) {
        CurrentLine = CurrentFcb->lines.head;
        SetCurrentLineNumber( 1 );
    } else {
        if( dir == INSERT_BEFORE ) {
            SetCurrentLineNumber( CurrentPos.line + 1 );
        }
        UpdateLineNumbers( 1L, CurrentFcb->next );
    }
    CheckCurrentFcbCapacity();

} /* AddNewLineAroundCurrent */