/*
 * 			Ecompile_&_Save.ced
 *
 * 		   $VER: Steve Chapman 30.03.95 
 *
 * USAGE:
 * 
 *       Save this as REXX:Ecompile_&_Save.ced and assign
 *       a Cygnus Ed function key to Ecompile_&_Save.ced
 *
 *
 * SYNOPSIS:
 *
 *       Has E compile the program in CED, saving any 
 *       changes first adding 1 to the file name.
 *    
 *      ie.  PROGRAM.1.e	  becomes   PROGRAM.2.e  ect.
 * 
 *      If there is a compiler error then CED returns to that spot.
 *
 *
 */


/* constants and assigns */

   ec    = 'WORK:PROGRAMMING/amiga_e/bin/ecdemo'  /* change this assignment to your own */

Main:
   signal on ERROR

   address 'rexx_ced'
   options results

/* open a window for dos i/o */

   call close 'STDOUT'
   call close 'STDIN'
   call open 'STDIN','CON:0/0/640/100'
   call pragma '*','STDIN'
   call open 'STDOUT','*'

/* find name of file and directory */

   'status 19'
   pathfile = result
   say 'filename is' pathfile

/* save file if changed */

   'status 18'
  if result ~= 0 then do
     
      say 'saving changes..'

   parse var pathfile FName '.e'
   DevDiv = POS(':', FName)+1
   FNPOS = LASTPOS('/',FName)+1
   ExtPos = LASTPOS('.', FName)+1
   PARSE VAR FName Dev = DevDiv Path = FNPOS File =ExtPos Ext
   NEWNUMBER = Ext + 1
   DEVS = insert(dev,path,,)  
   PATHH = insert(DEVS,file,,)
   NEWFILE = insert(PATHH,NEWNUMBER,,)
   NEWFILENAME = insert(NEWFILE,'.e',,)
   SAY 'New file name is ' NEWFILENAME
   
  'save as' NEWFILENAME
   pathfile = NEWFILENAME
   end
   else say 'no changes..'

/* compile it */

   parse var pathfile pf '.e'
   say 'compiling..'
   address 'COMMAND' ec pf
   
   ADDRESS 'COMMAND' pf



   SAY ' '
   SAY 'Hit Return'
   pull
   'cedtofront'
   exit 0

/* branches here if RC > 0 from ec */

ERROR:

   errline = RC
   'cedtofront'
   'jump to line' errline
   'okay1' 'error in line #'errline
   exit 0

