Debian Codegraph @

bin/rdaj

raw
1 #!/usr/bin/perl
2 #
3 # This is a little script to snarf the journal entry from an Athena
4 # or Artemis project file and write it to STDOUT
5 # -------------------------------------------------------------------
6
7 use strict;
8 use Safe;
9 use Text::Wrap;
10 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
11 use Compress::Zlib;
12 use Getopt::Long;
13
14 my $help;
15 GetOptions('h' => \$help,
16 'help' => \$help);
17
18 if ($help or not $ARGV[0]) {
19 require Pod::Text;
20 $^W=0;
21 if ($Pod::Text::VERSION < 2.0) {
22 Pod::Text::pod2text($0, *STDOUT);
23 } elsif ($Pod::Text::VERSION >= 2.0) {
24 my $parser = Pod::Text->new;
25 open STDIN, $0;
26 $parser->parse_from_filehandle;
27 };
28 exit;
29 };
30
31 Archive::Zip::setErrorHandler( \&is_zip_error_handler );
32 my $zip = Archive::Zip->new();
33 if ($zip->read( $ARGV[0] ) == AZ_OK) {
34 $zip->extractMemberWithoutPaths("descriptions/journal.artemis", "...horae_journal");
35 die "Hmmm... that was a zip file but not an Artemis project file...\n" unless (-e "...horae_journal");
36 if (-s "...horae_journal" < 3) {
37 print " << empty journal >> \n";
38 exit;
39 };
40 open P, "...horae_journal";
41 print while (<P>);
42 close P;
43 unlink "...horae_journal";
44 exit;
45 } else {
46 die "Whoops! That file doesn't seem to exist!\n" unless (-e $ARGV[0]);
47 my $athena_fh = gzopen($ARGV[0], "rb") or die "could not open $ARGV[0] as an Athena or Artemis project file\n";
48 my $nline = 0;
49 my $line = q{};
50 my $cpt = new Safe;
51 while ($athena_fh->gzreadline($line) > 0) {
52 ++$nline;
53 next unless ($line =~ m{^\@journal});
54 my $cpt = new Safe;
55 @ {$cpt->varglob('journal')} = $cpt->reval($line);
56 my @j = ();
57 push @j, wrap("","",$_) foreach (@ {$cpt->varglob('journal')});
58 my $journal = join($/, @j);
59 if ($journal =~ /^[\s\n\r]*$/) {
60 print " << empty journal >> \n";
61 exit;
62 };
63 print $journal, $/;
64 exit;
65 };
66 };
67
68 sub is_zip_error_handler { 1; };
69
70 1;
71
72 __END__
73
74 =head1 NAME
75
76 rdaj - echo the Athena or Artemis project journal entry to the screen
77
78 =head1 SYNOPSIS
79
80 rdaj [-h] project_file
81
82 =head1 DESCRIPTION
83
84 This little program grabs the journal entry from your Athena or
85 Artemis project files and echos it to the screen.
86
87 =head1 AUTHOR
88
89 Bruce Ravel, [email protected]
90 http://cars9.uchicago.edu/~ravel
91
92 =cut