vpemain2.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 595 行 · 第 1/2 页

CPP
595
字号
            case EXECUTE_NORMAL: {
                setStatus( "Executing..." );
                execute( cmd );
                break;
            }
            case EXECUTE_BATCH: {
                runBatch( cmd );
                break;
            }
            case EXECUTE_MAKE: {
                if( makeMake() ) {
                    runBatch( cmd );
                }
                break;
            }
            case EXECUTE_BROWSE: {
                executeBrowse( cmd );
                break;
            }
            case EXECUTE_EDITOR: {
                executeEditor( cmd );
                break;
            }
            case EXECUTE_TOUCH_ALL: {
                MsgRetType      rc;
                unsigned        i;
                VComponent      *comp;
                rc = WMessageDialog::messagef( this, MsgQuestion, MsgYesNo,
                        _viperRequest,
                        "Do you really want to remake all targets and their components?" );
                if( rc == MsgRetYes ) {
                    i = _compViews.count();
                    while( i > 0 ) {
                        comp = (VComponent *)_compViews[ i-1 ];
                        comp->touchComponent( TRUE );
                        i--;
                    }
                }
                break;
            }
            case EXECUTE_HELP: {
                if( _otherhelp == NULL ) {
                    delete _otherhelp;
                }
                _otherhelp = new WSystemHelp( this, "", cmd );
                _otherhelp->sysHelpContent();
                break;
            }
        }
        stopWait();
        setStatus( NULL );
        if( _quitAnyways ) {
            exit( NULL );
        }
    }
    return( TRUE );
}

bool VpeMain::execute( const WString& cmd )
{
    if( _config->debug() && !confirm( "Starting '%s'", cmd ) ) {
        return( FALSE );
    }
    startWait();

    int icount = strlen( cmd );
    for( int i=0; i<icount; ) {
        WString cbuff;
        while( isspace( cmd[i] ) ) i++;
        for( ;i<icount; ) {
            char ch = cmd[i];
            i++;
            if( ch == '\n' || ch == '\r' ) break;
            cbuff.concat( ch );
        }
        if( cbuff.size() > 0 ) {
            if( strnicmp( cbuff, "!Error ", 7 ) == 0 ) {
                WString msg;
                for( int i=7; i<cbuff.size() && cbuff[i] != '$'; i++ ) {
                    msg.concat( cbuff[i] );
                }
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, msg );
                return( FALSE );
            } else {
                if( !executeOne( cbuff ) ) {
                    return( FALSE );
                }
            }
        }
    }
    return( TRUE );
}

bool VpeMain::executeOne( const WString& cmd )
{
    int i = 0;
    WWindowState wstate = WWinStateShowNormal;
    WWindowType wtype = WWinTypeDefault;
    if( strnicmp( cmd, "!FullScreen ", 12 ) == 0 ) {
        i += 12;
        wtype = WWinTypeFullScreen;
    } else if( strnicmp( cmd, "!Windowed ", 10 ) == 0 ) {
        i += 10;
        wtype = WWinTypeWindowed;
    } else if( strnicmp( cmd, "!Hidden ", 8 ) == 0 ) {
        i += 10;
        wstate = WWinStateHide;
    }
    int ret = WSystemService::sysExec( &cmd[i], wstate, wtype );
    stopWait();

#ifdef __OS2__
    if( ret == -1 ) {

        // this is a kludge because the WMessageDialog can only handle
        // finitely long strings
        WString         cmdmsg;
        cmdmsg = cmd;
        cmdmsg.truncate( MAX_CMD_LINE );

        //
        // WARNING - this may stop working if WCLASS modifies errno
        //
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                "Unable to run %s: %s.",
                                (const char*)cmdmsg, strerror( errno ) );
        return( FALSE );
    }
#endif

#if defined( __WINDOWS__ ) || defined ( __NT__ )
    if( ret <= 32 ) {

        // this is a kludge because the WMessageDialog can only handle
        // finitely long strings
        WString         cmdmsg;
        cmdmsg = cmd;
        cmdmsg.truncate( MAX_CMD_LINE );

        switch( ret ) {
        case 0:
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "%s: Out of memory.", (const char*)cmdmsg );
            break;
        case 2:
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "%s: Program or one of its components not found.", (const char*)cmdmsg );
            break;
        case 3:
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "%s: Path not found.", (const char*)cmdmsg );
            break;
        case 16:
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "%s: Contains multiple writeable data segments.", (const char*)cmdmsg );
            break;
        default:
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "%s: return code=%d.", (const char*)cmdmsg, ret );
        }
        return( FALSE );
    }
#endif
    return( TRUE );
}

void VpeMain::executeEditor( const WString& cmd )
{
    if( _config->debug() && !confirm( "executeEditor: '%s'", cmd ) ) {
        return;
    }
    setStatus( "Executing editor..." );
    WStringList x( cmd );
    if( _editorIsDll ) {
        if( _editorDll.isInitialized() ) {      //internal-use DLL
            if( x.stringAt(0) == "EditSaveAll" ) {
                // don't start a new editor up if one is not already there
                _editorDll.EDITSaveAll();
            } else if( _editorDll.EDITConnect() ) {
                if( x.stringAt(0) == "EditFile" ) {
                    char* file = (char*)(const char*)x.stringAt( 1 );
                    char* help = (char*)(const char*)x.stringAt( 2 );
                    if( _editorDll.EDITFile( file, help ) ) {
                        _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                    } else {
                        WMessageDialog::messagef( this, MsgError, MsgOk,
                                    _viperInfo, "Unable to start editor" );
                    }
                } else if( x.stringAt( 0 ) == "EditLocate" ) {
                    long lRow = atol( x.stringAt( 1 ) );
                    int nCol = atoi( x.stringAt( 2 ) );
                    int len = atoi( x.stringAt( 3 ) );
                    _editorDll.EDITLocate( lRow, nCol, len );
                    _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                } else if( x.stringAt( 0 ) == "EditLocateError" ) {
                    long lRow = atol( x.stringAt( 1 ) );
                    int nCol = atoi( x.stringAt( 2 ) );
                    int len = atoi( x.stringAt( 3 ) );
                    int resId = atoi( x.stringAt( 4 ) );
                    char* msg = (char*)(const char*)x.stringAt( 5 );
                    _editorDll.EDITLocateError( lRow, nCol, len, resId, msg );
                    _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                } else if( x.stringAt(0) == "EditFileAtPos" ) {
                    char* file = (char*)(const char*)x.stringAt( 1 );
                    file += 2; // for "-f" before filename
                    long lRow = atol( x.stringAt( 2 ) );
                    int nCol = atoi( x.stringAt( 3 ) );
                    int len = atoi( x.stringAt( 4 ) );
                    int resId = atoi( x.stringAt( 5 ) );
                    char* msg = (char*)(const char*)x.stringAt( 6 );
                    char* help = (char*)(const char*)x.stringAt( 7 );
                    if( _editorDll.EDITFile( file, help ) ) {
                        _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                        _editorDll.EDITLocateError( lRow, nCol, len, resId, msg );
                        _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                    } else {
                        WMessageDialog::messagef( this, MsgError, MsgOk,
                                    _viperInfo, "Unable to start editor" );
                    }
                } else if( x.stringAt(0) == "TakeFocus" ) {
                    _editorDll.EDITShowWindow( EDIT_SHOWNORMAL );
                }
            } else {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperInfo,
                                          "Unable to connect to editor" );
            }
        } else {
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperInfo,
                                        "Editor not available" );
        }
    } else if( x.stringAt(0) == "EditFile" ) {
        WString bat( _editor );
        bat.concat( ' ' );
        bat.concat( x.cStringAt(1) );
        execute( bat );
    } else if( x.stringAt(0) == "EditFileAtPos" ) {
        WString bat( _editor );
        bat.concat( ' ' ); // space after editor name before parms
        int parmsize = _editorParms.size();

        for( int i=0; i < parmsize; i++ ) {
            switch( _editorParms[i] ) {
            case '%':
                switch( _editorParms[i+1] ) {
                case 'f': // file name
                    // string contains "-f<filename>" so strip the -f
                    bat.concat( (char*)(const char*)x.stringAt( 1 )+2 );
                    break;
                case 'r': // row to go to
                    bat.concat( x.stringAt( 2 ) );
                    break;
                case 'c': // column to go to
                    bat.concat( x.stringAt( 3 ) );
                    break;
                case 'l': // length of hilight
                    bat.concat( x.stringAt( 4 ) );
                    break;
                case 'h': // helpid
                    bat.concat( x.stringAt( 5 ) );
                    break;
                case 'e': // error message
                    bat.concat( x.stringAt( 6 ) );
                    break;
                case '%': // a real '%'
                    bat.concat( x.stringAt( '%' ) );
                    break;
                default:
                    // ignore the '%' and the character
                    break;
                }
                i+=2; // skip % and following char
            default:
                bat.concat( _editorParms[i] );
                break;
            }
        }
        execute( bat );
    }
}

bool VpeMain::makeMake()
{
    WString     editcmd( "EditSaveAll" );

    if( !running() ) {
        if( checkProject() ) {
            executeEditor( editcmd );
            setStatus( "Creating MAKE file(s)..." );
            if( _project->makeMakeFile() ) {
                return( TRUE );
            }
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                      "Unable to create makefile(s)" );
            return( FALSE );
        }
        return( FALSE );
    }
    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Makefile in use" );
    return( FALSE );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?