home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / rexx / texedit.rexx < prev    next >
OS/2 REXX Batch file  |  1991-07-29  |  10KB  |  330 lines

  1. /*RX
  2.  * AREXX    Name:TeXedit.rexx    version:1.41    date:27-Jul-91
  3.  *
  4.  This ARexx script is called from virtex (or initex) in case of an
  5. error or if the 'e' command is used, and it's given the current file
  6. and line number as argument. It may be called from the TeX-server too.
  7. We will successively call CygnusEd (CED) or Micro(GNU)Emacs (MG) to
  8. load the file and the logfile. Other editors welcome!
  9.  *
  10. INPUTS:
  11.  1: filename to edit (please no spaces in filename)
  12.  2: line where error occured
  13.  *
  14. BUGS:
  15.  GETCLIP("TEXFILE") gets precedence over any other information for
  16. retrieving the logfile, so if you alternately start virtex directly
  17. from CLI while the server is active, the wrong files may be loaded.
  18.  *
  19.  This file tries to cope with the following version (PasTeX 1.2a)
  20. > This is a PD-Version of Pas-TeX (made Jan 30 1991 [br]/[hes])
  21. > This is TeX, C Version 3.1
  22. (The logfile is sometimes put at the wrong place.)
  23.  *
  24.  Does not handle names relative to the local root correctly (like ":foo/bar")
  25.  *
  26.  See each editor relative bugs below.
  27.  *
  28. FILES:
  29.  Rexx:namestruc
  30.  LIBS:rexxsupport.library
  31. AUTHORS:
  32.  *    J\"org H\"ohle, since March 91
  33.  *    Georg Hessmann, previous version
  34.  */
  35.  
  36. /* call trace('all') */
  37.  
  38. /**
  39. TeXRexx     = "TeX:rexx/"        / * where our scripts stay * /
  40. namestruc= TeXRexx||namestruc
  41. **/
  42.  
  43. IF ~SHOW('L','rexxsupport.library') THEN
  44.     IF ~ADDLIB('rexxsupport.library',0,-30,0) THEN DO
  45.         say "Can't open 'rexxsupport.library'!"
  46.         EXIT 20
  47.         END
  48.  
  49. /* The TeX server may want to know that we have been called */
  50. CALL SETCLIP("TEXTIME",TIME('s'))
  51.  
  52. PARSE ARG filename number .
  53.  
  54. /*say address()*/
  55. /* if the TeX 'e' command was used to call the editor, don't ask if
  56.     files should be loaded. */
  57. IF address() = 'TeX-Rexx-Port' & "EDIT" ~= UPPER(mygetenv("TEXREXX"))
  58. THEN askload = 0
  59. ELSE askload = 1
  60.  
  61. /**
  62. OPTIONS RESULTS
  63. namestruc filename
  64. IF 0~= RC THEN DO
  65.     say "TeXEdit.rexx: Function "namestruc" not found!"
  66.     EXIT 10
  67.     END
  68. ELSE PARSE VALUE RESULT WITH ivol idirs ibase .
  69. **/
  70. PARSE VALUE namestruc(filename) WITH ivol idirs ibase .
  71.  
  72. /* The idea behind the following statements is to get an absolute path
  73. for <filename>. The result will be stored in <errnfile>. For example, "CD
  74. TeX:bar" "virtex foo" should give <filename>=foo, and
  75. <errnfile>=TeX:bar/foo. This is necessary because the editor doesn't
  76. know where file foo is located, but will be able to load file
  77. TeX:bar/foo. */
  78.  
  79. mainname = GETCLIP("TEXFILE")
  80. if "" == mainname THEN DO
  81.    /* TeX has not been started through some Start_TeX.#? script. */
  82.    /* We have a hard time finding the right directories */
  83.  
  84.    texdir = pragma('d')
  85.  
  86.    /* Amiga OS dirnames should end with either : or /
  87.     thus you need just append the filename */
  88.    IF RIGHT(texdir,1)~=':' & RIGHT(texdir,1)~='/' THEN texdir = texdir||'/'
  89.  
  90.    IF 0 = ivol THEN DO
  91.     errnfile = texdir||SUBSTR(filename, 1+ivol)
  92.     /* The logfile is in the current dir */
  93.     logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
  94.     END
  95.    ELSE DO
  96.     errnfile=filename
  97.     IF 0 = idirs THEN
  98. /* This is a bug in virtex from PasTeX12a (made Jan 30 1991 [br]/[hes])
  99.     The logfile is *not* in virtex's directory, but rather in the
  100. source's directory if a device name, but no subsequent directory was
  101. given. I.e, virtex (CD in RAM) TeX:sample would put the errorfile in
  102. TeX: and not in RAM: as it should be. */
  103.        logfile = LEFT(filename, ivol+idirs+ibase)||".log"
  104.     ELSE logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
  105.     END
  106.    DROP texdir
  107.    END
  108.  
  109. ELSE DO    /* TeX was started through Start_TeX.#? scripts */
  110.     /* "TEXFILE" tells us CD and the main file */
  111. /**
  112.    namestruc mainname
  113.    PARSE VALUE RESULT WITH mvol mdirs mbase .
  114. **/
  115.    PARSE VALUE namestruc(mainname) WITH mvol mdirs mbase .
  116.  
  117.    IF 0 ~= ivol THEN errnfile = filename
  118.    ELSE    errnfile = LEFT(mainname, mvol+mdirs)||SUBSTR(filename, 1+ivol)
  119.    logfile = LEFT(mainname, mvol+mdirs+mbase)||".log"
  120.    DROP mvol mdirs mbase
  121.    END
  122.  
  123.  
  124. /* 0 = ibase would mean that the call was incorrect, for example when
  125.    TEXREXXEDIT says "TeXedit.rexx" and not "TeXedit.rexx %s %d" */
  126. IF 0 = ibase | ~EXISTS(errnfile) THEN DO
  127.     say "TeXedit.rexx: Can't find erroneous file."
  128.     EXIT 10
  129.     END
  130. ELSE IF ~EXISTS(logfile) THEN DO
  131.     say "TeXedit.rexx: Can't find log file."
  132.     logfile = ""
  133.     /* but we continue */
  134.     END
  135.  
  136. DROP ivol idirs ibase
  137.  
  138. /********************************************************/
  139. /*    Here starts each editor specific parts        */
  140.  
  141. /************************/
  142. /*    Cygnus Ed    */
  143. IF SHOW('P', 'rexx_ced') THEN DO
  144.  
  145. ADDRESS "rexx_ced"
  146. OPTIONS RESULTS
  147.  
  148. cedtofront
  149.  
  150. /* testen ob die Files nicht schon geladen sind. (hes) */
  151.  
  152. /* the following should not be commented out, as this macro is called
  153. asynchronously, and it would be very bad for the user to have it's
  154. input mixed with the newly loaded files. Popping up a requester
  155. ensures that the user does not type in something and waits for the
  156. files to be loaded. This is the method I use for synchronization (JCH) */
  157.  
  158. IF askload THEN DO
  159.     okay2 'TeX found an error in 'errnfile'. Load files ?'
  160.     IF 1 ~= RESULT THEN EXIT 0
  161.     END
  162.  
  163. /* TODO: We should really delete old logfiles automatically, without letting
  164.     CED open a requester to ask if an old modified file may be
  165.     overwritten or not */
  166.  
  167. IF "" ~= logfile THEN DO
  168.     'jump to file "'logfile'"'
  169.     IF 0 ~= RESULT THEN Quit /* always assume the logfile currently
  170.         loaded is old, because TeX generated a new one. */
  171.     Open new
  172.     /*expand view*/
  173.     open '"'logfile'"'
  174.     editable file    /* now it's non-editable */
  175.     beg of file
  176.     /* if we don't have the line number: search the number in the logfile (hes) */
  177.     /* bringt das wirklich etwas ? Der erste Fehler steht
  178.         sowieso gegen Anfang der Logdatei */
  179.     IF 0 ~= number THEN 'Search for...' "l."||number
  180.     ELSE DO
  181.       'Search for...' "l." /* ^M bringt nichts, und dann Steuercodes hier...*/
  182.       'Right'
  183.       'Status 55'        /* take the current line from CED */
  184.       PARSE VAR RESULT "l."number .
  185.         END
  186.     /* changed from Search "! " (hes) */
  187.     END
  188. ELSE    okay1 "Couldn''t find logfile associated with TeX error!"
  189.  
  190. /* the following line should really read "jump to file errnfile" and
  191. not filename, because I have done extra work to get the right
  192. directory. But this information is only in errnfile, which contains an
  193. absolute pathname, and not in filename, which is the parameter
  194. supplied by virtex or initex, usually a relative pathname. CED's
  195. current directory is not necessarily virtex'es one. It also seems that
  196. CED is not smart enough as to make the difference between
  197. foo:tgmoae/myfile and bar:tgmoab/myfile. If I say jump to file
  198. foo:tgmoae/myfile it may as well jump to bar:tgmoab/myfile, whichever
  199. window comes first. */
  200.  
  201. 'jump to file "'errnfile'"'
  202. IF 0 = RESULT THEN DO
  203.     open new
  204.     open '"'errnfile'"'
  205.     END
  206.  
  207. /*expand view*/
  208.  
  209. /* TODO: another editor may have modified the disk file, or the user
  210. the currently loaded file, while virtex compiled an old version. How
  211. can I get rid of that stupid filerequester in that case? I said "open
  212. errnfile", so why does CED pop up a filerequester (and may put the
  213. user in the wrong directory too) ? */
  214.  
  215. IF 0~= number THEN jumpto number
  216. beg of line
  217.  
  218. EXIT 0
  219. END    /* End of CED part */
  220.  
  221.  
  222. /****************************************************************/
  223. /*    Micro(Gnu)Emacs (MG), to be found on AmigaLibDisk352    */
  224. IF SHOW('P','mg') THEN DO
  225.  
  226. ADDRESS 'mg'
  227. OPTIONS RESULTS
  228.  
  229. /* The following waits until MG is deiconified */
  230. 'amiga-window-to-top'    /* should activate window ? */
  231.  
  232. /* we need to prevent the user from continuing to type and thus
  233. modifying the newly created buffers. I choose the rexx-lock/unlock
  234. method to synchronise with the user because MG3b4 has some cursor
  235. position/display bugs: the cursor may erroneously appear in some
  236. buffer and overwrite it (on the screen only), and not appear in the
  237. bottom line where it belongs. */
  238.  
  239. IF askload THEN DO
  240.     'rexx-lock'    /* this is dangerous if this script aborts */
  241.     ADDRESS VALUE RESULT
  242.  
  243.     'rexx-request "TeX found an error. Load files ? "'
  244.     retc=RC
  245.     rets=RESULT
  246.  
  247.     'rexx-unlock'
  248.     ADDRESS VALUE RESULT
  249.  
  250.     IF 1 < retc /* abort */ | LEFT(UPPER(rets),1)='N' THEN DO
  251.         'rexx-display ""'
  252.         EXIT 0
  253.         END
  254.     DROP retc rets
  255.     END
  256.  
  257. 'find-file "'errnfile'"'
  258. /* MG doesn't seem to set the RC value on a find-file */
  259. 'rexx-buffer' buf
  260. /* buf.1 is the buffer name,