home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / text / font / metafont / rexx / mfedit.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-12-21  |  8.1 KB  |  356 lines

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