星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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