| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# This is a little script to list all the group labels in an Athena |
| 4 |
# project file and write it to STDOUT |
| 5 |
# |
| 6 |
# copyright (c) 2007 Bruce Ravel |
| 7 |
# |
| 8 |
# ------------------------------------------------------------------- |
| 9 |
|
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
|
| 13 |
use Safe; |
| 14 |
use Compress::Zlib; |
| 15 |
use Getopt::Long; |
| 16 |
|
| 17 |
my $help; |
| 18 |
GetOptions('h' => \$help, |
| 19 |
'help' => \$help); |
| 20 |
if ($help or not $ARGV[0]) { |
| 21 |
require Pod::Text; |
| 22 |
$^W=0; |
| 23 |
if ($Pod::Text::VERSION < 2.0) { |
| 24 |
Pod::Text::pod2text($0, *STDOUT); |
| 25 |
} elsif ($Pod::Text::VERSION >= 2.0) { |
| 26 |
my $parser = Pod::Text->new; |
| 27 |
open STDIN, $0; |
| 28 |
$parser->parse_from_filehandle; |
| 29 |
}; |
| 30 |
exit; |
| 31 |
}; |
| 32 |
|
| 33 |
my $cpt = new Safe; |
| 34 |
my %array = (); |
| 35 |
my $uhoh = 0; |
| 36 |
|
| 37 |
foreach my $file (@ARGV) { |
| 38 |
if (not -e $file) { |
| 39 |
warn "$file is not a file\n"; |
| 40 |
next; |
| 41 |
}; |
| 42 |
my $prj = gzopen($file, "rb") or ($uhoh=1); |
| 43 |
if ($uhoh) { |
| 44 |
warn "could not open $file as an Athena project\n"; |
| 45 |
$uhoh = 0; |
| 46 |
next; |
| 47 |
}; |
| 48 |
print "===> $file:\n\n"; |
| 49 |
my $line = q{}; |
| 50 |
my $count = 0; |
| 51 |
while ($prj->gzreadline($line) > 0) { |
| 52 |
next if ($line !~ /^\@args/); |
| 53 |
## read the array in a Safe compartment |
| 54 |
@ {$cpt->varglob('array')} = $cpt->reval( $line ); |
| 55 |
%array = @ {$cpt->varglob('array')}; |
| 56 |
printf " %3d: %s\n", ++$count, $array{label}; |
| 57 |
%array = (); |
| 58 |
}; |
| 59 |
$prj->gzclose(); |
| 60 |
print "\n"; |
| 61 |
}; |
| 62 |
|
| 63 |
1; |
| 64 |
|
| 65 |
__END__ |
| 66 |
|
| 67 |
=head1 NAME |
| 68 |
|
| 69 |
lsprj - list the contents of an Athena project |
| 70 |
|
| 71 |
=head1 SYNOPSIS |
| 72 |
|
| 73 |
lsprj [-h] project_file(s) |
| 74 |
|
| 75 |
=head1 DESCRIPTION |
| 76 |
|
| 77 |
This little program lists the contents of one or more Athena project |
| 78 |
file and echos that list to the screen. |
| 79 |
|
| 80 |
=head1 AUTHOR |
| 81 |
|
| 82 |
Bruce Ravel, [email protected] |
| 83 |
http://cars9.uchicago.edu/~ravel |
| 84 |
|
| 85 |
=cut |