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.6 by root, Mon Aug 19 23:25:34 2002 UTC vs.
Revision 1.10 by root, Tue Dec 28 21:32:27 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines