#!/usr/bin/perl
#############################################################################
#
# rx_* dispatcher and handlers for VFU File Manager
# (c) Vladi Belperchinov-Shabanski "Cade" 2002
# <cade@biscom.net> <cade.datamax.bg> http://cade.webbg.com
# $Id: rx_auto,v 1.5 2006/08/05 20:15:40 cade Exp $
#
# usage:
#   rx_* l archive directory   # list archive directory
#   rx_* v archive             # list entire archive
#   rx_* x archive files...    # extract one file
#   rx_* x archive @listfile   # extract list of files
#
#############################################################################
use strict;

my $CTTL = 16; # cache time to live in seconds

my $file = $ARGV[1];

for( glob "/tmp/*.rx.cache" )
  {
  # clean cache--silently skip errors
  next unless time() - file_mtime( $_ ) > $CTTL;
  unlink $_;
  }

my $rx = choose( $file ) or die "$0: this file type is not nown to me, sorry\n";

exec( $rx, @ARGV );

sub choose
{
  local $_ = shift;
  return "rx_tar" if /\.(?:tar(?:\.(?:z|gz|bz2))?|t[bgx]z)$/i;
  return "rx_zip" if /\.(?:zip|jar|pk3|egg|maff)$/i;
  return "rx_deb" if /\.deb$/i;
  return "rx_ftp" if /\.ftp$/i;
  return "rx_rar" if /\.rar$/i;
  return "rx_rpm" if /\.rpm$/i;
  return undef;
}

sub file_mtime
{
  return (stat($_[0]))[9];
}

