ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
(Generate patch)

Comparing Convert-UUlib/example-decoder (file contents):
Revision 1.4 by root, Sun Mar 31 22:03:56 2002 UTC vs.
Revision 1.7 by root, Sun Oct 13 13:47:09 2002 UTC

1#!/usr/bin/perl 1 # decode all the files in the directory uusrc/ and copy
2 # the resulting files to uudst/
2 3
3# decode all the files in the directory uusrc/ and copy 4 use Convert::UUlib ':all';
4# the resulting files to uudst/
5 5
6use Convert::UUlib ':all'; 6 sub namefilter {
7 my($path)=@_;
8 $path=~s/^.*[\/\\]//;
9 $path;
10 }
7 11
8sub namefilter { 12 sub busycb {
9 my($path)=@_; 13 my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_;
10 $path=~s/^.*[\/\\]//; 14 $_[0]=straction($action);
11 $path; 15 print "busy_callback(", (join ",",@_), ")\n";
12} 16 0;
17 }
13 18
14sub busycb { 19 SetOption OPT_IGNMODE, 1;
15 my($action,$curfile,$partno,$numparts,$percent,$fsize)=@_; 20 SetOption OPT_VERBOSE, 1;
16 $_[0]=straction($action);
17 print "busy_callback(",join(",",@_),")\n";
18 0;
19}
20 21
21SetOption (OPT_IGNMODE, 1); 22 # show the three ways you can set callback functions. I normally
22SetOption (OPT_VERBOSE, 1); 23 # prefer the one with the sub inplace.
24 SetFNameFilter \&namefilter;
23 25
24# show the three ways you can set callback functions 26 SetBusyCallback "busycb", 333;
25SetFNameFilter (\&namefilter);
26 27
27SetBusyCallback ("busycb",333); 28 SetMsgCallback sub {
29 my ($msg, $level) = @_;
30 print uc strmsglevel $_[1], ": $msg\n";
31 };
28 32
29SetMsgCallback (sub { 33 # the following non-trivial FileNameCallback takes care
30 my($msg,$level)=@_; 34 # of some subject lines not detected properly by uulib:
31 print uc(strmsglevel($_[1])),": $msg\n"; 35 SetFileNameCallback sub {
32}); 36 return unless $_[1]; # skip "Re:"-plies et al.
37 local $_ = $_[0];
33 38
34SetFileNameCallback sub { 39 # the following rules are rather effective on some newsgroups,
35 return unless $_[1]; # skip "Re:"-plies et al. 40 # like alt.binaries.games.anime, where non-mime, uuencoded data
36 local _$ = $_[0]; 41 # is very common
37 42
38 # the following rules are rather effective on some newsgroups, 43 # if we find some *.rar, take it as the filename
39 # like alt.binaries.games.anime, where non-mime, uuencoded data 44 return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i;
40 # is very common
41 45
42 # if we find some *.rar, take it 46 # one common subject format
43 return $1 if /(\S+\.(?:[rstuvwxyz]\d\d|rar))\s/i; 47 return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
44 48
45 # - filename.par (04/55) 49 # - filename.par (04/55)
46 return $1 if /- "?(\S+\.\S+?)"? (:yenc )?\(\d+\/\d+\)/i; 50 return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
47 51
48 # otherwise just pass what we have 52 # - (xxx) No. 1 sayuri81.jpg 756565 bytes
49 return (); 53 # - (20 files) No.17 Roseanne.jpg [2/2]
50}; 54 return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
51 55
56 # otherwise just pass what we have
57 return ();
58 };
52 59
60 # now read all files in the directory uusrc/*
53for(<uusrc/*>) { 61 for(<uusrc/*>) {
54 my($retval,$count)=LoadFile ($_,$_,1); 62 my($retval,$count)=LoadFile ($_, $_, 1);
55 print "file($_), status(",strerror($retval),") parts($count)\n"; 63 print "file($_), status(", strerror $retval, ") parts($count)\n";
56} 64 }
57 65
58SetOption (OPT_SAVEPATH, "uudst/"); 66 SetOption OPT_SAVEPATH, "uudst/";
59 67
68 # now wade through all files and their source parts
60$i=0; 69 $i = 0;
61while($uu=GetFileListItem($i)) { 70 while ($uu = GetFileListItem($i)) {
62 $i++; 71 $i++;
63 print "file nr. $i"; 72 print "file nr. $i";
64 print " state ",$uu->state; 73 print " state ", $uu->state;
65 print " mode ",$uu->mode; 74 print " mode ", $uu->mode;
66 print " uudet ",strencoding($uu->uudet); 75 print " uudet ", strencoding $uu->uudet;
67 print " size ",$uu->size; 76 print " size ", $uu->size;
68 print " filename ",$uu->filename; 77 print " filename ", $uu->filename;
69 print " subfname ",$uu->subfname; 78 print " subfname ", $uu->subfname;
70 print " mimeid ",$uu->mimeid; 79 print " mimeid ", $uu->mimeid;
71 print " mimetype ",$uu->mimetype; 80 print " mimetype ", $uu->mimetype;
72 print "\n"; 81 print "\n";
73 82
74 # print additional info about all parts 83 # print additional info about all parts
75 for($uu->parts) { 84 for ($uu->parts) {
76 while(my($k,$v)=each(%$_)) { 85 while (my ($k, $v) = each %$_) {
77 print "$k > $v, "; 86 print "$k > $v, ";
78 } 87 }
79 print "\n"; 88 print "\n";
80 } 89 }
81 90
82 print strerror($uu->decode_temp)."\n"; 91 $uu->decode_temp;
83 print " temporarily decoded to ",$uu->binfile,"\n"; 92 print " temporarily decoded to ", $uu->binfile, "\n";
84 $uu->remove_temp; 93 $uu->remove_temp;
85 94
86 print strerror($uu->decode)."\n"; 95 print strerror $uu->decode;
87 print " saved as uudst/",$uu->filename,"\n"; 96 print " saved as uudst/", $uu->filename, "\n";
88} 97 }
89 98
90print "cleanup...\n"; 99 print "cleanup...\n";
91 100
92CleanUp(); 101 CleanUp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines