home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / text / tex / pastex / mf / rexx / mfedit.rexx < prev    next >
OS/2 REXX Batch file  |  1994-05-11  |  9KB  |  370 lines

  1. /*
  2. ** AREXX $VER:MFEdit.rexx 1.1 (31.1.1994)
  3. **
  4. ** This ARexx script is called from VirMF (or IniMF) 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 arguments.  We will successively call CygnusEd (CED)
  7. ** or Micro(GNU)Emacs (MG) to load the file and the logfile.
  8. ** 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. **    Does not handle names relative to the local root correctly (like ":foo/bar")
  16. **
  17. **    See each editor relative bugs below.
  18. **
  19. ** FILES:
  20. **    Rexx:NameStruc
  21. **    LIBS:rexxsupport.library
  22. **
  23. ** AUTHORS:
  24. **    Jörg Höhle, since March 91 (TeXEdit.rexx)
  25. **    Georg Heßmann, previous version (TeXEdit.rexx)
  26. **    Andreas Scherer (MFEdit.rexx)
  27. **
  28. ** CHANGES:
  29. **    31.1.1994: Make sure the MF-file is loaded before visiting the
  30. **               log-file.  There was an empty view if no file was
  31. **               actually loaded.  (V1.1)
  32. */
  33.  
  34. If ~Show('Libraries','rexxsupport.library') Then
  35.   If ~AddLib('rexxsupport.library',0,-30,0) Then Do
  36.     Say "Konnte 'rexxsupport.library' nicht öffnen!"
  37.     Exit 20
  38.   End
  39.  
  40. Parse Arg FILENAME NUMBER .
  41.  
  42. /*
  43. ** If the MetaFont 'e' command was used to call the editor,
  44. ** don't ask if files should be loaded.
  45. */
  46. If "EDIT" ~= Upper(MyGetEnv("MFREXX")) Then
  47.   ASKLOAD = 0
  48. Else
  49.   ASKLOAD = 1
  50.  
  51. Parse Value NameStruc(FILENAME) With IVOL IDIRS IBASE .
  52.  
  53. /*
  54. ** The idea in the following statements is to get an absolute path
  55. ** for <filename>. The result will be stored in <errnfile>. For example,
  56. ** "CD MF:bar" "virmf foo" should give <filename>=foo, and
  57. ** <errnfile>=MF:bar/foo. This is necessary because the editor doesn't
  58. ** know where file foo is located, but will be able to load file
  59. ** MF:bar/foo.
  60. */
  61.  
  62. /*
  63. ** We have a hard time finding the right directories.
  64. */
  65. MFDIR = Pragma('d')
  66.  
  67. /*
  68. ** Amiga OS dirnames should end with either `:' or `/'.
  69. ** Thus you need just append the filename.
  70. */
  71. If Right(MFDIR,1) ~= ':' & Right(MFDIR,1) ~= '/' Then
  72.   MFDIR = MFDIR||'/'
  73.  
  74. If 0 = IVOL Then
  75.   ERRNFILE = MFDIR||SubStr(FILENAME,1+IVOL)
  76. /*
  77. ** The logfile is in the current dir.
  78. */
  79. Else
  80.   ERRNFILE = FILENAME
  81.  
  82. LOGFILE = MFDIR||SubStr(FILENAME,1+IVOL+IDIRS,IBASE)||".log"
  83. Drop MFDIR
  84.  
  85. /*
  86. ** 0 = ibase would mean that the call was incorrect, for example when
  87. ** MFREXXEDIT says "MFEdit.rexx" and not "MFEdit.rexx %s %d"
  88. */
  89. If 0 = IBASE | ~Exists(ERRNFILE) Then Do
  90.   Say "MFEdit.rexx: Konnte fehlerhafte Datei "ERRNFILE" nicht finden."
  91.   Exit 10
  92. End; Else If ~Exists(LOGFILE) Then Do
  93.   Say "MFEdit.rexx: Konnte Logfile nicht finden."
  94.   LOGFILE = ""
  95.  
  96. /*
  97. ** But we continue.
  98. */
  99. End
  100.  
  101. Drop IVOL IDIRS IBASE
  102.  
  103. /*
  104. ** Here starts each editor's specific part.
  105. */
  106.  
  107. /*
  108. ** Cygnus Ed Professional Version 3.5+
  109. */
  110. If Show('Port','rexx_ced') Then Do
  111.   Address 'rexx_ced'
  112.  
  113.   Options Results
  114.  
  115.   CEDtoFront
  116.  
  117. /*
  118. ** The following should not be commented out, as this macro is called
  119. ** asynchronously, and it would be very bad for the user to have it's
  120. ** input mixed with the newly loaded files. Popping up a requester
  121. ** ensures that the user does not type in something and waits for the
  122. ** files to be loaded. This is the method I use for synchronization. (JCH)
  123. */
  124.   If ASKLOAD Then Do
  125.     Okay2 "MetaFont fand einen Fehler in der Datei"'0A'X"'"ERRNFILE"'. Datei laden?"
  126.     If 1 ~= RESULT Then
  127.       Exit 0
  128.   End
  129.  
  130. /*
  131. ** Make sure the MetaFont-file is loaded.  This works with CED 3.5+ only.
  132. ** There was no mechanism to make sure that the errorneous file was
  133. ** actually loaded in one of the views.  If it wasn't, the next command
  134. ** would open a second view for the log file and a *third* for the
  135. ** MF-file, but half of the CED screen was left empty with `Unnamed.'
  136. ** You could replace this by `jump to file' for CED 2.12.
  137. */
  138.   OW ERRNFILE
  139.  
  140. /*
  141. ** TODO: We should really delete old logfiles automatically, without letting
  142. **       CED open a requester to ask if an old modified file may be
  143. **       overwritten or not.
  144. */
  145.  
  146.   If "" ~= LOGFILE Then Do
  147.     'jump to file "'LOGFILE'"'
  148. /*
  149. ** Always assume the logfile currently loaded is old,
  150. ** because MetaFont generated a new one.
  151. */
  152.     If 0 ~= RESULT Then Do
  153.       Quit
  154.     End
  155.  
  156.     Open new
  157.     Open '"'LOGFILE'"'
  158.  
  159. /*
  160. ** Now it's non-editable.
  161. */
  162.     Editable file
  163.     Beg of file
  164.  
  165. /*
  166. ** If we don't have the line number: search the number in the logfile. (hes)
  167. */
  168.     If 0 ~= NUMBER Then
  169.       'Search for...' "l."||NUMBER
  170.     Else Do
  171. /*
  172. ** ^M bringt nichts, und dann Steuercodes hier ...
  173. */
  174.       'Search for...' "l."
  175.       'Right'
  176.  
  177. /*
  178. ** Take the current line from CED.
  179. */
  180.       'Status 55'
  181.       Parse Var RESULT "l."NUMBER .
  182.     End
  183. /*
  184. ** Changed from Search "! " (hes)
  185. */
  186.   End; Else
  187.     Okay1 "Konnte kein richtiges Logfile finden!"
  188.  
  189. /*
  190. ** The following line should really read "jump to file errnfile" and not
  191. ** filename, because I have done extra work to get the right directory. But
  192. ** this information is only in errnfile, which contains an absolute pathname,
  193. ** and not in filename, which is the parameter supplied by virmf or inimf,
  194. ** usually a relative pathname. CED's current directory is not necessarily
  195. ** virmf's one. It also seems that CED is not smart enough as to make the
  196. ** difference between foo:tgmoae/myfile and bar:tgmoab/myfile. If I say
  197. ** jump to file foo:tgmoae/myfile it may as well jump to bar:tgmoab/myfile,
  198. ** whichever window comes first.
  199. */
  200.   'jump to file "'ERRNFILE'"'
  201.   If 0 = RESULT Then Do
  202. /*
  203. ** Not reached with `OW ERRNFILE' above.
  204. */
  205.     Open new
  206.     Open '"'errnfile'"'
  207.   End
  208.  
  209. /*
  210. ** TODO: another editor may have modified the disk file, or the user
  211. ** the currently loaded file, while virmf compiled an old version. How
  212. ** can I get rid of that stupid filerequester in that case? I said "open
  213. ** errnfile", so why does CED pop up a filerequester (and may put the
  214. ** user in the wrong directory too)?
  215. */
  216.  
  217.   If 0 ~= NUMBER Then
  218.     JumpTo NUMBER
  219.  
  220.   Beg of line
  221.  
  222.   Exit 0
  223. End
  224. /*
  225. ** End of CED part.
  226. */
  227.  
  228. /*
  229. ** Micro(Gnu)Emacs (MG), to be found on AmigaLibDisk352.
  230. */
  231. If Show('Port','mg') Then Do
  232.   Address 'mg'
  233.  
  234.   Options Results
  235.  
  236. /*
  237. ** The following waits until MG is deiconified.
  238. */
  239.   'amiga-window-to-top'
  240.  
  241. /*
  242. ** We need to prevent the user from continuing to type and thus
  243. ** modifying the newly created buffers. I choose the rexx-lock/unlock
  244. ** method to synchronise with the user because MG3b4 has some cursor
  245. ** position/display bugs: the cursor may erroneously appear in some
  246. ** buffer and overwrite it (on the screen only), and not appear in the
  247. ** bottom line where it belongs.
  248. */
  249.  
  250.   If ASKLOAD Then Do
  251. /*
  252. ** This is dangerous if this script aborts.
  253. */
  254.     'rexx-lock'
  255.  
  256.     Address Value RESULT
  257.  
  258.     'rexx-request "MetaFont fand einen Fehler. Datei laden? "'
  259.     RETC = RC
  260.     RETS = RESULT
  261.  
  262.     'rexx-unlock'
  263.  
  264.     Address Value RESULT
  265.  
  266.     If 1 < RETC | Left(Upper(RETS),1) = 'N' Then Do
  267.       'rexx-display ""'
  268.       Exit 0
  269.     End
  270.  
  271.     Drop RETC RETS
  272.   End
  273.  
  274.   'find-file "'ERRNFILE'"'
  275. /*
  276. ** MG doesn't seem to set the RC value on a find-file.
  277. */
  278.   'rexx-buffer' BUF
  279.  
  280. /*
  281. ** buf.1 is the buffer name, buf.3 the number of lines.
  282. */
  283.   If NUMBER < BUF.3 Then Do
  284.     'delete-other-windows'
  285.  
  286.     If "" ~= LOGFILE Then Do
  287.       'split-window-vertically'
  288.  
  289. /*
  290. ** Now get rid of old logfiles. Here I make sure that I get rid of
  291. ** every suspicious logfile, because multiple pathes may lead to the same
  292. ** file, as for example SYS:mf/sample.log & MF:sample.log.
  293. */
  294.       'rexx-buffer-list' BUFFERS
  295.  
  296.       Parse Value NameStruc(LOGFILE) With IVOL IDIRS IBASE
  297.  
  298.       LOGNAME = Upper(SubStr(LOGFILE,1+IVOL+IDIRS))
  299.  
  300.       Do I=1 To BUFFERS.0
  301.         If 0 < Index(Upper(BUFFERS.I.FILE),LOGNAME) Then Do
  302.           'switch-to-buffer "'BUFFERS.I.NAME'"'
  303.           'not-modified'
  304.           'kill-buffer "'BUFFERS.I.NAME'"'
  305.         End
  306.       End
  307.  
  308.       'find-file "'LOGFILE'"'
  309. /*
  310. ** MG doesn't seem to set the RC value.
  311. */
  312.       'beginning-of-buffer'
  313.  
  314.       If 0 ~= NUMBER Then
  315.         're-search-forward "^l."NUMBER'
  316.       Else Do
  317. /*
  318. ** Try to use normal search?
  319. */
  320.         're-search-forward "^l."' /* ^ means begin of line */
  321.  
  322. /*
  323. ** If search successfull get current line contents.
  324. */
  325.         If 0 = RC Then Do
  326.           'rexx-