#!/bin/ksh
#
# $Revision: 1.9 $ $Date: 2012-07-26 16:36:09-04 $
# $Source: /home/vogelke/bin/RCS/tc,v $
# $Host: sys7.com $
# $UUID: 3579d7d5-6daf-3b3e-834b-3c0793257020 $
#
#<tc: list contents of a gzipped archive file
# if invoked as "tcv", print verbose listing.

export PATH=/usr/local/bin:/bin:/usr/bin
tag="${0##*/}"

case "$#" in
    0)  echo "$tag: need a file"; exit 0 ;;
    *)  file="$1" ;;
esac

case "$tag" in
    tcv) topt='tvf'; popt='-v' ;;
    *)   topt='tf';  popt= ;;
esac

case "$file" in
    *.tgz)     exec gunzip     -c "$file" | tar $topt - ;;
    *.txz)     exec unxz       -c "$file" | tar $topt - ;;
    *.bz2)     exec bunzip2    -c "$file" | tar $topt - ;;
    *.tbz)     exec bunzip2    -c "$file" | tar $topt - ;;
    *.pax.gz)  exec gunzip     -c "$file" | pax $popt ;;
    *.pax.xz)  exec unxz       -c "$file" | pax $popt ;;
    *.tar.gz)  exec gunzip     -c "$file" | tar $topt - ;;
    *.tar.xz)  exec unxz       -c "$file" | tar $topt - ;;
    *.tar.bz2) exec bunzip2    -c "$file" | tar $topt - ;;
    *.tar.Z)   exec uncompress -c "$file" | tar $topt - ;;
    *.pax)     exec pax $popt < "$file" ;;
    *.zip)     exec unzip -lv "$file" ;;
    *)         exec tar $topt "$file" ;;
esac

exit 1     # should not get this far...
