ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
Revision: 1.4
Committed: Sun Mar 31 22:03:56 2002 UTC (22 years, 1 month ago) by root
Branch: MAIN
Changes since 1.3: +12 -3 lines
Log Message:
*** empty log message ***

File Contents

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