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