home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / hp4laser / part01 < prev    next >
Encoding:
Text File  |  1993-03-03  |  9.8 KB  |  377 lines

  1. Newsgroups: comp.sources.misc
  2. From: rick@digibd.com (Rick Richardson)
  3. Subject: v35i112:  hp4laser - LaserJet II-IV SYSV lp spooler interface for PCL or PS, Part01/01
  4. Message-ID: <1993Mar3.185614.19860@sparky.imd.sterling.com>
  5. X-Md4-Signature: d7ec740fb5b9ec3060de6055e893697a
  6. Date: Wed, 3 Mar 1993 18:56:14 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: rick@digibd.com (Rick Richardson)
  10. Posting-number: Volume 35, Issue 112
  11. Archive-name: hp4laser/part01
  12. Environment: HPLJ-IV, SYSV
  13.  
  14. As usual, the lp model scripts you get with the various System V UNIXes are
  15. way behind the times.  Here's the latest version of our lp model to drive
  16. the HP LaserJet IV with the Adobe Postscript SIMMS.  Its been tested with
  17. the LJ IV, attached to a DigiBoard DigiFAX buffered parallel port, but
  18. it should work on a serial port or the dumb parallel port as well.  We
  19. happily print PCL and PS files to our printer, and the script takes care
  20. of switching the printer mode as needed.  We don't worry about whether
  21. the PCL files are binary or text, the script handles it.
  22.  
  23. Also, you won't be able to use the postscript features, but it should be
  24. able to drive a LaserJet II or LaserJet III printer.  You are expected to
  25. adjust the CONFIGURATION SECTION of the script when you install it.
  26.  
  27. Also note: I've provided -oraw, -og, and -otroff lp options for backwards
  28. compatibility with older lp models.  However, it is not necessary to use
  29. these options when sending binary PCL data to the printer.  This is because
  30. this script always runs the interface in "raw" mode.  An HP PCL escape
  31. sequence is used to tell the printer to convert newlines to CR+NL.  This
  32. baby is bulletproof!  Vendor supplied lp models typically use "stty" to
  33. do the NL conversion, which results in havoc for binary PCL streams unless
  34. the proper option is supplied.
  35.  
  36. -Rick Richardson
  37. DigiBoard, Inc.
  38.  
  39. #! /bin/sh
  40. # This is a shell archive.  Remove anything before this line, then unpack
  41. # it by saving it into a file and typing "sh file".  To overwrite existing
  42. # files, type "sh file -c".  You can also feed this as standard input via
  43. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  44. # will see the following message at the end:
  45. #        "End of shell archive."
  46. # Contents:  hp4laser
  47. # Wrapped by rick@digibd on Thu Feb 25 11:50:39 1993
  48. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  49. if test -f hp4laser -a "${1}" != "-c" ; then 
  50.   echo shar: Will not over-write existing file \"hp4laser\"
  51. else
  52. echo shar: Extracting \"hp4laser\" \(6649 characters\)
  53. sed "s/^X//" >hp4laser <<'END_OF_hp4laser'
  54. X# hp4laser:
  55. X#    lp model interface for HP LaserJet Series IIIsi and IV.
  56. X#
  57. X#    With the Adobe Postscript SIMM installed, this script will auto-detect
  58. X#    postscript files (by looking for %! as the first characters in the file,
  59. X#    and switch the printer mode as needed.
  60. X#
  61. X#    This script probably works fine with LJ II's and III's without
  62. X#    postscript support.  Set ps_simm=no in the CONFIGURATION SECTION.
  63. X#
  64. X#    See the CONFIGURATION SECTION below to adjust for your site.
  65. X#
  66. X#    Copyright 1993 Digi International.  All Rights Reserved.
  67. X#
  68. X#    Permission granted for non-commercial use without fee
  69. X#
  70. X# command arguments are:
  71. X#    request-id user-name title copies printer-options file1 [file2 ...]
  72. X#    $1         $2        $3    $4     $5
  73. X#
  74. X# options (lp -oXXX) are:
  75. X#    -otroff        #No cr/lf mapping (for JetRoff, etc.)
  76. X#    -oraw        #Same
  77. X#    -og        #Same (SCO's naming convention)
  78. X#    -oland        #Landscape orientation for unformatted text
  79. X#    -oport        #Portrait orientation for unformatted text
  80. X#    -o2on1        #Two pages on one page for unformatted text
  81. X#    -oi        #Indent 8 characters for unformatted text
  82. X#    -o17cpi        #17 CPI for unformatted text
  83. X#    -opcl        #Force use of PCL mode
  84. X#    -ops        #Force use of PS mode
  85. X#
  86. X#    -onobanner    Force no banner
  87. X#    -onofilebreak    Force no file break
  88. X# TODO:
  89. X#    -ocpi=pica    10 CPI
  90. X#    -ocpi=elite    12 CPI
  91. X#    -ocpi=        Other CPI
  92. X#    -olpi=        LPI
  93. X#    -olength=
  94. X#    -owidth=
  95. X#    -oindent=    Offset page by N characters
  96. X#
  97. X# Testing:
  98. X#    After configuring the stuff below, you can test this script without
  99. X#    actually installing it into the "lp" system with this typical command:
  100. X#
  101. X#        ./hp4laser 9999 rick title 1 "" FILE > DEVICE
  102. X#
  103. X#    Where FILE is a file to print, and DEVICE is the device you use, e.g.
  104. X#    /dev/ttyi1A, /dev/lp0, or /dev/dfax0lp.  You have to be root.
  105. X#
  106. X# Installation:
  107. X#    To install this model as the interface script, do these commands:
  108. X#        /usr/lib/lpshut
  109. X#        /usr/lib/lpadmin -p ${name} -v ${dev} -m ${model}
  110. X#        /usr/lib/lpsched
  111. X#        lpstat -r
  112. X#        /usr/lib/accept ${name}
  113. X#        enable ${name}
  114. X#        /usr/lib/lpadmin -d${name}
  115. X#    Where ${name} is the name you want for your printer, ${dev} is the
  116. X#    device name, and ${model} is the name of this file.
  117. X#
  118. X
  119. X#
  120. X# BEGIN CONFIGURATION SECTION (adjust these as needed)
  121. X#
  122. Xspeed=parallel    #Serial interface speed (e.g. 38400), or "parallel"
  123. Xbanner=no    #Enable printing of banner page ("yes" or "no")
  124. Xps_simm="yes"    #Have Adobe Postscript SIMM installed ("yes" or "no")
  125. Xidlemode="pcl"    #Idle printer in "pcl" mode or "ps" mode (when ps_simm=yes)
  126. X#
  127. X# END CONFIGURATION SECTION
  128. X#
  129. X
  130. X#
  131. X#    Word perfect uses its own spooling system
  132. X#
  133. Xfor option in $5
  134. Xdo
  135. X    if [ $option = WP50 ]
  136. X    then
  137. X        /usr/wp/bin/wpp50 <$6
  138. X        exit 0
  139. X    fi
  140. Xdone
  141. X
  142. X#
  143. X#    Give names to the command line arguments
  144. X#
  145. Xprinter=`basename $0`
  146. Xrequest_id=$1
  147. Xuser_name=$2
  148. Xtitle="$3"
  149. Xcopies=$4
  150. Xoptions=$5
  151. Xshift 5
  152. Xfiles="$*"
  153. Xnfiles=$#
  154. X
  155. X#
  156. X#    If serial interface, set speed
  157. X#
  158. Xif [ "$speed" != "parallel" ]
  159. Xthen
  160. X    stty $speed clocal cs8 ixon ixoff -ixany -parenb onlcr -tabs -opost <&1
  161. Xfi
  162. X
  163. X#
  164. X#    Define some shorthand for PCL sequences
  165. X#
  166. XNORAW="\033&k2G"        #Translate LF to CR+LF and FF to CR+FF
  167. XRAW="\033&k0G"            #Do not translate CR, LF, or FF
  168. X
  169. XRESETJOB="\033E\033&l2A"    #Reset printer, eject if any printing on page,
  170. X                #Select letter paper by default
  171. XRESETPAGE="\033E"        #Reset printer, eject if any printing on page
  172. XPSMODE="\033%-12345X@PJL enter language=postscript\n"    # Switch to PS
  173. XPCLMODE="\033%-12345X@PJL enter language=pcl\n"        # Switch to PCL
  174. X
  175. X#
  176. X#    getarg <arg>:    given an <arg> of the form "x=y", return the "y"
  177. X#
  178. Xgetarg () {
  179. X    echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
  180. X}
  181. X
  182. X#
  183. X#    postscript <file>: if <file> is a Postscript file, return true
  184. X#
  185. Xpostscript () {
  186. X    if [ $ps_simm = no ]; then return 1; fi
  187. X    if [ $force = "pcl" ]; then return 1; fi
  188. X    if [ $force = "ps" ]; then return 0; fi
  189. X    #case "`sed -n '1s/\(..\).*/\1/p' $1`" in
  190. X    #%!)    return 0;;
  191. X    #?%)    return 0;;
  192. X    #*)    return 1;;
  193. X    #esac
  194. X    ctrl_d=`echo "\004\c"`
  195. X    read a <$1
  196. X    case "$a" in
  197. X    %!*)        return 0;;
  198. X    "$ctrl_d"%!*)    return 0;;
  199. X    *)        return 1;;
  200. X    esac
  201. X}
  202. X
  203. X#
  204. X#    Definition of the banner page for an HP printer
  205. X#
  206. Xpcl_banner () {
  207. X    PCOURIER=    # "\033&l66p2e7.6c66F"
  208. X    GRAY="\033*c2400a150b30g2P"
  209. X    TLOC="\033*p0x0Y"
  210. X    echo "$RESETJOB$NORAW$PCOURIER$TLOC$GRAY\n\n\n\n"
  211. X    banner "  $user_name"
  212. X    echo "\n"
  213. X    full_name=`grep "^$user_name:" /etc/passwd | line | cut -d: -f5`
  214. X    if [ -n "$full_name" ]
  215. X    then
  216. X        echo "                User: $full_name\n"
  217. X    else
  218. X        echo "\n"
  219. X    fi
  220. X    echo "                Request id: $request_id    Printer: $printer`\n"
  221. X    echo "                Options: $options\n"
  222. X    echo "                `date`"
  223. X    echo "\n"
  224. X    if [ -n "$title" ]
  225. X    then
  226. X        banner $title
  227. X    fi
  228. X    echo "$RESETJOB\c"
  229. X}
  230. X
  231. X#
  232. X#    Postscript banner page
  233. X#
  234. Xps_banner () {
  235. X    :
  236. X}
  237. X
  238. X#
  239. X#    Switch to PS mode
  240. X#
  241. Xps_mode () {
  242. X    echo "$PSMODE"
  243. X    echo "\r\004\c"
  244. X    echo "letter"    # Force inital paper selection to be letter
  245. X}
  246. X
  247. X#
  248. X#    Switch to HP mode
  249. X#
  250. Xpcl_mode () {
  251. X    echo "$PCLMODE\c"
  252. X    echo "$RESETJOB\c"
  253. X}
  254. X
  255. X#
  256. X#    Process user options
  257. X#
  258. Xraw=0
  259. Xorient=port
  260. Xcpi=10
  261. Xlpi=6
  262. Xindent=0
  263. Xlength=0
  264. Xwidth=0
  265. Xfilebreak=1
  266. Xtwo_on_one=0
  267. Xforce=no
  268. Xfor o in $options
  269. Xdo
  270. X    case $o in
  271. X    raw|troff|g)    raw=1;;
  272. X    land)        orient=land;;
  273. X    port)        orient=port;;
  274. X    17cpi)        cpi=16.66;;
  275. X    i)        indent=8;;
  276. X    2on1)        two_on_one=1;;
  277. X    cpi=pica)    cpi=10;;
  278. X    cpi=elite)    cpi=12;;
  279. X    cpi=*)        cpi=`getarg ${o}`;;
  280. X    indent=*)    indent=`getarg ${o}`;;
  281. X    length=*)    length=`getarg ${o}`;;
  282. X    width=*)    width=`getarg ${o}`;;
  283. X    lpi=*)        lpi=`getarg ${o}`;;
  284. X    nobanner)    banner=no;;
  285. X    nofilebreak)    filebreak=0;;
  286. X    ps)        force="ps";;
  287. X    pcl)        force="pcl";;
  288. X    esac
  289. Xdone
  290. X
  291. X#
  292. X#    Init the printer, set exit traps
  293. X#
  294. Xif [ $ps_simm = no ]; then
  295. X    # force PCL only operation
  296. X    PCLMODE=
  297. X    idlemode=pcl
  298. Xfi
  299. Xcase $idlemode in
  300. Xpcl)    cur_mode=pcl; pcl_mode; echo "$RESETJOB\c"
  301. X    trap 'pcl_mode; exit' 0 2 3 15
  302. X    ;;
  303. Xps)    cur_mode=ps; ps_mode;
  304. X    trap 'ps_mode; exit' 0 2 3 15
  305. X    ;;
  306. Xesac
  307. X
  308. X#
  309. X#    Get printer banner page out in portrait, courier
  310. X#
  311. Xif [ $banner = yes ]
  312. Xthen
  313. X    case $idlemode in
  314. X    pcl)    pcl_banner;;
  315. X    ps)    ps_banner;;
  316. X    esac
  317. Xfi
  318. X
  319. X#
  320. X#    Set variables to use when file is printed in PCL mode
  321. X#
  322. XSET=
  323. XSET="$SET\033(s${cpi}H"
  324. XSET="$SET\033&a${indent}L"
  325. Xif [ $raw = 1 ]; then CRMODE=$RAW; else CRMODE=$NORAW; fi
  326. Xif [ $orient = "land" ]; then
  327. X    SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
  328. Xfi
  329. Xif [ $two_on_one = 1 ]; then
  330. X    SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
  331. Xfi
  332. X
  333. X#
  334. X#    Loop for each copy, and then for each file
  335. X#
  336. Xcopy=1
  337. Xwhile [ $copy -le $copies ]
  338. Xdo
  339. X    for file in $files
  340. X    do
  341. X        if postscript $file
  342. X        then
  343. X            ps_mode
  344. X            cat $file
  345. X        else
  346. X            pcl_mode
  347. X            echo "$SET$CRMODE\c"
  348. X            if [ $two_on_one = 1 ]
  349. X            then
  350. X                cat "$file" | newform -i | \
  351. X                    sed "s/^/| /" | pr -2 -w175 -t
  352. X            else
  353. X                cat "$file"
  354. X            fi
  355. X            if [ $filebreak = 1 ]; then echo "$RESETPAGE\c"; fi
  356. X        fi
  357. X    done
  358. X    copy=`expr $copy + 1`
  359. Xdone
  360. Xexit 0
  361. END_OF_hp4laser
  362. if test 6649 -ne `wc -c <hp4laser`; then
  363.     echo shar: \"hp4laser\" unpacked with wrong size!
  364. fi
  365. chmod +x hp4laser
  366. # end of overwriting check
  367. fi
  368. echo shar: End of shell archive.
  369. exit 0
  370. -- 
  371. Rick Richardson        Senior Staff Engineer    Investment advice for 1993-1996:
  372. DigiBoard, Inc.        Email: rick@digibd.com    Go long on Arkansas chicken
  373. 6400 Flying Cloud Dr.    Fax:   (612) 943-0803    Go short on everything else
  374. Eden Prarie, MN 55344    Tel:   (612) 943-5383    <standard disclaimer>
  375.  
  376. exit 0 # Just in case...
  377.