home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- *
- * Compile.WShell.ced Copyright (c) 1989, Peter Cherna
- *
- * ARexx program for CygnusEd Professional. Scans the current file
- * for embedded "Auto:" commands and executes them. Permits a
- * C-language source file to be compiled. Will detect any errors, and
- * launch NextError.ced if any compiler errors are detected.
- * Optimized for use with WShell.
- *
- * Version 1.30: May 7, 1989 Release 1.2: August 29, 1989
- *
- ************************************************************************/
-
-
- /* Allow CygnusEd to pass status variables */
- options results
-
- /* Tell ARexx to talk to CygnusEd */
- address 'rexx_ced'
-
- cr = '0A'X
-
- /* Get path of current file path, and append a slash if needed: */
- status 20
- path = result
- if length(path) > 0 & right(path,1) ~= ':' then path = path || '/'
-
- /* Get name of current file: */
- status 21
- sourcefile = result
-
- say cr || 'Scanning' sourcefile
- /* ErrorOffset will be the byte offset into AztecC.err of the next error */
- call setclip 'ErrorOffset','0'
-
- if exists('AztecC.err') then address command "delete AztecC.err"
-
- /* Get number of changes to current file, to see if file has been modified
- since the last save: */
- status 18
- nchanges = result
- plural = ' has'
- if nchanges ~= 1 then plural = 's have'
- if result > 0 then
- DO
- okay2 nchanges 'change' || plural 'been made to' sourcefile || cr'Save before compiling?'
- if result = 1 then Save
- END
-
- /* Chop .extension off filename: */
- if lastpos('.',sourcefile) = 0 then
- filename = sourcefile
- else
- filename = left(sourcefile,lastpos('.',sourcefile)-1);
-
- /* Open the source file, and look for "Auto:" commands in first 30 lines: */
- if open('source',path || sourcefile) then
- DO
- address command 'WBTF'
-
- maxcheck = 30
- done = 0
- inauto = 0
- DO until (done ~= 0)
- line = readln('source')
- /* Look for an "Auto:" command to perform: */
- auto = index(line,'Auto:')
- if auto > 0 then
- DO
- inauto = 1
- cmd = substr(line,auto+5)
-
- find = index(cmd,'<path>')
- DO while find > 0
- cmd = delstr(cmd,find,6)
- cmd = insert(path,cmd,find-1)
- find = index(cmd,'<path>')
- END
- find = index(cmd,'<file>')
- DO while find > 0
- cmd = delstr(cmd,find,6)
- cmd = insert(filename,cmd,find-1)
- find = index(cmd,'<file>')
- END
-
- /* Perform the "Auto:" command: */
- options failat 21
- address command cmd
- options failat 10
-
- /* If you use WShell, the variable RC will be non-zero if the
- command failed. Stop here if RC was non-zero. */
- if (RC ~= 0) then
- done = 2
- else if exists('AztecC.err') then
- done = 1
- END
- else
- DO
- /* No "Auto:" command found on this line. If some "Auto:"
- commands were already found, then we're done */
- if inauto then done = 1
- else
- DO
- maxcheck = maxcheck - 1
- if maxcheck = 0 then done = 1
- END
- END
- END
- END
-
- if inauto = 0 then
- DO
- say 'No "Auto:" commands found.' || cr
- cedtofront
- okay1 'No "Auto:" commands found.'
- exit
- END
- else
- DO
- if exists('AztecC.err') then
- DO
- say 'Compilation failed.' || cr
- cedtofront
- /* Get the current file's name to see if we are in this file's view? */
- status 21
- if sourcefile ~= result then
- DO
- okay2 'Compilation failed.'cr'Show errors?'
- if result = 1 then
- call NextError.ced
- END
- else
- call NextError.ced
- exit
- END
- else
- DO
- if (done = 2) then
- /* Only WShell users will get a case of done = 2 (one of the
- "Auto:" commands failed. The reason is that only WShell
- allows ARexx to receive a return code based on the command
- that was sent to the shell. */
- DO
- say 'Command "' || word(cmd,1) || '" failed.' || cr
- cedtofront
- okay2 'Command "' || word(cmd,1) || '" failed.'cr'Return to Workbench screen?'
- if result = 1 then
- address command 'WBTF'
- exit
- END
- else
- DO
- say 'Done.' || cr
- cedtofront
- /* Under WShell, we can guarantee that all the "Auto:"
- commands worked, so it's fair to report that the
- compilation was successful. */
- okay2 'Compilation successful.' || cr'Return to Workbench screen?'
- if result = 1 then
- address command 'WBTF'
- END
- END
- END
- exit
-