home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / rexx / ttx / tex-server.rexx < prev    next >
OS/2 REXX Batch file  |  1991-11-16  |  8KB  |  301 lines

  1. /*RX
  2.  * AREXX    NAME:TeX-server.rexx    Version:1.5JS    DATE:15-Nov-91
  3.  *
  4.  *  Changed by Jan Schroeder to activate SDVI after loading ***
  5.  *
  6.  *  This script creates an ARexx port, by the name of
  7.  *
  8.  *    Port Name = "Start_TeX"
  9.  *
  10.  * and waits there for the commands
  11.  *
  12.  *    - compile <format-file> <TeX-file including-absolute-path>
  13.  *        - the filename *must* have an extension.
  14.  *        - if <format-file>=='&', use tex'es default format.
  15.  *    - quit
  16.  *        exits the server.
  17.  *
  18.  * It may be called with one parameter: the name of the public screen
  19.  * (OS 2.0) in which this server runs.
  20.  *
  21. AUTHORS:
  22.  *             April 91        J\"org H\"ohle
  23.  *        before        Georg Hessmann
  24. NOTES:
  25.  An `absolute path' is given if you use a volume, device or assign'ed
  26. name like TeX_Disk1:, RAM: or TeX:.
  27.  *
  28.  * Make virtex resident (ARP or AmigaDOS, depending on your shell), or
  29. include it in your shell path. However the default of 'virtex' may be
  30. overridden at any time by the ARexx variable virtex (lowercase!) (see
  31. further below). This has been implemented to be able to switch
  32. between smallTeX and BigTeX on the fly.
  33.  *
  34. BUGS:
  35.  Does not allow blanks in filenames and directories, because neither
  36. ARexx nor TeX are happy with them.
  37.  *
  38. FILES:
  39.  Rexx:namestruc        : namestruc is a function, and must stay in REXX:
  40.                 for now. Sorry about that.
  41.  Libs:rexxsupport.library
  42.  *
  43.  */
  44.  
  45. portname = "Start_TeX"        /* PortName */
  46.  
  47. /* Failat 10 */
  48. OPTIONS RESULTS
  49.  
  50. PARSE ARG PubScreen
  51. IF PubScreen = "" THEN PubScreen = "Workbench"
  52.  
  53. IF ~show('L','rexxsupport.library') THEN
  54.     IF ~addlib('rexxsupport.library',0,-30,0) THEN DO
  55.         say "Can't open 'rexxsupport.library'!"
  56.         EXIT 20
  57.         END
  58.  
  59. /* ARexx V1.10 sets RC to Result * 65536 + Result2
  60.      V1.14 and 1.15 set RC to Result    on a shell command call.
  61. */
  62. parse version . rexxver .
  63. filter2 = rexxver < "V1.14"
  64. /*say 'ver'rexxver 'filter 'filter2*/
  65.  
  66. SIGNAL ON break_C
  67. SIGNAL ON break_D
  68.  
  69. FALSE = 0
  70. TRUE = 1
  71.  
  72. say
  73. say "*******************************************************"
  74. say "*                                                     *"
  75. say "*    Welcome to the ARexx - Passauer TeX Interface    *"
  76. say "*                                                     *"
  77. say "*******************************************************"
  78.  
  79. say
  80. oldedit = upper(mygetenv(TEXREXX))
  81. /* default is no change, logical ? */
  82. IF "EDIT" = oldedit THEN DO
  83.     OPTIONS PROMPT "Call editor automatically on first error (Y/n)? "
  84.     PARSE UPPER PULL yn .
  85.     IF LEFT(yn,1) = "N"    THEN newedit = "e"
  86.                 ELSE newedit = "edit"
  87.     END
  88. ELSE DO
  89.     OPTIONS PROMPT "Call editor automatically on first error (y/N)? "
  90.     PARSE UPPER PULL yn .
  91.     IF LEFT(yn,1) = "Y"    THEN newedit = "edit"
  92.                 ELSE newedit = "e"
  93.     END
  94.  
  95. IF UPPER(newedit) ~= oldedit THEN CALL mysetenv(TEXREXX,newedit)
  96. /* if it were undefined, virtex would call ENV:EDITOR.
  97.      We want Rexx scripts to be used (TeXEdit.rexx). */
  98. DROP newedit oldedit
  99.  
  100. say
  101. OPTIONS PROMPT "Ask for format when default requested (y/N) ? "
  102. PARSE UPPER PULL yn .
  103. IF (LEFT(yn,1) = "Y") THEN
  104.   CALL SETCLIP("TEXQUERY","TRUE")
  105. ELSE
  106.   CALL SETCLIP("TEXQUERY")
  107.  
  108. OPTIONS PROMPT "? >"
  109. DROP yn
  110.  
  111. say
  112. say "- Opening port "portname"."
  113.  
  114. IF ~openport(portname) THEN DO
  115.   say
  116.   say "- Can't open it !"
  117.   EXIT 20
  118. END
  119.  
  120.  
  121. empty = FALSE
  122.  
  123. mainloop:
  124. DO UNTIL com = 'quit'
  125.  
  126.   IF ~empty THEN DO
  127.     CALL SETCLIP("TEXTIME")
  128.     say "- Waiting for command (compile/quit) on port "portname"."
  129.   END
  130.  
  131.   CALL waitpkt(portname)
  132.  
  133.   packet = getpkt(portname)
  134.   IF (packet == NULL()) THEN empty = TRUE /* say "- Received NULL packet." */
  135.           /* ARexx 1.14 and 1.15 tend to send *lots* of NULL packets */
  136.   ELSE DO
  137.  
  138.     empty = FALSE
  139.  
  140.     PARSE VALUE getarg(packet) WITH com format fullname
  141.  
  142.     CALL REPLY(packet, 0)
  143.  
  144.     IF (com = 'compile') THEN DO
  145.  
  146.     /* and now, Server-to-front */
  147.     ADDRESS COMMAND PToFront PubScreen
  148.     /* Result: 5: not OS 2.0, 10: PubScreen not found,
  149.         15: no Intuition.library. */
  150.  
  151.     IF '&' ~= left(format,1) THEN format = '&'||format
  152.     ELSE IF '&' = format THEN format = "" /* use virtex default format */
  153.  
  154.     fullname = STRIP(fullname)    /* beware of blanks (eg RAM DISK:) */
  155.  
  156.     /* make RAM DISK: a special case */
  157.     IF "RAM DISK:" = UPPER(LEFT(fullname,9)) THEN
  158.          fullname="RAM:"||SUBSTR(fullname,10)
  159.  
  160. /* KLUDGE: Do NOT accept names with blanks, I could do a better job here */
  161.     IF 0 ~= INDEX(fullname," ") THEN
  162.        say "- Sorry, no spaces in filenames :"fullname
  163.     ELSE DO
  164.  
  165. /**     namestruc fullname
  166.      if 0 ~= RC THEN DO
  167.         say "- Function "namestruc" not found, aborted!"
  168.         SIGNAL finish
  169.         END
  170.      PARSE VALUE RESULT WITH ivol idir iname .
  171. **/
  172.      PARSE VALUE namestruc(fullname) WITH ivol idir iname .
  173.  
  174.      texdir = LEFT(fullname, ivol+idir)  /*(TeX:doc/sample.tex-> TeX:doc/)*/
  175.      nameonly = SUBSTR(fullname, 1+ivol+idir)        /*(sample.tex)*/
  176.      baseonly = SUBSTR(fullname, 1+ivol+idir, iname)    /*(sample)*/
  177.      fullbase = LEFT(fullname, ivol+idir+iname)    /*(TeX:doc/sample)*/
  178.  
  179.      IF 0=ivol THEN DO
  180.        say "- An absolute path must be used (eg. <device|volumename>:...) !"
  181.        END
  182.      ELSE IF (SUBSTR(fullname, 1+ivol+idir+iname,1) ~= ".") THEN DO
  183.        say "- Sorry, filename must have a .<extension> :"fullname
  184.        END
  185.      ELSE DO
  186.  
  187.       IF ~EXISTS(fullname) THEN DO
  188.        say "- Couldn't locate "fullname" ! Missing a path ?"
  189.        END
  190.       ELSE DO
  191.  
  192.        CALL DELETE(fullbase||".log")
  193.        /* I feel there's no need to delete the .dvi file. */
  194.  
  195.        virtex = GETCLIP("virtex")    /* get TeX or bigTeX */
  196.        IF "" = virtex THEN virtex = 'virtex'
  197.  
  198.        say '- Start command: 'virtex format nameonly
  199.        say '   in directory 'texdir
  200.        CALL PRAGMA('directory',texdir)
  201.  
  202.        CALL SETCLIP("TEXFILE",fullname)
  203.        now = TIME('s')
  204.        CALL SETCLIP("TEXTIME",now)
  205.  
  206. /* The "< *" is a hack, no ? */
  207.        ADDRESS COMMAND virtex' < * 'format nameonly
  208.  
  209. /* How can I get rid of the Rexx message "+++ Command returned >=65536"
  210.    with versions of ARexx <= V1.10 ? */
  211.        IF filter2 THEN errorcode = RC % 65536 /* ARexx V1.10    */
  212.        ELSE           errorcode = RC      /* ARexx V1.14, V1.15    */
  213.        IF errorcode == 0 THEN DO
  214.         say
  215.         say "- Compiled file "fullname" without errors."
  216.         IF (SHOW('P','showdvi')) THEN DO
  217.            ADDRESS "showdvi"
  218.            OPTIONS RESULTS
  219.            getfile
  220.            loadedfile = RESULT
  221.            getdir
  222.            loadeddir = RESULT
  223.            IF RIGHT(loadeddir,1)~=':' & RIGHT(loadeddir,1)~='/' THEN
  224.                loadeddir = loadeddir||'/'
  225.            IF texdir = loadeddir & 1 = INDEX(UPPER(loadedfile||".dvi"),UPPER(baseonly||".dvi")) THEN DO
  226.             say "- Updating file in ShowDVI."
  227.             loadagain
  228.             END
  229.            ELSE DO
  230.             say "- Loading file "fullbase".dvi into ShowDVI."
  231.             loadnew fullbase||".dvi"
  232.             END
  233.            tofront
  234.            activate
  235.            END
  236.         ELSE DO
  237.            say "- ShowDVI is not running."
  238.            END
  239.         END
  240.        ELSE DO
  241.         say
  242.         say "- Compilation not successful, error level "errorcode"."
  243.         IF getclip("TEXTIME") == now & EXISTS(fullbase||".log") THEN DO
  244.           editscript = WORD(mygetenv("TEXREXXEDIT"),1)
  245.           IF "" = editscript THEN editscript = 'TeXedit.rexx'
  246.           say "- Calling editor for file "fullname" via "editscript"."
  247.           editscript fullname 0
  248.           END
  249.         END
  250.        END    /* exists */
  251.       END    /* !ivol, "." */
  252.      END    /* !index */
  253.     END    /* compile */
  254.     END        /* !NULL() */
  255.   END        /* do */
  256.  
  257. finish:
  258.  
  259. ADDRESS COMMAND PToFront PubScreen
  260. /* Result: 5: not OS 2.0, 10: PubScreen not found, 15: no Intuition.library */
  261.  
  262. say "- Closing down port "portname
  263. CALL CLOSEPORT portname
  264.  
  265. IF PubScreen ~= "Workbench" THEN
  266.     say "  Type CTRL-\ or hit the CLOSE Gadget to close the window."
  267.     /* das koennte man im Prinzip immer (unter 2.0) ausgeben */
  268.  
  269. SIGNAL cleanup
  270.  
  271. break_C:
  272. break_D:
  273. say
  274. say "- Break received."
  275.  
  276. cleanup:
  277. CALL SETCLIP("TEXFILE")
  278. CALL SETCLIP("TEXTIME")
  279. CALL SETCLIP("TEXQUERY")
  280. EXIT
  281.  
  282.  
  283. mygetenv: PROCEDURE    /* when will ARexx supply GetEnv/SetEnv ? */
  284.    PARSE ARG name
  285.  
  286.    IF open(TEMPFILE,"ENV:"||name,'r') THEN DO
  287.     gives = readln(TEMPFILE)
  288.     CALL close TEMPFILE
  289.     END
  290.    ELSE gives = ""
  291.  
  292.    RETURN gives
  293.  
  294. mysetenv: PROCEDURE
  295.    PARSE ARG name,content
  296.  
  297.    ADDRESS COMMAND "SetEnv" name content
  298.  
  299.    RETURN
  300.  
  301.