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

  1. #!perl -lw
  2. # Version 0.01
  3. use strict;
  4. use Getopt::Std;
  5. use RISCOS::Throwback;
  6. use RISCOS::Chunkfile;
  7. use RISCOS::File ':DEFAULT', '/glob/';
  8. use RISCOS::Filespec;
  9. use RISCOS::Chunk;
  10. use RISCOS::AOF;
  11. use RISCOS::ALF;
  12. use RISCOS::Time qw (time2utc time2local);
  13. # Keep paths intact (eg Unix:o.UnixLib
  14. glob_control (&fileglob_PrintOriginalPath);
  15.  
  16. use vars qw(%opt);
  17. getopts ('dx', \%opt);
  18. $opt{'d'} = 1 unless keys %opt;
  19.  
  20. sub do_file
  21. {
  22.     my $file = shift;
  23.     my $chunks = new RISCOS::Chunkfile shift;
  24.     # So that name and data source can differ
  25.     my $entry = shift;
  26.     my $directory;
  27.  
  28.     unless ($chunks) {
  29.     warn "'$file' is not a chunkfile";
  30.     }
  31.     elsif ($chunks->Lookup ('OBJ_HEAD'))
  32.     {
  33.     # izza AOF
  34.     if ($entry) {
  35.     warn "Attempting to read entry '$entry' from AOF file '$file'\n";
  36.     } else {
  37.         &do_aof ($chunks, $file);
  38.     }
  39.     }
  40.     elsif ($chunks->Lookup ('LIB_DIRY'))
  41.     {
  42.     if (my $library = new RISCOS::ALF $chunks) {
  43.         # izza ALF
  44.         if ($entry) {
  45.         &do_alf ($library, $file, $library->Dir_Lookup ($entry));
  46.         } else {
  47.             &do_alf ($library, $file, values %{$library->Dir});
  48.         }
  49.     }
  50.     }
  51.     else
  52.     {
  53.     warn "'$file' is not a recognised chunkfile - contains "
  54.       . join (', ', keys %{$chunks->Keys()}) . ' chunks';
  55.     }
  56. }
  57.     
  58. sub do_alf ($$;@) {
  59.    my $library = shift;
  60.    my $file = shift;
  61.  
  62.     foreach (@_) {
  63.     # Reference to chunk data means "treat this as file to load"
  64.     do_file ("$file," . $_->Name(),
  65.          \($library->By_Number($_->Index())->Data), '');
  66.     }
  67. }
  68.  
  69. sub do_aof ($$) {
  70.     my $chunks = new RISCOS::AOF shift;
  71.     my $file = shift;
  72.  
  73.     print "# from $file";
  74.  
  75.     foreach my $symbol (@{$chunks->Symbols}) {
  76.     print $symbol->Name() if $opt{'d'} and $symbol->Scope eq '';
  77.     print $symbol->Name() if $opt{'x'} and $symbol->Scope eq 'extern';
  78.     }
  79.     print '';
  80. }
  81.  
  82. foreach (@ARGV)
  83. {
  84.     # Try to make the entry the longest comma free string possible
  85.     my ($file, $entry) = ($_);
  86.  
  87.     # Found a comma? If so separate as it's probably a $file,$entry for ALF
  88.     ($file, $entry) = /^(.*?),?([^,]*)$/ if tr/,//;
  89.  
  90.     my @files = glob ($file);
  91.  
  92.     @files = $file unless @files;    # Push pattern if unmatched
  93.  
  94.     foreach $file (@files)
  95.     {
  96.     do_file ($file, $file, $entry);
  97.     }
  98. }
  99.  
  100. __END__
  101.     $stringtable = aof_stringtable $chunks[$stringtable->[0]] ->Data();
  102.  
  103.     while (($key, $val) = each %$stringtable) {
  104.         print "$key: '$val'";
  105.     }
  106. ----
  107.         foreach (keys %$directory) {
  108.         print $_, "\t", scalar time2local ($directory->{$_}->Time()->Time());
  109.