home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.misc
- Path: sparky!uunet!wupost!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!kakwa.ucs.ualberta.ca!news
- From: sherwood@fenris.space.ualberta.ca (Sherwood Botsford)
- Subject: Re: Question about printing multiple documents...
- Message-ID: <1992Jul28.192129.6663@kakwa.ucs.ualberta.ca>
- Sender: news@kakwa.ucs.ualberta.ca
- Nntp-Posting-Host: fenris.space.ualberta.ca
- Organization: University Of Alberta, Edmonton Canada
- References: <27JUL92.18000038@enh.nist.gov>
- Date: Tue, 28 Jul 1992 19:21:29 GMT
- Lines: 453
-
- aoml@enh.nist.gov writes
- > I am currently programing a very large application. It would be nice if I
- > could print several files with one command. Does anyone know of a utility
- > which would do this? I prefer non-commercial (of course) software. If there
- > is a unix command that would accomplish the same thing, that would be fine.
- >
- > Thanks in advance,
- >
- > Kevin
- > (Please E-Mail Answers)
-
- see lpd
-
- However, paf is neater, in that it defaults to 2 up, prints the filename and
- date on the bottom, your name (Handy if 15 people use the same printer)
-
- Below is the paf script.
- ON fenris==>cat /usr/local/bin/paf
- #! /bin/sh
- # @(#) paf Shell script to Print Ascii Files
- #
- # This routine generates file listings on postscript printers. The command
- # arguments are the names of the files to print. If no arguments are given
- # the standard input is used. The following options may be specified:
- #
- # Stolen from Jim Hoover (hoover)
- # Modifyed by Anthony Mutiso
- # Modified by Bob Beck
- #
- # $Revision: 1.9 $
- # $Date: 90/06/11 09:47 $
- #
- # $Log: paf,v $
- # Revision 1.9 90/06/11 09:47:21 beck
- # ported to seymour, changed printers, man page.
- # fixed help so that it displays defaults for env vars PRINTER
- # and USER.
- # modified to use awk instead of nawk.
- #
- # Revision 1.8 90/05/07 12:41:24 anthony
- # Fixed a PATH string, and the help message printing.
- # Anthony
- #
- # Revision 1.7 89/10/11 00:12:44 anthony
- # FIxed -n Bug
- # Fixed the echoing to work with the vax which does
- # not have /usr/5bin/echo
- #
- # Revision 1.6 89/09/25 12:28:28 anthony
- # Added Umask 066 for file creation protection
- # Fixed the width option to work correctly
- # Corrected Usage string printing, and 1 Col Portrait mode default
- # Converted echoing to use /usr/5bin/echo
- #
- # Revision 1.5 89/06/29 14:58:36 anthony
- # Fixed stdin bug
- # Added -V for version option.
- #
- # Revision 1.4 89/05/29 14:09:00 anthony
- # Added -P<spool> command option to simulate lpr(1) style options.
- #
- # Revision 1.3 89/05/29 13:22:37 anthony
- # Improved date string handling
- # Will no longer spool empty files
- # Checks for unaccessable files in read access on files to be printed
- # Invalidates unrecognized command options.
- # Comment: Good for Release.
- #
- # Revision 1.2 89/05/29 13:16:52 anthony
- # Major clean up
- #
- # Revision 1.1 89/05/26 15:08:00 anthony
- # Initial revision
- #
- # Revision 1.1 89/05/26 15:06:26 anthony
- # Initial revision
- #
- #
- # Man page /usr/cavell/u1/grad/anthony/man/manl/paf.l
- #
- # REMARKS
- # -------
-
- # The default values for characters per column and lines per page are:
-
- # Format Columns -width -length
- # ---------------------------------------------
- # Portrait 1 80 53
- # Portrait 2 80 109
- # Landscape 1 132 49
- # Landscape 2 80 61
- # Otherwise 80 auto
-
- # If you specify only "width" then "length" is calculated automatically
- according
- # to the number of lines that fit with the font size that holds the cpl.
- # If you specify the lpp the font will be anamorphically scaled to fit the
- # "width" and "length" in one column.
-
- # Any ^L found in the data will cause a new page to be started. The first
- # character after the ^L will start the first line of the new page.
-
- # --------------------
-
- # SET DEFAULTS
-
- # set -x # DEBUG
-
- trap "/bin/rm -f $tmpfile" 15
-
- PATH=/usr/new/bin:/usr/local/bin:/bin:/usr/bin:/usr/ucb:/usr/5bin; export PATH
-
- umask 066 # Make all created files readonly to user
- script=/usr/local/lib # Place where support files can be found.
- ECHO="echo"
-
- userstring="User: $USER"
- case "$1" in
- -us*) ;;
- help|Help|HELP|-H*|-h*) ;;
- *)
- eval `date | awk '{
- printf ("dateline=\"%s %s %s %s %s %s\"; ", $1, $2, $3, $4, $5, $6)
- printf ("date=\"Date: %s %s, %s\"; ", $2, $3, $6)
- printf ("time=\" -- Time: %s\"\n", $4)}'`;;
- esac
-
-
- name=`basename $0`
- usage1="usage: $name [-form[at]|-fmt P|L] [-col[umns] n] [-wi[dth] n]
- [-len[gth] n]"
- usage2=" [-ti[tle] string] [-P[rinter] string] [-D[ate] string] [-T[ime]
- string]"
- usage3=" [-U[ser] string] [-v] [-s] [-n] [-m[ail]] [-o[utput] file|-]
- [-q[uite]]"
- usage4=" [-us[age]|-h[elp]] [-V]"
- printeropts="-h"
-
- revision='$Revision: 1.9 $ $Date: 90/06/11 09:47 $'
- fmtopt=L
- catopts=""
- outopt="--"
- widthopt=0
- lengthopt=0 # 0 ==> auto
- quietopt=0
- fileprefix="File: "
- hdrprefix=""
- userprefix=""
- defprinter="lp"
-
- if [ "$PRINTER" ]; then printer=$PRINTER; fi
-
- if [ $# -eq 0 ]; then
- inputfiles="--"
- else
-
- while :
- do
- case "$1" in
- -fmt|-form*)
- if [ "$2" = "P" -o "$2" = "p" -o "$2" = "L" -o "$2" = "l" ];
- then
- fmtopt=$2
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi
- else
- $ECHO $name error
- $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO
- "$usage4"
- exit 2
- fi;;
- -col*)
- colsopt=$2
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -wi*)
- widthopt=$2
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -len*)
- lengthopt=$2
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -ti*)
- titleopt="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -P*)
- case "$1" in
- -Pws)
- printer="ws";;
- -Pgr)
- printer="gr";;
- -P|-Print*)
- printer="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- *)
- $ECHO "$name: Invalid printer name ($1)"; exit 2;;
- esac;;
- -D|-Date*) date="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -T|-Time*) time="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -U|-User*) userstring="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -V)
- $ECHO "$name: $revision" | sed 's/\$//g';
- exit 0;;
- -o|-out*)
- outopt="$2"
- if [ $# -gt 1 ]; then
- shift
- else
- $ECHO "$name: insufficient options."
- exit 2
- fi;;
- -m|-mail*)
- printeropts="$printeropts -m";;
- -s)
- catopts="$catopts -s";;
- -v)
- catopts="$catopts -v";;
- -n)
- catopts="$catopts -n";;
- -q*)
- quietopt=1;;
- -us*)
- $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO
- "$usage4"
- exit 0;;
- help|Help|HELP|-H*|-h*)
- cat >&1 << EOF-HELP-MESSAGE
- $name (Print Ascii File) usage: $name [options] files...
- where options are the following
- -fmt [P|L] Generates the listing in Portrait or Landscap
- format, default is Landscape format.
- -form[at] [P|L] Same a -fmt
- -col[umns] number Generates the listing in "n" columns per page, default
- is two columns for landscape mode and one for portrait.
- -wi[dth] number Generates the listing with room for "n" characters
- per column. default is 80.
- -len[gth] number Generates the listing with room for "number" lines per
- page. default is 57 in landscape, 55 in portrait.
- -ti[tle] string Specifies the title for each listing page,
- default is the input file names.
- -P[rinter] string Specifies the printer to use, default is currently
- "$PRINTER", from your PRINTER environment variable
- (if defined - "lp" if not).
- "string" should be one of "ws" or "gr".
- -P<spool> Where <spool> is one of "consult" "netlw" "genoffntx"
- or "demonext".
- -D[ate] string Specifies the date string to be used, default is
- calculated date today.
- -T[ime] string Specifies the time string to be used, default is
- the time current time.
- -U[ser] string Specifies the user string to be used, default is
- currently "$USER", from your USER environment variable
- -v Runs input through cat -v to hide control characters,
- default is off.
- -s Runs input through cat -s to squeeze white space,
- default is off.
- -n Add line numbers to the listing, default is off.
- -m[ail] Mail user when file is printed.
- -o[utput] file|- Sends the output to the file file or to standard
- output,
- if option is - send output stdout (sets -q option).
- -q[uiet] Run quietly (do not generate "placate the user
- messages").
- -us[age] Give some help messages.
- -h[elp] Same as -usage.
- -V Print revision information.
- ......... See 'man $name' for more help.
-
- EOF-HELP-MESSAGE
- exit 0;;
- -*)
- $ECHO "$name: invalid option ($1)"
- $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO
- "$usage4"
- exit 0;;
- *)
- inputfiles="$inputfiles $1";;
- esac
- if [ $# -gt 1 ]; then shift; else break; fi
- done
-
- if [ ! "$inputfiles" ]; then inputfiles="--"; fi
-
- fi
-
- # IS THE PRINTER SET YET?
- if [ "$outopt" = "--" ]; then
- if [ ! "$printer" ]; then
- printer=$defprinter;
- $ECHO "$name: Using printer ""$printer""."
- fi
- fi
-
- # QUIET IF I AM WRITING TO STDOUT
- if [ "$outopt" = "-" ]; then quietopt=1; fi
-
- # SET OTHER OPTION
-
- if [ ! "$colsopt" ]; then
- if [ "$fmtopt" = "L" ]; then
- colsopt=2
- else
- colsopt=1
- fi
- fi
- datestring="$date$time"
- hostname=`hostname`
-
- case "$fmtopt$colsopt" in
- "P1") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
- else cpc=$widthopt; foldopt=-$widthopt; fi;;
- "P2") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
- else cpc=$widthopt; foldopt=-$widthopt; fi;;
- "L1") if [ $widthopt -eq 0 ]; then cpc=132; foldopt=-132
- else cpc=$widthopt; foldopt=-$widthopt; fi;;
- "L2") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
- else cpc=$widthopt; foldopt=-$widthopt; fi;;
- *) if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
- else cpc=$widthopt; foldopt=-$widthopt; fi;;
- esac
-
- # BEGIN PROCESSING
- # Process each file separately.
-
- tmpfile=/tmp/$name.$$
-
- for file in $inputfiles; do
-
- if [ \( -f "$file" -a -r "$file" \) -o "$file" = "--" ]; then
- processedfiles="$processedfiles $file"
- if [ $quietopt -eq 0 ]; then
- if [ "$file" != "--" ]; then
- $ECHO "$name: processing file '$file'."
- else
- $ECHO "$name: processing 'standard input'."
- fi
- fi
- else
- if [ $quietopt -eq 0 ]; then
- $ECHO "$name: file $file not found!"
- fi
- continue
- fi
-
- if [ "$titleopt" ]; then hdr="$titleopt";
- elif [ "$file" = "--" ]; then hdr="standard input";
- else hdr="$fileprefix$file";
- fi
-
- (
- # $ECHO "%%Title: $USER@$hostname/$name->ps"
- # $ECHO "%%DocumentFonts:"
- # $ECHO "%%Creator: $name->ps"
- # $ECHO "%%CreationDate: $dateline"
- # $ECHO "%%Pages: (atend)"
- # $ECHO "%%For: $USER@$hostname"
- # $ECHO "%%EndComments"
- $ECHO "%!"
- $ECHO "save"
- $ECHO "/dateIs ($datestring) def"
- $ECHO "/headIs ($hdrprefix$hdr) def"
- $ECHO "/userIs ($userprefix$userstring) def"
- $ECHO "/fmtIs ($fmtopt) def"
- $ECHO "/nCols $colsopt def"
- $ECHO "/CPC $cpc def"
- $ECHO "/LPP $lengthopt def"
-
- cat $script/print.ps
-
- #
- # expand tabs into spaces, number/compress/fold lines.
- # escape the special characters ( ) and / inside the postscript string.
- # make each line into the postscript command ( line ) doLine
-
- if [ "$file" = "--" ]; then expand; else expand "$file"; fi |
- if [ "$catopts" != "" ]; then cat $catopts | fold $foldopt; else fold
- $foldopt; fi |
- sed -e 's/\\/\\\\/g' -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/.*/(&)
- doLine/'
-
- $ECHO "newPage restore"
-
- ) | if [ "$outopt" = "--" ]; then
- cat >> $tmpfile
- elif [ "$outopt" = "-" ]; then
- cat
- else $ECHO "" > $outopt; cat >> $outopt
- fi
- done
-
- if [ "$outopt" = "--" ]; then
- if [ "$processedfiles" ]; then
- lpr -P$printer $printeropts $tmpfile
- fi
- /bin/rm -f $tmpfile
- outstream="printer $printer"
- elif [ "$outopt" = "-" ]; then
- outstream="stdout"
- else outstream="$outopt"
- fi
-
- if [ "$quietopt" -eq 0 ]; then
- if [ "$inputfiles" = "--" ]; then
- $ECHO "$name: done files ( StandardInput ) spooled to $outstream."
- else
- $ECHO "$name: done files ($processedfiles ) spooled to $outstream."
- fi
- fi
-