#!/usr/local/bin/perl -w # # $Id: multidecode 356 2011-09-24 23:25:47Z svnuser $ # # $Log: multidecode,v $ # Revision 1.1 1998/05/24 05:23:40 merlin # First version checked in CVS # # # Multi uuencode files decoder # This will take a file as an input and decode files in the current directory # It handles multi messages files (provided messages are in the right order), # including files that are not complete. # (those are not decoded, and the parsing continues). # # Yeah, I know, the code is kind of ugly, loop breakers, and a goto. It is also # kind of difficult to take care of all the possible cases and have clean code # # By Marc Merlin (marcsoft@magic.metawire.com) 02/15/97 $oldfh = select( STDERR ); $| = 1; # make unbuffered select(STDOUT); $| = 1; # make unbuffered select( $oldfh ); $debug=2; $file=shift @ARGV; $file2="uudecode.$$"; open (STREAM, $file) || die "Can't open $file\n"; print "$file opened\n"; while(1) { open (OUTPUT, ">$file2") || die "Can't open $file2\n"; while() { last if /^begin /; print "Skipping: $_" if ($debug>1); } if (! defined $_) { close OUTPUT; unlink $file2; print "End of parsed file\n" if $debug; exit; } ( $found = $_ ) =~ s/^begin \d+ (.+)$/$1/; chomp $found; print "Spotted beginning of file $found in $_" if $debug; NEWFILE: { do { do { print OUTPUT $_; chop($oldline=$_); $_=; } while(!/^$/); if ($oldline ne "end") { print "End of stream, looking for next message\n" if $debug; do { if (! defined $_) { close OUTPUT; unlink($file2); print "End of parsed file\n" if $debug; exit; } if (/^begin/) { print "Found new file while looking for other parts of $found\nDecoding of $found aborted\n" if $debug; close OUTPUT; unlink($file2); open (OUTPUT, ">$file2") || die "Can't open $file2\n"; ( $found = $_ ) =~ s/^begin \d+ (.+)$/$1/; chomp $found; print "Spotted beginning of file $found in $_" if $debug; goto NEWFILE; } print "Skipping: $_" if ($debug>1); } while(($_=) !~ /^M[^a-z]/ ); print "Got first line of next message\n" if $debug; } } while ($oldline ne "end"); } print "End of binary\n" if $debug; close OUTPUT; system "uudecode $file2"; unlink $file2; }