home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / rexx / start_tex.mg < prev    next >
Text File  |  1991-07-28  |  3KB  |  111 lines

  1. /*RX
  2.  * AREXX    Name:Start_TeX.mg    Version:1.41    Date:27-Jul-91
  3.  *
  4.  This AREXX script saves and compiles the current MicroGNUEmacs
  5. buffer. The only (optional) argument is the format to be used. A '?'
  6. formatname will interactively ask for the format to use.
  7.  *
  8.  A command is send to the TeX server to compile the file. Hence a
  9. return value of 0 does not mean that the file compiled well, but only
  10. that the command was sent to the server and replied to. 
  11.  *
  12. AUTHOR:
  13.  *    J\"org H\"ohle, March 91
  14.  *
  15. BUGS:
  16.  virtex doesn't like filenames with blanks (and ARexx parses them
  17. hardly too), so avoid them in file, directory *and* device names.
  18.  *
  19. FILES:
  20.  ENV:TEXFORMAT: default format used
  21.  *
  22.  */
  23.  
  24. OPTIONS FAILAT 3
  25. OPTIONS RESULTS
  26.  
  27. portname = 'Start_TeX'
  28. script = 'TeX-server.rexx'    /* no path required, message only    */
  29.  
  30. IF "" = GETCLIP("TEXQUERY") THEN askformat = 0
  31. ELSE askformat = 1        /* ask interactively for format name    */
  32.  
  33. PARSE ARG format .
  34. IF "?" = format THEN DO
  35.     askformat= 1
  36.     format     = ""
  37.     END
  38. ELSE IF '&' = LEFT(format,1) THEN
  39.     format = SUBSTR(format,2)
  40.  
  41. 'rexx-buffer' buf
  42. /* buf.2 is the complete filename (beware of spaces) */
  43.  
  44. IF "TEX" ~= UPPER(RIGHT(buf.2,3)) THEN DO
  45.     /* more foolproof : use namestruc() to verify extension */
  46.     'rexx-display "Sorry, filename must end in `tex''."'
  47.     EXIT 5
  48.     END
  49.  
  50. 'save-buffer'
  51. /* fails if file is write protected */
  52.  
  53. IF (SHOW('P', portname)) THEN DO
  54.     envformat = mygetenv("TEXFORMAT")
  55.     IF "" = format THEN DO
  56.         format = envformat
  57.         IF askformat | "" = envformat THEN DO
  58.         IF "" = format THEN format = 'plain'
  59.  
  60.         'rexx-request "Which format to use ? (default 'format') "'
  61.         /* 0: answered, 1: default, 2: abort(^G) */
  62.         IF 0 = RC THEN format = RESULT
  63.         ELSE IF 1 < RC THEN DO
  64.             'rexx-display ""'
  65.             EXIT 5
  66.             END
  67.  
  68.         END /* askformat */
  69.         END /* !format */
  70.  
  71.     if format ~= envformat THEN CALL mysetenv("TEXFORMAT",format)
  72.  
  73.     'rexx-display "Calling TeX server 'portname'."'
  74.     
  75.     /* We want to free MG if the TeX server is just busy with
  76.         another file */
  77.     'rexx-unlock'
  78.     /* we free this MG port and get the name of a new one for later use */
  79.     freeMG = RESULT
  80.  
  81.     ADDRESS VALUE portname
  82.     'compile' format buf.2
  83.     ADDRESS VALUE freeMG
  84.     'rexx-display "TeX server called for file 'buf.2'."'
  85.     END
  86. ELSE DO
  87.     /* The TeX server must be started first */
  88.     'rexx-display "The TeX server 'script' is not running !"'
  89.     EXIT 5
  90.     END
  91. EXIT
  92.  
  93.  
  94. mygetenv: procedure    /* when will ARexx supply GetEnv/SetEnv ? */
  95.    PARSE ARG name
  96.  
  97.    IF open(TEMPFILE,"ENV:"||name,'r') THEN DO
  98.     gives = readln(TEMPFILE)
  99.     CALL close TEMPFILE
  100.     END
  101.    ELSE gives = ""
  102.  
  103.    RETURN gives
  104.  
  105. mysetenv: procedure
  106.    PARSE ARG name,content
  107.  
  108.    ADDRESS COMMAND "SetEnv" name content
  109.  
  110.    RETURN
  111.