#!/bin/sh

# Launcher script for advi with support for .gz and .bz2 files
# Copyright (C) 2003 
#   Stefano Zacchiroli <zack@debian.org>, 
#   Sylvain LE GALL <sylvain.le-gall@polytechnique.org>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# See /usr/share/common-licenses/GPL on a Debian GNU/Linux system.

ADVI="/usr/bin/advi"
UNZIP="/bin/gunzip"
BUNZIP="/usr/bin/bunzip2"
RM="/bin/rm"
UNGZFILE=""
DVIFILE=""

# Using trap to handle all signals that can be send / received
# and send it to advi

SIGNALS=" 1  2  3  4  5  6  7  8  9 10 11\
         12 13 14 15 17 18 19 20 21 22 23\
	 24 25 26 27 28 29 30 31 35 36 37\
	 38 39 40 41 42 43 44 45 46 47 48\
	 49 50 51 52 53 54 55 56 57 58 59\
	 60 61 62 63 64"

for i in $*; do 
	case $i in
	*.gz)
		TMPFILE=`tempfile -p advi_ -s .dvi`
		if [ -x $UNZIP ]; then
			$UNZIP -c $i > $TMPFILE
			UNGZFILE="$UNGZFILE $TMPFILE"
			DVIFILE="$DVIFILE $TMPFILE"
		else
			echo "Cannot find $UNZIP"
		fi
		;;
	*.bz2)
		TMPFILE=`tempfile -p advi_ -s .dvi`
		if [ -x $BUNZIP ]; then
			$BUNZIP -c $i > $TMPFILE
			UNGZFILE="$UNGZFILE $TMPFILE"
			DVIFILE="$DVIFILE $TMPFILE"
		else
			echo "Cannot find $BUNZIP"
		fi
		;;
	*)
		DVIFILE="$DVIFILE $i"
		;;
	esac
done

$ADVI $DVIFILE

$RM -f $UNGZFILE

