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.24 by root, Fri Feb 28 16:57:25 2020 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines