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.ced < prev    next >
Text File  |  1989-12-29  |  4KB  |  155 lines

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