home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7028 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.7 KB  |  123 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!mdisea!uw-coco!uw-beaver!fluke!dbc
  3. From: dbc@tc.fluke.COM (Dan Carson)
  4. Subject: Re: UUDECODE and perl ...
  5. Message-ID: <1992Nov18.002509.1941@tc.fluke.COM>
  6. Organization: John Fluke Mfg. Co., Inc., Everett, WA
  7. References: <1992Nov11.150851.10057@news.eng.convex.com>> <MERLYN.92Nov11094326@romulus.reed.edu> <sjaak.721911835@athena.research.ptt.nl>
  8. Date: Wed, 18 Nov 1992 00:25:09 GMT
  9. Lines: 112
  10.  
  11. In article <sjaak.721911835@athena.research.ptt.nl> J.W.Schilperoort@research.ptt.nl writes:
  12. >And here is my patch to Randal's program to allow unpacking more than
  13. >one file at a time. Very handy when, say from nn, you pipe all parts of
  14. >10 binaries through uumerge (the parts have to be in the right order, but
  15. >for me they usually are).
  16. >
  17. >            Sjaak.
  18. >Sjaak Schilperoort                   J.W.Schilperoort@research.ptt.nl
  19. >PTT Research, The Netherlands
  20.  
  21. Our stuff never comes in in order.  For those of you with this problem,
  22. here is an example solution.  It lists subjects in comp.binaries.ibm.pc,
  23. sorts, merges and decodes your selections.  The uudecode part is straight
  24. out of the book.
  25.  
  26. Disclaimers:
  27.   1) Absolute pathnames may vary.
  28.   2) I'm in analog design.  No guarantees on any software I write.
  29.  
  30. Dan Carson
  31. dbc@tc.fluke.COM
  32. John Fluke Mfg.
  33. Everett, WA
  34.  
  35.  
  36. #! /usr/local/perl
  37. #  uudecode stuff in comp.binaries.ibm.pc
  38. #  5/15/91 dbc  Initial version
  39. #  5/31/91 dbc  Only list programs with all parts present
  40. #  1/13/92 dbc  Updated regexp - New moderator changed Subject: format
  41. #  5/14/92 dbc  Sort by date
  42.  
  43. $regexp = ':[^:]+:\s*(([^,]+).*(\d\d)\/(\d\d).*)'; # Matches 'Subject:' line
  44. $spool  = '/usr/spool/news/comp/binaries/ibm/pc/';
  45.  
  46. opendir(DIR,$spool) || die "Can't open $spool\n";
  47. @files = readdir(DIR);
  48. @files = grep(/^\d/,@files);             # Articles begin with a number
  49. closedir(DIR);
  50.  
  51. file: foreach $article (@files) {
  52.   open(IN, $spool . $article) || next file;
  53.   line: while(<IN>) {                    # Memorize Subject: lines
  54.     next line unless /^Subject/;
  55.     ($desc,$prog,$part,$num) = /$regexp/;
  56.     next file unless $prog;
  57.     next file unless $num;
  58.     if($part == 1) {
  59.       $desc{$prog} = $desc ;
  60.       $article1{$prog} = $article;
  61.     }
  62.     $file{$prog} .= "$part/$num:$article ";
  63.     last line;
  64.   }
  65. }
  66.  
  67. @all = sort {$article1{$a} cmp $article1{$b};} keys %desc;
  68.  
  69. while($prog = shift @all) {              # List the programs in the spool
  70.   $part  = $file{$prog} =~ tr/:/:/;      # Don't list program if all the
  71.   ($num) = $file{$prog} =~ /\/(\d*):/;   #   parts haven't come in yet
  72.   next if $num != $part;
  73.   push(@prog,$prog);
  74.   $n++;
  75.   printf("%3d  %s\n",$n,$desc{$prog});
  76. }
  77.  
  78. print "\nTake your pick: ";
  79. chop($in = <>);
  80. @in = split(/[,\s]+/,$in);               # Let user pick programs to decode
  81.  
  82. while($in = shift @in) {
  83.   if($in =~ /^(\d+)-(\d+)/) {
  84.     unshift(@in,($1 .. $2));
  85.     next;
  86.   }
  87.   @files = sort split(/ /,$file{$prog[$in - 1]});
  88.   grep(s/.*://,@files);
  89.   print "$in: Decoding $prog[$in - 1] articles @files\n";
  90.   foreach $infile (@files) {
  91.     &uudecode($spool . $infile);
  92.   }
  93.   warn "Missing begin in #$in\n" unless $sawbegin;
  94.   warn "Missing end in #$in\n" unless $sawend;
  95.   chmod oct($mode), $file if $mode && $file;
  96.   $sawbegin = $sawend = 0;
  97. }
  98.  
  99. exit(0);
  100.  
  101.  
  102.  
  103.  
  104. sub uudecode {
  105.   open(IN, $_[0]);
  106.   unless($sawbegin) {
  107.     while(<IN>) {              # The rest is modified from the book
  108.       $sawbegin++, last if ($mode,$file) = /^begin\s*(\d*)\s*(\S*)/;
  109.     }
  110.     open(OUT,"> $file") if $file ne "";
  111.   }
  112.   while(<IN>) {
  113.     if(/^end/) {
  114.       $sawend++;
  115.       last;
  116.     }
  117.     s/[a-z]+$//; # handle stupid trailing lowercase letters
  118.     next if /[a-z]/;
  119.     next unless int((((ord() - 32) & 077) + 2) / 3) == int(length() / 4);
  120.     print OUT unpack("u", $_);         # One line does the actual work
  121.   }
  122. }
  123.