#!/usr/bin/perl # # $Id: enprint,v 1.1 1996/05/20 23:36:38 vogelke Exp $ # # NAME: # enprint # # SYNOPSIS: # enprint [-hv] files # # DESCRIPTION: # "enprint" reads the output from an enscript command that involves # multiple files, and makes sure that the page numbers go up sensibly. # Each new file will not start on page 1. # # OPTIONS: # "-h" prints help information and exits. # "-v" prints the current version and exits. # # AUTHOR: # Karl E. Vogel # Control Data Systems, Inc. # # HISTORY: # $Log: enprint,v $ # Revision 1.1 1996/05/20 23:36:38 vogelke # Initial revision # # eval 'exec perl -S $0 ${1+"$@"}' # If the shell can't handle "#!", if 0; # fire up perl directly. require "getopts.pl"; # command line args. $ENV{"PATH"} = "/bin:/usr/sbin:/usr/local/bin"; $tmp = "/tmp/enprint.$$"; ($myname) = split (/\//, reverse ($0)); $myname = reverse ($myname); # script basename. $debug_on = 0; # 0=normal, 1=debugging output. $saw_interrupt = 0; # 0=normal, 1=caught signal. # # Trap most common signals. # $SIG{'HUP'} = 'sigcatcher'; $SIG{'INT'} = 'sigcatcher'; $SIG{'QUIT'} = 'sigcatcher'; $SIG{'TERM'} = 'sigcatcher'; # # Handle command line arguments (if any). # $opt_h = 1 unless &Getopts ('hv'); &synopsis if $opt_h; &version if $opt_v; $newpage = 1; while (<>) { chop; if (/StartPage$/) { ($page, $title, $rest) = split; print "($newpage) $title $rest\n"; $newpage++; } else { print "$_\n" } } &exit (0); #--------------------------------------------------------------------- # Print a short usage message from the comment header and exit. # sub usage { if (open (PROG, "$myname")) { while () { last if /^# NAME:/; } print STDERR " NAME:\n"; while () { last if /^\s*$/; last if /^# AUTHOR:/; s/^#//; print STDERR; } close (PROG); } else { print STDERR "No usage information available.\n" ; } &exit (1); } #--------------------------------------------------------------------- # Print an optional message followed by a short synopsis of the # comment header. Then exit with value 1. # sub synopsis { local($msg) = @_; warn "\n$myname: $msg\n\n" if $msg; if (open (PROG, "$myname")) { while () { last if /^# NAME:/; } print STDERR " NAME:\n"; while () { last if /^\s*$/; last if /^# AUTHOR:/; s/^#//; print STDERR; } close (PROG); } else { print STDERR "No synopsis information available.\n" ; } &exit (1); } #--------------------------------------------------------------------- # Do something if we get a signal. # sub sigcatcher { local($sig) = @_; &exit (2, "caught signal SIG$sig -- shutting down.\n"); } #--------------------------------------------------------------------- # Print the current version and exit. # sub version { $_ = '$RCSfile: enprint,v $ $Revision: 1.1 $ ' . '$Date: 1996/05/20 23:36:38 $'; s/RCSfile: //; s/.Date: //; s/,v . .Revision: / v/; s/\$//g; print "$_\n"; exit (0); } #--------------------------------------------------------------------- # Clean up. # sub exit { local($code, $msg) = @_; unlink ($tmp) unless $debug_on; warn "$myname: $msg\n" if $msg; exit ($code); }