##
## This is file `api-example.tcl',
## generated with the docstrip utility.
##
## The original source files were:
##
## api.dtx  (with options: `examples')
## 
##
## ===================================================================
## AlphaTcl - core Tcl engine
##                                   created: 2001-10-06 21:13:40
##                               last update: 2001-11-09 13:15:59
## Author: Frˇdˇric Boulanger
## E-mail: Frederic.Boulanger@supelec.fr
##   mail: Supˇlec - Service Informatique
##         Plateau de Moulon, 3 rue Joliot-Curie
##         F-91192 Gif-sur-Yvette cedex
##    www: http://wwwsi.supelec.fr/fb/
##
## Description:
##
##   The api package manages the declaration of APIs and of
##   implementations of these APIs with real applications in the
##   AlphaTcl library.
##
##   See api.dtx or its typeset form (api.pdf for instance) for the
##   documentation of this package.
##
## History
##
## modified   by  rev reason
## ---------- --- --- -----------
## 2001-10-06 FBO 1.0 original
## 2001-10-23 FBO 1.1 handle app paths as well as creators
## ===================================================================
###### API examples #######
## "tex" is an API that uses a filename, a format and options.
## format defaults to "tex " and options to nothing
api::declare tex "Typeset a file with TeX" filename {format latex} {options ""}
## same for "pdftex"
api::declare pdftex "Typeset a file with pdfTeX" filename {format pdflatex} {options ""}
## "dvips" is an API that uses a filename and options
api::declare dvips "Convert a DVI file to PostScript" filename {options ""}
## "ps2pdf is an API that uses a filename a paper size and options
## The default value of papersize is "a4"
api::declare ps2pdf "Distill a PostScript file into PDF" filename {options ""} {papersize a4}

if {${alpha::platform} == "alpha"} {
  # Mac OS applications
  # Use CMacTeX for tex, pdftex and dvips
  api::registerApp tex CMacTeX *XeT {
    AEBuild $apiTarget CMTX exec \
      ---- [tclAE::build::TEXT "tex &$format [file tail $filename]"] \
      dest [tclAE::build::alis "[file dirname $filename]:"]
  }
  api::registerApp pdftex CMacTeX *XeT {
    AEBuild $apiTarget CMTX exec \
      ---- [tclAE::build::TEXT "pdftex &$format [file tail $filename]"] \
      dest [tclAE::build::alis "[file dirname $filename]:"]
  }
  api::registerApp dvips CMacTeX *XeT {
    AEBuild $apiTarget CMTX exec \
      ---- [tclAE::build::TEXT "dvips $options \"$filename\""]
  }
  # Use macps2pdf for ps2pdf
  api::registerApp ps2pdf MacGhostView TMCA {
    set cmdline ""
    append cmdline "gs $options -dCompatibilityLevel=1.2 -dMaxSubsetPct=100"
    append cmdline " -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=$papersize"
    append cmdline " -sOutputFile=[file rootname [file tail $filename]].pdf"
    append cmdline " -c save pop -f [file tail $filename]"
    AEBuild $apiTarget CMTX exec \
     ---- [tclAE::build::TEXT $cmdline] \
     dest [tclAE::build::alis "[file dirname $filename]:"]
  }
  # We may also register OzTeX for tex
  api::registerApp tex OzTeX OTEX {
    sendOpenEvent noReply $apiTarget $filename
  }
} else {
  # Windows or Unix applications
  api::registerApp tex miktex csh {
    tex $options &$format $filename
  }
  api::registerApp pdftex miktex csh {
    pdftex $options &pdf$format $filename
  }
  api::registerApp dvips miktex csh {
    dvips $options $filename
  }
  api::registerApp ps2pdf miktex csh {
    gs $options -dCompatibilityLevel=1.2 -dMaxSubsetPct=100 -dNOPAUSE \
     -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=$papersize \
     -sOutputFile=[file rootname $filename].pdf \
     -c save pop -f $filename
  }
}
#
api::chooseAppFor tex CMacTeX
api::chooseAppFor pdftex CMacTeX
api::chooseAppFor dvips CMacTeX
api::chooseAppFor ps2pdf MacGhostView

api::invoke -foreground tex -format latex -filename [file join [pwd] essai.tex]
api::invoke -foreground dvips -filename [file join [pwd] essai.dvi]
api::invoke -foreground ps2pdf -filename [file join [pwd] essai.ps]
## 
##
## End of file `api-example.tcl'.
