File: rdaj

package info (click to toggle)
horae 071~svn536-1
  • links: PTS
  • area: contrib
  • in suites: wheezy
  • size: 12,996 kB
  • sloc: perl: 67,215; lisp: 744; sh: 78; makefile: 76; ansic: 35
file content (92 lines) | stat: -rwxr-xr-x 2,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
#
# This is a little script to snarf the journal entry from an Athena
# or Artemis project file and write it to STDOUT
# -------------------------------------------------------------------

use strict;
use Safe;
use Text::Wrap;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Compress::Zlib;
use Getopt::Long;

my $help;
GetOptions('h'    => \$help,
	   'help' => \$help);

if ($help or not $ARGV[0]) {
  require Pod::Text;
  $^W=0;
  if ($Pod::Text::VERSION < 2.0) {
    Pod::Text::pod2text($0, *STDOUT);
  } elsif ($Pod::Text::VERSION >= 2.0) {
    my $parser = Pod::Text->new;
    open STDIN, $0;
    $parser->parse_from_filehandle;
  };
  exit;
};

Archive::Zip::setErrorHandler( \&is_zip_error_handler );
my $zip = Archive::Zip->new();
if ($zip->read( $ARGV[0] ) == AZ_OK) {
  $zip->extractMemberWithoutPaths("descriptions/journal.artemis", "...horae_journal");
  die "Hmmm... that was a zip file but not an Artemis project file...\n" unless (-e "...horae_journal");
  if (-s "...horae_journal" < 3) {
    print "  << empty journal >> \n";
    exit;
  };
  open P, "...horae_journal";
  print while (<P>);
  close P;
  unlink  "...horae_journal";
  exit;
} else {
  die "Whoops!  That file doesn't seem to exist!\n" unless (-e $ARGV[0]);
  my $athena_fh = gzopen($ARGV[0], "rb") or die "could not open $ARGV[0] as an Athena or Artemis project file\n";
  my $nline = 0;
  my $line = q{};
  my $cpt = new Safe;
  while ($athena_fh->gzreadline($line) > 0) {
    ++$nline;
    next unless ($line =~ m{^\@journal});
    my $cpt = new Safe;
    @ {$cpt->varglob('journal')} = $cpt->reval($line);
    my @j = ();
    push @j, wrap("","",$_) foreach (@ {$cpt->varglob('journal')});
    my $journal = join($/, @j);
    if ($journal =~ /^[\s\n\r]*$/) {
      print "  << empty journal >> \n";
      exit;
    };
    print $journal, $/;
    exit;
  };
};

sub is_zip_error_handler { 1; };

1;

__END__

=head1 NAME

rdaj - echo the Athena or Artemis project journal entry to the screen

=head1 SYNOPSIS

   rdaj [-h] project_file

=head1 DESCRIPTION

This little program grabs the journal entry from your Athena or
Artemis project files and echos it to the screen.

=head1 AUTHOR

  Bruce Ravel, bravel@anl.gov
  http://cars9.uchicago.edu/~ravel

=cut