uumerge.pl

Matthias Urlichs urlichs at smurf.sub.org
Mon Jul 9 07:17:44 AEST 1990


In alt.sources, article <1990Jul7.182135.19069 at alembic.acs.com>,
  csu at alembic.acs.com (Dave Mack) writes:
< #
< # TODO: modify to allow more than one collection of files on
< #	command line.
< #

Well, here's my version; after merging and uudecoding N files per hand I
decided that enough was enough. (You might guess what newsgroup I'm talking
about... :-)

It also isn't perturbed if the occasional line in there does start with M.

Warning: My programming style is atrocious, and my Perl style doubly so.
Especially, the $x? variables really should be an array, the number of M lines
required should be an option, and the M itself also.


#!/usr/local/bin/perl
$files = 0;
$isopen = 0;
$file = "";
$lines = 0;

$ARGV[$[] = "-" unless ($#ARGV >= $[);

sub nextline {
   local($next) = (0);
   if ($file eq "") { $next = 1; }
   else {
      $_ = <FILE>;
      if ($_ eq "") { $next = 1;  }
   }
   if ($next) {
      $file = $ARGV[$[];
      if ($#ARGV < $[) {
	 $_ = "";
      } elsif ($#ARGV >= $[) {
	 shift @ARGV;
	 print STDERR "Reading $file\n";
	 if ($file eq "-") {
	    open (FILE,"<&STDIN");
	 } else {
	    open (FILE,$file);
	 }
	 $_ = &nextline;
      } else {
	 $_ = "";
      }
   }
   $_;
}

loop: while(($_ = &nextline) ne "") {
    scan: while (1) {
       if (/^begin\s\d\d\d\s(.*)\s*$/) {
	  print STDERR "Writing $1\n";
	  open (OUT,"|uudecode");
	  print OUT $_;
	  $files++;
	  $isopen = 1;
	  last scan;
       }
    } continue {
       &nextline;
       last loop if ($_ eq "");
    }
    
    $isuu = 3;
    lines: while (($_ = &nextline) ne "") {
       last if /^end/;
       if (/^M/ && $isuu > 2) {
          print OUT $x3, $x2, $x1, $_;
          $x3 = ""; $x2 = ""; $x1 = "";
	  $lines++;
          next lines;
       } else {
          $x3 = $x2; $x2 = $x1; $x1 = $_;
	  if (/^M/) {
	    $isuu++;
	  } else {
	    $isuu = 0;
	  }
       }
    }  

    print STDERR "$lines lines.\n";
    if (/^end/ && $isopen) {
        print OUT $x3, $x2, $x1, $_;
        close(OUT);
	$isopen = 0;
    } elsif ($isopen) {
	close(OUT);
	die "End of file not found";
    } else {
	die "No files found";
    }
    $lines = 0;
}

print STDERR "$files files found.\n";
exit 0;
-- 
Matthias Urlichs -- urlichs at smurf.sub.org -- urlichs at smurf.ira.uka.de
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(Voice)/621227(PEP)



More information about the Alt.sources mailing list