Exemplo n.º 1
0
/*
 * GetTextForSpecialKey - get text for ^D,^E,^W, ALT_L, ^L, ^R
 */
bool GetTextForSpecialKey( int str_max, vi_key event, char *tmp )
{
    int         i, l;

    switch( event ) {
    case VI_KEY( CTRL_E ):
    case VI_KEY( CTRL_W ):
        tmp[0] = '\0';
        GimmeCurrentWord( tmp, str_max, event == VI_KEY( CTRL_E ) );
        tmp[str_max] = '\0';
        break;
    case VI_KEY( ALT_L ):
        if( CurrentLine == NULL ) {
            break;
        }
        i = CurrentPos.column - 1;
        if( i < 0 )
            i = 0;
        ExpandTabsInABuffer( &CurrentLine->data[i], CurrentLine->len - i, tmp, str_max );
        break;
    case VI_KEY( CTRL_L ):
        if( CurrentLine == NULL ) {
            break;
        }
        ExpandTabsInABuffer( &CurrentLine->data[0], CurrentLine->len, tmp, str_max );
        break;
    case VI_KEY( CTRL_R ):
        if( CurrentLine == NULL ) {
            break;
        }
        if( SelRgn.lines ) {
            assert( SelRgn.start.line == SelRgn.end.line );
            i = 1;
            l = CurrentLine->len + 1;
        } else {
            if( SelRgn.start.column < SelRgn.end.column ) {
                i = SelRgn.start.column;
                l = SelRgn.end.column - SelRgn.start.column + 1;
            } else {
                i = SelRgn.end.column;
                l = SelRgn.start.column - SelRgn.end.column + 1;
            }
        }
        ExpandTabsInABuffer( &CurrentLine->data[i - 1], l, tmp, str_max );
        tmp[l] = '\0';
    default:
        return( false );
    }
    return( true );

} /* GetTextForSpecialKey */
Exemplo n.º 2
0
/*
 * GetTextForSpecialKey - get text for ^D,^E,^W, ALT_L, ^L, ^R
 */
bool GetTextForSpecialKey( vi_key event, char *buff, int buffsize )
{
    int         i;
    int         len;

    if( buffsize > 0 )
        buff[0] = '\0';
    switch( event ) {
    case VI_KEY( CTRL_E ):
    case VI_KEY( CTRL_W ):
        GimmeCurrentWord( buff, buffsize, event == VI_KEY( CTRL_E ) );
        break;
    case VI_KEY( ALT_L ):
        if( CurrentLine != NULL ) {
            i = CurrentPos.column - 1;
            if( i < 0 )
                i = 0;
            ExpandTabsInABuffer( &CurrentLine->data[i], CurrentLine->len - i, buff, buffsize );
        }
        break;
    case VI_KEY( CTRL_L ):
        if( CurrentLine != NULL ) {
            ExpandTabsInABuffer( &CurrentLine->data[0], CurrentLine->len, buff, buffsize );
        }
        break;
    case VI_KEY( CTRL_R ):
        if( CurrentLine != NULL ) {
            if( SelRgn.lines ) {
                assert( SelRgn.start.line == SelRgn.end.line );
                i = 1;
                len = CurrentLine->len + 1;
            } else {
                if( SelRgn.start.column < SelRgn.end.column ) {
                    i = SelRgn.start.column;
                    len = SelRgn.end.column - SelRgn.start.column + 1;
                } else {
                    i = SelRgn.end.column;
                    len = SelRgn.start.column - SelRgn.end.column + 1;
                }
            }
            ExpandTabsInABuffer( &CurrentLine->data[i - 1], len, buff, buffsize );
        }
        break;
    default:
        return( false );
    }
    return( true );

} /* GetTextForSpecialKey */
Exemplo n.º 3
0
/*
 * DisplayLineInWindowWithSyntaxStyle - display wrt syntax lang. settings
 */
vi_rc DisplayLineInWindowWithSyntaxStyle( window_id wn, int c_line_no, line *line,
                                        linenum line_no, char *text, int start_col,
                                        unsigned int junk )
{
    static ss_block     ss[MAX_SS_BLOCKS];
    int                 dummy;
    bool                saveRealTabs;
    int                 a;
    vi_rc               rc;
    char                *tmp;
    // dc               c_line;

    junk = junk;
    if( EditFlags.RealTabs ) {
        a = strlen( text );
        tmp = StaticAlloc();
        ExpandTabsInABuffer( text, a, tmp, MaxLinem1 + 2 );
    } else {
        tmp = text;
    }

    // this code commented out cause it doesn't quite work.
    // it should be close considering it mirrors the WINDOWS version.

    // get the laguage flags state previous to this line
    // c_line = DCFindLine( c_line_no - 1, wn );
    // SSGetLanguageFlags( &(c_line->flags) );

    // parse the line (generate new flags as well)
    ss[0].end = BEYOND_TEXT;
    SSDifBlock( ss, tmp, start_col, line, line_no, &dummy );

    // prevent displayLineInWindowGeneric from expanding tabs - blech
    saveRealTabs = EditFlags.RealTabs;
    EditFlags.RealTabs = FALSE;

    // display the thing
    rc = displayLineInWindowGeneric( wn, c_line_no, tmp, start_col, ss );
    EditFlags.RealTabs = saveRealTabs;

    // now say that it has been displayed and the flags are OK
    // DCValidateLine( c_line, start_col, tmp );

    if( EditFlags.RealTabs ) {
        StaticFree( tmp );
    }
    return( rc );
}
Exemplo n.º 4
0
/*
 * displayLineInWindowGeneric - takes an ss_block directly
 */
vi_rc displayLineInWindowGeneric( window_id wn, int c_line_no,
                                char *text, int start_col, ss_block *ss )
{
    wind                *w;
    char_info           *txt;
    char                *over, *tmp, *otmp;
    char_info           _FAR *scr;
    int                 addr, start, end, a, spend;
    int                 cnt1, cnt2, startc, spl;
    char_info           blank, what;
#ifdef __VIO__
    unsigned            oscr;
    unsigned            tbytes;
#endif
    bool                has_mouse, write_eol;
    unsigned            ss_i; // index into text, not ss[ss_i]

    if( EditFlags.Quiet ) {
        return( ERR_NO_ERR );
    }
    w = Windows[wn];

    write_eol = FALSE;
    if( EditFlags.RealTabs ) {
        a = strlen( text );
        otmp = tmp = StaticAlloc();
        ExpandTabsInABuffer( text, a, tmp, MaxLinem1 + 2 );
    } else {
        tmp = text;
    }
    tmp += start_col;
    a = strlen( tmp );

    /*
     * find dimensions of line
     */
    if( w->has_border ) {
        if( c_line_no < 1 || c_line_no > w->height - 2 ) {
            if( EditFlags.RealTabs ) {
                StaticFree( otmp );
            }
            return( ERR_WIND_NO_SUCH_LINE );
        }
        start = 1;
        spl = c_line_no;
        spend = end = w->width - 1;
        if( a < end - 1 ) {
            end = a + 1;
        } else if( a >= end ) {
            write_eol = TRUE;
        }
    } else {
        if( c_line_no < 1 || c_line_no > w->height ) {
            if( EditFlags.RealTabs ) {
                StaticFree( otmp );
            }
            return( ERR_WIND_NO_SUCH_LINE );
        }
        start = 0;
        spl = c_line_no - 1;
        spend = end = w->width;
        if( a < end ) {
            end = a;
        } else if( a > end ) {
            write_eol = TRUE;
        }
    }
    startc = start;
    cnt1 = end - start;
    cnt2 = spend - end;

    c_line_no--;
    w = AccessWindow( wn );

    /*
     * initialize
     */
    addr = startc + spl * w->width;
    txt = (char_info *) &(w->text[sizeof( char_info ) * addr]);
    scr = (char_info _FAR *) &Scrn[(w->x1 + startc +
                                   (spl + w->y1) * WindMaxWidth) * sizeof(char_info)];
#ifdef __VIO__
    oscr = (unsigned) ((char *) scr - Scrn);
    tbytes = cnt1 + cnt2;
#endif

    ss_i = 0;
    what.attr = MAKE_ATTR( w, SEType[ss->type].foreground,
                              SEType[ss->type].background );
    blank.ch = ' ';

    has_mouse = DisplayMouse( FALSE );

    /*
     * display line
     */
    if( w->overcnt[spl] ) {
        over = &(w->overlap[addr]);
        while( cnt1-- != 0 ) {
            what.ch = (*tmp);
            WRITE_SCREEN_DATA( *txt, what );
            if( *over++ == NO_CHAR ) {
                WRITE_SCREEN( *scr, what );
            }
            tmp++;
            scr++;
            txt++;
            if( ++ss_i > ss->end ) {
                ss++;
                what.attr = MAKE_ATTR( w, SEType[ss->type].foreground,
                                          SEType[ss->type].background );
            }
        }
        if( write_eol && *(over - 1) == NO_CHAR ) {
            WriteLongLineMarker( wn, &( SEType[SE_EOFTEXT] ),
                                 txt - 1, scr - 1, *(tmp - 1) );
        } else {
            blank.attr = MAKE_ATTR( w, SEType[ss->type].foreground,
                                       SEType[ss->type].background );
            while( cnt2-- != 0 ) {
                WRITE_SCREEN_DATA( *txt, blank );
                if( *over++ == NO_CHAR ) {
                    WRITE_SCREEN( *scr, blank );
                }
                scr++;
                txt++;
            }
        }
    } else {
        while( cnt1-- != 0 ) {
            what.ch = (*tmp);
            WRITE_SCREEN_DATA( *txt, what );
            WRITE_SCREEN( *scr, what );
            scr++;
            txt++;
            tmp++;
            if( ++ss_i > ss->end ) {
                ss++;
                what.attr = MAKE_ATTR( w, SEType[ss->type].foreground,
                                          SEType[ss->type].background );
            }
        }
        if( write_eol ) {
            WriteLongLineMarker( wn, &( SEType[SE_EOFTEXT] ),
                                 txt - 1, scr - 1, *(tmp - 1) );
        } else {
            blank.attr = MAKE_ATTR( w, SEType[ss->type].foreground,
                                       SEType[ss->type].background );
            while( cnt2-- != 0 ) {
                WRITE_SCREEN_DATA( *txt, blank );
                WRITE_SCREEN( *scr, blank );
                txt++;
                scr++;
            }
        }
    }

#ifdef __VIO__
    MyVioShowBuf( oscr, tbytes );
#endif
    if( EditFlags.RealTabs ) {
        StaticFree( otmp );
    }
    ReleaseWindow( w );
    DisplayMouse( has_mouse );
    return( ERR_NO_ERR );

} /* displayLineInWindowGeneric */
Exemplo n.º 5
0
/*
 * doCompressExpand - convert tabs to spaces, and spaces to tabs
 */
static vi_rc doCompressExpand( bool compress )
{
    int         k;
    long        bytes_saved = 0;
    long        bytes_added = 0;
    long        otabcnt;
    linenum     linecnt = 0;
    char        *tmp;
    vi_rc       rc;

    /*
     * init
     */
    rc = ModificationTest();
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    rc = SaveAndResetFilePos( 1 );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    tmp = StaticAlloc();

    /*
     * process all lines
     */
    TabCnt = 0;
    for( ;; ) {

        if( compress ) {
            otabcnt = TabCnt;
            ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, tmp, EditVars.MaxLine );
            TabCnt = otabcnt;
            k = strlen( tmp );
            ConvertSpacesToTabsUpToColumn( k, tmp, k, WorkLine->data, EditVars.MaxLine );
            WorkLine->len = strlen( WorkLine->data );
            bytes_saved += CurrentLine->len - WorkLine->len;
        } else {
            ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, WorkLine->data, EditVars.MaxLine );
            WorkLine->len = strlen( WorkLine->data );
            bytes_added += WorkLine->len - CurrentLine->len;
        }
        ReplaceCurrentLine();

        /*
         * get next line
         */
        linecnt++;
        rc = CGimmeNextLinePtr( &CurrentFcb, &CurrentLine );
        if( rc != ERR_NO_ERR ) {
            if( rc == ERR_NO_MORE_LINES ) {
                break;
            }
            RestoreCurrentFilePos();
            StaticFree( tmp );
            return( rc );
        }

    }

    StaticFree( tmp );
    RestoreCurrentFilePos();

    Modified( TRUE );
    DCDisplayAllLines();
    Message1( "%l lines processed in \"%s\"", linecnt, CurrentFile->name );
    if( compress ) {
        Message2( " %l tabs added (%l bytes saved)", TabCnt, bytes_saved );
    } else {
        Message2( " %l tabs removed (%l bytes added)", TabCnt, bytes_added );
    }
    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* doCompressExpand */
Exemplo n.º 6
0
vi_rc Change( range *r )
{
    int         scol, ecol;
    int         tmp;
    vi_rc       rc;
    vi_key      key;
#ifndef __WIN__
    int         vecol;
#endif

    /*
     * change line ranges
     */
    if( r->start.line != r->end.line ) {
        StartUndoGroup( UndoStack );
        if( !r->line_based ) {
            rc = Cut( r->start.line, r->start.column, r->end.line, r->end.column, true );
            r->end.column = -1;
            scol = -1;
            ecol = -1;
        } else {
            if( r->start.line == CurrentPos.line ) {
                r->start.line++;
            } else {
                r->end.line--;
            }
            if( r->start.line <= r->end.line ) {
                rc = DeleteLineRange( r->start.line, r->end.line, 0 );
                if( rc != ERR_NO_ERR ) {
                    EndUndoGroup( UndoStack );
                    return( rc );
                }
            }
            scol = FindStartOfCurrentLine() - 1;
            ecol = CurrentLine->len - 1;
        }
        DCDisplayAllLines();
        rc = DeleteAndInsertText( scol, ecol );
        EndUndoGroup( UndoStack );
        return( rc );
    }

    /*
     * change text on current line
     */
    rc = ERR_NO_ERR;
    GoToLineNoRelCurs( r->start.line );
    ecol = r->end.column;
    scol = r->start.column;
#ifdef __WIN__
//    GetCurrentLine();
    strcpy( WorkLine->data, CurrentLine->data );
    tmp = WorkLine->data[ecol];
    WorkLine->data[ecol] = '$';
#else
    vecol = VirtualColumnOnCurrentLine( ecol + 1 );
    vecol--;
    ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, WorkLine->data, EditVars.MaxLine + 1 );
    WorkLine->len = strlen( WorkLine->data );
    tmp = WorkLine->data[vecol];
    WorkLine->data[vecol] = '$';
#endif
    if( WorkLine->len == 0 ) {
        WorkLine->data[1] = '\0';
    }
    EditFlags.InsertModeActive = true;
    GoToColumn( scol + 1, CurrentLine->len );
    EditFlags.InsertModeActive = false;
    DisplayWorkLine( true );
    UnselectRegion();
    DCUpdate();
#ifndef __WIN__
    HiliteAColumnRange( CurrentPos.line, scol, ecol );
#endif

    /*
     * now, get ready to do change
     */
    key = GetNextEvent( false );
#ifdef __WIN__
    WorkLine->data[ecol] = tmp;
#else
    WorkLine->data[vecol] = tmp;
#endif
    DisplayWorkLine( true );
    if( key == VI_KEY( ESC ) && !EditFlags.ChangeLikeVI ) {
        WorkLine->len = -1;
        GoToColumn( scol + 1, CurrentLine->len );
    } else {
        KeyAdd( key );
        rc = DeleteAndInsertText( scol, ecol );
    }
    return( rc );

} /* Change */
Exemplo n.º 7
0
/*
 * fileGrep - search a single dir and build list of files
 */
static void fileGrep( char *dir, char **list, int *clist, window_id wn )
{
    char        fn[FILENAME_MAX], data[FILENAME_MAX], ts[FILENAME_MAX];
    char        path[FILENAME_MAX];
    char        drive[_MAX_DRIVE], directory[_MAX_DIR], name[_MAX_FNAME];
    char        ext[_MAX_EXT];
    int         i;
#if defined( __WIN__ ) && defined( __NT__ )
    LVITEM      lvi;
#endif
    vi_rc       rc;

    /*
     * get file path prefix
     */
    _splitpath( dir, drive, directory, name, ext );
    strcpy( path, drive );
    strcat( path, directory );
//    _makepath( path, drive, directory, NULL,NULL );

    /*
     * run through each entry and search it; building a list of matches
     */
    rc = GetSortDir( dir, FALSE );
    if( rc != ERR_NO_ERR ) {
        return;
    }
    for( i = 0; i < DirFileCount; i++ ) {
        if( !(DirFiles[i]->attr & _A_SUBDIR ) ) {

            strcpy( fn, path );
            strcat( fn, DirFiles[i]->name );
#ifdef __WIN__
            EditFlags.BreakPressed = SetGrepDialogFile( fn );
#else
            DisplayLineInWindow( wn, 1, fn );
#endif
            if( EditFlags.BreakPressed ) {
                return;
            }
            if( isFgrep ) {
                rc = fSearch( fn, ts );
            } else {
                rc = eSearch( fn, ts );
            }
            if( rc == FGREP_FOUND_STRING ) {

                ExpandTabsInABuffer( ts, strlen( ts ), data, MAX_DISP );
                strcpy( ts, data );
                MySprintf( data, "%X \"%s\"", fn, ts );
#ifdef __WIN__
                /*
                 * for windows - the handle passed in is the list box
                 * and the entire string is added to it but only the file
                 * name is added to the list
                 */
#ifdef __NT__
                if( IsCommCtrlLoaded() ) {
                    lvi.mask = LVIF_TEXT;
                    lvi.iItem = SendMessage( wn, LVM_GETITEMCOUNT, 0, 0L );
                    lvi.iSubItem = 0;
                    lvi.pszText = fn;
                    SendMessage( wn, LVM_INSERTITEM, 0, (LPARAM)&lvi );
                    lvi.iSubItem = 1;
                    lvi.pszText = ts;
                    SendMessage( wn, LVM_SETITEM, 0, (LPARAM)&lvi );
                } else {
#endif
                    SendMessage( wn, LB_ADDSTRING, 0, (LPARAM)data );
                    MySprintf( data, "%X", fn );
#ifdef __NT__
                }
#endif
#endif
                AddString( &(list[*clist]), data );
                (*clist)++;

            } else if( rc != ERR_NO_ERR ) {
                return;
            }
        }
    }

} /* fileGrep */