home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
text
/
tex
/
pastex
/
rexx
/
texedit.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1991-07-28
|
10KB
|
330 lines
/*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) 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.)
*
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
*/
/* call trace('all') */
/**
TeXRexx = "TeX:rexx/" / * 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,