home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / text / tex / pastex / rexx / ttx / texedit.rexx < prev    next >
OS/2 REXX Batch file  |  1991-11-19  |  7KB  |  271 lines

  1. /*RX
  2.  * AREXX    Name:TeXedit.rexx    version:1.5JS        date:15-Nov-91
  3.  *
  4.  
  5. ATTENTION!! There were necessary changes out of the editors specific
  6.             part to include TTX. It will be possible to get them into
  7.             the specific part, just try it out. Until now, please
  8.             insert other editors at the end of this file, behind the
  9.             TTX-part. They still should work.
  10.  
  11.             If there is no line-number given the number will be fetched out
  12.             of the logfile.
  13.  
  14.  This ARexx script is called from virtex (or initex) in case of an
  15. error or if the 'e' command is used, and it's given the current file
  16. and line number as argument. It may be called from the TeX-server too.
  17. We will successively call TurboText (TTX) to load the file and the
  18. logfile. Other editors welcome!
  19.  *
  20. INPUTS:
  21.  1: filename to edit (please no spaces in filename)
  22.  2: line where error occured
  23.  *
  24. BUGS:
  25.  GETCLIP("TEXFILE") gets precedence over any other information for
  26. retrieving the logfile, so if you alternately start virtex directly
  27. from CLI while the server is active, the wrong files may be loaded.
  28.  *
  29.  This file tries to cope with the following version (PasTeX 1.2a)
  30. > This is a PD-Version of Pas-TeX (made Jan 30 1991 [br]/[hes])
  31. > This is TeX, C Version 3.1
  32. (The logfile is sometimes put at the wrong place.)
  33.  *
  34.  Does not handle names relative to the local root correctly (like ":foo/bar")
  35.  *
  36.  See each editor relative bugs below.
  37.  *
  38. FILES:
  39.  Rexx:namestruc
  40.  LIBS:rexxsupport.library
  41. AUTHORS:
  42.  *    J\"org H\"ohle, since March 91
  43.  *    Georg Hessmann, previous version
  44.  *  Jan Schroeder (not Schr\"oder!!), update for TurboText
  45.  */
  46.  
  47. /*
  48.  * IF ~SHOW('L','rexxsupport.library') THEN
  49.  *     IF ~ADDLIB('rexxsupport.library',0,-30,0) THEN DO
  50.  *         say "Can't open 'rexxsupport.library'!"
  51.  *         EXIT 20
  52.  *         END
  53.  */
  54.  
  55. /* The TeX server may want to know that we have been called */
  56.  
  57. CALL SETCLIP("TEXTIME",TIME('s'))
  58. PARSE ARG filename number .
  59.  
  60. /* if the TeX 'e' command was used to call the editor, don't ask if
  61.     files should be loaded. */
  62.  
  63. IF address() = 'TeX-Rexx-Port' & "EDIT" ~= UPPER(mygetenv("TEXREXX"))
  64. THEN askload = 0
  65. ELSE askload = 1
  66.  
  67. PARSE VALUE namestruc(filename) WITH ivol idirs ibase .
  68.  
  69. /* The idea behind the following statements is to get an absolute path
  70. for <filename>. The result will be stored in <errnfile>. For example, "CD
  71. TeX:bar" "virtex foo" should give <filename>=foo, and
  72. <errnfile>=TeX:bar/foo. This is necessary because the editor doesn't
  73. know where file foo is located, but will be able to load file
  74. TeX:bar/foo. */
  75.  
  76. mainname = GETCLIP("TEXFILE")
  77. if "" == mainname THEN DO
  78.    /* TeX has not been started through some Start_TeX.#? script. */
  79.    /* We have a hard time finding the right directories */
  80.  
  81.    texdir = pragma('d')
  82.  
  83.    /* Amiga OS dirnames should end with either : or /
  84.     thus you need just append the filename */
  85.    IF RIGHT(texdir,1)~=':' & RIGHT(texdir,1)~='/' THEN texdir = texdir||'/'
  86.  
  87.    IF 0 = ivol THEN DO
  88.     errnfile = texdir||SUBSTR(filename, 1+ivol)
  89.     /* The logfile is in the current dir */
  90.     logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
  91.     END
  92.    ELSE DO
  93.     errnfile=filename
  94.     IF 0 = idirs THEN
  95.  
  96.     /* This is a bug in virtex from PasTeX12a (made Jan 30 1991 [br]/[hes])
  97.     The logfile is *not* in virtex's directory, but rather in the
  98.     source's directory if a device name, but no subsequent directory was
  99.     given. I.e, virtex (CD in RAM) TeX:sample would put the errorfile in
  100.     TeX: and not in RAM: as it should be. */
  101.  
  102.     logfile = LEFT(filename, ivol+idirs+ibase)||".log"
  103.     ELSE logfile = texdir||SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
  104.     END
  105.    DROP texdir
  106.    END
  107.  
  108. ELSE DO    /* TeX was started through Start_TeX.#? scripts */
  109.     /* "TEXFILE" tells us CD and the main file */
  110.  
  111.    PARSE VALUE namestruc(mainname) WITH mvol mdirs mbase .
  112.    IF 0 ~= ivol THEN errnfile = filename
  113.    ELSE    errnfile = LEFT(mainname, mvol+mdirs)||SUBSTR(filename, 1+ivol)
  114.    logfile = LEFT(mainname, mvol+mdirs+mbase)||".log"
  115.    efile = RIGHT(mainname,mbase+4)
  116.    lfile = SUBSTR(filename, 1+ivol+idirs, ibase)||".log"
  117.    DROP mvol mdirs mbase
  118. END
  119.  
  120. /* 0 = ibase would mean that the call was incorrect, for example when
  121. TEXREXXEDIT says "TeXedit.rexx" and not "TeXedit.rexx %s %d" */
  122.  
  123. IF 0 = ibase | ~EXISTS(errnfile) THEN DO
  124.  say "TeXedit.rexx: Can't find erroneous file."
  125.  EXIT 10
  126. END
  127. ELSE IF ~EXISTS(logfile) THEN DO
  128.  say "TeXedit.rexx: Can't find log file."
  129.  logfile = ""
  130.  /* but we continue */
  131. END
  132.  
  133. DROP ivol idirs ibase
  134.  
  135.  
  136. /* turbotext part */
  137. IF SHOW('P', 'TURBOTEXT') THEN DO
  138.  
  139.     DO i=0 TO 20
  140.     h='TURBOTEXT'i
  141.     IF SHOW('P', h) THEN LEAVE
  142.     END
  143.  
  144.     ADDRESS VALUE h
  145.     OPTIONS RESULTS
  146.  
  147.     Screen2Front
  148.  
  149.     /* testen ob die Files nicht schon geladen sind. (hes) */
  150.  
  151.     IF askload THEN DO
  152.     RequestBool PROMPT errnfile TITLE '"TeX found an error! Load files?."'
  153.     IF "YES" ~= RESULT THEN EXIT
  154.     END
  155.  
  156.      /* TODO: We should really delete old logfiles automatically, without letting
  157.     CED open a requester to ask if an old modified file may be
  158.     overwritten or not */
  159.  
  160.      IF "" ~= lfile THEN DO
  161.  
  162.     getdocuments
  163.     docs = RESULT
  164.     i = 0
  165.     host = ""
  166.     DO WHILE docs ~= ''
  167.           PARSE VAR docs '"' a '"' port docs
  168.           IF a = lfile THEN DO
  169.             host = port
  170.         LEAVE
  171.           END
  172.           i = i+1
  173.     END
  174.  
  175.     IF "" = host THEN DO /* always assume the logfile currently
  176.         loaded is old, because TeX generated a new one. */
  177.         /*expand view*/
  178.         opendoc
  179.         host = RESULT
  180.     END
  181.  
  182.     ADDRESS VALUE host
  183.     openfile logfile
  184.     setreadonly    /* now it's non-editable */
  185.     MoveSOF
  186.     /* if we don't have the line number: search the number in the logfile (hes) */
  187.     /* bringt das wirklich etwas ? Der erste Fehler steht
  188.         sowieso gegen Anfang der Logdatei */
  189.     IF 0 ~= number THEN find "l."||number
  190.     ELSE DO
  191.       find "l."
  192.       GetCursorPos
  193.       PARSE VAR RESULT l c f
  194.       GetLine c
  195.       PARSE VAR RESULT n dum
  196.       number = SUBSTR(n,3)
  197.         END
  198.    END
  199.    ELSE  RequestBool PROMPT '"Couldn''t find logfile"' TITLE '"Where is the Log-File?"'
  200.  
  201.   /*
  202.    * CleanUp
  203.    */
  204.  
  205.   GetDocuments
  206.   docs       = RESULT
  207.   numWindows = Words(docs)/2
  208.  
  209.   GetScreenInfo
  210.   screenWidth  = Word(RESULT,3)
  211.   screenHeight = Word(RESULT,4)
  212.  
  213.   wHeight = (screenHeight-2) % numWindows
  214.   yPos    = 2
  215.  
  216.   DO i=1 TO numWindows
  217.     IF (i = numWindows) THEN DO
  218.       wHeight = wHeight+2
  219.     END
  220.  
  221.     INTERPRET ADDRESS Word(docs,(i*2))
  222.     GetWindowInfo
  223.     PARSE VAR RESULT dum wX wY sX sY .
  224.  
  225.     /* If sizing first would put it off the screen, size it last */
  226.     IF ((wY+wHeight > screenHeight) | (wX>0)) THEN DO
  227.       MoveWindow (-wX) (yPos-wY)
  228.       SizeWindow screenWidth-sX (wHeight-2)-sY
  229.  
  230.     END; ELSE DO
  231.       SizeWindow screenWidth-sX (wHeight-2)-sY
  232.       MoveWindow (-wX) (yPos-wY)
  233.  
  234.     END
  235.  
  236.     yPos = yPos+wHeight
  237.   END
  238.  
  239.   GetPort efile
  240.   host = RESULT
  241.   ADDRESS VALUE host
  242.  
  243.   ActivateWindow
  244.   IF 0 ~= number THEN move number
  245.   MoveSOL
  246.  
  247.   EXIT
  248. END    /* End of TTX part */
  249.  
  250.  
  251.  
  252. /*
  253.  * Insert other editors here
  254.  */
  255.  
  256.  
  257.  
  258. SAY "TeXedit.rexx: No supported editor active."
  259. EXIT 10
  260.  
  261. mygetenv: procedure    /* when will ARexx supply GetEnv/SetEnv ? */
  262.    PARSE ARG name
  263.  
  264.    IF open(TEMPFILE,"ENV:"||name,'r') THEN DO
  265.     gives = readln(TEMPFILE)
  266.     CALL close TEMPFILE
  267.     END
  268.    ELSE gives = ""
  269.  
  270.    RETURN gives
  271.