home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / edit / macro / amigae / ec30b_compile.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-10  |  14KB  |  407 lines

  1. /* $VER: 2.0, ©1994 BURGHARD Eric.                            */
  2.  
  3. --8<--------- Cut this Speed up RexxMast Processing a little ---------------
  4.  
  5.    Compile current file using EC3.0 ,EPP1.4d and MAC2E4.0 if it must
  6.    Errors, Warnings, Auto-Revision, Compile to disk,
  7.    Run arguments, EC arguments are handled.
  8.    File notification mechanism to avoid useless compilation
  9.    EC,EPP,Mac2E must be located on EDEVICE:
  10.    EC,EPP,Mac2E are put in RAM: on first use.
  11.    A directory E/ is make in T:
  12.  
  13.  VARIABLES:
  14.  ----------
  15.    Environnement vars set: (name stand for "your E Source name")
  16.               ENV:ECOpt    : ECompiler args (see EC docs)
  17.               T:E/name.opt : Executable args
  18.               T:E/name.mcf : Macros Files
  19.               T:E/name.mcp : Macros Path
  20.  
  21.    GED boolean vars set:
  22.               USER1  : Compile to disk
  23.               USER2  : Replace Macros (Mac2E)
  24.               USER3  : Auto-Revision
  25.               USER4  : Warnings
  26.  
  27.  NOTEZ BIEN:  Errors handling depends on EPP or EC errors output,
  28.  -----------   So you may have to modify this script if you use
  29.                other version than 2.1b|3.0 for EC, 1.4d for EPP,
  30.               and 4.0 for Mac2E.
  31.  
  32.  BUGS:        Perhaps Not all EPP1.4d are handled.
  33.  -----        Folowing EC errors messages are not handled
  34.                 - 'not enought memory while (re-)allocating'
  35.                 - 'reference(s) out of 32k: switch to LARGE model'
  36.                 - 'reference(s) out of 256k'
  37.                 because EC2.1b don't return an error code. So you
  38.                 may have an error from this script like, 'can not
  39.                 rename ''filename1' as 'filename2'': object not find
  40.                 cause EC didn't generate executable file and didn't
  41.                 released an error code. So View T:Eerror to know the
  42.                 reason of the failure.
  43.               As EC2.1b didn't release DOS warning code, i must
  44.                 parse t:Eerror to find them: Currently handled warning
  45.                 messages are the ones beginning with 'UNREFERENCED'
  46.                 or 'WARNING' in T:Eerror. This could change for another
  47.                 version of EC then 2.1b.
  48.               Autorevision processing is space sensitive; check that
  49.                 parenthesis are present in string requester of GUI config
  50.                 panel; i could normally do it in this script but i can not
  51.                 succed. Autorevision force files to be always compiled
  52.                 because source are always 'modified'.
  53.  
  54. ---------------------------------------------------------------------------
  55. */
  56.  
  57. options results                             /* enable return codes     */
  58.                                             /* not started by GoldEd ? */
  59. if (LEFT(ADDRESS(), 6) ~= "GOLDED") then address 'GOLDED.1'
  60. 'LOCK CURRENT QUIET'                        /* lock GUI, gain access   */
  61. if rc then exit
  62. options failat 6                            /* ignore warnings         */
  63. signal on syntax                            /* ensure clean exit       */
  64.  
  65. 'QUERY FILE PATH USER1 ANYTEXT'
  66. parse var result name ' ' path ' ' optcdisk ' ' anytext
  67.  
  68. if (anytext=="TRUE") then do
  69.   if (upper(right(name,2)))='.E' then do
  70.     if right(path,1)~=":" then path=''path'/'
  71.     if ~exists("T:E") then address command 'Makedir T:E'
  72.     oldname=name
  73.     name=left(name,length(name)-2)
  74.     if optcdisk="TRUE" then do
  75.       name=''path''name''
  76.     end
  77.     else name='T:E/'name''
  78.     nameo=name
  79.     'QUERY MODIFY ABAK LINE COLUMN FIND'
  80.     parse var result modify ' ' backup ' ' olne ' ' col ' ' fstr
  81.     exist=exists(name)
  82.     if (optcdisk="TRUE") then do
  83.       'MISC AUTOBAK="TRUE"'
  84.       if modify="TRUE" then 'SAVE ALL NAME 'nameo'.e'
  85.     end
  86.     else do
  87.       'MISC AUTOBAK="FALSE"'
  88.       if (~exist | modify="TRUE") then 'SAVE ALL NAME 'nameo'.e'
  89.     end
  90.     'MISC AUTOBAK="'backup'"'
  91.     if exist then do
  92.       'NOTIFY FILE 'path''oldname' CHECK'
  93.       notify=result
  94.       if rc=5 then do
  95.         'NOTIFY FILE 'path''oldname' START'
  96.         notify=1
  97.       end
  98.     end
  99.     else notify=1
  100.     if (~exist | (exist & (modify="TRUE" | (modify="FALSE" & notify~=0)))) then do
  101.       call Compile
  102.       if ~exist then 'NOTIFY FILE 'path''oldname' START'
  103.     end
  104.     else do
  105.       'REQUEST BODY="File have already been compiled !" BUTTON="ReCompile|Run|Cancel"'
  106.       if result=1 then do
  107.         call Compile
  108.       end
  109.       else if result=2 then do
  110.         cmd=''
  111.         call Execute
  112.       end
  113.     end
  114.     'FIND STRING="'fstr'" FIRST QUIET'
  115.     'GOTO LINE='olne' COLUMN='col''
  116.   end
  117.   else 'REQUEST STATUS=" E Sources names must end with '.e'"'
  118. end
  119. else 'REQUEST STATUS=" Text buffer is empty ?!"'
  120. 'UNLOCK'
  121. exit
  122.  
  123. Compile:
  124.     /* ------------------------ Macros processing ------------------------ */
  125.     load = 0                                /* Bool for right source error pos */
  126.     if right(oldname,6)~="_mac.e" then do     /* Don't compile Mac2E outputs */
  127.       'QUERY USER2'
  128.       if result=="TRUE" then do
  129.         load=1                               /* Bool for right source error pos */
  130.         if ~exists("ram:MAC2E") then address command 'copy EDEVICE:MAC2E RAM:'
  131.         if ~exists("T:E") then address command 'Makedir T:E'
  132.         optname=left(oldname,length(oldname)-2)
  133.         macfile='T:E/'optname'.mcf'
  134.         macpath='T:E/'optname'.mcp'
  135.         if ~exists(macpath) then do
  136.           ok=open(fhandle,macpath,"write")
  137.           ok=writeln(fhandle,"EDEVICE:PreAnalyzedMacroFiles")
  138.           ok=close(fhandle)
  139.         end
  140.         if exists(macfile) then do
  141.           ok=open(fhandle,macfile,"read")
  142.           macname=readln(fhandle)
  143.           ok=close(fhandle)
  144.         end
  145.         else do
  146.           address command 'EDEVICE:RtRequest 'macfile' 'macpath' TITLE="Select macros definitions files" EXIST'
  147.           if rc~=0 then do
  148.             'NAME 'path''oldname''
  149.             'REQUEST STATUS=" You must specifie a macros definitions file !"'
  150.             'UNLOCK'
  151.             exit
  152.           end
  153.           else do
  154.             ok=open(fhandle,macfile,"read")
  155.             macname=readln(fhandle)
  156.             ok=close(fhandle)
  157.           end
  158.         end
  159.         errhdlr=1
  160.         'REQUEST STATUS=" Begining macro remplacement ..."'
  161.         signal on error
  162.         address command 'RAM:Mac2E >T:Eerror 'name'.e 'nameo'_mac.e 'macname''
  163.         signal off error
  164.         'REQUEST STATUS=""'
  165.         name=''nameo'_mac'                    /* Source Name for Next tools */
  166.       end
  167.     end
  168.  
  169.     /* --------------------- Compilation processing ---------------------- */
  170.     if ~exists("ram:EC30b") then address command 'copy EDEVICE:EC30b RAM:'
  171.     if exists("ENV:ECOpt") then do
  172.       ok=open(readhandle,"ENV:ECOpt","read")
  173.       optec=readln(readhandle)
  174.       ok=close(readhandle)
  175.     end
  176.     else optec=""
  177.     errhdlr = 0                                /* Bool for Error processing */
  178.     'REQUEST STATUS=" Compiling in process ..."'
  179.     signal on error
  180.     address command 'RAM:EC30b >T:Eerror 'optec' 'name''
  181.     signal off error
  182.     if optmodule then ext='.m'
  183.     else ext=''
  184.     if ''name''ext''~=''nameo''ext'' then do                     /* Name of final executable */
  185.       if exists(''nameo''ext'') then address command 'Delete 'nameo''ext' QUIET'
  186.       address command 'Rename 'name''ext' 'nameo''ext' QUIET'
  187.     end
  188.     'REQUEST STATUS=""'
  189.  
  190.     /* ----------------------- Version processing ------------------------ */
  191.     if (modify==TRUE|notify~=0) then do
  192.       'QUERY USER3'
  193.       if (result==TRUE) then do
  194.         'PING SLOT=0'                               /* save cursor position */
  195.         'MARK HIDE'                                    /* no blocks, please */
  196.         'QUERY FIND VAR SPAT'                          /* remember settings */
  197.         'QUERY USECASE VAR USECASE'
  198.         'FIND STRING="''$VER:" FIRST CASE=TRUE QUIET'  /* search version id */
  199.         if (rc==0) then do                                      /* found ?? */
  200.           'QUERY BUFFER'            /* what is the line we are over now ?  */
  201.           parse var result '$VER: ' vername ' ' version '.' revision ' ('
  202.           revision=revision+1
  203.           if (revision<10) then revision='00'revision''
  204.           else if (revision<100) then revision='0'revision''
  205.           'NEXT'
  206.           'NEXT'
  207.           'DELETE WORD'                   /* delete old revision string */
  208.           'DEL'
  209.           'DELETE WORD'
  210.           'DEL'
  211.           'DELETE WORD'
  212.           'DEL'
  213.           'DELETE WORD'
  214.           'DEL'
  215.           'TEXT T="'version'.'revision' ('date()') "'                  /* insert new into the text */
  216.         end
  217.         else do
  218.           'FIND STRING=main() CASE=TRUE FIRST QUIET'
  219.           if (rc==0) then do
  220.             'FOLD OPEN=TRUE'
  221.             'FIND STRING=ENDPROC CASE=TRUE NEXT'
  222.             'QUERY ABSLINE VAR LNE'
  223.             'DOWN'
  224.             'QUERY ABSLINE'
  225.             if (result==lne) then do
  226.               'GOTO EOL'
  227.               'CR'
  228.             end
  229.             else do
  230.               'FIRST'
  231.               'QUERY WORD'
  232.               if result='/*FEND*/' then do
  233.                 'QUERY ABSLINE VAR LNE'
  234.                 'DOWN'
  235.                 'QUERY ABSLINE'
  236.                 if (result==lne) then do
  237.                   'GOTO EOL'
  238.                   'CR'
  239.                 end
  240.               end
  241.             end
  242.           end
  243.           else do
  244.             'GOTO BOTTOM'
  245.             'GOTO EOL'
  246.             'CR'
  247.           end
  248.           'QUERY FILE VAR FILE'
  249.           file=left(file,length(file)-2)
  250.           'TEXT T="CHAR ''$VER: 'file' 1.000 ('date()') © BURGHARD Eric | WANABOSO/AGOA''" CR'
  251.           'FOLD ALL OPEN=FALSE'
  252.         end
  253.         'PONG SLOT=0'
  254.         'FIND STRING="'spat'" CASE='usecase''
  255.       end
  256.     end
  257.  
  258.     /* ------------------- Warning Message processing -------------------- */
  259.     'QUERY USER4'
  260.     if result='TRUE' then do
  261.       ok = open(filehandler,'T:Eerror','Read')
  262.       if ok = 0 then 'REQUEST STATUS=" Could not read E Compiler error output"'
  263.       else do
  264.         reqmsg=''
  265.         do until eof(filehandler)
  266.           line  = readln(filehandler)
  267.           pos=index(line,'UNREFERENCED')
  268.           if pos~=0 then do
  269.             reqmsg=substr(line,pos,length(line)-pos+1)
  270.             do while ~eof(filehandler)
  271.               line=readln(filehandler)
  272.               pos=index(line,'WARNING')
  273.               if pos~=0 then reqmsg=''reqmsg'|'substr(line,pos,length(line)-pos+1)''
  274.             end
  275.           end
  276.           else do
  277.             pos=index(line,'WARNING')
  278.             if pos~=0 then reqmsg=substr(line,pos,length(line)-pos+1)
  279.           end
  280.         end
  281.         if reqmsg~='' then do
  282.            reqmsg=compress(reqmsg,'"')
  283.           'REQUEST TITLE="ECompiler warning message..." BODY="'reqmsg'"'
  284.         end
  285.         ok = close(filehandler)
  286.       end
  287.     end
  288.     cmd='REQUEST BODY="Compilation Done ! Run program ?" BUTTON="_run|_cancel"'
  289.  
  290. Execute:
  291.     /* ---------------------------- Execute ------------------------------ */
  292.     if optcdisk=='FALSE' then 'NAME NEW 'path''oldname''  /* restore old file name */
  293.     'FIND STRING="OPT MODULE" FIRST QUIET'
  294.     if (rc~=0) then do
  295.       result=1
  296.       if cmd~='' then cmd
  297.       if (result == 1) then do
  298.         'REQUEST STATUS=" 'nameo' is running"'
  299.         if Exists('T:E/'oldname'.opt') then do
  300.           optname=left(oldname,length(oldname)-2)
  301.           ok = open(filehandle,'T:E/'optname'.opt',"read")
  302.           runopt=readln(filehandle)
  303.           ok = close(filehandle)
  304.         end
  305.         else runopt=""
  306.         options failat 100
  307.         address command ''nameo' 'runopt''
  308.         options failat 10
  309.       end
  310.       'REQUEST STATUS=""'
  311.     end
  312.     else 'REQUEST STATUS=" Module correctly generated"'
  313.     return
  314.  
  315.    /* ---------------------- Errors processing ------------------------ */
  316. error:
  317.   signal off error                              /* Avoid looping problems */
  318.   'REQUEST STATUS=""'
  319.   if optcdisk=='FALSE' then 'NAME NEW 'path''oldname''  /* restore old file name */
  320.   ok = open(filehandler,'T:Eerror','Read')
  321. select
  322.  
  323.   when errhdlr = 0 then do                          /* EC Error Handler      */
  324.     if ok = 0 then 'REQUEST STATUS=" Could not read E Compiler error output"'
  325.     else do
  326.       linestring=''
  327.       withstring=''
  328.       errorstring=''
  329.       errortext=''
  330.       pointext=''
  331.       line=readln(filehandler)
  332.       do while ~eof(filehandler)
  333.         line = readln(filehandler)
  334.         select
  335.         when index(line,'ERROR:')~=0 then do
  336.          parse var line 'ERROR: ' errorstring
  337.           errorstring=strip(errorstring)
  338.           parse var errorstring left '"' right
  339.         end
  340.         when find(line,'WITH:')~=0 then do
  341.           parse var line 'WITH: ' withstring
  342.           withstring=strip(withstring)
  343.           parse var withstring left '"' right
  344.         end
  345.         when find(line,'LINE ')~=0 then do
  346.           parse var line 'LINE ' errorline ': ' linestring '/*'
  347.           linestring=strip(linestring,L)
  348.           linestring=left(linestring,64)
  349.           linestring=strip(linestring)
  350.           parse var linestring left '"' right
  351.         end
  352.         otherwise nop
  353.         end
  354.       end
  355.       if linestring~='' then errortext=''linestring''
  356.        errpos=index(errortext,'')
  357.        if errpos~=0 then do
  358.          errortext=delstr(errortext,errpos,8)
  359.          errortext=delstr(errortext,errpos+1,4)
  360.          pointext=copies(' ',errpos)
  361.          pointext=insert('-^-',pointext,errpos-2,3)
  362.        end
  363.       if pointext~='' then errortext=''errortext'|'pointext''
  364.       if errorstring~='' then errortext=''errorstring'...|'errortext''
  365.       if load=1 then 'OPEN NEW NAME="'name'.e"'
  366.       'FOLD OPEN=TRUE ALL'
  367.       'GOTO LINE='errorline''
  368.       errortext=compress(errortext,'"')
  369.       'REQUEST TITLE="ECompiler 3.0b error" BODY="'errortext'"'
  370.     end
  371.   end
  372.  
  373.   when errhdlr=1 then do                     /* MAC2E Error Handler */
  374.     if ok = 0 then 'REQUEST STATUS=" Could not read Mac2E error output"'
  375.     else do
  376.       do 3                                   /* Jump Mac2E HeadLines     */
  377.         line = readln(filehandler)
  378.       end
  379.       do while ~eof(filehandler)
  380.         line = readln(filehandler)
  381.         if index(line,'...')==0 then do
  382.           parse var line line '!'
  383.           errortext=compress(errortext,'"')
  384.           'REQUEST TITLE="Mac2E 4.0 error" BODY="'line'"'
  385.           ok = close(filehandler)
  386.           'UNLOCK'
  387.           exit
  388.         end
  389.       end
  390.     end
  391.   end
  392.  
  393.   otherwise nop
  394.  
  395. end
  396.  
  397. ok = close(filehandler)
  398. 'UNLOCK'
  399. exit
  400.  
  401. syntax:
  402. say "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
  403. 'UNLOCK'
  404. exit
  405.  
  406.  
  407.