home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 21 PDrivers / 21-PDrivers.zip / psnupos2.zip / psnup < prev    next >
Text File  |  1995-01-24  |  2KB  |  105 lines

  1. #!/bin/sh
  2. #
  3. # @(#)psnup    1.4 9/1/90 (cc.utexas.edu) /usr/share/src/public/postscript/psnup/SCCS/s.psnup
  4. #
  5.  
  6. # Psnup -- take a postscript file and filter it to give n-up printing.
  7. # The real work is done by the nup.pro and nup.pre postscript scripts
  8. # supplied by Ned Batchelder at U. Penn. <ned@UPenn.CSNet>.
  9. #
  10. # Roy Smith <phri!roy> Wed Apr 22 13:33:39 EST 1987.
  11.  
  12. # Where to find the prologue and epilogue files.
  13. lib=/usr/local/lib/ps
  14. prologue=$lib/nup.pro
  15. epilogue=$lib/nup.epi
  16.  
  17. # Default parameters.
  18. Nup=2        # 2 spots per page.
  19. Reverse=false    # No reversal (upper left to lower right).
  20. Start=0        # First page goes in spot number 0.
  21. File=""        # No file (read from standard input).
  22.  
  23. #
  24. # Canonicalize arguments and complain about usage.
  25. # This uses Rich Salz's getopt(1) which in turn needs getopt(3),
  26. # both of which are public domain and in the mod.sources archive.
  27. #
  28. set -- `getopt "n:rs:" $@`
  29. if [ $? != 0 ]
  30. then
  31.     echo "usage: psnup [-n 2|4|8|16] [-r] [-s #] [file]" >&2
  32.     exit 1
  33. fi
  34.  
  35. # Step through arguments.
  36. skip=0
  37. for flag
  38. do
  39.     if [ $skip -eq 1 ]
  40.     then
  41.         shift
  42.         skip=0
  43.         continue
  44.     fi
  45.  
  46.     case "$flag" in
  47.         -n)    case "$2" in
  48.                2|4|8|16) Nup="$2"
  49.                          ;;
  50.                *)        echo psnup: -n must be 2, 4, 8, or 16 >&2
  51.                          exit 1
  52.                          ;;
  53.             esac
  54.             skip=1
  55.             ;;
  56.         -r)    Reverse=true
  57.             ;;
  58.         -s)    Start="$2"
  59.             skip=1
  60.             ;;
  61.         --)    break
  62.             ;;
  63.     esac
  64.     shift
  65. done
  66. shift        # because "--" causes break and skips shift after esac.
  67. File="$1"    # if any arguments left, use the first as a file name.
  68.  
  69. #
  70. # Before we begin, make sure all the files are readable.
  71. #
  72. if [ ! -r $prologue ]
  73. then
  74.     echo psnup: error reading $prologue, call for help. >&2
  75.     exit 1
  76. fi
  77. if [ -n "$File" -a ! -r "$File" ]
  78. then
  79.     echo psnup: "$File" unreadable or non-existant. >&2
  80.     exit 1
  81. fi
  82. if [ ! -r $epilogue ]
  83. then
  84.     echo psnup: error reading $epilogue, call for help. >&2
  85.     exit 1
  86. fi
  87.  
  88. #
  89. # Emit the prologue, inserting parameters along the way.
  90. #
  91. sed    -e "s/@#@Pages@#@/$Nup/" \
  92.     -e "s/@#@Rev@#@/$Reverse/" \
  93.     -e "s/@#@Start@#@/$Start/" \
  94.     $prologue
  95.  
  96. #
  97. # Emit the file.  Note that if there was no file name, $File
  98. # is the null string and this just copies stdin to stdout.
  99. cat $File
  100.  
  101. #
  102. # Emit the epilogue
  103. #
  104. cat $epilogue
  105.