You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.1 KiB

1 month ago
  1. #!/bin/sh
  2. #
  3. # Unix lpr filter. The default setup sends output directly to a pipe,
  4. # which requires the Ghostscript process to fork, and thus may cause
  5. # small systems to run out of memory/swap space. An alternative strategy,
  6. # based on a suggestion by Andy Fyfe (andy@cs.caltech.edu), uses a named
  7. # pipe for output, which avoids the fork and can thus save a lot of memory.
  8. #
  9. # Unfortunately this approach can cause problems when a print job is aborted,
  10. # as the abort can cause one of the processes to die, leaving the process
  11. # at the other end of the pipe hanging forever.
  12. #
  13. # Because of this, the named pipe method has not been made the default,
  14. # but it may be restored by commenting out the lines referring to
  15. # 'gsoutput' and uncommenting the lines referring to 'gspipe'.
  16. #
  17. # This definition is changed on install to match the
  18. # executable name set in the makefile
  19. GS_EXECUTABLE=gs
  20. PBMPLUSPATH=/usr/local/bin
  21. PSFILTERPATH=/usr/local/lib/ghostscript
  22. LOCALPATH=/usr/local/bin
  23. X11HOME=/usr/X11R6
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/etc
  25. PATH=${PATH}\:${LOCALPATH}\:${PBMPLUSPATH}\:${PSFILTERPATH}
  26. LD_LIBRARY_PATH=${X11HOME}/lib
  27. export PATH LD_LIBRARY_PATH acctfile host user
  28. user= host= acctfile=/dev/null
  29. #
  30. # Redirect stdout to stderr (for the logfile) and open a new channel
  31. # connected to stdout for the raw data. This enables us to keep the
  32. # raw data separate from programmed postscript output and error messages.
  33. #
  34. exec 3>&1 1>&2
  35. #
  36. # Get username and hostname from filter parameters
  37. #
  38. while [ $# != 0 ]
  39. do case "$1" in
  40. -n) user=$2 ; shift ;;
  41. -h) host=$2 ; shift ;;
  42. -*) ;;
  43. *) acctfile=$1 ;;
  44. esac
  45. shift
  46. done
  47. #
  48. # Get the filter, printer device and queue type (direct/indirect)
  49. #
  50. filter=`basename $0`
  51. device=`dirname $0`
  52. type=`dirname ${device}`
  53. device=`basename ${device}`
  54. fdevname=$device
  55. type=`basename ${type}`
  56. #
  57. # Find the bpp and number of colors, if specified
  58. #
  59. colorspec="`echo ${device} | sed 's/.*\.[0-9][0-9]*\.\([0-9][0-9]*\)$/\1/'`"
  60. if test "$colorspec" = "${device}"
  61. then
  62. colorspec=""
  63. else
  64. device=`basename ${device} .$colorspec`
  65. colorspec="-dColors=$colorspec"
  66. fi
  67. bpp="`echo ${device} | sed 's/.*\.\([0-9][0-9]*\)$/\1/'`"
  68. if test "$bpp" = "${device}"
  69. then
  70. bpp=1
  71. else
  72. device=`basename ${device} .$bpp`
  73. fi
  74. #
  75. # Information for the logfile
  76. #
  77. lock=`dirname ${acctfile}`/lock
  78. cf=`sed -n '$p' ${lock}`
  79. job=`sed -n 's/^J//p' ${cf}`
  80. echo "gsbanner: ${host}:${user} Job: ${job} Date: `date`"
  81. echo "gsif: ${host}:${user} ${fdevname} start - `date`"
  82. #
  83. # Set the direct or indirect output destinations
  84. #
  85. #gspipe=/tmp/gspipe.$$
  86. #mknod ${gspipe} p
  87. case "${type}" in
  88. direct)
  89. gsoutput="cat 1>&3" ;;
  90. # cat ${gspipe} 1>&3 & ;;
  91. indirect)
  92. gsoutput="lpr -P${device}.raw" ;;
  93. # cat ${gspipe} | lpr -P${device}.raw & ;;
  94. esac
  95. (
  96. #
  97. # Any setup required may be done here (eg. setting gamma for colour printing)
  98. #
  99. #echo "{0.333 exp} dup dup currenttransfer setcolortransfer"
  100. #
  101. # The input data is filtered here, before being passed on to Ghostscript
  102. #
  103. case "${filter}" in
  104. gsif) cat ;;
  105. gsnf) psdit ;;
  106. gstf) pscat ;;
  107. gsgf) psplot ;;
  108. gsvf) rasttopnm | pnmtops ;;
  109. gsdf) dvi2ps -sqlw ;;
  110. gscf|gsrf) echo "${filter}: filter not available" 1>&2 ; exit 0 ;;
  111. esac
  112. #
  113. # This is the postlude which does the accounting
  114. #
  115. echo "\
  116. (acctfile) getenv
  117. { currentdevice /PageCount gsgetdeviceprop dup cvi 0 gt
  118. { exch (a) file /acctfile exch def
  119. /string 20 string def
  120. string cvs dup length dup
  121. 4 lt
  122. { 4 exch sub
  123. { acctfile ( ) writestring } repeat
  124. } { pop } ifelse
  125. acctfile exch writestring
  126. acctfile (.00 ) writestring
  127. acctfile (host) getenv
  128. { string cvs } { (NOHOST) } ifelse writestring
  129. acctfile (:) writestring
  130. acctfile (user) getenv
  131. { string cvs } { (NOUSER) } ifelse writestring
  132. acctfile (\n) writestring
  133. acctfile closefile
  134. } { pop } ifelse
  135. } if
  136. quit"
  137. ) | $GS_EXECUTABLE -q -P- -dSAFER -dNOPAUSE -sDEVICE=${device} \
  138. -dBitsPerPixel=${bpp} $colorspec \
  139. -sOutputFile=\|"${gsoutput}" -
  140. # -sOutputFile=${gspipe} -
  141. rm -f ${gspipe}
  142. #
  143. # End the logfile entry
  144. #
  145. echo "gsif: end - `date`"