home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff297.lzh / DevKit / Rexx / Compile.WShell.ced < prev    next >
Text File  |  1989-12-29  |  4KB  |  167 lines

  1. /************************************************************************
  2.  *
  3.  * Compile.WShell.ced                Copyright (c) 1989, Peter Cherna
  4.  *
  5.  * ARexx program for CygnusEd Professional.  Scans the current file
  6.  * for embedded "Auto:" commands and executes them.  Permits a
  7.  * C-language source file to be compiled.  Will detect any errors, and
  8.  * launch NextError.ced if any compiler errors are detected.
  9.  * Optimized for use with WShell.
  10.  *
  11.  * Version 1.30:  May 7, 1989        Release 1.2:  August 29, 1989
  12.  *
  13.  ************************************************************************/
  14.  
  15.  
  16. /* Allow CygnusEd to pass status variables */
  17. options results
  18.  
  19. /* Tell ARexx to talk to CygnusEd */
  20. address 'rexx_ced'
  21.  
  22. cr = '0A'X
  23.  
  24. /*    Get path of current file path, and append a slash if needed: */
  25. status 20
  26. path = result
  27. if length(path) > 0 & right(path,1) ~= ':' then path = path || '/'
  28.  
  29. /*    Get name of current file: */
  30. status 21
  31. sourcefile = result
  32.  
  33. say cr || 'Scanning' sourcefile
  34. /*    ErrorOffset will be the byte offset into AztecC.err of the next error */
  35. call setclip 'ErrorOffset','0'
  36.  
  37. if exists('AztecC.err') then address command "delete AztecC.err"
  38.  
  39. /*    Get number of changes to current file, to see if file has been modified
  40.     since the last save: */
  41. status 18
  42. nchanges = result
  43. plural = ' has'
  44. if nchanges ~= 1 then plural = 's have'
  45. if result > 0 then
  46. DO
  47.     okay2 nchanges 'change' || plural 'been made to' sourcefile || cr'Save before compiling?'
  48.     if result = 1 then Save
  49. END
  50.  
  51. /*    Chop .extension off filename: */
  52. if lastpos('.',sourcefile) = 0 then
  53.     filename = sourcefile
  54. else
  55.     filename = left(sourcefile,lastpos('.',sourcefile)-1);
  56.  
  57. /*    Open the source file, and look for "Auto:" commands in first 30 lines: */
  58. if open('source',path || sourcefile) then
  59. DO
  60.     address command 'WBTF'
  61.  
  62.     maxcheck = 30
  63.     done = 0
  64.     inauto = 0
  65.     DO until (done ~= 0)
  66.         line = readln('source')
  67.         /*    Look for an "Auto:" command to perform: */
  68.         auto = index(line,'Auto:')
  69.         if auto > 0 then
  70.         DO
  71.             inauto = 1
  72.             cmd = substr(line,auto+5)
  73.  
  74.             find = index(cmd,'<path>')
  75.             DO while find > 0
  76.                 cmd = delstr(cmd,find,6)
  77.                 cmd = insert(path,cmd,find-1)
  78.                 find = index(cmd,'<path>')
  79.             END
  80.             find = index(cmd,'<file>')
  81.             DO while find > 0
  82.                 cmd = delstr(cmd,find,6)
  83.                 cmd = insert(filename,cmd,find-1)
  84.                 find = index(cmd,'<file>')
  85.             END
  86.  
  87.             /*    Perform the "Auto:" command: */
  88.             options failat 21
  89.             address command cmd
  90.             options failat 10
  91.  
  92.             /*    If you use WShell, the variable RC will be non-zero if the
  93.                 command failed.  Stop here if RC was non-zero. */
  94.             if (RC ~= 0) then
  95.                 done = 2
  96.             else if exists('AztecC.err') then
  97.                 done = 1
  98.         END
  99.         else
  100.         DO
  101.             /*    No "Auto:" command found on this line.  If some "Auto:"
  102.                 commands were already found, then we're done */
  103.             if inauto then done = 1
  104.             else
  105.             DO
  106.                 maxcheck = maxcheck - 1
  107.                 if maxcheck = 0 then done = 1
  108.             END
  109.         END
  110.     END
  111. END
  112.  
  113. if inauto = 0 then
  114. DO
  115.     say 'No "Auto:" commands found.' || cr
  116.     cedtofront
  117.     okay1 'No "Auto:" commands found.'
  118.     exit
  119. END
  120. else
  121. DO
  122.     if exists('AztecC.err') then
  123.     DO
  124.         say 'Compilation failed.' || cr
  125.         cedtofront
  126.         /*    Get the current file's name to see if we are in this file's view? */
  127.         status 21
  128.         if sourcefile ~= result then
  129.         DO
  130.             okay2 'Compilation failed.'cr'Show errors?'
  131.             if result = 1 then
  132.                 call NextError.ced
  133.         END
  134.         else
  135.             call NextError.ced
  136.         exit
  137.     END
  138.     else
  139.     DO
  140.         if (done = 2) then
  141.         /*    Only WShell users will get a case of done = 2 (one of the
  142.             "Auto:" commands failed.  The reason is that only WShell
  143.             allows ARexx to receive a return code based on the command
  144.             that was sent to the shell. */
  145.         DO
  146.             say 'Command "' || word(cmd,1) || '" failed.' || cr
  147.             cedtofront
  148.             okay2 'Command "' || word(cmd,1) || '" failed.'cr'Return to Workbench screen?'
  149.             if result = 1 then
  150.                 address command 'WBTF'
  151.             exit
  152.         END
  153.         else
  154.         DO
  155.             say 'Done.' || cr
  156.             cedtofront
  157.             /*    Under WShell, we can guarantee that all the "Auto:"
  158.                 commands worked, so it's fair to report that the
  159.                 compilation was successful.  */
  160.             okay2 'Compilation successful.' || cr'Return to Workbench screen?'
  161.             if result = 1 then
  162.                 address command 'WBTF'
  163.         END
  164.     END
  165. END
  166. exit
  167.