#!/bin/csh -f
#
# Preview PostScript file and delete it after viewing
#
# Parameters
#    Postscript file path

set file = "$1"

if ($?WINDIR) then

   #
   # Convert backslashes to forward slashes
   #

   set file = "$file:as#\\#/#"

   #
   # Set to full path of postscript viewer
   #

   # set viewer = "<Path of postscript viewer>"

   set acro_path = (c:/Program\ Files/Adobe/*/Acrobat/Acrobat.exe)
   set acro_path = "$acro_path[1]"

   set gv_viewer   = 'gv'
   set gv_path     = (`which "$gv_viewer"`)

   if ($?viewer) then

      ("$viewer "$file"; \rm "$file") &

   else if (-f "$acro_path") then

      set tmp_file = $TMP/ps_preview.$$
      set local_dir = "$0:h"
      source $local_dir/ps2pdf "$file" $tmp_file
      if ($status == 1) then
         exit 1
      endif
      setenv TCSH_NOASYNCGUI 1
      ("$acro_path" $tmp_file; \rm $tmp_file) &

   else if (-f "$gv_viewer") then

      ("$gv_viewer" "$file"; \rm "$file") &

   else
      echo "Can't find Postscript viewer"
      exit 1
   endif 

else

   #
   # Unix/Linux section
   #

   #
   # Set to name or full path of viewer
   #
   set acro_viewer = 'acroread'
   set gv_viewer   = 'gv'
   set acro_path   = (`which "$acro_viewer"`)
   set gv_path     = (`which "$gv_viewer"`)

   if (-f "$acro_path") then
      set tmp_file = /tmp/ps_preview.$$
      ps2pdf "$file" $tmp_file
      if ($status == 0) then
         ("$acro_viewer" $tmp_file; \rm $tmp_file) &
      endif
   else if (-f "$gv_path") then
      ("$gv_viewer" "$file"; \rm "$file") &
   else
      echo "Can't find Postscript viewer"
      exit 1
   endif 

endif
