… | |
… | |
34 | ); |
34 | ); |
35 | |
35 | |
36 | our @_funcs = qw( |
36 | our @_funcs = qw( |
37 | Initialize CleanUp GetOption SetOption strerror SetMsgCallback |
37 | Initialize CleanUp GetOption SetOption strerror SetMsgCallback |
38 | SetBusyCallback SetFileCallback SetFNameFilter SetFileNameCallback |
38 | SetBusyCallback SetFileCallback SetFNameFilter SetFileNameCallback |
39 | FNameFilter LoadFile GetFileListItem RenameFile DecodeToTemp |
39 | FNameFilter LoadFile GetFileListItem GetFileList RenameFile DecodeToTemp |
40 | RemoveTemp DecodeFile InfoFile Smerge QuickDecode EncodeMulti |
40 | RemoveTemp DecodeFile InfoFile Smerge QuickDecode EncodeMulti |
41 | EncodePartial EncodeToStream EncodeToFile E_PrepSingle |
41 | EncodePartial EncodeToStream EncodeToFile E_PrepSingle |
42 | E_PrepPartial |
42 | E_PrepPartial |
43 | |
43 | |
44 | straction strencoding strmsglevel |
44 | straction strencoding strmsglevel |
… | |
… | |
48 | our @EXPORT_OK = @_funcs; |
48 | our @EXPORT_OK = @_funcs; |
49 | our %EXPORT_TAGS = (all => [@_consts,@_funcs], constants => \@_consts); |
49 | our %EXPORT_TAGS = (all => [@_consts,@_funcs], constants => \@_consts); |
50 | |
50 | |
51 | bootstrap Convert::UUlib $VERSION; |
51 | bootstrap Convert::UUlib $VERSION; |
52 | |
52 | |
53 | Initialize(); |
53 | # dummy function for compatiiblity with pre-1.7 versions |
54 | |
54 | sub Initialize { } |
55 | # not when < 5.005_6x |
|
|
56 | # END { CleanUp() } |
|
|
57 | |
55 | |
58 | for (@_consts) { |
56 | for (@_consts) { |
59 | my $constant = constant($_); |
57 | my $constant = constant ($_); |
60 | no strict 'refs'; |
58 | no strict 'refs'; |
61 | *$_ = sub () { $constant }; |
59 | *$_ = sub () { $constant }; |
62 | } |
60 | } |
63 | |
61 | |
64 | # action code -> string mapping |
62 | # action code -> string mapping |
… | |
… | |
105 | use Convert::UUlib ':all'; |
103 | use Convert::UUlib ':all'; |
106 | |
104 | |
107 | # read all the files named on the commandline and decode them |
105 | # read all the files named on the commandline and decode them |
108 | # into the CURRENT directory. See below for a longer example. |
106 | # into the CURRENT directory. See below for a longer example. |
109 | LoadFile $_ for @ARGV; |
107 | LoadFile $_ for @ARGV; |
110 | for (my $i = 0; my $uu = GetFileListItem $i; $i++) { |
108 | |
|
|
109 | for my $uu (GetFileList) { |
111 | if ($uu->state & FILE_OK) { |
110 | if ($uu->state & FILE_OK) { |
112 | $uu->decode; |
111 | $uu->decode; |
113 | print $uu->filename, "\n"; |
112 | print $uu->filename, "\n"; |
114 | } |
113 | } |
115 | } |
114 | } |
… | |
… | |
216 | On my machine, a fairly complete decode with DBI backend needs about 10MB |
215 | On my machine, a fairly complete decode with DBI backend needs about 10MB |
217 | RSS to decode 20000 files. |
216 | RSS to decode 20000 files. |
218 | |
217 | |
219 | =over |
218 | =over |
220 | |
219 | |
221 | =item Initialize |
|
|
222 | |
|
|
223 | Not normally necessary, (re-)initializes the library. |
|
|
224 | |
|
|
225 | =item CleanUp |
220 | =item CleanUp |
226 | |
221 | |
227 | Not normally necessary, could be called at the end to release memory |
222 | Release memory, file items and clean up files. Should be called after a |
228 | before starting a new decoding round. |
223 | decoidng run, if you want to start a new one. |
229 | |
224 | |
230 | =back |
225 | =back |
231 | |
226 | |
232 | =head2 Setting and querying options |
227 | =head2 Setting and querying options |
233 | |
228 | |
… | |
… | |
297 | C<undef> of no file with that number exists. |
292 | C<undef> of no file with that number exists. |
298 | |
293 | |
299 | The first file has number C<0>, and the series has no holes, so you can |
294 | The first file has number C<0>, and the series has no holes, so you can |
300 | iterate over all files by starting with zero and incrementing until you |
295 | iterate over all files by starting with zero and incrementing until you |
301 | hit C<undef>. |
296 | hit C<undef>. |
|
|
297 | |
|
|
298 | This function has to walk the linear list of fils on each access, so |
|
|
299 | if you want to iterate over all items, it is usually faster to use |
|
|
300 | C<GetFileList>. |
|
|
301 | |
|
|
302 | =item @items = GetFileList |
|
|
303 | |
|
|
304 | Similar to C<GetFileListItem>, but returns all files in one go. |
302 | |
305 | |
303 | =back |
306 | =back |
304 | |
307 | |
305 | =head2 Decoding files |
308 | =head2 Decoding files |
306 | |
309 | |
… | |
… | |
440 | |
443 | |
441 | =back |
444 | =back |
442 | |
445 | |
443 | =head1 LARGE EXAMPLE DECODER |
446 | =head1 LARGE EXAMPLE DECODER |
444 | |
447 | |
|
|
448 | The general workflow for decoding is like this: |
|
|
449 | |
|
|
450 | =over |
|
|
451 | |
|
|
452 | =item 1. Configure options with C<SetOption> or C<SetXXXCallback>. |
|
|
453 | |
|
|
454 | =item 2. Load all source files with C<LoadFile>. |
|
|
455 | |
|
|
456 | =item 3. Optionally C<Smerge>. |
|
|
457 | |
|
|
458 | =item 4. Iterate over all C<GetFileList> items (i.e. result files). |
|
|
459 | |
|
|
460 | =item 5. C<CleanUp> to delete files and free items. |
|
|
461 | |
|
|
462 | =back |
|
|
463 | |
445 | This is the file C<example-decoder> from the distribution, put here |
464 | What follows is the file C<example-decoder> from the distribution that |
446 | instead of more thorough documentation. |
465 | illustrates the above worklfow in a non-trivial example. |
447 | |
466 | |
448 | #!/usr/bin/perl |
467 | #!/usr/bin/perl |
449 | |
468 | |
450 | # decode all the files in the directory uusrc/ and copy |
469 | # decode all the files in the directory uusrc/ and copy |
451 | # the resulting files to uudst/ |
470 | # the resulting files to uudst/ |
… | |
… | |
513 | # otherwise just pass what we have |
532 | # otherwise just pass what we have |
514 | () |
533 | () |
515 | }; |
534 | }; |
516 | |
535 | |
517 | # now read all files in the directory uusrc/* |
536 | # now read all files in the directory uusrc/* |
518 | for(<uusrc/*>) { |
537 | for (<uusrc/*>) { |
519 | my ($retval, $count) = LoadFile ($_, $_, 1); |
538 | my ($retval, $count) = LoadFile ($_, $_, 1); |
520 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
539 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
521 | } |
540 | } |
522 | |
541 | |
523 | SetOption OPT_SAVEPATH, "uudst/"; |
542 | SetOption OPT_SAVEPATH, "uudst/"; |
524 | |
543 | |
525 | # now wade through all files and their source parts |
544 | # now wade through all files and their source parts |
526 | $i = 0; |
545 | for my $uu (GetFileList) { |
527 | while ($uu = GetFileListItem $i) { |
546 | print "file ", $uu->filename, "\n"; |
528 | $i++; |
|
|
529 | print "file nr. $i"; |
|
|
530 | print " state ", $uu->state; |
547 | print " state ", $uu->state, "\n"; |
531 | print " mode ", $uu->mode; |
548 | print " mode ", $uu->mode, "\n"; |
532 | print " uudet ", strencoding $uu->uudet; |
549 | print " uudet ", strencoding $uu->uudet, "\n"; |
533 | print " size ", $uu->size; |
550 | print " size ", $uu->size, "\n"; |
534 | print " filename ", $uu->filename; |
|
|
535 | print " subfname ", $uu->subfname; |
551 | print " subfname ", $uu->subfname, "\n"; |
536 | print " mimeid ", $uu->mimeid; |
552 | print " mimeid ", $uu->mimeid, "\n"; |
537 | print " mimetype ", $uu->mimetype; |
553 | print " mimetype ", $uu->mimetype, "\n"; |
538 | print "\n"; |
|
|
539 | |
554 | |
540 | # print additional info about all parts |
555 | # print additional info about all parts |
|
|
556 | print " parts"; |
541 | for ($uu->parts) { |
557 | for ($uu->parts) { |
542 | while (my ($k, $v) = each %$_) { |
558 | for my $k (sort keys %$_) { |
543 | print "$k > $v, "; |
559 | print " $k=$_->{$k}"; |
544 | } |
560 | } |
545 | print "\n"; |
561 | print "\n"; |
546 | } |
562 | } |
547 | |
563 | |
548 | print $uu->filename; |
|
|
549 | |
|
|
550 | $uu->remove_temp; |
564 | $uu->remove_temp; |
551 | |
565 | |
552 | if (my $err = $uu->decode ()) { |
566 | if (my $err = $uu->decode) { |
553 | print ", ", strerror $err, "\n"; |
567 | print " ERROR ", strerror $err, "\n"; |
554 | } else { |
568 | } else { |
555 | print ", saved as uudst/", $uu->filename, "\n"; |
569 | print " successfully saved as uudst/", $uu->filename, "\n"; |
556 | } |
570 | } |
557 | } |
571 | } |
558 | |
572 | |
559 | print "cleanup...\n"; |
573 | print "cleanup...\n"; |
560 | |
574 | |