#! /bin/sh
#
# Written by andrey joukov
# (C) 1996 2:5020/337.13@fidonet.org
# beta version 1.0
#
UNRAR=rar
#
# NOTE: rar ver 2.0 by Eugene Roshal
# ftp.elf.stuba.sk/pub/pc/pack
#

mcrarfs_list ()
{
     $UNRAR v -c- $1 | @AWK@ -v uid=${UID-0} '
BEGIN { flag=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
/^-------/ { flag++; if (flag > 1) exit 0; next }
{
if (flag == 0) next
if (NF == 1) str = $1
else {
    if (str ~ /^\^/)
	str=substr(str, 2)
    split($4, a, "-")
    if (a[3] < 50)
	a[3] = 2000 + a[3]
    else
	a[3] = 1900 + a[3]
    if (index($6, "D") != 0)
	$6="drwxr-xr-x"
    else
	if (index($6, ".") != 0)
	    $6="-rw-r--r--"
    printf "%s   1 %-8d %-8d %8d %3s %2d %4d %s %s\n", $6, uid, 0, $1, substr(date, (a[2]-1)*3+1, 3), a[1], a[3], $5, str
}
}' 2>/dev/null
}

mcrarfs_copyout ()
{
    $UNRAR p -c- -inul $1 $2 > $3 2>/dev/null
}

case "$1" in
  list) mcrarfs_list $2; exit 0;;
  copyout) mcrarfs_copyout $2 $3 $4; exit 0;;
esac
exit 1
