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.2 by root, Tue Jun 12 03:20:44 2001 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
34for(<uusrc/*>) { 39 # the following rules are rather effective on some newsgroups,
35 my($retval,$count)=LoadFile ($_,$_,1); 40 # like alt.binaries.games.anime, where non-mime, uuencoded data
36 print "file($_), status(",strerror($retval),") parts($count)\n"; 41 # is very common
37}
38 42
39SetOption (OPT_SAVEPATH, "uudst/"); 43 # if we find some *.rar, take it as the filename
44 return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i;
40 45
41$i=0; 46 # one common subject format
42while($uu=GetFileListItem($i)) { 47 return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
43 $i++;
44 print "file nr. $i";
45 print " state ",$uu->state;
46 print " mode ",$uu->mode;
47 print " uudet ",strencoding($uu->uudet);
48 print " size ",$uu->size;
49 print " filename ",$uu->filename;
50 print " subfname ",$uu->subfname;
51 print " mimeid ",$uu->mimeid;
52 print " mimetype ",$uu->mimetype;
53 print "\n";
54 48
55 # print additional info about all parts 49 # - filename.par (04/55)
56 for($uu->parts) { 50 return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
57 while(my($k,$v)=each(%$_)) {
58 print "$k > $v, ";
59 }
60 print "\n";
61 }
62 51
63 print strerror($uu->decode_temp)."\n"; 52 # - (xxx) No. 1 sayuri81.jpg 756565 bytes
64 print " temporarily decoded to ",$uu->binfile,"\n"; 53 # - (20 files) No.17 Roseanne.jpg [2/2]
65 $uu->remove_temp; 54 return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
66 55
67 print strerror($uu->decode)."\n"; 56 # otherwise just pass what we have
68 print " saved as uudst/",$uu->filename,"\n"; 57 return ();
69} 58 };
70 59
71print "cleanup...\n"; 60 # now read all files in the directory uusrc/*
61 for(<uusrc/*>) {
62 my($retval,$count)=LoadFile ($_, $_, 1);
63 print "file($_), status(", strerror $retval, ") parts($count)\n";
64 }
72 65
66 SetOption OPT_SAVEPATH, "uudst/";
67
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
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
73CleanUp(); 101 CleanUp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines