#!/usr/bin/perl

# Change the above to where your Perl is. Some have it in /usr/bin,
# some in /usr/local/bin, and some even in /local/bin. Check first.

$uudecode = 'uudecode';

# If you have uudecode in a funny directory, or somewhere not
# accessible by the obvious paths, or under a different name, you
# know what to do.

# ---- THE MEAT OF THINGS: FOR THE BRAVE OF HEART ONLY ---- #

$version = '1.0';
# Change this if you get happy with this code.

# MultiUU extracts multiple uuencoded files concatenated together.
# Designed for keeping a whole lot of uuencoded files together.
# Do what you like with it, but please, keep the copyright in.

# (C)1996 Cameron Kaiser. All rights reserved.

# ADD YOUR CHANGES, MODIFICATIONS HERE. LET ME KNOW WHAT YOU DO!
# spectre@deepthought.armory.com
#
# v1.0: It works. Whoopee.

if (!@ARGV || ($ARGV[0] ne 'v' && $ARGV[0] ne 'x') || !$ARGV[1]) {
	die "usage: multiuu [ v | x ] <uu-archive>" .
		"\n\tv: view archive\n" .
		"\tx: extract archive\n" .
		"\nyou must have uudecode to run this!" .
		"\n(c)1996 cameron kaiser\n"; }

	print 
"multiuu $version (c)1996 cameron kaiser ** spectre\@www.armory.com\n\n";
$option = (shift @ARGV) eq 'v';
printf ("%-50s %3s (%s)\n\n", "file-name", "rwx", $ARGV[0]) if ($option);

$infile = 0;
while(<ARGV>) {
	if (/begin (\d+) (.*)/) {
		$mode = $1;
		$file = $2;
		if (!$option) { 
			open(UU, "|$uudecode");
			select(UU); $| = 1; select(stdout);
			print stdout "\textracting: $file\n";
		}
		$infile = 1; }
	next if (!$infile);
	if ($option) {
		printf("%-50s %3s\n", $file, $mode); 
		$infile = 0;
		next; }
	print UU $_;
	if (/end/) {
		$infile = 0;
		close(UU); }
}
