Esempio n. 1
0
/*
 * writeRange - write a range of lines in an fcb to current file
 */
static vi_rc writeRange( linenum s, linenum e, fcb *cfcb, long *bytecnt, int write_crlf, bool last_eol )
{
    line        *cline;
    int         i, len = 0;
    char        *buff, *data;
    vi_rc       rc;

    if( s > e ) {
        return( ERR_NO_ERR );
    }

    rc = GimmeLinePtrFromFcb( s, cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    buff = WriteBuffer;

    /*
     * copy data into buffer
     */
    while( s <= e ) {

        data = cline->data;
        while( *data != 0 ) {
            *buff = *data;
            buff++;
            data++;
        }
        len += cline->len;
        if( s != e || last_eol ) {
            if( write_crlf ) {
                *buff++ = CR;
                len++;
            }
            *buff++ = LF;
            len++;
        }
        cline = cline->next;
        s++;

    }

    /*
     * now write the buffer
     */
    if( fileHandle == 0 ) {
        i = fwrite( WriteBuffer, 1, len, stdout );
    } else {
        i = write( fileHandle, WriteBuffer, len );
    }
    if( i != len ) {
        return( ERR_FILE_WRITE );
    }

    *bytecnt += (long) len;
    return( ERR_NO_ERR );

} /* writeRange */
Esempio n. 2
0
/*
 * writeRange - write a range of lines in an fcb to current file
 */
static vi_rc writeRange( linenum s, linenum e, fcb *cfcb, long *bytecnt, bool write_crlf, bool last_eol )
{
    line        *cline;
    int         len1, len;
    char        *buff;
    vi_rc       rc;

    if( s > e ) {
        return( ERR_NO_ERR );
    }

    rc = GimmeLinePtrFromFcb( s, cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    buff = WriteBuffer;

    /*
     * copy data into buffer
     */
    len = 0;
    for( ; s <= e; ++s ) {
        len1 = trimLine( buff, cline );
        buff += len1;
        len += len1;
        if( s != e || last_eol ) {
            if( write_crlf ) {
                *buff++ = CR;
                len++;
            }
            *buff++ = LF;
            len++;
        }
        cline = cline->next;
    }

    /*
     * now write the buffer
     */
    if( fileHandle == 0 ) {
        len1 = fwrite( WriteBuffer, 1, len, stdout );
    } else {
        len1 = write( fileHandle, WriteBuffer, len );
    }
    if( len1 != len ) {
        return( ERR_FILE_WRITE );
    }

    *bytecnt += (long)len;
    return( ERR_NO_ERR );

} /* writeRange */
Esempio n. 3
0
/*
 * GimmeLinePtr - give a pointer to line data
 */
vi_rc GimmeLinePtr( linenum lineno, file *cfile, fcb **cfcb, line **cline )
{
    vi_rc       rc;
    fcb         *tfcb;

    rc = FindFcbWithLine( lineno, cfile, &tfcb );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    rc = GimmeLinePtrFromFcb( lineno, tfcb, cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    *cfcb = tfcb;
    return( ERR_NO_ERR );

} /* GimmeLinePtr */