home *** CD-ROM | disk | FTP | other *** search
- /*RX
- * AREXX Name:TeXedit.rexx version:1.41 date:27-Jul-91
- *
- This ARexx script is called from virtex (or initex) in case of an
- error or if the 'e' command is used, and it's given the current file
- and line number as argument. It may be called from the TeX-server too.
- We will successively call CygnusEd (CED) or Micro(GNU)Emacs (MG) and GoldED to
- load the file and the logfile. Other editors welcome!
- *
- INPUTS:
- 1: filename to edit (please no spaces in filename)
- 2: line where error occured
- *
- BUGS:
- GETCLIP("TEXFILE") gets precedence over any other information for
- retrieving the logfile, so if you alternately start virtex directly
- from CLI while the server is active, the wrong files may be loaded.
- *
- This file tries to cope with the following version (PasTeX 1.2a)
- > This is a PD-Version of Pas-TeX (made Jan 30 1991 [br]/[hes])
- > This is TeX, C Version 3.1
- (The logfile is sometimes put at the wrong place.)
- >> I have only tried with Version 3.14 (Rene Laederach)
- *
- Does not handle names relative to the local root correctly (like ":foo/bar")
- *
- See each editor relative bugs below.
- *
- FILES:
- Rexx:namestruc
- LIBS:rexxsupport.library
- AUTHORS:
- * J\"org H\"ohle, since March 91
- * Georg Hessmann, previous version
- * Ren\'e\ Laederach for GoldED part
- */
-
- /* call trace('all') */
-
- /**
- TeXRexx = "rexx:TeX" / * where our scripts stay * /
- namestruc= TeXRexx||namestruc
- **/
-
- IF ~SHOW('L','rexxsupport.library') THEN
- IF ~ADDLIB('rexxsupport.library',0,-30,0) THEN DO
- say "Can't open 'rexxsupport.library'!"
- EXIT 20
- END
-
- /* The TeX server may want to know that we have been called */
- CALL SETCLIP("TEXTIME",TIME('s'))
-
- PARSE ARG filename number .
-
- /*say address()*/
- /* if the TeX 'e' command was used to call the editor, don't ask if
- files should be loaded. */
- IF address() = 'TeX-Rexx-Port' & "EDIT" ~= UPPER(mygetenv("TEXREXX"))
- THEN askload = 0
- ELSE askload = 1
-
- /**
- OPTIONS RESULTS
- namestruc filename
- IF 0~= RC THEN DO
- say "TeXEdit.rexx: Function "namestruc" not found!"
- EXIT 10
- END
- ELSE PARSE VALUE RESULT WITH ivol idirs ibase .
- **/
- PARSE VALUE namestruc(filename) WITH ivol idirs ibase .
-
- /* The idea behind the following statements is to get an absolute path
- for <filename>. The result will be stored in <errnfile>. For example, "CD
- TeX:bar" "virtex foo" should give <filename>=foo, and
- <errnfile>=TeX:bar/foo. This is necessary because the editor doesn't
- know where file foo is located, but will be able to load file
- TeX:bar/foo. */
-
- mainname = GETCLIP("TEXFILE")
- if "" == mainname THEN DO
- /* TeX has not been started through some Start_TeX.#? script. */
- /* We have a hard time finding the right directories */
-
- texdir = pragma('d')
-
- /* Amiga OS dirnames should end with either : or /
- thus you need just append the filename */
- IF RIGHT(texdir,1)~=':' & RIGHT(texdir,1)~='/' THEN texdir = texdir||'/'
-
- IF 0 = ivol THEN DO
- errnfile = texdir||SUBSTR(filename, 1+ivol)
- /* The logfile is in the current dir */
- logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
- END
- ELSE DO
- errnfile=filename
- IF 0 = idirs THEN
- /* This is a bug in virtex from PasTeX12a (made Jan 30 1991 [br]/[hes])
- The logfile is *not* in virtex's directory, but rather in the
- source's directory if a device name, but no subsequent directory was
- given. I.e, virtex (CD in RAM) TeX:sample would put the errorfile in
- TeX: and not in RAM: as it should be. */
- logfile = LEFT(filename, ivol+idirs+ibase)||".log"
- ELSE logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
- END
- DROP texdir
- END
-
- ELSE DO /* TeX was started through Start_TeX.#? scripts */
- /* "TEXFILE" tells us CD and the main file */
- /**
- namestruc mainname
- PARSE VALUE RESULT WITH mvol mdirs mbase .
- **/
- PARSE VALUE namestruc(mainname) WITH mvol mdirs mbase .
-
- IF 0 ~= ivol THEN errnfile = filename
- ELSE errnfile = LEFT(mainname, mvol+mdirs)||SUBSTR(filename, 1+ivol)
- logfile = LEFT(mainname, mvol+mdirs+mbase)||".log"
- DROP mvol mdirs mbase
- END
-
-
- /* 0 = ibase would mean that the call was incorrect, for example when
- TEXREXXEDIT says "TeXedit.rexx" and not "TeXedit.rexx %s %d" */
- IF 0 = ibase | ~EXISTS(errnfile) THEN DO
- say "TeXedit.rexx: Can't find erroneous file."
- EXIT 10
- END
- ELSE IF ~EXISTS(logfile) THEN DO
- say "TeXedit.rexx: Can't find log file."
- logfile = ""
- /* but we continue */
- END
-
- DROP ivol idirs ibase
-
- /********************************************************/
- /* Here starts each editor specific parts */
-
- /************************/
- /* Cygnus Ed */
- IF SHOW('P', 'rexx_ced') THEN DO
-
- ADDRESS "rexx_ced"
- OPTIONS RESULTS
-
- cedtofront
-
- /* testen ob die Files nicht schon geladen sind. (hes) */
-
- /* the following should not be commented out, as this macro is called
- asynchronously, and it would be very bad for the user to have it's
- input mixed with the newly loaded files. Popping up a requester
- ensures that the user does not type in something and waits for the
- files to be loaded. This is the method I use for synchronization (JCH) */
-
- IF askload THEN DO
- okay2 'TeX found an error in 'errnfile'. Load files ?'
- IF 1 ~= RESULT THEN EXIT 0
- END
-
- /* TODO: We should really delete old logfiles automatically, without letting
- CED open a requester to ask if an old modified file may be
- overwritten or not */
-
- IF "" ~= logfile THEN DO
- 'jump to file "'logfile'"'
- IF 0 ~= RESULT THEN Quit /* always assume the logfile currently
- loaded is old, because TeX generated a new one. */
- Open new
- /*expand view*/
- open '"'logfile'"'
- editable file /* now it's non-editable */
- beg of file
- /* if we don't have the line number: search the number in the logfile (hes) */
- /* bringt das wirklich etwas ? Der erste Fehler steht
- sowieso gegen Anfang der Logdatei */
- IF 0 ~= number THEN 'Search for...' "l."||number
- ELSE DO
- 'Search for...' "l." /* ^M bringt nichts, und dann Steuercodes hier...*/
- 'Right'
- 'Status 55' /* take the current line from CED */
- PARSE VAR RESULT "l."number .
- END
- /* changed from Search "! " (hes) */
- END
- ELSE okay1 "Couldn''t find logfile associated with TeX error!"
-
- /* the following line should really read "jump to file errnfile" and
- not filename, because I have done extra work to get the right
- directory. But this information is only in errnfile, which contains an
- absolute pathname, and not in filename, which is the parameter
- supplied by virtex or initex, usually a relative pathname. CED's
- current directory is not necessarily virtex'es one. It also seems that
- CED is not smart enough as to make the difference between
- foo:tgmoae/myfile and bar:tgmoab/myfile. If I say jump to file
- foo:tgmoae/myfile it may as well jump to bar:tgmoab/myfile, whichever
- window comes first. */
-
- 'jump to file "'errnfile'"'
- IF 0 = RESULT THEN DO
- open new
- open '"'errnfile'"'
- END
-
- /*expand view*/
-
- /* TODO: another editor may have modified the disk file, or the user
- the currently loaded file, while virtex compiled an old version. How
- can I get rid of that stupid filerequester in that case? I said "open
- errnfile", so why does CED pop up a filerequester (and may put the
- user in the wrong directory too) ? */
-
- IF 0~= number THEN jumpto number
- beg of line
-
- EXIT 0
- END /* End of CED part */
-
-
- /****************************************************************/
- /* Micro(Gnu)Emacs (MG), to be found on AmigaLibDisk352 */
- IF SHOW('P','mg') THEN DO
-
- ADDRESS 'mg'
- OPTIONS RESULTS
-
- /* The following waits until MG is deiconified */
- 'amiga-window-to-top' /* should activate window ? */
-
- /* we need to prevent the user from continuing to type and thus
- modifying the newly created buffers. I choose the rexx-lock/unlock
- method to synchronise with the user because MG3b4 has some cursor
- position/display bugs: the cursor may erroneously appear in some
- buffer and overwrite it (on the screen only), and not appear in the
- bottom line where it belongs. */
-
- IF askload THEN DO
- 'rexx-lock' /* this is dangerous if this script aborts */
- ADDRESS VALUE RESULT
-
- 'rexx-request "TeX found an error. Load files ? "'
- retc=RC
- rets=RESULT
-
- 'rexx-unlock'
- ADDRESS VALUE RESULT
-
- IF 1 < retc /* abort */ | LEFT(UPPER(rets),1)='N' THEN DO
- 'rexx-display ""'
- EXIT 0
- END
- DROP retc rets
- END
-
- 'find-file "'errnfile'"'
- /* MG doesn't seem to set the RC value on a find-file */
- 'rexx-buffer' buf
- /* buf.1 is the buffer name, buf.3 the number of lines */
- IF number < buf.3 THEN DO
- 'delete-other-windows'
- IF "" ~= logfile THEN DO
- 'split-window-vertically'
- /* 'other-window' */
-
- /* now get rid of old logfiles. Here I make sure that I get rid of
- every suspicious logfile, because multiple pathes may lead to the same
- file, as for example DH0:TeX/sample.log & TeX:sample.log */
-
- 'rexx-buffer-list' buffers
- PARSE VALUE namestruc(logfile) WITH ivol idirs ibase
- logname=UPPER(SUBSTR(logfile,1+ivol+idirs))
- DO i=1 TO buffers.0
- IF 0 < INDEX(UPPER(buffers.i.file),logname) THEN DO
- 'switch-to-buffer "'buffers.i.name'"'
- 'not-modified'
- 'kill-buffer "'buffers.i.name'"'
- END
- END
-
- 'find-file "'logfile'"'
- /* mg doesn't seem to set the RC value */
- 'beginning-of-buffer'
- IF 0 ~= number THEN 're-search-forward "^l."number'
- ELSE DO
- /* try to use normal search ? */
- 're-search-forward "^l."' /* ^ means beg. of line */
- IF 0 = RC THEN DO /* search successfull */
- 'rexx-line' /* get current line contents */
- PARSE VAR RESULT "l."number .
- /*number = WORD(RESULT, 2) ?*/
- END
- END
- 'other-window'
- 'rexx-display "Now what''s that error?"'
- END
- ELSE DO
- 'rexx-display "Couldn''t find logfile associated with TeX error!"'
- /* EXIT 0 * 5? */
- END
- IF 0 ~= number THEN 'goto-line 'number
- END
- ELSE DO
- 'not-modified'
- 'kill-buffer "'buf.name'"' /* kill this empty buffer */
- 'rexx-display "Couldn''t find erroneous file !"'
- EXIT 5
- END
- EXIT 0
- END /* End of MG part*/
-
-
- /***********************************************/
- /* GoldED */
- /* Done by R.Laederach */
-
- IF SHOW('P', 'GOLDED.1') THEN DO /* Here I should get the right ARexx port on */
- /* the spot, but how can I know which GoldED */
- /* was used to edit the text when coming from*/
- ADDRESS "GOLDED.1" /* virtex? */
- OPTIONS RESULTS
-
- 'SCREEN FRONT'
-
- 'LOCK CURRENT'
-
- IF askload THEN DO
- 'REQUEST BUTTON="_Yep!|_Nope!" BODY="TeX found an error in the TeX source file. Load Files?"'
- if (RESULT = 'TRUE') THEN EXIT 0
- END
-
- IF "" ~= logfile THEN DO
- 'REQUEST HIDE = TRUE'
- 'WINDOW USE' logfile
- IF RC < 0 THEN QUIT
- 'REQUEST HIDE = FALSE'
- MORE
- 'WINDOW HEIGHT' 80 /* I still want to see my text */
- 'OPEN NAME' logfile
- 'GOTO TOP'
- IF 0 ~= number THEN 'FIND STRING=l.'||number
- else DO
- 'FIND STRING="l."'
- 'FIRST'
- 'QUERY BUFFER'
- PARSE VAR RESULT "l." number errorstring
- IF "" ~= errorstring THEN DO
- wordnumber = WORDS(errorstring)
- errorword = WORD(errorstring,wordnumber)
- END
- END
- END
- else DO
- 'REQUEST BODY="Could not find logfile associated with TeX error"'
- UNLOCK
- END
-
- 'WINDOW USE' errnfile
- notok = (RC ~= 0)
- if (notok) THEN DO
- MORE
- 'OPEN NAME' errnfile
- END
-
- IF 0 ~= number THEN DO
- 'GOTO LINE' number
- FIRST
- 'FIND QUIET NEXT STRING='||errorword /* Got him! */
- UNLOCK /* Important: Calling unlock.ged sucks! */
- END
-
- EXIT 0
- END /* End of GoldED part */
-
-
- SAY "TeXedit.rexx: No supported editor active."
- EXIT 10
-
- mygetenv: procedure /* when will ARexx supply GetEnv/SetEnv ? */
- PARSE ARG name
-
- IF open(TEMPFILE,"ENV:"||name,'r') THEN DO
- gives = readln(TEMPFILE)
- CALL close TEMPFILE
- END
- ELSE gives = ""
-
- RETURN gives
-