home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / misc / 18238 < prev    next >
Encoding:
Text File  |  1992-07-28  |  14.6 KB  |  466 lines

  1. Newsgroups: comp.sys.next.misc
  2. Path: sparky!uunet!wupost!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!kakwa.ucs.ualberta.ca!news
  3. From: sherwood@fenris.space.ualberta.ca (Sherwood Botsford)
  4. Subject: Re: Question about printing multiple documents...
  5. Message-ID: <1992Jul28.192129.6663@kakwa.ucs.ualberta.ca>
  6. Sender: news@kakwa.ucs.ualberta.ca
  7. Nntp-Posting-Host: fenris.space.ualberta.ca
  8. Organization: University Of Alberta, Edmonton Canada
  9. References: <27JUL92.18000038@enh.nist.gov>
  10. Date: Tue, 28 Jul 1992 19:21:29 GMT
  11. Lines: 453
  12.  
  13. aoml@enh.nist.gov writes
  14. > I am currently programing a very large application.  It would be nice if I
  15. > could print several files with one command.  Does anyone know of a utility
  16. > which would do this?  I prefer non-commercial (of course) software.  If there
  17. > is a unix command that would accomplish the same thing, that would be fine.
  18. > Thanks in advance,
  19. > Kevin
  20. > (Please E-Mail Answers)
  21.  
  22. see lpd
  23.  
  24. However, paf is neater, in that it defaults to 2 up, prints the filename and  
  25. date on the bottom, your name (Handy if 15 people use the same printer)
  26.  
  27. Below is the paf script.
  28. ON fenris==>cat /usr/local/bin/paf
  29. #! /bin/sh
  30. # @(#) paf Shell script to Print Ascii Files
  31. #
  32. # This routine generates file listings on postscript printers.  The command
  33. # arguments are the names of the files to print.  If no arguments are given
  34. # the standard input is used.  The following options may be specified:
  35. #
  36. # Stolen from Jim Hoover (hoover)
  37. # Modifyed by Anthony Mutiso
  38. # Modified by Bob Beck 
  39. #
  40. # $Revision: 1.9 $
  41. # $Date: 90/06/11 09:47 $
  42. #
  43. # $Log: paf,v $
  44. # Revision 1.9  90/06/11  09:47:21  beck
  45. # ported to seymour, changed printers, man page.
  46. # fixed help so that it displays defaults for env vars PRINTER
  47. # and USER.
  48. # modified to use awk instead of nawk. 
  49. #
  50. # Revision 1.8  90/05/07  12:41:24  anthony
  51. # Fixed a PATH string, and the help message printing.
  52. # Anthony
  53. # Revision 1.7  89/10/11  00:12:44  anthony
  54. # FIxed -n Bug
  55. # Fixed the echoing to work with the vax which does
  56. # not have /usr/5bin/echo
  57. # Revision 1.6  89/09/25  12:28:28  anthony
  58. # Added Umask 066 for file creation protection
  59. # Fixed the width option to work correctly
  60. # Corrected Usage string printing, and 1 Col Portrait mode default
  61. # Converted echoing to use /usr/5bin/echo
  62. # Revision 1.5  89/06/29  14:58:36  anthony
  63. # Fixed stdin bug
  64. # Added -V for version option.
  65. # Revision 1.4  89/05/29  14:09:00  anthony
  66. # Added -P<spool> command option to simulate lpr(1) style options.
  67. # Revision 1.3  89/05/29  13:22:37  anthony
  68. # Improved date string handling
  69. # Will no longer spool empty files
  70. # Checks for unaccessable files in read access on files to be printed
  71. # Invalidates unrecognized command options.
  72. # Comment: Good for Release.
  73. # Revision 1.2  89/05/29  13:16:52  anthony
  74. # Major clean up
  75. # Revision 1.1  89/05/26  15:08:00  anthony
  76. # Initial revision
  77. # Revision 1.1  89/05/26  15:06:26  anthony
  78. # Initial revision
  79. #
  80. # Man page /usr/cavell/u1/grad/anthony/man/manl/paf.l
  81. #
  82. # REMARKS
  83. # -------
  84.  
  85. # The default values for characters per column and lines per page are:
  86.  
  87. #       Format          Columns         -width  -length
  88. #       ---------------------------------------------
  89. #       Portrait        1                 80      53
  90. #       Portrait        2                 80     109
  91. #       Landscape       1                132      49
  92. #       Landscape       2                 80      61
  93. #       Otherwise                         80    auto
  94.  
  95. # If you specify only "width" then "length" is calculated automatically  
  96. according
  97. # to the number of lines that fit with the font size that holds the cpl.
  98. # If you specify the lpp the font will be anamorphically scaled to fit the
  99. # "width" and "length" in one column.
  100.  
  101. # Any ^L found in the data will cause a new page to be started.  The first
  102. # character after the ^L will start the first line of the new page.
  103.  
  104. # --------------------
  105.  
  106. # SET DEFAULTS
  107.  
  108. # set -x # DEBUG
  109.  
  110. trap "/bin/rm -f $tmpfile" 15 
  111.  
  112. PATH=/usr/new/bin:/usr/local/bin:/bin:/usr/bin:/usr/ucb:/usr/5bin; export PATH
  113.  
  114. umask 066       # Make all created files readonly to user
  115. script=/usr/local/lib   # Place where support files can be found.
  116. ECHO="echo"
  117.  
  118. userstring="User: $USER"
  119. case "$1" in
  120.    -us*) ;;
  121.    help|Help|HELP|-H*|-h*) ;;
  122.    *)
  123.    eval `date | awk '{
  124.       printf ("dateline=\"%s %s %s %s %s %s\"; ", $1, $2, $3, $4, $5, $6)
  125.       printf ("date=\"Date: %s %s, %s\"; ", $2, $3, $6)
  126.       printf ("time=\" -- Time: %s\"\n", $4)}'`;;
  127. esac
  128.  
  129.  
  130. name=`basename $0`
  131. usage1="usage: $name [-form[at]|-fmt P|L] [-col[umns] n] [-wi[dth] n]  
  132. [-len[gth] n]"
  133. usage2="        [-ti[tle] string] [-P[rinter] string] [-D[ate] string] [-T[ime]  
  134. string]"
  135. usage3="        [-U[ser] string] [-v] [-s] [-n] [-m[ail]] [-o[utput] file|-]  
  136. [-q[uite]]"
  137. usage4="        [-us[age]|-h[elp]] [-V]"
  138. printeropts="-h"
  139.  
  140. revision='$Revision: 1.9 $ $Date: 90/06/11 09:47 $'
  141. fmtopt=L
  142. catopts=""
  143. outopt="--"
  144. widthopt=0
  145. lengthopt=0                     # 0 ==> auto
  146. quietopt=0
  147. fileprefix="File: "
  148. hdrprefix=""
  149. userprefix=""
  150. defprinter="lp"
  151.  
  152. if [ "$PRINTER" ]; then printer=$PRINTER; fi 
  153.  
  154. if [ $# -eq 0 ]; then
  155.    inputfiles="--"
  156. else
  157.  
  158.    while :
  159.    do
  160.        case "$1" in
  161.             -fmt|-form*)
  162.                if [ "$2" = "P" -o "$2" = "p" -o "$2" = "L" -o "$2" = "l" ];  
  163. then
  164.                   fmtopt=$2
  165.                   if [ $# -gt 1 ]; then
  166.                      shift
  167.                   else
  168.                      $ECHO "$name: insufficient options."
  169.                      exit 2
  170.                   fi
  171.                else
  172.                   $ECHO $name error
  173.                   $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO  
  174. "$usage4"
  175.                   exit 2
  176.                fi;;
  177.             -col*)
  178.                colsopt=$2
  179.                if [ $# -gt 1 ]; then
  180.                   shift
  181.                else
  182.                   $ECHO "$name: insufficient options."
  183.                   exit 2
  184.                fi;;
  185.             -wi*)
  186.                widthopt=$2
  187.                if [ $# -gt 1 ]; then
  188.                   shift
  189.                else
  190.                   $ECHO "$name: insufficient options."
  191.                   exit 2
  192.                fi;;
  193.             -len*)
  194.                lengthopt=$2
  195.                if [ $# -gt 1 ]; then
  196.                   shift
  197.                else
  198.                   $ECHO "$name: insufficient options."
  199.                   exit 2
  200.                fi;;
  201.             -ti*)
  202.                titleopt="$2"
  203.                if [ $# -gt 1 ]; then
  204.                   shift
  205.                else
  206.                   $ECHO "$name: insufficient options."
  207.                   exit 2
  208.                fi;;
  209.             -P*)
  210.                case "$1" in
  211.                   -Pws)
  212.                      printer="ws";;
  213.                   -Pgr)
  214.                      printer="gr";;
  215.                   -P|-Print*)
  216.                      printer="$2"
  217.                      if [ $# -gt 1 ]; then
  218.                         shift
  219.                      else
  220.                         $ECHO "$name: insufficient options."
  221.                         exit 2
  222.                      fi;;
  223.                   *)
  224.                     $ECHO "$name: Invalid printer name ($1)"; exit 2;;
  225.                esac;;
  226.             -D|-Date*) date="$2"
  227.                if [ $# -gt 1 ]; then
  228.                   shift
  229.                else
  230.                   $ECHO "$name: insufficient options."
  231.                   exit 2
  232.                fi;;
  233.             -T|-Time*) time="$2"
  234.                if [ $# -gt 1 ]; then
  235.                   shift
  236.                else
  237.                   $ECHO "$name: insufficient options."
  238.                   exit 2
  239.                fi;;
  240.             -U|-User*) userstring="$2"
  241.                if [ $# -gt 1 ]; then
  242.                   shift
  243.                else
  244.                   $ECHO "$name: insufficient options."
  245.                   exit 2
  246.                fi;;
  247.             -V)
  248.                $ECHO "$name: $revision" | sed 's/\$//g';
  249.                exit 0;;
  250.             -o|-out*)
  251.                outopt="$2"
  252.                if [ $# -gt 1 ]; then
  253.                   shift
  254.                else
  255.                   $ECHO "$name: insufficient options."
  256.                   exit 2
  257.                fi;;
  258.             -m|-mail*)
  259.                printeropts="$printeropts -m";;
  260.             -s)
  261.                catopts="$catopts -s";;
  262.             -v)
  263.                catopts="$catopts -v";;
  264.             -n)
  265.                catopts="$catopts -n";;
  266.             -q*)
  267.                quietopt=1;;
  268.          -us*)
  269.                $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO  
  270. "$usage4"
  271.                exit 0;;
  272.          help|Help|HELP|-H*|-h*)
  273.                cat >&1 << EOF-HELP-MESSAGE
  274. $name (Print Ascii File) usage: $name [options] files...
  275. where options are the following
  276. -fmt            [P|L]   Generates the listing in Portrait or Landscap
  277.                         format, default is Landscape format.
  278. -form[at]       [P|L]   Same a -fmt
  279. -col[umns]      number  Generates the listing in "n" columns per page, default
  280.                         is two columns for landscape mode and one for portrait.
  281. -wi[dth]        number  Generates the listing with room for "n" characters
  282.                         per column. default is 80.
  283. -len[gth]       number  Generates the listing with room for "number" lines per
  284.                         page. default is 57 in landscape, 55 in portrait.
  285. -ti[tle]        string  Specifies the title for each listing page,
  286.                         default is the input file names.
  287. -P[rinter]      string  Specifies the printer to use, default is currently 
  288.                         "$PRINTER", from your PRINTER environment variable
  289.                         (if defined - "lp" if not).
  290.                         "string" should be one of "ws" or "gr".
  291. -P<spool>               Where <spool> is one of "consult" "netlw" "genoffntx"
  292.                         or "demonext".
  293. -D[ate]         string  Specifies the date string to be used, default is 
  294.                         calculated date today.
  295. -T[ime]         string  Specifies the time string to be used, default is 
  296.                         the time current time.
  297. -U[ser]         string  Specifies the user string to be used, default is 
  298.                         currently "$USER", from your USER environment variable
  299. -v                      Runs input through cat -v to hide control characters,
  300.                         default is off.
  301. -s                      Runs input through cat -s to squeeze white space,
  302.                         default is off.
  303. -n                      Add line numbers to the listing, default is off.
  304. -m[ail]                 Mail user when file is printed.
  305. -o[utput]       file|-  Sends the output to the file file or to standard  
  306. output,
  307.                         if option is - send output stdout (sets -q option).
  308. -q[uiet]                Run quietly (do not generate "placate the user  
  309. messages").
  310. -us[age]                Give some help messages.
  311. -h[elp]                 Same as -usage.
  312. -V                      Print revision information.
  313. .........              See 'man $name' for more help.
  314.  
  315. EOF-HELP-MESSAGE
  316.                exit 0;;
  317.          -*)
  318.                $ECHO "$name: invalid option ($1)"
  319.                $ECHO "$usage1"; $ECHO "$usage2"; $ECHO "$usage3"; $ECHO  
  320. "$usage4"
  321.                exit 0;;
  322.          *)
  323.                inputfiles="$inputfiles $1";;
  324.        esac
  325.        if [ $# -gt 1 ]; then shift; else break; fi
  326.    done
  327.  
  328.    if [ ! "$inputfiles" ]; then inputfiles="--"; fi
  329.  
  330. fi
  331.  
  332. # IS THE PRINTER SET YET?
  333. if [ "$outopt" = "--" ]; then
  334.    if [ ! "$printer" ]; then 
  335.       printer=$defprinter;
  336.       $ECHO "$name: Using printer ""$printer""."
  337.    fi
  338. fi
  339.  
  340. # QUIET IF I AM WRITING TO STDOUT
  341. if [ "$outopt" = "-" ]; then quietopt=1; fi
  342.  
  343. # SET OTHER OPTION
  344.  
  345. if [ ! "$colsopt" ]; then
  346.    if [ "$fmtopt" = "L" ]; then
  347.       colsopt=2
  348.    else
  349.       colsopt=1
  350.    fi
  351. fi
  352. datestring="$date$time"
  353. hostname=`hostname`
  354.  
  355. case "$fmtopt$colsopt" in
  356.    "P1") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
  357.          else cpc=$widthopt; foldopt=-$widthopt; fi;;
  358.    "P2") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
  359.          else cpc=$widthopt; foldopt=-$widthopt; fi;;
  360.    "L1") if [ $widthopt -eq 0 ]; then cpc=132; foldopt=-132
  361.          else cpc=$widthopt; foldopt=-$widthopt; fi;;
  362.    "L2") if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
  363.          else cpc=$widthopt; foldopt=-$widthopt; fi;;
  364.    *)    if [ $widthopt -eq 0 ]; then cpc=80; foldopt=-80
  365.          else cpc=$widthopt; foldopt=-$widthopt; fi;;
  366. esac
  367.  
  368. # BEGIN PROCESSING
  369. # Process each file separately.
  370.  
  371. tmpfile=/tmp/$name.$$
  372.  
  373. for file in $inputfiles; do
  374.  
  375.     if [ \( -f "$file" -a -r "$file" \) -o "$file" = "--" ]; then
  376.        processedfiles="$processedfiles $file"
  377.       if [ $quietopt -eq 0 ]; then
  378.          if [ "$file" != "--" ]; then
  379.             $ECHO "$name: processing file '$file'."
  380.          else
  381.             $ECHO "$name: processing 'standard input'."
  382.          fi
  383.       fi
  384.     else
  385.        if [ $quietopt -eq 0 ]; then
  386.           $ECHO "$name: file $file not found!"
  387.        fi
  388.        continue
  389.     fi
  390.  
  391.     if [ "$titleopt" ]; then hdr="$titleopt";
  392.     elif [ "$file" = "--" ]; then hdr="standard input";
  393.     else hdr="$fileprefix$file";
  394.     fi
  395.  
  396.     (
  397. #       $ECHO "%%Title: $USER@$hostname/$name->ps"
  398. #       $ECHO "%%DocumentFonts:"
  399. #       $ECHO "%%Creator: $name->ps"
  400. #       $ECHO "%%CreationDate: $dateline"
  401. #       $ECHO "%%Pages: (atend)"
  402. #       $ECHO "%%For: $USER@$hostname"
  403. #       $ECHO "%%EndComments"
  404.         $ECHO "%!"
  405.         $ECHO "save"
  406.         $ECHO "/dateIs   ($datestring) def"
  407.         $ECHO "/headIs   ($hdrprefix$hdr)  def"
  408.         $ECHO "/userIs  ($userprefix$userstring) def"
  409.         $ECHO "/fmtIs    ($fmtopt)  def"
  410.         $ECHO "/nCols    $colsopt   def"
  411.         $ECHO "/CPC      $cpc    def"
  412.         $ECHO "/LPP      $lengthopt    def"
  413.  
  414.         cat $script/print.ps
  415.  
  416. #
  417. #       expand tabs into spaces,  number/compress/fold lines.
  418. #       escape the special characters ( ) and / inside the postscript string.  
  419. #       make each line into the postscript command ( line ) doLine
  420.  
  421.         if [ "$file" = "--" ]; then expand; else expand "$file"; fi |
  422.         if [ "$catopts" != "" ]; then cat $catopts | fold $foldopt; else fold  
  423. $foldopt; fi |
  424.         sed -e 's/\\/\\\\/g' -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/.*/(&)  
  425. doLine/'
  426.  
  427.         $ECHO "newPage restore"
  428.  
  429.         ) | if [ "$outopt" = "--" ]; then
  430.                cat >> $tmpfile
  431.             elif [ "$outopt" = "-" ]; then
  432.                  cat 
  433.             else $ECHO "" > $outopt; cat >> $outopt
  434.             fi
  435.     done
  436.  
  437. if [ "$outopt" = "--" ]; then
  438.    if [ "$processedfiles" ]; then
  439.       lpr -P$printer $printeropts $tmpfile
  440.    fi
  441.    /bin/rm -f $tmpfile
  442.    outstream="printer $printer"
  443. elif [ "$outopt" = "-" ]; then
  444.    outstream="stdout"
  445. else outstream="$outopt"
  446. fi
  447.  
  448. if [ "$quietopt" -eq 0 ]; then
  449.    if [ "$inputfiles" = "--" ]; then
  450.       $ECHO "$name: done files ( StandardInput ) spooled to $outstream."
  451.    else
  452.       $ECHO "$name: done files ($processedfiles ) spooled to $outstream."
  453.    fi
  454. fi
  455.