Example #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 */
Example #2
0
RefPtr<CodeBlock> ScriptExecutable::newCodeBlockFor(
    CodeSpecializationKind kind, JSFunction* function, JSScope* scope, JSObject*& exception)
{
    VM* vm = scope->vm();

    ASSERT(vm->heap.isDeferred());
    ASSERT(startColumn() != UINT_MAX);
    ASSERT(endColumn() != UINT_MAX);

    if (classInfo() == EvalExecutable::info()) {
        EvalExecutable* executable = jsCast<EvalExecutable*>(this);
        RELEASE_ASSERT(kind == CodeForCall);
        RELEASE_ASSERT(!executable->m_evalCodeBlock);
        RELEASE_ASSERT(!function);
        return adoptRef(new EvalCodeBlock(
            executable, executable->m_unlinkedEvalCodeBlock.get(), scope,
            executable->source().provider()));
    }
    
    if (classInfo() == ProgramExecutable::info()) {
        ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
        RELEASE_ASSERT(kind == CodeForCall);
        RELEASE_ASSERT(!executable->m_programCodeBlock);
        RELEASE_ASSERT(!function);
        return adoptRef(new ProgramCodeBlock(
            executable, executable->m_unlinkedProgramCodeBlock.get(), scope,
            executable->source().provider(), executable->source().startColumn()));
    }
    
    RELEASE_ASSERT(classInfo() == FunctionExecutable::info());
    RELEASE_ASSERT(function);
    FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
    RELEASE_ASSERT(!executable->codeBlockFor(kind));
    JSGlobalObject* globalObject = scope->globalObject();
    ParserError error;
    DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
    ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
    UnlinkedFunctionCodeBlock* unlinkedCodeBlock =
    executable->m_unlinkedExecutable->codeBlockFor(*vm, executable->m_source, kind, debuggerMode, profilerMode, error, executable->isArrowFunction());
    recordParse(executable->m_unlinkedExecutable->features(), executable->m_unlinkedExecutable->hasCapturedVariables(), firstLine(), lastLine(), startColumn(), endColumn()); 
    if (!unlinkedCodeBlock) {
        exception = vm->throwException(
            globalObject->globalExec(),
            error.toErrorObject(globalObject, executable->m_source));
        return nullptr;
    }

    SourceProvider* provider = executable->source().provider();
    unsigned sourceOffset = executable->source().startOffset();
    unsigned startColumn = executable->source().startColumn();

    return adoptRef(new FunctionCodeBlock(
        executable, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn));
}
Example #3
0
static bool swapString( input_buffer *input )
{
    char        *tmp;

    tmp = alloca( strlen( input->last_str ) + 1 );
    strcpy( tmp, input->last_str );
    strcpy( input->last_str, input->buffer );
    strcpy( input->buffer, tmp );
    endColumn( input );
    return( true );

} /* swapString */
Example #4
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 */
Example #5
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 #6
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 #7
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 #8
0
PassRefPtr<CodeBlock> ScriptExecutable::newCodeBlockFor(
    CodeSpecializationKind kind, JSFunction* function, JSScope** scope, JSObject*& exception)
{
    VM* vm = (*scope)->vm();

    ASSERT(vm->heap.isDeferred());
    ASSERT(startColumn() != UINT_MAX);
    ASSERT(endColumn() != UINT_MAX);

    if (classInfo() == EvalExecutable::info()) {
        EvalExecutable* executable = jsCast<EvalExecutable*>(this);
        RELEASE_ASSERT(kind == CodeForCall);
        RELEASE_ASSERT(!executable->m_evalCodeBlock);
        RELEASE_ASSERT(!function);
        return adoptRef(new EvalCodeBlock(
            executable, executable->m_unlinkedEvalCodeBlock.get(), *scope,
            executable->source().provider()));
    }
    
    if (classInfo() == ProgramExecutable::info()) {
        ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
        RELEASE_ASSERT(kind == CodeForCall);
        RELEASE_ASSERT(!executable->m_programCodeBlock);
        RELEASE_ASSERT(!function);
        return adoptRef(new ProgramCodeBlock(
            executable, executable->m_unlinkedProgramCodeBlock.get(), *scope,
            executable->source().provider(), executable->source().startColumn()));
    }
    
    RELEASE_ASSERT(classInfo() == FunctionExecutable::info());
    RELEASE_ASSERT(function);
    FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
    RELEASE_ASSERT(!executable->codeBlockFor(kind));
    JSGlobalObject* globalObject = (*scope)->globalObject();
    ParserError error;
    DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
    ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
    UnlinkedFunctionCodeBlock* unlinkedCodeBlock =
        executable->m_unlinkedExecutable->codeBlockFor(
            *vm, executable->m_source, kind, debuggerMode, profilerMode, error);
    recordParse(executable->m_unlinkedExecutable->features(), executable->m_unlinkedExecutable->hasCapturedVariables(), lineNo(), lastLine(), startColumn(), endColumn()); 
    if (!unlinkedCodeBlock) {
        exception = vm->throwException(
            globalObject->globalExec(),
            error.toErrorObject(globalObject, executable->m_source));
        return 0;
    }

    // Parsing reveals whether our function uses features that require a separate function name object in the scope chain.
    // Be sure to add this scope before linking the bytecode because this scope will change the resolution depth of non-local variables.
    if (!executable->m_didParseForTheFirstTime) {
        executable->m_didParseForTheFirstTime = true;
        function->addNameScopeIfNeeded(*vm);
        *scope = function->scope();
    }
    
    SourceProvider* provider = executable->source().provider();
    unsigned sourceOffset = executable->source().startOffset();
    unsigned startColumn = executable->source().startColumn();

    return adoptRef(new FunctionCodeBlock(
        executable, unlinkedCodeBlock, *scope, provider, sourceOffset, startColumn));
}