#!/bin/sh -
umask 077

# zzcat - uncompress stdin and/or files to stdout
# Steve Kinzler, steve@kinzler.com, Nov 11
# http://kinzler.com/me/home.html#unix

case "$#" in
0)	set x -; shift;;
esac

tmp=/tmp/zzcat$$
trap "rm -f $tmp; exit" 0 1 2 13 15

for file
do
	in="$file"
	case "$file" in
	-)	cat > $tmp
		in=$tmp
		case "`file $tmp`" in	# warning, heuristic
		*gzip*)		file=.gz;;
		*bzip2*)	file=.bz2;;
		*lzip*)		file=.lz;;
		*xz*)		file=.xz;;
		*compress*)	file=.Z;;
		*)		file=;;
		esac;;
	esac

	case "$file" in
	*.gz|*.z)	gzip  -d -n;;
	*.bz2)		bzip2 -d;;
	*.lz)		lzip  -d;;
	*.xz)		xz    -d;;
	*.Z)		uncompress;;
	*)		cat;;
	esac < "$in"
	rm -f $tmp
done
