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.3 by root, Sun Mar 31 21:42:36 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 my ($subject, $filename) = @_; 41 # is very common
37 ## if we find some *.rar, take it
38 return $1 if $subject =~ /(\S+\.(?:[rstuvwxyz]\d\d|rar))\s/i;
39 # otherwise just pass what we have
40 return ();
41};
42 42
43 # if we find some *.rar, take it as the filename
44 return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i;
43 45
44for(<uusrc/*>) { 46 # one common subject format
45 my($retval,$count)=LoadFile ($_,$_,1); 47 return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
46 print "file($_), status(",strerror($retval),") parts($count)\n";
47}
48 48
49SetOption (OPT_SAVEPATH, "uudst/"); 49 # - filename.par (04/55)
50 return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
50 51
51$i=0; 52 # - (xxx) No. 1 sayuri81.jpg 756565 bytes
52while($uu=GetFileListItem($i)) { 53 # - (20 files) No.17 Roseanne.jpg [2/2]
53 $i++; 54 return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
54 print "file nr. $i";
55 print " state ",$uu->state;
56 print " mode ",$uu->mode;
57 print " uudet ",strencoding($uu->uudet);
58 print " size ",$uu->size;
59 print " filename ",$uu->filename;
60 print " subfname ",$uu->subfname;
61 print " mimeid ",$uu->mimeid;
62 print " mimetype ",$uu->mimetype;
63 print "\n";
64 55
65 # print additional info about all parts 56 # otherwise just pass what we have
66 for($uu->parts) { 57 return ();
67 while(my($k,$v)=each(%$_)) { 58 };
68 print "$k > $v, ";
69 }
70 print "\n";
71 }
72 59
73 print strerror($uu->decode_temp)."\n"; 60 # now read all files in the directory uusrc/*
74 print " temporarily decoded to ",$uu->binfile,"\n"; 61 for(<uusrc/*>) {
75 $uu->remove_temp; 62 my($retval,$count)=LoadFile ($_, $_, 1);
63 print "file($_), status(", strerror $retval, ") parts($count)\n";
64 }
76 65
77 print strerror($uu->decode)."\n"; 66 SetOption OPT_SAVEPATH, "uudst/";
78 print " saved as uudst/",$uu->filename,"\n";
79}
80 67
81print "cleanup...\n"; 68 # now wade through all files and their source parts
69 $i = 0;
70 while ($uu = GetFileListItem($i)) {
71 $i++;
72 print "file nr. $i";
73 print " state ", $uu->state;
74 print " mode ", $uu->mode;
75 print " uudet ", strencoding $uu->uudet;
76 print " size ", $uu->size;
77 print " filename ", $uu->filename;
78 print " subfname ", $uu->subfname;
79 print " mimeid ", $uu->mimeid;
80 print " mimetype ", $uu->mimetype;
81 print "\n";
82 82
83 # print additional info about all parts
84 for ($uu->parts) {
85 while (my ($k, $v) = each %$_) {
86 print "$k > $v, ";
87 }
88 print "\n";
89 }
90
91 $uu->decode_temp;
92 print " temporarily decoded to ", $uu->binfile, "\n";
93 $uu->remove_temp;
94
95 print strerror $uu->decode;
96 print " saved as uudst/", $uu->filename, "\n";
97 }
98
99 print "cleanup...\n";
100
83CleanUp(); 101 CleanUp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines