home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / scripts / ChunkRead < prev    next >
Text File  |  1998-07-14  |  2KB  |  90 lines

  1. #!perl -w
  2. # Version 0.01
  3. use strict;
  4. use Getopt::Std;
  5. use RISCOS::Throwback;
  6. use RISCOS::Chunkfile qw(load_chunkfile index_chunkfile);
  7. use RISCOS::Filespec;
  8. use RISCOS::Chunk;
  9. # use RISCOS::AOF qw (aof_stringtable aof_symboltable);
  10. use RISCOS::ALF qw (alf_directory);
  11. use RISCOS::Time qw (time2utc time2local);
  12.  
  13. use vars qw(%opt);
  14. getopts ('d', \%opt);
  15. $opt{'d'} = 0 unless keys %opt;
  16.  
  17. # Try to make the entry the longest comma free string possible
  18. my ($file, $entry) = (shift);
  19.  
  20. # Found a comma? If so separate as it's probably a $file,$entry for ALF
  21. ($file, $entry) = $file =~ /^(.*?),?([^,]*)$/ if $file =~ tr/,//;
  22.  
  23. $entry = shift unless $entry;
  24.  
  25. my $output = shift;
  26.  
  27. die "$0 <ALF File> <Entry> [<Output>]" unless defined $entry;
  28.  
  29. if ($output) {
  30.     open (STDOUT, ">$output") or die "Couldn't open '$output': $!";
  31. }
  32.  
  33. do_file ($file, $file, $entry);
  34.  
  35. exit 0;
  36.  
  37. sub do_file
  38. {
  39.     my $file = shift;
  40.     my @chunks = load_chunkfile shift;
  41.     # So that name and data source can differ
  42.     my $entry = shift;
  43.     my $index = index_chunkfile @chunks;
  44.  
  45.     unless (@chunks) {
  46.         warn "'$file' is not a chunkfile";
  47.     }
  48.     elsif (defined $$index{OBJ_SYMT})
  49.     {
  50.     # izza AOF
  51.     warn "Attempting to read entry '$entry' from AOF file '$file'\n";
  52.     }
  53.     elsif (defined $$index{LIB_DIRY})
  54.     {
  55.     my $directory  = $$index{LIB_DIRY};
  56.         if (@$directory > 1)
  57.     {
  58.     warn "Multiple directories in ALF file '$file' - chunks "
  59.       . join ',', @$directory;
  60.     next;
  61.     }
  62.     $directory = alf_directory $chunks[$directory->[0]];
  63.     # izza ALF
  64.     
  65.     if ($entry) {
  66.         &do_chunk (\@chunks, $file, $directory->{$entry});
  67.     } else {
  68.         &do_chunk (\@chunks, $file, values %$directory);
  69.     }
  70.     }
  71.     else
  72.     {
  73.         warn "'$file' is not a recognised ALF file - contains "
  74.           . join (', ', keys %$index) . ' chunks';
  75.     }
  76. }
  77.     
  78. sub do_chunk ($$;@) {
  79.     my $chunks = shift;
  80.     my $file = shift;
  81.    
  82.     die "Can't dump library out yet :-(" if $opt{d};
  83.  
  84.     foreach (@_) {
  85.         # Reference to chunk data means "treat this as file to load"
  86.     print ($chunks->[$_->Index()]->Data);
  87.     }
  88. }
  89.  
  90.