/*-- AutoRev header do NOT edit!
*
*   Program         :   Editor.c
*   Copyright       :   Copyright  1991-92 Jaba Development
*   Author          :   Jan van den Baard
*   Creation Date   :   05-Apr-92
*   Current version :   2.0
*   Translator      :   Dice v2.06.40
*
*   REVISION HISTORY
*
*   Date          Version         Comment
*   ---------     -------         ------------------------------------------
*   05-Apr-92     2.0             Calling the editor. (rewrite)
*
*-- REV_END --*/

#ifndef __DETACH

#include "View.h"

Prototype void EditFile( void );

extern struct WBStartup *WBenchMsg;
extern struct Screen    *vwScreen;
extern struct Window    *vwWindow;
extern struct MsgPort   *vwIdPort;
extern struct AsciiText *vwText;
extern UBYTE             vwName[];


void EditFile( void )
{
    WORD                 rc, unload = TRUE;
    UBYTE                ebuf[ 256 ];

    if ( ! vwText )     return;

    if ( ! WBenchMsg ) {
        if ( GetVar( "EDITOR", ebuf, 256, NULL ) > 0 ) {
            strcat( ebuf, " \"" );
            strcat( ebuf, vwName );
            strcat( ebuf, "\"" );
            ScreenToBack( vwScreen );
            ErrorLine( "Running the editor..." );
            Busy();

            rc = SystemTags( ebuf, SYS_Input,   Input(),
                                   SYS_Output,  Output(),
                                   TAG_DONE );

            if ( rc == -1 ) {
                Error( "Could not run the editor." );
                goto CleanExit;
            }
        } else {
            Error( "ENV:EDITOR environment variable not set (Use SetEnv)." );
            goto CleanExit;
        }
    } else {
        Error( "Option not available with Workbench." );
        goto CleanExit;
    }

    sprintf( ebuf, "Editor return code : %ld", rc );
    ErrorLine( ebuf );
CleanExit:
    ClearMsgPort( vwIdPort );
    ScreenToFront( vwScreen );
    Ready();
}
#endif
