home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / PascalPCQ / PCQ.ced < prev    next >
Text File  |  1991-04-22  |  6KB  |  194 lines

  1. /*
  2.  
  3.                Compile a CED file using PCQ Pascal
  4.  
  5. This is an ARexx script that uses PCQ Pascal version 1.2 to run
  6. through the entire compile/assemble/link/execute cycle for the
  7. file in the current view of CygnusEd Professional.  You can
  8. install this script as one of the DOS/Arexx commands, then be able
  9. to run the compiler et al with one key.  The actual steps this
  10. script takes are:
  11.  
  12.         1. Save the program if any changes have been made.
  13.         2. Run the compiler on it
  14.         3. Run the peephole optimizer if the user wants to.
  15.         4. Run the assembler on it
  16.         5. If there were no problems, and the user wants to,
  17.            link the program.
  18.               5a. If there were no problems in the link step, and
  19.                   again if the user wants to, run the program.
  20.  
  21. All intermediate files are created in T:.  The output, which will
  22. either be an executable program, an object file, or nothing, will
  23. be in the same directory as the source file.
  24.  
  25. You will need to supply the correct pathnames for Pascal, Peep,
  26. A68k, Blink and PCQ.lib in the body of this script.  If the
  27. commands are on the command path, they won't have to be changed,
  28. but you still should supply a complete pathname for PCQ.lib so
  29. you can compile programs residing in any directory.
  30.  
  31. If a program compiles correctly, it _should_ run through the other
  32. programs without a problem.  Based on that assumption, I don't
  33. spend much effort checking for errors in the optimize, assemble or
  34. link steps.
  35.  
  36. I heartily recommend that if you plan to use this script, you
  37. modify it to meet your needs exactly.  It will be time well spent.
  38.  
  39. */
  40.  
  41.  
  42. options results
  43.  
  44. /* Since I run this from inside CED, this isn't really necessary */
  45.  
  46. address 'rexx_ced'
  47.  
  48. /* Get the current file name, without the path information */
  49.  
  50. status 21
  51. filename = result
  52.  
  53. if (filename = "") | (pos('.p',filename) = 0) then do
  54.     'okay1 Expecting a ".p" file'
  55.     exit
  56. end
  57.  
  58. /* Get # changes to current view, save if > 0 */
  59.  
  60. status 18
  61. if result > 0 then 'save'
  62.  
  63. filename = delstr(filename,lastpos('.p',filename),2)
  64.  
  65. /* We create a little batch file to actually run the compiler  */
  66.  
  67. if ~open(batchfile, 't:CompilePCQ.batch', 'W') then do
  68.     'okay1 Could not create command file'
  69.     exit
  70. end
  71.  
  72. /* In case the program includes any files using relative file  */
  73. /* specifications, we need to set the current directory to the */
  74. /* same as the source code.                                    */
  75.  
  76. status 20
  77. writeln(batchfile, 'cd' result)
  78.  
  79. /* Get filename with complete path */
  80.  
  81. status 19
  82. inputfile = result
  83.  
  84. outputfile = 't:' || filename || '.asm'
  85.  
  86. /* Make sure to use the appropriate path name for the compiler */
  87.  
  88. writeln(batchfile, 'Pascal >T:CompilePCQ.out -q' inputfile outputfile)
  89. close(batchfile)
  90.  
  91.  
  92. /* Run the script, then lose it */
  93.  
  94. address command 'execute t:CompilePCQ.batch'
  95. address command 'delete >nil: t:CompilePCQ.batch'
  96.  
  97. /* Report any errors from PCQ */
  98.  
  99. if open(logfile, 't:CompilePCQ.out', 'R') then do
  100.     do until eof(logfile)
  101.         ErrorString = readln(logfile)
  102.  
  103.         /* This first test is just a reminder, in case you want to */
  104.         /* process all errors.  "Abort" would never come first.    */
  105.  
  106.         if ErrorString = "Compilation Aborted" then do
  107.             address command 'delete >nil:' outputfile
  108.             'okay1 Compilation Aborted'
  109.             exit
  110.         end
  111.  
  112.         if ErrorString ~= "" then do
  113.             parse var errorstring '"' errorfilename '" At' LineNo,
  114.                                        ',' ColumnNo ':' ErrorText
  115.             if errorfilename = inputfile then do
  116.                 'jumpto' LineNo 1
  117.                 do for ColumnNo /* this properly handles tabs */
  118.                     'right'
  119.                 end
  120.                 'okay1 Error:' || ErrorText
  121.             end; else 'okay1 Error in' errorfilename || '0A'X || ErrorText
  122.             close(logfile)
  123.             address command 'delete >nil: t:CompilePCQ.out'
  124.             exit
  125.         end
  126.     end
  127.     close(logfile)
  128.     address command 'delete >nil: t:CompilePCQ.out'
  129. end; else exit
  130.  
  131. inputfile = outputfile
  132.  
  133. 'okay2 Compiled correctly' || '0A'X || '    Run Peep?'
  134. if result then do
  135.     outputfile = 't:' || filename || '.s'
  136.  
  137.     /* Be sure to use the appropriate path for Peep */
  138.  
  139.     address command 'Peep >nil:' inputfile outputfile
  140.  
  141.     address command 'delete >nil:' inputfile
  142.  
  143.     inputfile = outputfile
  144. end
  145.  
  146. outputfile = 't:' || filename || '.o'
  147.  
  148. /* Be sure to use the appropriate path for A68k */
  149.  
  150. address command 'A68k -q' inputfile outputfile
  151.  
  152. address command 'delete >nil:' inputfile
  153.  
  154. inputfile = outputfile
  155.  
  156. /* Get the file name, complete with path info */
  157.  
  158. status 19
  159. outputfile = delstr(result,lastpos('.p',result),2)
  160.  
  161. if exists(inputfile) then do
  162.     'okay2 Assembled Correctly' || '0A'X || '     Run Blink?'
  163.     if result then do
  164.  
  165.         /* Be sure to supply the correct paths */
  166.         /* for Blink and PCQ.lib               */
  167.  
  168.         address command 'Blink >T:CompilePCQ.out',
  169.                  inputfile 'to' outputfile 'library PCQ.lib'
  170.         if open(logfile, 'T:CompilePCQ.out', 'R') then do
  171.             do until eof(logfile)
  172.                 ErrorString = readln(logfile)
  173.                 if upper(left(ErrorString,5)) = "ERROR" then do
  174.                     'okay1 Error linking' outputfile || '0A'X ||,
  175.                            ErrorString
  176.                     address command 'delete >nil: t:CompilePCQ.out'
  177.                     exit
  178.                 end
  179.             end
  180.             address command 'delete >nil: t:CompilePCQ.out'
  181.             'okay2 Linked without errors.  Execute?'
  182.             if result then do
  183.                 'getstring "' || outputfile '" "Enter Command String"'
  184.                 if result ~= "" then do
  185.                     address command result
  186.                 end
  187.             end
  188.         end; else 'okay1 Error executing linker'
  189.     end; else address command 'copy' inputfile outputfile || '.o'
  190.  
  191.     address command 'delete >nil:' inputfile
  192. end; else 'okay1 Error assembling'
  193.  
  194.