Beispiel #1
0
static bool fileComplete( input_buffer *input, vi_key first_event )
{
    bool        exit, done;
    vi_rc       rc;
    vi_key      event;
    int         old_len;

    exit = false;
    if( input->curr_pos != strlen( input->buffer ) ) {
        MyBeep();
    } else {
        saveStr( input );
        old_len = strlen( input->buffer ) - 1;
        rc = StartFileComplete( input->buffer, old_len,
                                 input->buffer_length, first_event );
        if( rc > ERR_NO_ERR ) {
            MyBeep();
        } else {
            if( rc != FILE_COMPLETE ) {
                done = false;
                do {
                    endColumn( input );
                    displayLine( input );
                    event = GetNextEvent( true );
                    switch( event ) {
                    case VI_KEY( FAKEMOUSE ):
                    case VI_KEY( MOUSEEVENT ):
                    case VI_KEY( TAB ):
                    case VI_KEY( SHIFT_TAB ):
                    case VI_KEY( UP ):
                    case VI_KEY( DOWN ):
                    case VI_KEY( LEFT ):
                    case VI_KEY( RIGHT ):
                    case VI_KEY( PAGEDOWN ):
                    case VI_KEY( PAGEUP ):
                    case VI_KEY( ALT_END ):
                        rc = ContinueFileComplete( input->buffer, old_len,
                                                    input->buffer_length, event );
                        if( rc != ERR_NO_ERR ) {
                            FinishFileComplete();
                            if( rc == FILE_COMPLETE_ENTER ) {
                                exit = true;
                            }
                            done = true;
                        }
                        old_len = strlen( input->buffer );
                        break;
                    default:
                        KeyAdd( event );
                        PauseFileComplete();
                        done = true;
                    }
                } while( !done );
            }
        }
    }
    return( exit );

} /* fileComplete */
Beispiel #2
0
// original save/load data format
static void save_bagObjects(BagObject *bo, int count) {
	int totalSize = 0;
	for (int i = 0; i < count; ++i) {
		totalSize += bo[i].dataSize;
	}
	assert(totalSize < 0xFFFF);
	saveInt16(totalSize);
	for (int i = 0; i < count; ++i) {
		saveStr(bo[i].data, bo[i].dataSize);
	}
	saveInt16(count);
	int offset = 0;
	for (int i = 0; i < count; ++i) {
		saveInt16(offset);
		saveStr(bo[i].name, 20);
		offset += bo[i].dataSize;
	}
}
Beispiel #3
0
static bool getHistory( input_buffer *input )
{
    int             offset;
    char            *cmd;

    offset = input->curr_hist % input->h->max;
    cmd = input->h->data[offset];
    if( cmd != NULL ) {
        saveStr( input );
        strcpy( input->buffer, cmd );
        endColumn( input );
        return( true );
    }
    return( false );

} /* getHistory */
Beispiel #4
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 */
Beispiel #5
0
static void saveOrLoadStr(char *s, int16 len = -1) {
	bool countTermChar = (len == -2); // deal with original buggy file format...
	bool storeLen = (len < 0);
	if (storeLen) {
		len = strlen(s);
		if (countTermChar) {
			++len;
		}
		saveOrLoadInt16(len);
	}
	switch (_saveOrLoadMode) {
	case kSaveMode:
		saveStr(s, len);
		break;
	case kLoadMode:
		loadStr(s, len);
		if (storeLen) {
			s[len] = 0;
		}
		break;
	}
}
Beispiel #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 */
Beispiel #7
0
static void doHistorySearch( input_buffer *input )
{
    int             curr;
    char            *str;
    vi_key          event;

    curr = input->h->curr;
    str = alloca( strlen( input->buffer ) + 1 );
    strcpy( str, input->buffer );
    event = VI_KEY( CTRL_TAB );
    while( curr != -1 ) {
        if( event == VI_KEY( ALT_TAB ) || event == VI_KEY( CTRL_TAB ) ) {
            saveStr( input );
            curr = searchHistory( input, str, curr );
            displayLine( input );
            event = GetNextEvent( true );
            continue;
        }
        KeyAdd( event );
        return;
    }

} /* doHistorySearch */
Beispiel #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 */