#!/usr/bin/env perl # File: evince.wrapper.in # License: Creative Commons Attribution-NonCommercial-ShareAlike 2.5 # Revision: 211031 #--------------------------------------------------------------------- # important note #--------------------------------------------------------------------- # This software is provided on an AS IS basis with ABSOLUTELY NO WAR- # RANTY. The entire risk as to the quality and performance of the # software is with you. Should the software prove defective, you as- # sume the cost of all necessary servicing, repair or correction. In # no event will any of the developers, or any other party, be liable # to anyone for damages arising out of use of the software, or inabil- # ity to use the software. #--------------------------------------------------------------------- # overview #--------------------------------------------------------------------- # Label must be single-quoted here my $USAGE_TEXT = << 'END_OF_USAGE_TEXT'; Usage: $PROGNAME --run This is a sample Perl program that simply prints "Hello world". END_OF_USAGE_TEXT #--------------------------------------------------------------------- # module setup #--------------------------------------------------------------------- require 5.8.1; use strict; use Carp; use warnings; use Cwd; # Trap warnings $SIG{__WARN__} = sub { die @_; }; #--------------------------------------------------------------------- # basic constants #--------------------------------------------------------------------- use constant ZERO => 0; # Zero use constant ONE => 1; # One use constant TWO => 2; # Two use constant FALSE => 0; # Boolean FALSE use constant TRUE => 1; # Boolean TRUE #--------------------------------------------------------------------- # program parameters #--------------------------------------------------------------------- my $PURPOSE = 'Sample Perl program'; my $REVISION = '110119'; my $USE_LESS = FALSE; # Flag: Use "less" for usage text #--------------------------------------------------------------------- # global variables #--------------------------------------------------------------------- my $PROGNAME; # Program name (without path) $PROGNAME = $0; $PROGNAME =~ s@.*/@@; #--------------------------------------------------------------------- # support routines #--------------------------------------------------------------------- # "UsageError" prints usage text for the current program, then term- # inates the program with exit status one. #--------------------------------------------------------------------- sub UsageError { $USAGE_TEXT =~ s@^\s+@@s; $USAGE_TEXT =~ s@\$PROGNAME@$PROGNAME@g; $USAGE_TEXT = << "END"; # "END" must be double-quoted here $PROGNAME $REVISION - $PURPOSE $USAGE_TEXT END $USAGE_TEXT =~ s@\s*\z@\n@s; if ($USE_LESS && (-t STDOUT) && open (OFD, "|/usr/bin/less")) { # "END" must be double-quoted here $USAGE_TEXT = << "END"; To exit this "help" text, press "q" or "Q". To scroll up or down, use PGUP, PGDN, or the arrow keys. $USAGE_TEXT END print OFD $USAGE_TEXT; close OFD; } else { print "\n", $USAGE_TEXT, "\n"; } exit ONE; } #--------------------------------------------------------------------- # utility routines #--------------------------------------------------------------------- sub readfile { my ($ifname) = @_; undef $/; open (IFD, "<$ifname") || die; my $data = ; close (IFD); $data; } #--------------------------------------------------------------------- sub writefile { my ($ifname, $data) = @_; undef $/; open (OFD, ">$ifname") || die; print OFD $data; close (OFD); $data; } sub fixstring { my ($str) = @_; $str = "" unless defined $str; $str =~ s@^\s+@@s; $str =~ s@\s+\z@@s; $str =~ s@\s+@ @gs; $str; } #--------------------------------------------------------------------- # main routine #--------------------------------------------------------------------- sub Main { my $ifname; # Input-file name or pathname my $str; # Scratch #--------------------------------------------------------------------- # Initial setup. select STDERR; $| = ONE; # Force STDERR flush on write select STDOUT; $| = ONE; # Force STDOUT flush on write for my $ii (ZERO .. $#ARGV) { my $arg = $ARGV [$ii]; if (($arg =~ m@\.(abw|docx?|epub|odt|rtf|wpd)\z@) && (-f $arg) && (-r $arg)) { my $str = `epubtopdf "$arg" 2>&1`; $str = "" unless defined $str; $str =~ s@\s+\z@@s; if ($str =~ m@ (/\S+/\S+?\.pdf)\z@) { $ARGV [$ii] = $1; } } } # Create a required directory my $HOME = $ENV {'HOME'}; system "mkdir -p $HOME/.gnome2/evince"; my $PRODTREE = $ENV {'PRODTREE'}; exec "$PRODTREE/evince/xbin/evince", @ARGV; } #--------------------------------------------------------------------- # main program #--------------------------------------------------------------------- &Main(); # Call the main routine exit ZERO; # Normal exit