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.7 by root, Sun Oct 13 13:47:09 2002 UTC vs.
Revision 1.8 by root, Tue Oct 15 23:20:30 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines