#!/bin/sh
#130520 sfs
CMD_UNZIP=unzip

mczip_list () {

$CMD_UNZIP -Z -l -T "$1" | gawk '
{if (NR == 1) { next }}
{if (NR == 2) { next }}
/^[0-9]/ { next }
{
perm = substr($1, 1, 1) "rwxrwxrwx"
date = substr($8, 5, 2) "-" substr($8, 7, 2) "-" substr($8, 1, 4) " " substr($8, 10, 2) ":" substr($8, 12, 2) 
name = $9
	{if($10 != ""){name = name " " $10}}
	{if($11 != ""){name = name " " $11}}
	{if($12 != ""){name = name " " $12}}
	{if($13 != ""){name = name " " $13}}
	{if($14 != ""){name = name " " $14}}
	{if($15 != ""){name = name " " $15}}
	{if($16 != ""){name = name " " $16}}
printf "%s 1 root root %s %s %s\n", perm, $4, date, name
}'
}

mczip_copyout () {
$CMD_UNZIP -p "$1" "$2" > "$3"
}

LC_ALL=C

cmd="$1"
shift

case "$cmd" in
  list)
    mczip_list "$@";
    exit 0;;
  copyout)
    mczip_copyout "$@";
    exit 0;;
esac
exit 1
