home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1565 < prev    next >
Internet Message Format  |  1990-12-28  |  3KB

  1. From: urlichs@smurf.sub.org (Matthias Urlichs)
  2. Newsgroups: alt.sources,comp.lang.perl
  3. Subject: Re: uumerge.pl
  4. Message-ID: <qskfe2.[75@smurf.sub.org>
  5. Date: 8 Jul 90 21:17:44 GMT
  6.  
  7. In alt.sources, article <1990Jul7.182135.19069@alembic.acs.com>,
  8.   csu@alembic.acs.com (Dave Mack) writes:
  9. < #
  10. < # TODO: modify to allow more than one collection of files on
  11. < #    command line.
  12. < #
  13.  
  14. Well, here's my version; after merging and uudecoding N files per hand I
  15. decided that enough was enough. (You might guess what newsgroup I'm talking
  16. about... :-)
  17.  
  18. It also isn't perturbed if the occasional line in there does start with M.
  19.  
  20. Warning: My programming style is atrocious, and my Perl style doubly so.
  21. Especially, the $x? variables really should be an array, the number of M lines
  22. required should be an option, and the M itself also.
  23.  
  24.  
  25. #!/usr/local/bin/perl
  26. $files = 0;
  27. $isopen = 0;
  28. $file = "";
  29. $lines = 0;
  30.  
  31. $ARGV[$[] = "-" unless ($#ARGV >= $[);
  32.  
  33. sub nextline {
  34.    local($next) = (0);
  35.    if ($file eq "") { $next = 1; }
  36.    else {
  37.       $_ = <FILE>;
  38.       if ($_ eq "") { $next = 1;  }
  39.    }
  40.    if ($next) {
  41.       $file = $ARGV[$[];
  42.       if ($#ARGV < $[) {
  43.      $_ = "";
  44.       } elsif ($#ARGV >= $[) {
  45.      shift @ARGV;
  46.      print STDERR "Reading $file\n";
  47.      if ($file eq "-") {
  48.         open (FILE,"<&STDIN");
  49.      } else {
  50.         open (FILE,$file);
  51.      }
  52.      $_ = &nextline;
  53.       } else {
  54.      $_ = "";
  55.       }
  56.    }
  57.    $_;
  58. }
  59.  
  60. loop: while(($_ = &nextline) ne "") {
  61.     scan: while (1) {
  62.        if (/^begin\s\d\d\d\s(.*)\s*$/) {
  63.       print STDERR "Writing $1\n";
  64.       open (OUT,"|uudecode");
  65.       print OUT $_;
  66.       $files++;
  67.       $isopen = 1;
  68.       last scan;
  69.        }
  70.     } continue {
  71.        &nextline;
  72.        last loop if ($_ eq "");
  73.     }
  74.     
  75.     $isuu = 3;
  76.     lines: while (($_ = &nextline) ne "") {
  77.        last if /^end/;
  78.        if (/^M/ && $isuu > 2) {
  79.           print OUT $x3, $x2, $x1, $_;
  80.           $x3 = ""; $x2 = ""; $x1 = "";
  81.       $lines++;
  82.           next lines;
  83.        } else {
  84.           $x3 = $x2; $x2 = $x1; $x1 = $_;
  85.       if (/^M/) {
  86.         $isuu++;
  87.       } else {
  88.         $isuu = 0;
  89.       }
  90.        }
  91.     }  
  92.  
  93.     print STDERR "$lines lines.\n";
  94.     if (/^end/ && $isopen) {
  95.         print OUT $x3, $x2, $x1, $_;
  96.         close(OUT);
  97.     $isopen = 0;
  98.     } elsif ($isopen) {
  99.     close(OUT);
  100.     die "End of file not found";
  101.     } else {
  102.     die "No files found";
  103.     }
  104.     $lines = 0;
  105. }
  106.  
  107. print STDERR "$files files found.\n";
  108. exit 0;
  109. -- 
  110. Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de
  111. Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(Voice)/621227(PEP)
  112.