home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / text / general / texify / texify.ced < prev    next >
Text File  |  1991-02-15  |  16KB  |  584 lines

  1. /********************************************************************************/
  2. /* ARexx program         TeXify    V 1.10    (Sep 90)            */
  3. /*                                        */
  4. /*                Just put this ARexx program on a CygnusEd Fkey    */
  5. /*               and edit your TeX source. When finish with editing,    */
  6. /*               press the function key and you get your source    */
  7. /* Copyright 1990          showing up in TeXs preview. If not, you get your    */
  8. /* by Wolf-Juergen Faust   cursor positioned at the error position with an    */
  9. /* Am Dorfgarten 10        error message. For a new TeXify version call    FIDO    */
  10. /* W-6000 Frankfurt 50       +(49) 6173 2544 (HST DS) or contact me...        */
  11. /* Germany                                    */
  12. /* FIDO: 2:243/43.5 (Wolf Faust)                        */
  13. /* UUCP: cbmvax.commodore.com!cbmehq!cbmger!venus!wfaust            */
  14. /* Tel: +(49) 69 5486556                            */
  15. /*                                        */
  16. /*    YOU MUST ADOPT THE FIRST COMMANDS TO YOUR ENVIRONMENT !!!!!!!!!!!!    */
  17. /*    ==================================================================    */
  18. /*      (See the readme and ARexx files you MUST get with this file!)        */
  19. /* Versions needed:                                */
  20. /* ARexx >= V 1.10  (tested: 1.10, 1.12, 1.14)                    */
  21. /* CEDPro>= V 2.00  (tested: 2.10, 2.11, 2.12)                    */
  22. /* TeX   >= V 2.09o (tested: 2.09o, 2.09p)                    */
  23. /* After adopting the first two commands: KS 1.2, 1.3, 2.0 (all versions tested)*/
  24. /********************************************************************************/
  25.  
  26.  
  27.  
  28. /* Now, here's the command for starting TeX in backround. I offer you        */
  29. /* two examples. One for WShell and one for the normal Commodore shell.        */
  30. /* Shutting down TeX is simple in WShell/Conman: klick on the closegadget.    */
  31. /* For the normal TeX shell you have to type the usual CTRL-F.            */
  32.  
  33. /* Commodore Shell version: (change all paths according to your system !)    */
  34. /* For Kickstart 2.0 users: delete all paths before resident shell commands!!!  */
  35. cmd1 =    'echo >t:tex1 "stack 10000"'
  36. cmd2 =    'echo >t:tex2 "tex:c/tex -R"'
  37. cmd3 =    'echo >t:tex3 "endcli"'
  38. cmd4 =    'join t:tex1 t:tex2 t:tex3 to t:tex'
  39. cmd5 =    'NewShell CON:0/11/640/180/Press_CTRL-F_to_close FROM t:tex'
  40.  
  41.                             /***  OR  ***/
  42.  
  43. /* WShell version:    (change only cmd5 ! cmd1-4 as above !)            */
  44. /* cmd5 =    'NewWsh FROM t:tex'                        */
  45.  
  46.  
  47.  
  48. /* Preview startup command: (change path according to your system !)        */
  49. preview = "run >nil: <nil: tex:c/preview"
  50.  
  51. /* Path for Manx's(!) Set command: (KS2.0: add path for Manxs SET!!!!!!        */
  52. setpath = "tex:c/Set"
  53.  
  54. /* CEDPro startup command:  (change path according to your system !)        */
  55. ced = "dh0:c/ced"
  56.  
  57. /* Max. errors before TeXify stops TeX (default should be arround 3)        */
  58. errorcount = 3
  59.  
  60. /* Keyword for the TeX macropackage given in the first line (default: "macropackage")            */
  61. package = "macropackage"
  62.  
  63. /* Max. time needed between loading TeX, Preview... and showing up their Ports(default: 10)    */
  64. timeout = 10  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. /***  START        (don't change anything after this...)  ***/
  77. /*** Return ***/
  78. cr = '0A'X
  79.  
  80. /*** program receives answers ***/
  81. options results
  82.  
  83. /*** now lets get to business with CygnusEd ***/
  84. address 'rexx_ced'
  85.  
  86. /*** ask for the file name, sans directory of the current file ***/
  87. status 21
  88. srcfile = result
  89.  
  90. /*** What about the name ??! Valid ??***/
  91. last = lastpos('.',srcfile)
  92. do while ((srcfile = "") | (last=0))
  93.     if srcfile = "" then srcfile = "untitled.tex"
  94.     okay2 "ERROR ! TeXfile needs a name with suffix !"||cr||"Continue ?"
  95.     if result = 0 then exit 5
  96.     getfilename srcfile 'Give name for new TeX sourcefile...'
  97.     if result ~= "RESULT" then do
  98.         last = lastpos('.',result)
  99.         fullsrc = result
  100.         if last ~= 0 then do
  101.             save as result
  102.             status 21
  103.             srcfile = result
  104.             last = lastpos('.',srcfile)
  105.             end
  106.         else
  107.             srcfile = fullsrc
  108.         end
  109.     else
  110.         last = 0
  111.     end
  112.  
  113. /***  path+filename: maybe part of path is missing ! special code needed  ***/
  114. status 19
  115. fullsrc = result
  116. last = lastpos(':',fullsrc)
  117.  
  118. /*** current dir maybe needed for joining with incomplete path ***/
  119. status 75
  120. if last = 0 then fullsrc = result||fullsrc
  121. last = lastpos('/',fullsrc)
  122. if last~=0 then do
  123.     path = left(fullsrc,last)
  124.     texpath = left(fullsrc,last-1)
  125.     end
  126. else do
  127.     last = lastpos(':',fullsrc)
  128.     path = left(fullsrc,last)
  129.     texpath = path
  130.     end
  131.  
  132. /*** change suffix of source to .log later...***/
  133. srcnam = left(fullsrc,lastpos('.',fullsrc)-1)
  134.  
  135. /*** get suffix of current textfile ***/
  136. sfx = right(srcfile,length(srcfile)-lastpos('.',srcfile))
  137.  
  138. /*** is suffix .tex ?? maybe just a wrong key ?? ***/
  139. if upper(sfx) ~= 'TEX' then do
  140.     okay2 'Suffix ' sfx ' is not a TeX file !' cr||'Start TeX anyway ?'
  141.     if result = 0 then exit 5
  142.     end
  143.  
  144. /*** are there any changes ? do I have to save the text first ??  ***/
  145. status 18
  146. if result ~= 0 then do 
  147.     save
  148.     end
  149.  
  150. /*** look out for macropackage in textfile ***/
  151. status 46
  152. y = result 
  153. status 47
  154. x = result
  155. 'Beg of file'
  156. status 55
  157. macro = left(upper(result),length(result)-1)
  158.  
  159. 'Jumpto' x+1  y+1
  160. if left(macro,1) = "%" then do
  161.     macro = strip(strip(macro,'L','%'),'L')
  162.     if (pos(upper(package),macro) = 1) then do
  163.         macro = subword(strip(strip(substr(macro,length(package)+1),'L'),'L','='),1)
  164.         if pos('%',macro)>0 then do
  165.             macro = left(macro,pos('%',macro)-1)
  166.             end
  167.         macro = strip(macro,'T')
  168.         end
  169.         else macro = ""
  170.     end
  171.     else macro = ""
  172. if macro ~= "" then do
  173.     /*** get contents of manx texformat environment ***/
  174.     address command setpath||" >t:tex1"
  175.     ti = time('S') + 5;
  176.     rc = 0
  177.     do while ((rc=0) & (time('S') < ti))
  178.         rc = open('log','t:tex1')
  179.         if rc = 0 then call delay(50)
  180.         end
  181.     if rc = 0 then do
  182.         okay1 "INTERNAL ERROR ! Can't read temporary file t:tex !"
  183.         exit 5
  184.         end
  185.     oldmacro = "PLAIN" /* default setting */
  186.     do until eof('log')
  187.         logline = upper(readln('log'))
  188.         if left(logline,10) = "TEXFORMAT=" then do
  189.             oldmacro = strip(strip(substr(logline,length("TEXFORMAT=")+1),'L'),'T')
  190.             end
  191.         end
  192.     call close 'log'
  193.     /*** set up new macropackage ***/
  194.     if oldmacro ~= macro then do
  195.         address command setpath||' texformat='||macro
  196.         if (show('P','AmigaTeX')) then do
  197.             address 'AmigaTeX' 'Exit'
  198.             delay(20)
  199.             end
  200.         end
  201.     end
  202.  
  203. /*** It's time for support !  **/
  204. if ~show('l','rexxsupport.library') then
  205.    if ~addlib('rexxsupport.library',0,-30) then
  206.       do
  207.          Okay1 'Error ! No rexxsupport.library !'
  208.          exit 5
  209.          end
  210.  
  211. /*** Hey TeX ! Wakeup !    ***/
  212. /*** If TeX is not running in backround, get it started ! ***/
  213. if ~show('P','AmigaTeX') then do
  214.     address command    cmd1
  215.     if RC > 9 then okay1 'Error ! Check TeXify configuration for starting TeX!'
  216.     address command    cmd2
  217.     if RC > 9 then okay1 'Error ! Check TeXify configuration for starting TeX!'
  218.     address command    cmd3
  219.     if RC > 9 then okay1 'Error ! Check TeXify configuration for starting TeX!'
  220.     address command    cmd4
  221.     if RC > 9 then okay1 'Error ! Check TeXify configuration for starting TeX!'
  222.     address command    cmd5
  223.     if RC > 9 then okay1 'Error ! Check TeXify configuration for starting TeX!'
  224.     /*** now give TeX time to showup ***/
  225.     ti = time('S') + timeout;
  226.     do while ((~show('P','AmigaTeX')) & (time('S') < ti))
  227.         call delay (50)
  228.         end
  229.     if ~show('P','AmigaTeX') then do
  230.         okay2 'Error ! TeX did not get started after 'timeout' seconds !' cr||'You may start TeX now by CLI and continue !'
  231.         if result = 0 then exit 5
  232.         end
  233.     end
  234.  
  235. /*** make path of activ file current path, so TeX can find .aux ... ***/
  236. address 'AmigaTeX' 'CD' texpath
  237.  
  238. /*** check if path command is executed succesfully ***/
  239. /*** if rc = 1 then TeX is busy ***/
  240. if RC = 1 then do
  241.     okay1 'Ooops ! TeX is busy ! Try TeX in ** status !?'
  242.     exit 5
  243.     end
  244. /*** if rc = 10 then path could not been found ***/
  245. if RC = 10 then do
  246.     okay2 'ERROR ! Path ' texpath ' not accessable !' cr|| 'Shall I try it anyway ??'
  247.     if result = 0 then exit 5
  248.     end
  249.  
  250. /**** Reset counter for TeXifyLookNext.ced ***/
  251. setclip('texlog',"0")
  252.  
  253. /*** just get shure there's no old misinterpreted .log .dvi file ***/
  254. if exists(srcnam||'.log') then call delete(srcnam||'.log')
  255. if exists(srcnam||'.dvi') then call delete(srcnam||'.dvi')
  256.  
  257. /*** now texify the textfile while showing TeXs prompting ***/
  258. address 'AmigaTeX'
  259. 'ToFront'
  260.  
  261. /*** give TeX something to do... ***/
  262. 'TeXify' srcfile
  263.  
  264. /*** is TeX in input status ** ? ***/
  265. if RC = 1 then do
  266.     Okay1 'Error ! Can not TeXify your file !' cr||'TeX is not in ** status !'
  267.     exit 5
  268.     end
  269.  
  270. /*** wait until TeX gets finished ***/
  271. 'NextPrompt'
  272. 'NextPrompt'
  273.  
  274. /*** get status of TeX for analysing ***/
  275. 'Prompt'
  276. prompt = getclip('AmigaTeX.Prompt')
  277. /*** if RC = 1 then TeX was not waiting for incoming Data... ** ***/
  278. if RC = 1 then do
  279.     /*** Activate CEDPro ***/
  280.     if  ~show('P','rexx_ced') then do
  281.         address command ced||" "||fullsrc
  282.         Delay(30)
  283.         end
  284.     address 'rexx_ced'
  285.     'jump to file' fullsrc
  286.     if result = 0 then do
  287.         'Open new'
  288.         'Open' fullsrc
  289.         end
  290.     'CedToFront'
  291.  
  292.     Okay1 'Error ! TeX does not behave right !'
  293.     exit 5
  294.     end
  295.  
  296. /*** Ooops ! if this happens, there is something wrong in your source ! ***/
  297. if prompt = "?" then do
  298.     n = 1;
  299.     do while (prompt = "?" & n<=errorcount)
  300.         /*** get position of error from TeX ***/
  301.         'ErrorLoc'
  302.         error = getclip('AmigaTeX.ErrorLoc')
  303.         parse var error filename.n line.n pos.n
  304.         if n<errorcount then do
  305.             'TeXify '||cr
  306.             'NextPrompt'
  307.             'NextPrompt'
  308.             end
  309.         n = n+1
  310.         /*** get status of TeX for analysing ***/
  311.         'Prompt'
  312.         prompt = getclip('AmigaTeX.Prompt')
  313.         if RC = 1 then do
  314.             /*** Activate CEDPro ***/
  315.             if  ~show('P','rexx_ced') then do
  316.                 address command ced||" "||fullsrc
  317.                 Delay(30)
  318.                 end
  319.             address 'rexx_ced'
  320.             'jump to file' fullsrc
  321.             if result = 0 then do
  322.                 'Open new'
  323.                 'Open' fullsrc
  324.                 end
  325.             'CedToFront'
  326.  
  327.             okay1 'Error ! TeX does not behave right !'
  328.             /*** now TeX window can disappear ***/
  329.             address 'AmigaTeX' 'ToBack'
  330.             exit 5
  331.             end
  332.         end
  333.     n = n-1
  334.     /*** now TeX can disappear ***/
  335.     'ToBack'
  336.     'Abort'
  337.  
  338.     /*** Do I have to start CEDPro? Activate CEDPro ! ***/
  339.     if  ~show('P','rexx_ced') then do
  340.         address command ced||" "||fullsrc
  341.         Delay(30)
  342.         end
  343.     address 'rexx_ced'
  344.     'jump to file' fullsrc
  345.     if result = 0 then do
  346.         'Open new'
  347.         'Open' fullsrc
  348.         end
  349.     'CedToFront'
  350.  
  351.     /*** wait a bit for TeX to finish .log file ***/
  352.     address 'AmigaTeX' 'NextPrompt'  /* TeX may need it twice... doesn't matter anyway */
  353.     address 'AmigaTeX' 'NextPrompt'
  354.     
  355.     /*** if there's no .log file, there's no explaining for your mistake ! ***/
  356.     if ~exists(srcnam|| '.log') then do
  357.         okay1 'Ooops ! Error in this line ! No .log file !'
  358.         exit 5
  359.         end
  360.  
  361.     /*** TeX may be finish with .log, but AmigaDos may need time! ***/
  362.     /*** Specially 68020/30 needs checking !                      ***/
  363.     ti = time('S') + 3;
  364.     rc = 0
  365.     do while ((rc=0) & (time('S') < ti))
  366.         rc = open('log',srcnam||'.log')
  367.         if rc = 0 then call delay(50)
  368.         end
  369.     if rc = 0 then do
  370.         okay1 "ERROR ! Error in this line !" cr|| "Can't open the existing .log file !"
  371.         exit 5
  372.         end
  373.         cause = 1
  374.         lin = 1
  375.     do until eof('log')
  376.         logline = readln('log')
  377.         if left(logline,2) = "! " then do
  378.             error.cause = right(logline,length(logline)-2)
  379.             cause = cause + 1
  380.             end
  381.         else if left(logline,2) = "l." then do
  382.             logline = subword(logline,1,1)
  383.             logline = delstr(logline,1,2)
  384.             if logline ~= line.lin then do
  385.                 pos.lin = 0
  386.                 filename.lin = "!"
  387.                 line.lin=logline
  388.                 end
  389.             lin = lin + 1
  390.             end
  391.         end
  392.     call close 'log'
  393.     lin = lin-1
  394.     if (lin > n) & (lin < errorcount) then n = lin
  395.     rc =  open('log','t:tex.log',write)
  396.     if rc = 0 then do
  397.         okay1 "ERROR ! Can't write errorfile in t: !"
  398.         exit 5
  399.         end
  400.     lin = 1
  401.     do lin = 1 for n
  402.         call writeln 'log',line.lin ||" "|| pos.lin ||" "|| filename.lin ||" "|| error.lin
  403.         end lin
  404.     call close out
  405.     setclip('texlog',"1")
  406.     setclip('texpath',path)
  407.     sfx= "."||sfx
  408.     setclip('texsfx',sfx)
  409.     'jump to file' filename.1
  410.     if result = 0 then do
  411.         if exists(path||filename.1) then do
  412.             'open new'
  413.             'open' path||filename.1
  414.             'jumpto' line.1 pos.1
  415.             okay1 error.1
  416.             exit 5
  417.             end
  418.         if exists(filename.1) then do
  419.             'open new'
  420.             'open' path||filename.1
  421.             'jumpto' line.1 pos.1
  422.             okay1 error.1
  423.             exit 5
  424.             end
  425.         'jump to file' filename.1||sfx
  426.         if result = 0 then do
  427.             if exists(path||filename.1||sfx) then do
  428.                 'open new'
  429.                 'open' path||filename.1||sfx
  430.                 'jumpto' line.1 pos.1
  431.                 okay1 error.1
  432.                 exit 5
  433.                 end
  434.             if exists(filename.1||sfx) then do
  435.                 'open new'
  436.                 'open' path||filename.1||sfx
  437.                 'jumpto' line.1 pos.1
  438.                 okay1 error.1
  439.                 exit 5
  440.                 end
  441.             'jumpto' line.1 pos.1
  442.             okay1 "Ooops ! Error in "||filename.1||"  TeX file !"||cr||error.1||cr||"Error in line:"||line.1||"  pos:" pos.1
  443.             exit 5
  444.             end
  445.         end
  446.     'jumpto' line.1 pos.1
  447.     okay1 error.1
  448.     exit 5
  449.     end
  450.  
  451.  
  452. /*** now TeX window can disappear ***/
  453. 'ToBack'
  454.  
  455. /*** if prompt = * then TeX aborted ... should be a missing \end ***/
  456. if prompt = "*" then do
  457.     'Abort'
  458.     /*** Activate CEDPro ***/
  459.     if  ~show('P','rexx_ced') then do
  460.         address command ced||" "||fullsrc
  461.         Delay(30)
  462.         end
  463.     address 'rexx_ced'
  464.     'jump to file' fullsrc
  465.     if result = 0 then do
  466.         'Open new'
  467.         'Open' fullsrc
  468.         end
  469.     'CedToFront'
  470.     okay1 'Ooops ! TeX ended in * status !' cr|| 'Maybe a forgotten \end ??'
  471.     exit 5
  472.     end
  473.  
  474. /*** seems that everything worked fine with tex ***/
  475. if prompt = '**' then do
  476.     /*** pop up CygnusEd screen, so you get there when quiting preview ***/
  477.     if  show('P','rexx_ced') then do
  478.         address 'rexx_ced' 
  479.         'CEDTOFRONT'
  480.         end
  481.  
  482.     /*** cut suffix from sourcefiles name; preview don't like suffix ***/
  483.     fullsrc = left(fullsrc,lastpos('.',fullsrc)-1)
  484.  
  485.     /*** do I have to start preview first ? ***/ 
  486.     if  ~show('P','TeXpreview') then  address command preview||" "||fullsrc
  487.     else do
  488.         address 'TeXpreview'
  489.         'ToFront'
  490.         'activate'
  491.         end
  492.  
  493.     /*** now give preview time to showup ***/
  494.     ti = time('S') + timeout;
  495.     do while ((~show('P','TeXpreview')) & (time('S') < ti))
  496.         call delay(50)
  497.         end
  498.     if ~show('P','TeXpreview') then do
  499.         /*** Activate CEDPro ***/
  500.         if  ~show('P','rexx_ced') then do
  501.             address command ced||" "||fullsrc
  502.             Delay(30)
  503.             end
  504.         address 'rexx_ced'
  505.         'jump to file' fullsrc
  506.         if result = 0 then do
  507.             'Open new'
  508.             'Open' fullsrc
  509.             end
  510.         'CedToFront'
  511.         okay1 "ERROR ! Couldn't start Preview after "timeout" secs !" cr||"       You may start Preview now by CLI !" cr||"    Your .dvi file seems to be fine !"
  512.         exit 5
  513.         end
  514.     exit
  515.     end
  516.  
  517. /*** unknown prompt from TeX !!!!!! ***/
  518. /*** now TeX can disappear ***/
  519. 'ToBack'
  520. 'Abort'
  521. /*** Activate CEDPro ***/
  522. if  ~show('P','rexx_ced') then do
  523.     address command ced||" "||fullsrc
  524.     Delay(30)
  525.     end
  526. address 'rexx_ced'
  527. 'jump to file' fullsrc
  528. if result = 0 then do
  529.     'Open new'
  530.     'Open' fullsrc
  531.     end
  532. 'CedToFront'
  533. /*** wait a bit for TeX to finish .log file ***/
  534. 'NextPrompt'  /* TeX may need it twice... doesn't matter anyway */
  535. 'NextPrompt'
  536.  
  537. /*** if there's no .log file, there's no explaining for your mistake ! ***/
  538. if ~exists(srcnam|| '.log') then do
  539.     okay1 'Ooops ! TeX aborted in  unknown status !'|| cr || "Can't open any .log file !"
  540.     exit 5
  541.     end
  542. /*** TeX may be finish with .log, but AmigaDos may need time! ***/
  543. /*** Specially 68020/30 needs checking !                      ***/
  544. ti = time('S') + 3;
  545. rc = 0
  546. do while ((rc=0) & (time('S') < ti))
  547.     rc = open('log',srcnam||'.log')
  548.     if rc = 0 then call delay(50)
  549.     end
  550. if rc = 0 then do
  551.     okay1 "ERROR ! TeX aborted in unknown status !"||cr||"Can't open the existing .log file !"
  552.     exit 5
  553.     end
  554. logline = ""
  555. do until (left(logline,2) = "! " )
  556.     logline = readln('log')
  557.     if eof('log') then do
  558.         /*** no '! ' found in file ***/
  559.         call close 'log'
  560.         okay1 "Ooops !  TeX aborted in unknown status !"||cr||"No error in .log file ! Try it by hand !"
  561.         exit 5
  562.         end
  563.     end
  564. errline = ""
  565. do until (left(errline,2) = "l.")
  566.     errline = readln('log')
  567.     if eof('log') then do
  568.         /*** no '! ' found in file ***/
  569.         call close 'log'
  570.         okay1 "Ooops !  TeX aborted in unknown status !"||cr||"There is an unknown error in TeX file !!!"
  571.         exit 5
  572.         end
  573.     end
  574. call close 'log'
  575. errline = subword(errline,1,1)
  576. errline = delstr(errline,1,2)
  577. /*** '! ' found in .log file; show error explanation ***/
  578. logline = right(logline,length(logline)-2)
  579. strip(logline,'B')
  580. 'jumpto' errline 1
  581. okay1 "Ooops !  TeX aborted in unknown status !"||cr||"Error in unknown TeX source ! Line: "||errline||cr||logline
  582. exit 5
  583. end
  584.