[comp.lang.rexx] AmigaTeX/TurboText scripts

giguere@csg.uwaterloo.ca (Eric Giguere) (06/20/91)

Here are three ARexx scripts I've written.  Two are useful to all owners
of AmigaTeX.  The third is useful only to those who have AmigaTeX and who
use TurboText as their text editor.

Eric Giguere
giguere@csg.uwaterloo.ca

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README StartTeX QuitTeX TeXify.ttx
# Wrapped by giguere@watserv1 on Thu Jun 20 01:43:58 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1060 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
XStartTeX, QuitTeX, and TeXify.ttx
X---------------------------------
X
XHere are three ARexx macros useful to AmigaTeX users.  The StartTeX script
Xstarts AmigaTeX (version 3) and the previewer.  The QuitTeX script tells
Xthe two programs to leave.  A third script, TeXify.ttx, is only useful
Xto TurboText users.  It takes the current document and passes it to AmigaTeX
Xfor processing, and reports any errors that occur.
X
XRead the comments in the scripts for documentation... 
X
XNote:  StartTeX and QuitTeX should not have a ".rexx" appended to the
X       filenames.  This is so that you can do things like
X
X                rx starttex
X
X       and still be able to do a "call StartTeX" from within a text
X       editor script.  In other words, the default extension might change
X       so we just don't use any extensions....
X
XThese are my initial passes at these macros.  They seem to work well enough.
XPlease let me know if there are features that need adding, or things that
Xdon't seem to work.
X
XEric Giguere
XBIX:      giguere
XInternet: giguere@csg.uwaterloo.ca
END_OF_FILE
if test 1060 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'StartTeX' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'StartTeX'\"
else
echo shar: Extracting \"'StartTeX'\" \(2498 characters\)
sed "s/^X//" >'StartTeX' <<'END_OF_FILE'
X/*
X * StartTeX -- Load AmigaTeX & the previewer if they're not already active.
X *             You may wish to customize the lines that actually start
X *             the programs.  The basic idea behind this program is to
X *             check for the 'AMIGATEX' and 'TEXPREVIEW' ARexx ports...
X *             if they don't exist then we assume the programs aren't loaded
X *             and so we start them going.  You must be using AmigaTeX
X *             version 3.0 or higher.
X *
X *   Dependencies:  Assumes "tex" and "previewer" are in the "tex:c"
X *                  directory.
X *
X * Written by Eric Giguere.  This script is placed in the public domain,
X * so do what you will with it.
X */
X
Xaddress command
X
X/* Load in rexxsupport.library if necessary */
X
Xif( ~show( 'l', 'rexxsupport.library' ) )then do
X    if( ~addlib( 'rexxsupport.library', 0, -30, 0 ) )then do
X        say "Could not open rexxsupport.library!"
X        exit 10
X    end
Xend
X
X/* Start up TeX & the previewer -- customize this if you want.  What
X   this does is write a two-line AmigaDOS script:
X
X           tex:c/tex -R
X           endcli
X
X   and then starts a new shell using this script.  When AmigaTeX
X   exits, the endcli will then cause the shell to quit as well...
X   A similar trick is used for the previewer.  I like to open a
X   CLI for the previewer because when the previewer starts Metafont
X   automatically I like to see how MF is progressing... */
X
Xif( ~show( 'p', 'AMIGATEX' ) )then do
X    'echo >t:starttex "tex:c/tex -R*Nendcli"'
X    'newshell con:0/30/640/120/TeX from t:starttex'
Xend
X
Xif( ~show( 'p', 'TEXPREVIEW' ) )then do
X    'echo >t:startpreview "tex:c/preview*Nendcli"'
X    'newshell con:0/12/640/29/Preview from t:startpreview'
Xend
X
X/*
X * Wait for preview to show up, then tell it to move to the back.
X */
X
Xif( ~WaitForPort( 'TEXPREVIEW' ) )then do
X    say "Previewer could not be started."
X    exit 10
Xend
X
Xaddress 'TEXPREVIEW' 'toback'
X
X/*
X * Wait for AmigaTeX to show up (it may take it longer), then tell it
X * to move to the front.
X */
X
Xif( ~WaitForPort( 'AMIGATEX' ) )then do
X    say "AmigaTeX could not be started."
X    exit 10
Xend
X
Xaddress 'AMIGATEX' 'tofront'
X
Xexit 0
X
X
X
X/*
X * WaitForPort -- Wait a while for a port to arrive.  Checks every
X *                half-second or so.
X */
X
XWaitForPort: procedure
X
X    if( arg() ~= 1 ) then return 0
X
X    name = arg(1)
X
X    do i = 1 to 20
X        if( show( 'p', name ) ) then return 1
X        call delay 25
X    end
X
X    return( show( 'p', name ) )
X
END_OF_FILE
if test 2498 -ne `wc -c <'StartTeX'`; then
    echo shar: \"'StartTeX'\" unpacked with wrong size!
fi
# end of 'StartTeX'
fi
if test -f 'QuitTeX' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'QuitTeX'\"
else
echo shar: Extracting \"'QuitTeX'\" \(403 characters\)
sed "s/^X//" >'QuitTeX' <<'END_OF_FILE'
X/*
X * QuitTeX -- If AmigaTeX & the previewer are running, tell them to quit.
X *
X * Written by Eric Giguere.  This script is placed in the public domain,
X * so do what you will with it.
X */
X
Xoptions failat 101 /* previewer sets RC to 100 when exit is sent... */
X
Xif( show( 'p', 'TEXPREVIEW' ) )then
X    address 'TEXPREVIEW' 'Exit'
X
Xif( show( 'p', 'AMIGATEX' ) )then
X    address 'AMIGATEX' 'Exit'
X
Xexit 0
END_OF_FILE
if test 403 -ne `wc -c <'QuitTeX'`; then
    echo shar: \"'QuitTeX'\" unpacked with wrong size!
fi
# end of 'QuitTeX'
fi
if test -f 'TeXify.ttx' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'TeXify.ttx'\"
else
echo shar: Extracting \"'TeXify.ttx'\" \(3857 characters\)
sed "s/^X//" >'TeXify.ttx' <<'END_OF_FILE'
X/*
X * TeXify.ttx -- An ARexx script for use with the TurboText editor to
X *               "texify" the current document.  It performs the following
X *               steps:
X *
X *                    1. Makes sure the current document has been saved
X *                       to disk (aborts if not).
X *                    2. Starts AmigaTeX and the previewer if not
X *                       already loaded (calls the StartTeX script).
X *                    3. Tells AmigaTeX & the previewer to change
X *                       directories.
X *                    4. Passes the name of the current document to
X *                       AmigaTeX.  (It's up to you to configure the
X *                       previewer to do any tracking...)
X *                    5. When AmigaTeX finishes, displays any errors
X *                       that have occurred.
X *
X *               Unfortunately at this time TurboText only offers limited
X *               capability requesters and I didn't feel like using
X *               rexxarplib so error reporting could be a little cleaner.
X *
X * Depends on:
X *     StartTeX() external function
X *
X *  Written by Eric Giguere... placed in the public domain.
X */
X
Xoptions results
Xoptions failat 5
X
X/* Get the name of the current document we're editing, then get
X   its path. */
X
X'GetFileInfo'
Xparse var result lines ' ' mod ' "' filename '"'
X
Xif( mod = "YES" | filename = "" )then do
X    call ErrorExit "Please save your file first!"
Xend
X
X'GetFilePath'
Xfullpath  = result
Xindex     = lastpos( filename, fullpath )
X
Xif( index = 0 )then do
X    call ErrorExit "Internal Error! Should not happen!"
Xend
X
Xpathonly = left( fullpath, index - 1 )
X
X/* Start TeX and the previewer... this brings TeX up front as well */
X
X'SetCurrentDir' pathonly
X'Screen2Back'
X
Xif( StartTex() ~= 0 )then do
X    call ErrorExit "Could not start TeX!"
Xend
X
X/* Make sure TeX is in a clean state, then tell it and the previewer to
X   change directories. */
X
Xcall DoAbortTeX
X
Xaddress 'AMIGATEX' 'CD' pathonly
Xaddress 'TEXPREVIEW' 'CD' pathonly
X
X/* Great!  Now tell TeX to TeXify it... */
X
Xaddress 'AMIGATEX' 'TeXify' filename
Xaddress 'AMIGATEX' 'NextPrompt'
Xaddress 'AMIGATEX' 'Prompt'
X
X/* If AmigaTeX can't find a file, ask user for it... */
X
Xdo while( result = 'file' )
X    'Screen2Front'
X    'RequestStr PROMPT "TeX is waiting for a file:" "nul.tex"'
X    newfile = result
X    'Screen2Back'
X    address 'AMIGATEX' 'ToFront'
X    address 'AMIGATEX' 'TeXify' newfile
X    address 'AMIGATEX' 'NextPrompt'
X    address 'AMIGATEX' 'Prompt'
Xend
X
X/* Did an error occur? */
X
Xif( result ~= '**' )then do
X    address 'AMIGATEX' 'ErrorLoc'
X    parse var result errfile errline errcol
X    call DoAbortTeX
X    'Screen2Front'
X
X    /* If the error occurred, first search through the list of active
X       documents for it, otherwise load it in a new document. */
X
X    'GetDocuments'
X    list  = result
X    found = 0
X
X    do while( list ~= "" & found = 0 )
X        parse var list '"' currfilename '" ' portname list
X        if( currfilename = errfile )then found = 1
X    end
X
X    if( found = 0 )then do
X        'OpenDoc'
X        portname = result
X        address value portname
X        'SetCurrentDir' pathonly
X        'OpenFile QUIET' errfile
X    end
X
X    address value portname
X    'Window2Front'
X    'ActivateWindow'
X    'Move' errline errcol
X    'RequestBool "TeXify Error" "Error in file ' || errfile || '"'
Xend
X
Xexit 0
X
X
X
X/* Display an error message and quit */
X
XErrorExit: procedure
X    'Screen2Front'
X    'RequestBool "TeXify Error" "' || arg(1) || '"'
X    exit 0
X
X/* This function merely kicks AmigaTeX a few times
X   until it's in a known state */
X
XDoAbortTeX: procedure
X    address 'AMIGATEX'
X    'Abort'
X    do i = 1 to 10 while rc ~= 0
X        'NextPrompt'
X        'Abort'
X    end
X    if( rc ~= 0 )then do
X        call ErrorExit "Could not wake TeX up!"
X    end
X    return
END_OF_FILE
if test 3857 -ne `wc -c <'TeXify.ttx'`; then
    echo shar: \"'TeXify.ttx'\" unpacked with wrong size!
fi
# end of 'TeXify.ttx'
fi
echo shar: End of shell archive.
exit 0

-- 
Eric Giguere                                       giguere@csg.UWaterloo.CA
           Unlike the cleaning lady, I have to do Windows.