ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/UUlib.pm
(Generate patch)

Comparing Convert-UUlib/UUlib.pm (file contents):
Revision 1.38 by root, Wed Sep 16 18:10:18 2009 UTC vs.
Revision 1.47 by root, Fri Feb 28 16:57:25 2020 UTC

6use Carp; 6use Carp;
7 7
8require Exporter; 8require Exporter;
9require DynaLoader; 9require DynaLoader;
10 10
11our $VERSION = '1.32'; 11our $VERSION = 1.62;
12 12
13our @ISA = qw(Exporter DynaLoader); 13our @ISA = qw(Exporter DynaLoader);
14 14
15our @_consts = qw( 15our @_consts = qw(
16 ACT_COPYING ACT_DECODING ACT_ENCODING ACT_IDLE ACT_SCANNING 16 ACT_COPYING ACT_DECODING ACT_ENCODING ACT_IDLE ACT_SCANNING
34); 34);
35 35
36our @_funcs = qw( 36our @_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
105 use Convert::UUlib ':all'; 105 use Convert::UUlib ':all';
106 106
107 # read all the files named on the commandline and decode them 107 # read all the files named on the commandline and decode them
108 # into the CURRENT directory. See below for a longer example. 108 # into the CURRENT directory. See below for a longer example.
109 LoadFile $_ for @ARGV; 109 LoadFile $_ for @ARGV;
110 for (my $i = 0; my $uu = GetFileListItem $i; $i++) { 110 for my $uu (GetFileList) {
111 if ($uu->state & FILE_OK) { 111 if ($uu->state & FILE_OK) {
112 $uu->decode; 112 $uu->decode;
113 print $uu->filename, "\n"; 113 print $uu->filename, "\n";
114 } 114 }
115 } 115 }
214again. 214again.
215 215
216On my machine, a fairly complete decode with DBI backend needs about 10MB 216On my machine, a fairly complete decode with DBI backend needs about 10MB
217RSS to decode 20000 files. 217RSS to decode 20000 files.
218 218
219=over 4 219=over
220 220
221=item Initialize 221=item Initialize
222 222
223Not normally necessary, (re-)initializes the library. 223Not normally necessary, (re-)initializes the library.
224 224
229 229
230=back 230=back
231 231
232=head2 Setting and querying options 232=head2 Setting and querying options
233 233
234=over 4 234=over
235 235
236=item $option = GetOption OPT_xxx 236=item $option = GetOption OPT_xxx
237 237
238=item SetOption OPT_xxx, opt-value 238=item SetOption OPT_xxx, opt-value
239 239
241 241
242See the C<OPT_xxx> constants above to see which options exist. 242See the C<OPT_xxx> constants above to see which options exist.
243 243
244=head2 Setting various callbacks 244=head2 Setting various callbacks
245 245
246=over 4 246=over
247 247
248=item SetMsgCallback [callback-function] 248=item SetMsgCallback [callback-function]
249 249
250=item SetBusyCallback [callback-function] 250=item SetBusyCallback [callback-function]
251 251
255 255
256=back 256=back
257 257
258=head2 Call the currently selected FNameFilter 258=head2 Call the currently selected FNameFilter
259 259
260=over 4 260=over
261 261
262=item $file = FNameFilter $file 262=item $file = FNameFilter $file
263 263
264=back 264=back
265 265
266=head2 Loading sourcefiles, optionally fuzzy merge and start decoding 266=head2 Loading sourcefiles, optionally fuzzy merge and start decoding
267 267
268=over 4 268=over
269 269
270=item ($retval, $count) = LoadFile $fname, [$id, [$delflag, [$partno]]] 270=item ($retval, $count) = LoadFile $fname, [$id, [$delflag, [$partno]]]
271 271
272Load the given file and scan it for encoded contents. Optionally tag it 272Load the given file and scan it for encoded contents. Optionally tag it
273with the given id, and if C<$delflag> is true, delete the file after it 273with the given id, and if C<$delflag> is true, delete the file after it
298 298
299The first file has number C<0>, and the series has no holes, so you can 299The first file has number C<0>, and the series has no holes, so you can
300iterate over all files by starting with zero and incrementing until you 300iterate over all files by starting with zero and incrementing until you
301hit C<undef>. 301hit C<undef>.
302 302
303This function has to walk the linear list of fils on each access, so
304if you want to iterate over all items, it is usually faster to use
305C<GetFileList>.
306
307=item @items = GetFileList
308
309Similar to C<GetFileListItem>, but returns all files in one go.
310
303=back 311=back
304 312
305=head2 Decoding files 313=head2 Decoding files
306 314
307=over 4 315=over
308 316
309=item $retval = $item->rename($newname) 317=item $retval = $item->rename ($newname)
310 318
311Change the ondisk filename where the decoded file will be saved. 319Change the ondisk filename where the decoded file will be saved.
312 320
313=item $retval = $item->decode_temp 321=item $retval = $item->decode_temp
314 322
317 325
318=item $retval = $item->remove_temp 326=item $retval = $item->remove_temp
319 327
320Remove the temporarily decoded file again. 328Remove the temporarily decoded file again.
321 329
322=item $retval = $item->decode([$target_path]) 330=item $retval = $item->decode ([$target_path])
323 331
324Decode the file to it's destination, or the given target path. 332Decode the file to its destination, or the given target path.
325 333
326=item $retval = $item->info(callback-function) 334=item $retval = $item->info (callback-function)
327 335
328=back 336=back
329 337
330=head2 Querying (and setting) item attributes 338=head2 Querying (and setting) item attributes
331 339
332=over 4 340=over
333 341
334=item $state = $item->state 342=item $state = $item->state
335 343
336=item $mode = $item->mode([newmode]) 344=item $mode = $item->mode ([newmode])
337 345
338=item $uudet = $item->uudet 346=item $uudet = $item->uudet
339 347
340=item $size = $item->size 348=item $size = $item->size
341 349
342=item $filename = $item->filename([newfilename}) 350=item $filename = $item->filename ([newfilename})
343 351
344=item $subfname = $item->subfname 352=item $subfname = $item->subfname
345 353
346=item $mimeid = $item->mimeid 354=item $mimeid = $item->mimeid
347 355
351 359
352=back 360=back
353 361
354=head2 Information about source parts 362=head2 Information about source parts
355 363
356=over 4 364=over
357 365
358=item $parts = $item->parts 366=item $parts = $item->parts
359 367
360Return information about all parts (source files) used to decode the file 368Return information about all parts (source files) used to decode the file
361as a list of hashrefs with the following structure: 369as a list of hashrefs with the following structure:
375Usually you are interested mostly the C<sfname> and possibly the C<partno> 383Usually you are interested mostly the C<sfname> and possibly the C<partno>
376and C<filename> members. 384and C<filename> members.
377 385
378=back 386=back
379 387
380=head2 Functions below not documented and not very well tested 388=head2 Functions below are not documented and not very well tested - feedback welcome
381 389
382 QuickDecode 390 QuickDecode
383 EncodeMulti 391 EncodeMulti
384 EncodePartial 392 EncodePartial
385 EncodeToStream 393 EncodeToStream
389 397
390=head2 EXTENSION FUNCTIONS 398=head2 EXTENSION FUNCTIONS
391 399
392Functions found in this module but not documented in the uulib documentation: 400Functions found in this module but not documented in the uulib documentation:
393 401
394=over 4 402=over
395 403
396=item $msg = straction ACT_xxx 404=item $msg = straction ACT_xxx
397 405
398Return a human readable string representing the given action code. 406Return a human readable string representing the given action code.
399 407
513 # otherwise just pass what we have 521 # otherwise just pass what we have
514 () 522 ()
515 }; 523 };
516 524
517 # now read all files in the directory uusrc/* 525 # now read all files in the directory uusrc/*
518 for(<uusrc/*>) { 526 for (<uusrc/*>) {
519 my ($retval, $count) = LoadFile ($_, $_, 1); 527 my ($retval, $count) = LoadFile ($_, $_, 1);
520 print "file($_), status(", strerror $retval, ") parts($count)\n"; 528 print "file($_), status(", strerror $retval, ") parts($count)\n";
521 } 529 }
522 530
523 SetOption OPT_SAVEPATH, "uudst/"; 531 SetOption OPT_SAVEPATH, "uudst/";
524 532
525 # now wade through all files and their source parts 533 # now wade through all files and their source parts
526 $i = 0; 534 for my $uu (GetFileList) {
527 while ($uu = GetFileListItem $i) { 535 print "file ", $uu->filename, "\n";
528 $i++;
529 print "file nr. $i";
530 print " state ", $uu->state; 536 print " state ", $uu->state, "\n";
531 print " mode ", $uu->mode; 537 print " mode ", $uu->mode, "\n";
532 print " uudet ", strencoding $uu->uudet; 538 print " uudet ", strencoding $uu->uudet, "\n";
533 print " size ", $uu->size; 539 print " size ", $uu->size, "\n";
534 print " filename ", $uu->filename;
535 print " subfname ", $uu->subfname; 540 print " subfname ", $uu->subfname, "\n";
536 print " mimeid ", $uu->mimeid; 541 print " mimeid ", $uu->mimeid, "\n";
537 print " mimetype ", $uu->mimetype; 542 print " mimetype ", $uu->mimetype, "\n";
538 print "\n";
539 543
540 # print additional info about all parts 544 # print additional info about all parts
545 print " parts";
541 for ($uu->parts) { 546 for ($uu->parts) {
542 while (my ($k, $v) = each %$_) { 547 for my $k (sort keys %$_) {
543 print "$k > $v, "; 548 print " $k=$_->{$k}";
544 } 549 }
545 print "\n"; 550 print "\n";
546 } 551 }
547 552
548 print $uu->filename;
549
550 $uu->remove_temp; 553 $uu->remove_temp;
551 554
552 if (my $err = $uu->decode ()) { 555 if (my $err = $uu->decode) {
553 print ", ", strerror $err, "\n"; 556 print " ERROR ", strerror $err, "\n";
554 } else { 557 } else {
555 print ", saved as uudst/", $uu->filename, "\n"; 558 print " successfully saved as uudst/", $uu->filename, "\n";
556 } 559 }
557 } 560 }
558 561
559 print "cleanup...\n"; 562 print "cleanup...\n";
560 563
561 CleanUp; 564 CleanUp;
565
566=head1 PERLMULTICORE SUPPORT
567
568This module supports the perlmulticore standard (see
569L<http://perlmulticore.schmorp.de/> for more info) for the following
570functions - generally these are functions accessing the disk and/or using
571considerable CPU time:
572
573 LoadFile
574 $item->decode
575 $item->decode_temp
576 $item->remove_temp
577 $item->info
578
579The perl interpreter will be reacquired/released on every callback
580invocation, so for performance reasons, callbacks should be avoided if
581that is costly.
582
583Future versions might enable multicore support for more functions.
584
585=head1 BUGS AND LIMITATIONS
586
587The original uulib library this module uses was written at a time where
588main memory of measured in megabytes and buffer overflows as a security
589thign didn't exist. While a lot of security fixes have been applied over
590the years (includign some defense in depth mechanism that can shield
591against a lot of as-of-yet undetected bugs), using this library for
592security purposes requires care.
593
594Likewise, file sizes when the uulib library was written were tiny compared
595to today, so do not expect this library to handle files larger than 2GB.
562 596
563=head1 AUTHOR 597=head1 AUTHOR
564 598
565Marc Lehmann <schmorp@schmorp.de>, the original uulib library was written 599Marc Lehmann <schmorp@schmorp.de>, the original uulib library was written
566by Frank Pilhofer <fp@informatik.uni-frankfurt.de>, and later heavily 600by Frank Pilhofer <fp@informatik.uni-frankfurt.de>, and later heavily
567bugfixed by Marc Lehmann. 601bugfixed by Marc Lehmann.
568 602
569=head1 SEE ALSO 603=head1 SEE ALSO
570 604
571perl(1), uudeview homepage at http://www.uni-frankfurt.de/~fp/uudeview/. 605perl(1), uudeview homepage at L<http://www.fpx.de/fp/Software/UUDeview/>.
572 606
573=cut 607=cut
608

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines