Example #1
0
static void destroyBlock( int i, char *start )
{
    char    new_ss[MAX_STR];

    if( EditVars.NumStatusSections == 1 ) {
        // unfortunately wstatus.c can't handle this right now
        // (it would be nice)
        MyBeep();
        return;
    }

    if( i != EditVars.NumStatusSections ) {
        memmove( EditVars.StatusSections + i, EditVars.StatusSections + i + 1, (EditVars.NumStatusSections - 1 - i) * sizeof( section_size ) );
    }
    EditVars.NumStatusSections--;
    EditVars.StatusSections = MemReAlloc( EditVars.StatusSections, EditVars.NumStatusSections * sizeof( section_size ) );

    strncpy( new_ss, EditVars.StatusString, start - EditVars.StatusString );
    new_ss[start - EditVars.StatusString] = '\0';
    while( start[0] && !(start[0] == '$' && start[1] == '[') ) {
        start++;
    }
    if( start[0] == '$' ) {
        start += 2;
        strcat( new_ss, start );
    }
    ReplaceString( &EditVars.StatusString, new_ss );

    totalRedraw();
}
Example #2
0
/*
 * ErrorBox - show an error message in a dialog box
 */
void ErrorBox( char *str, ... )
{
    va_list     al;
    char        tmp[MAX_STR];

    if( MessageWindow != NO_WINDOW ) {
        WindowAuxUpdate( MessageWindow, WIND_INFO_TEXT_COLOR,
                            messagew_info.hilight.foreground );
        WindowAuxUpdate( MessageWindow, WIND_INFO_BACKGROUND_COLOR,
                            messagew_info.hilight.background );
        va_start( al, str );
        MyVSprintf( tmp, str, al );
        va_end( al );

        SourceError( tmp );
        Message1Box( "%s", tmp );

        WindowAuxUpdate( MessageWindow, WIND_INFO_TEXT_COLOR,
                            messagew_info.text.foreground );
        WindowAuxUpdate( MessageWindow, WIND_INFO_BACKGROUND_COLOR,
                            messagew_info.text.background );
        MyBeep();
    } else {
        va_start( al, str );
#ifndef __WIN__
        MyVPrintf( str, al );
        MyPrintf( "\n" );
#endif
        va_end( al );
    }

} /* Error */
Example #3
0
static vi_key cursorKeyFilter( input_buffer *input, vi_key event )
{
    int         max_pos;

    max_pos = strlen( input->buffer );
    switch( event ) {
    case VI_KEY( NULL ):
        break;
    case VI_KEY( HOME ):
        input->curr_pos = 0;
        input->left_column = 0;
        break;
    case VI_KEY( END ):
        endColumn( input );
        break;
    case VI_KEY( RIGHT ):
        if( input->curr_pos < max_pos ) {
            input->curr_pos += 1;
            if( input->curr_pos > input->left_column + input->window.width ) {
                input->left_column += 1;
            }
        } else {
            MyBeep();
        }
        break;
    case VI_KEY( LEFT ):
        if( input->curr_pos > 0 ) {
            input->curr_pos -= 1;
            if( input->left_column > input->curr_pos ) {
                input->left_column = input->curr_pos;
            }
        }
        break;
    case VI_KEY( DEL ):
    case VI_KEY( BS ):
        saveStr( input );
        if( !deleteChar( input, event == VI_KEY( BS )
            || input->curr_pos == max_pos ) ) {
            MyBeep();
        }
        break;
    default:
        return( event );
    }
    return( VI_KEY( NULL ) );

} /* cursorKeyFilter */
Example #4
0
static void splitBlock( int i, char *start )
{
    char    new_ss[MAX_STR];
    int     diff;
    RECT    rect;

    if( EditVars.NumStatusSections == MAX_SECTIONS ) {
        MyBeep();
        return;
    }

    if( i == EditVars.NumStatusSections ) {
        GetWindowRect( status_window_id, &rect );
        diff = rect.right - EditVars.StatusSections[i - 1];
    } else if( i == 0 ) {
        diff = EditVars.StatusSections[1];
    } else {
        diff = EditVars.StatusSections[i] - EditVars.StatusSections[i - 1];
    }

    if( diff < BOUNDARY_WIDTH * 4 ) {
        MyBeep();
        return;
    }
    EditVars.NumStatusSections++;
    EditVars.StatusSections = MemReAlloc( EditVars.StatusSections, EditVars.NumStatusSections * sizeof( section_size ) );
    memmove( EditVars.StatusSections + i + 1, EditVars.StatusSections + i, (EditVars.NumStatusSections - 1 - i) * sizeof( section_size ) );
    if( i > 0 ) {
        EditVars.StatusSections[i] = EditVars.StatusSections[i - 1] + (diff / 2);
    } else {
        EditVars.StatusSections[i] /= 2;
    }

    while( start[0] && !(start[0] == '$' && start[1] == '[') ) {
        start++;
    }
    strncpy( new_ss, EditVars.StatusString, start - EditVars.StatusString );
    new_ss[start - EditVars.StatusString] = '\0';
    strcat( new_ss, "$[ " );
    strcat( new_ss, start );
    ReplaceString( &EditVars.StatusString, new_ss );

    totalRedraw();
}
Example #5
0
/*
 * SelectFileOpen - use common dialog file open to pick a file to edit
 */
vi_rc SelectFileOpen( const char *dir, char **result, const char *mask, bool want_all_dirs )
{
    OPENFILENAME        of;
    bool                rc;
    static long         filemask = 1;
    bool                is_chicago = false;

#if defined( __NT__ ) && !defined( _WIN64 )
    /* added to get around chicago crashing in the fileopen dlg */
    /* -------------------------------------------------------- */
    if( LOBYTE( LOWORD( GetVersion() ) ) >= 4 ) {
        is_chicago = true;
    }
    /* -------------------------------------------------------- */
#endif

    mask = mask;
    want_all_dirs = want_all_dirs;
    *result[0] = '\0';
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = root_window_id;
    of.lpstrFilter = (LPSTR)filterList;
    of.lpstrDefExt = NULL;
    of.nFilterIndex = filemask;
    of.lpstrFile = *result;
    of.nMaxFile = FILENAME_MAX;
    of.lpstrTitle = NULL;
    of.lpstrInitialDir = dir;
    if( is_chicago ) {
        of.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
    } else {
        of.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_ENABLEHOOK;
        of.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, InstanceHandle );
    }
    rc = GetOpenFileName( &of ) != 0;
    filemask = of.nFilterIndex;
    if( !is_chicago ) {
        (void)FreeProcInstance( (FARPROC)of.lpfnHook );
    }
    if( !rc && CommDlgExtendedError() == FNERR_BUFFERTOOSMALL ) {
        if( !is_chicago ) {
            MemFree( (char*)(of.lpstrFile) );
            *result = FileNameList;
        }
#if 0
        MyBeep();
        Message1( "Please open files in smaller groups" );
#endif
    }
    UpdateCurrentDirectory();
    return( ERR_NO_ERR );

} /* SelectFileOpen */
Example #6
0
static vi_key specialKeyFilter( input_buffer *input, vi_key event )
{
    char        *tmp;

    switch( event ) {
    case VI_KEY( ALT_O ):
    case VI_KEY( CTRL_O ):
        InsertTextForSpecialKey( event, input->buffer );
        break;
    case VI_KEY( CTRL_R ):
        if( !SelRgn.selected ||
            (SelRgn.lines && (SelRgn.start.line != SelRgn.end.line)) ) {
            MyBeep();
            break;
        }
    case VI_KEY( CTRL_W ):
    case VI_KEY( CTRL_E ):
    case VI_KEY( ALT_L ):
    case VI_KEY( CTRL_L ):
        if( input->curr_pos != strlen( input->buffer ) ) {
            MyBeep();
        } else {
            tmp = MemAlloc( input->buffer_length );
            assert( tmp != NULL );
            GetTextForSpecialKey( input->buffer_length - strlen( input->buffer ) - 1,
                                  event, tmp );
            saveStr( input );
            insertString( input, tmp );
            MemFree( tmp );
        }
        break;
    default:
        return( event );
        break;
    }
    return( VI_KEY( NULL ) );

} /* specialKeyFilter */
Example #7
0
static int searchHistory( input_buffer *input, char *str, int curr )
{
    int             index, i, len;
    history_data    *h;

    h = input->h;
    len = strlen( str );
    for( i = 0; i < h->max; i++ ) {
        curr -= 1;
        if( curr < 0 || curr < h->curr - h->max ) {
            curr = h->curr - 1;
        }
        index = curr % h->max;
        if( strnicmp( str, h->data[index], len ) == 0 ) {
            strcpy( input->buffer, h->data[index] );
            endColumn( input );
            return( curr );
        }
    }
    MyBeep();
    return( -1 );

} /* searchHistory */
Example #8
0
/*
 * getStringInWindow: main routine
 */
static bool getStringInWindow( input_buffer *input )
{
    vi_key      event;
    bool        old_mode;

    ReadingAString = true;
    initInput( input );
    input->last_str = alloca( input->buffer_length );
    memset( input->last_str, 0, input->buffer_length );
    if( input->h != NULL ) {
        input->curr_hist = input->h->curr;
    }
    for( ;; ) {
        event = GetNextEvent( false );
        event = cursorKeyFilter( input, event );
        event = historyFilter( input, event );
        event = specialKeyFilter( input, event );
        switch( event ) {
        case VI_KEY( NULL ):
            break;
        case VI_KEY( SHIFT_TAB ):
        case VI_KEY( TAB ):
            if( !fileComplete( input, event ) ) {
                endColumn( input );
                break;
            }
            /* fall through */
        case VI_KEY( ENTER ):
            if( input->buffer[0] == NO_ADD_TO_HISTORY_KEY ) {
                strcpy( &input->buffer[0], &input->buffer[1] );
            } else {
                addHistory( input );
            }
            /* fall through */
        case VI_KEY( ESC ):
            finiInput( input );
            /*
             * this call may not be necessary if the file complete window has
             * already closed of natural causes but it doesn't harm anything
             * if called when not needed - so we leave it here.
             */
            FinishFileComplete();
            ReadingAString = false;
            return( event != VI_KEY( ESC ) );
        case VI_KEY( INS ):
            input->overstrike = !input->overstrike;
            if( !EditFlags.NoInputWindow ) {
                NewCursor( input->window.id, input->overstrike ? EditVars.NormalCursorType : EditVars.InsertCursorType );
            }
            break;
        case VI_KEY( CTRL_END ):
            saveStr( input );
            input->buffer[input->curr_pos] = '\0';
            break;
        case VI_KEY( CTRL_X ):
        case VI_KEY( CTRL_U ):
            saveStr( input );
            input->buffer[0] = '\0';
            endColumn( input );
            break;
        case VI_KEY( CTRL_INS ):
            swapString( input );
            break;
        case VI_KEY( CTRL_V ):
        case VI_KEY( CTRL_Q ):
            insertChar( input, '^' );
            displayLine( input );
            // here we have a bit of a kluge
            input->curr_pos -= 1;
            event = GetNextEvent( false );
            saveStr( input );
            old_mode = input->overstrike;
            input->overstrike = true;
            insertChar( input, event );
            input->overstrike = old_mode;
            break;
        case VI_KEY( ALT_END ):
            /* just want to redraw the line - for windows */
            break;
        default:
            if( (event >= 32 && event < 256) || event == VI_KEY( CTRL_A ) ) {
                saveStr( input );
                if( !insertChar( input, event ) ) {
                    MyBeep();
                }
            }
        }
        if( !EditFlags.NoInputWindow ) {
            displayLine( input );
        }
    }

} /* getStringInWindow */
Example #9
0
/*
 * FindRegularExpression - do a forward search for a regular expression
 */
vi_rc FindRegularExpression( char *pat, i_mark *pos1, char **linedata,
                             linenum termline, find_type flags )
{
    vi_rc       rc;
    int         found;
    linenum     ilineno = 0;
    bool        wrapped = false;
    char        *data;
    line        *cline;
    fcb         *cfcb;
    int         scol;
    linenum     sline;

    /*
     * initialize for search
     */
    if( wrapMsgPrinted ) {
        wrapMsgPrinted = false;
        ClearWindow( message_window_id );
    }
    sline = pos1->line;
    if( flags & FINDFL_WRAP ) {
        ilineno = sline;
    }
    rc = CGimmeLinePtr( sline, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    scol = pos1->column;
    if( pat != NULL ) {
        rc = CurrentRegComp( pat );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }

    /*
     * loop until string found
     */
    data = &cline->data[scol];
    while( (found = RegExec( CurrentRegularExpression, data, (data == cline->data) )) == 0 ) {
        if( RegExpError != ERR_NO_ERR ) {
            return( RegExpError );
        }
        /*
         * get next line
         */
        rc = CGimmeNextLinePtr( &cfcb, &cline );
        if( rc == ERR_NO_ERR ) {
            ++sline;
        } else if( rc == ERR_NO_MORE_LINES ) {
            if( (flags & FINDFL_WRAP) == 0 ) {
                return( ERR_FIND_END_OF_FILE );
            } else {
                Message1( wrapMsg, "bottom" );
                MyBeep();
                wrapMsgPrinted = true;
            }
            if( wrapped ) {
                return( ERR_FIND_NOT_FOUND );
            }
            sline = 1;
            rc = CGimmeLinePtr( sline, &cfcb, &cline );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            wrapped = true;
        } else {
            return( rc );
        }
        if( sline > termline ) {
            return( ERR_FIND_PAST_TERM_LINE );
        }
        if( wrapped ) {
            if( sline > ilineno ) {
                return( ERR_FIND_NOT_FOUND );
            }
        }
        scol = 0;
        data = cline->data;
    }
    *linedata = cline->data;
    pos1->column = GetCurrRegExpColumn( cline->data );
    pos1->line = sline;
    return( ERR_NO_ERR );

} /* FindRegularExpression */
Example #10
0
/*
 * FindRegularExpressionBackwards - do a reverse search for a regular expression
 */
vi_rc FindRegularExpressionBackwards( char *pat, i_mark *pos1, char **linedata,
                                      linenum termline, find_type flags )
{
    vi_rc       rc;
    char        *data;
    bool        wrapped = false;
    bool        found;
    linenum     ilineno = 0;
    line        *cline;
    fcb         *cfcb;
    regexp      rcpy;
    int         scol;
    linenum     sline;

    /*
     * initialize for search
     */
    if( wrapMsgPrinted ) {
        wrapMsgPrinted = false;
        ClearWindow( message_window_id );
    }
    sline = pos1->line;
    rc = CGimmeLinePtr( sline, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    if( flags & FINDFL_WRAP ) {
        ilineno = sline;
    }
    scol = pos1->column;
    if( pat != NULL ) {
        rc = CurrentRegComp( pat );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }
    memset( &rcpy, 0, sizeof( rcpy ) );

    /*
     * loop until string found
     */
    for( ;; ) {
        data = cline->data;
        found = false;
        /*
         * run through all possible matches on the line, accepting
         * only the last one
         */
        if( scol >= 0 ) {
            while( *data != '\0' && RegExec( CurrentRegularExpression, data, (data == cline->data) ) ) {
                int     col, len;

                if( RegExpError != ERR_NO_ERR ) {
                    return( RegExpError );
                }
                col = GetCurrRegExpColumn( cline->data );
                len = GetCurrRegExpLength();
                if( col + len > scol ) {
                    break;
                }
                found = true;
                memcpy( &rcpy, CurrentRegularExpression, sizeof( regexp ) );
                data = &(cline->data[col + 1]);
            }
            if( found ) {
                break;
            }
        }

        /*
         * get next line
         */
        rc = GimmePrevLinePtr( &cfcb, &cline );
        if( rc == ERR_NO_ERR ) {
            --sline;
        } else if( rc == ERR_NO_MORE_LINES ) {
            if( (flags & FINDFL_WRAP) == 0 ) {
                return( ERR_FIND_TOP_OF_FILE );
            } else {
                Message1( wrapMsg, "top" );
                MyBeep();
                wrapMsgPrinted = true;
            }
            if( wrapped ) {
                return( ERR_FIND_NOT_FOUND );
            }
            rc = CFindLastLine( &sline );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            rc = CGimmeLinePtr( sline, &cfcb, &cline );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            wrapped = true;
        } else {
            return( rc );
        }
        if( sline < termline ) {
            return( ERR_FIND_PAST_TERM_LINE );
        }
        if( wrapped ) {
            if( sline < ilineno ) {
                return( ERR_FIND_NOT_FOUND );
            }
        }
        scol = cline->len;
    }
    *linedata = cline->data;
    memcpy( CurrentRegularExpression, &rcpy, sizeof( regexp ) );
    pos1->column = GetCurrRegExpColumn( cline->data );
    pos1->line = sline;
    return( ERR_NO_ERR );

} /* FindRegularExpressionBackwards */