/*****************************************************************************
*                                                                            *
* ARexx script:              ProAsm.edge v1.02     for the ProAsm Assembler  *
*                                                                            *
* This script assembles the source in the actual window of the Edge using    *
* the ProAsm assembler and the ASX user interface.                           *
* Please note that the source code in this window will be saved before       *
* assembly.                                                                  *
*                                                                            *
* by Daniel Weber                                                            *
* 31.Dec.93                                                                  *
*                                                                            *
*                                                                            *
* Usage:   ProAsm.edge                                                       *
*                                                                            *
*                                                                            *
* How to run:                                                                *
*                                                                            *
*  1)  Activate the view of the source file.                                 *
*  2a) Start this ARexx script via 'Send DOS/ARexx command...' (or somesuch) *
*  2b) You may put it into your Keyboard file, Menu file, etc. as:           *
*      RX SYNC rexx:edge/ProAsm.edge.                                        *
*  3)  Use 'GoToError show' to open the ErrorList window of Edge.            *
*                                                                            *
*****************************************************************************/

editorID = 'Edge'                       /* define editor ID             */

OPTIONS RESULTS
EdgePort = ADDRESS()

ADDRESS (''||EdgePort)                  /* get some information from the EDGE */


GetENVVar _FE_DosName			/* full file name               */
fullname = result


ADDRESS 'asx_rexx'
FindID editorID':'fullname
port = result
DO WHILE port~=''
  ADDRESS (''||port)
  EndOfAssembly                         /* quit all open jobs of this source */
  ADDRESS 'asx_rexx'
  FindID editorID':'fullname
  port = result
END


/**
 ** start assembly porcess...
 **/

BegOfAssembly                           /* begin a new job              */
port = result

IF port~='' THEN DO
  ADDRESS (''||edgeport)                /* ARexx weirdness              */
  GetENVVar _FE_BackDir
  backdir = result
  IF backdir = '' THEN backdir = 'ram:'
  GetENVVar _FE_Name
  name = result
  GetENVVar _FE_Changes
  IF result~=0 THEN DO
    RequestChoice title """ProAsm Message...""" """Changes made.\010Save source before assembly?"""
    IF RC = 0 THEN Save
  END
  SaveAs backdir||'asx_'||RIGHT(port,8)||name FORCE NOBACKUP NOICON
  ClearErr                              /* clear error list             */
  PutENVVar _FE_DosName fullname	/* reset name...                */

  /* assemble */
  ADDRESS (''||port)
  DefineID editorID':'fullname          /* set an ID (optional)         */
  Assemble backdir||'asx_edge_'||name
  PARSE VAR result . errors . warnings . optims optimbytes . codesize . workspace

  stat = 'File 'fullname' assembled to '
  stat = stat''codesize 'bytes.\010'optims 'optimizations saved' optimbytes 'bytes\010'
  stat = stat''errors 'Errors,' warnings 'Warnings,' workspace 'bytes of workspace used.'
  ADDRESS (''||edgeport)
  RequestNotify title """ProAsm Message..."""  ""stat""

  /* copy all error messages to edge */
  IF errors ~= 0 THEN DO
    ADDRESS (''||port)
    NextError
    errortext = result
    DO WHILE errortext ~=''
      /* PARSE VALUE errortext WITH 1 LineNumber '.' Column ' : ' ErrorMsg ' in file ' filename */
      PARSE VALUE errortext WITH 1 LineNumber ' : ' ErrorMsg
      Column = 0
      ADDRESS (''||edgeport)
      AddErr LineNumber Column """"ErrorMsg""""
      ADDRESS (''||port)
      NextError
      errortext = result
    END
    ADDRESS (''||edgeport)
    GoToError show  
  END

  ADDRESS (''||port)
  EndOfAssembly
END

EXIT(0)

