jw@pan.UUCP (Jamie Watson) (09/05/89)
Following this article I am posting a print queue backend specifically for the HP LaserJet printer. The following are some notes I made while writing and testing the program. - I implemented this backend using an Oki Laserline-6 with a LaserJet+ emulation cartridge for testing. We do not have any genuine LaserJet printers, and I am not sure what differences there are between the Oki emulation and the real LaserJet. I strongly suspect that things like which fonts are built-in are different; there may well be other, more significant differences. - The command line "-debug" flag puts the LaserJet in display mode, and turns on lf/cr mapping and end of line wrap. When things go wrong in the output, this makes it easy to see what is really being sent. - After considerable struggling, I chose to put the AIX lp device driver in plot mode and leave it that way. This disables all special functions in the driver. There are a number of problems in trying to actually use the special functions of the AIX lp device driver, including: . In cooked mode, the device driver counts characters in escape sequences as part of an output line. So the driver has to be in plot mode whenever escape or control sequences are sent. . Both the device driver and the LaserJet know how to do line wrap and trucation, page feeds when pages are full, and indent. Trying to keep the two of them in sync is a royal pain. . There are only two functions in the device driver which aren't in the LaserJet itself - tab expansion and lower to upper case mapping. There are utilities to perform the former on Unix, and I am not interested in the latter. - In implementing command line options, I have tried very hard to use the same options that the AIX "piobe" backend uses. Obviously, this was not possible in every case. - I have implemented every option the in the Oki interface manual which seems remotely useful. This means that there are a lot of options in this program which are not likely to be used; well, I suppose it is better to have too many options than not to have the one you need. It also means that you can give bizarre combinations of options on the command line which will probably not produce the output expected. Well, that's the way the LaserJet commands are... - There are at least two obvious ways to handle the numerous escape sequences that need to be sent to the printer. I chose to keep the sequence for each operation pretty much separate from all others. The alternative is to combine sequences which have the same opening characters. My approach produces a program with *lots* of repetition in escape sequences. The alternative produces a program with *lots* of conditional evaluation (?:) operations. Given that the speed of the printer is certain to be the significant factor in the use of this program, the two approaches seem equal to me. - The statusfile updating calls only set the percentage finished of the job. I couldn't see a reasonable way to count pages output in an arbitrary file which might contain massive amounts of data for font downloading, and very little actual data for printing. - I made mo attempt to implement job cost accounting, again because I couldn't see a rational way to do so. - The font selection flag (-fid=num) seems totally bogus to me, because the program has to have an explicit, built-in, knowledge of every font that is to be made available this way. However, the AIX piobe program has this flag, and it does provide considerable convenience in font selection for those fonts it knows about. jw
jw@pan.UUCP (Jamie Watson) (09/05/89)
#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: hpljbe.c hpljbe.1 # Wrapped by jw@pan on Mon Sep 4 22:34:24 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'hpljbe.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hpljbe.c'\" else echo shar: Extracting \"'hpljbe.c'\" \(10960 characters\) sed "s/^X//" >'hpljbe.c' <<'END_OF_FILE' X#include <fcntl.h> X#include <stdio.h> X#include <signal.h> X#include <sys/stat.h> X#include <sys/lprio.h> X#include <IN/standard.h> X X#define LANDSCAPE 01 X#define MANUALFEED 02 X#define WRAPLINES 04 X#define LJRAW 010 X#define LPFONT 020 X#define ITALIC 040 X#define LJDEBUG 0100 X Xextern int errno; Xextern void exit(); Xextern void burst_page(); X Xstruct ljopts { X int modes, tm, lm, rm, pl, fid, pitch, point, prop, lpi, cs, face, weight; X}; X Xvoid Xlj_line_term (n) Xint n; X{ X static char *c_lterm = "\033&k%dG"; /* Line Termination */ X X if (fprintf(stdout, c_lterm, n) < 0) { X (void)log_message("printer line termination set failed\n"); X exit(EXITBAD); X } X} X Xvoid Xlj_font (fid) Xint fid; X{ X static char *c_fonts[] = { X "", /* Internal Fonts */ X "\033&l0O\033(8U\033(s0p10h12v0s0b3T", /* Courier */ X "\033&l0O\033(8U\033(s0p10h12v0s3b3T", /* Courier Bold */ X "\033&l0O\033(8U\033(s0p10h12v1s0b3T", /* Courier Italic */ X "\033&l1O\033(8U\033(s0p10h12v0s0b3T", /* Courier Landscape */ X "\033&l0O\033(0U\033(s1p10v0s0b5T", /* Tms Roman */ X "\033&l0O\033(0U\033(s1p10v0s3b5T", /* Tms Roman Bold */ X "\033&l0O\033(0U\033(s1p10v1s0b5T", /* Tms Roman Italic */ X "\033&l0O\033(0U\033(s-1p10v0s0b5T", /* Tms Roman Compr */ X "\033&l0O\033(0U\033(s-1p10v0s3b5T", /* Tms Roman Compr Bold */ X "\033&l0O\033(0U\033(s-1p10v1s0b5T", /* Tms Roman Compr Italic */ X "\033&l0O\033(0U\033(s1p8v0s-1b5T", /* Tms Roman 8-point */ X "\033&l0O\033(0U\033(s-1p8v0s-1b5T", /* Tms Roman 8-point Compr */ X "\033&l0O\033(8U\033(s0p16.66h8.5v0s0b0T",/* Line Printer */ X "\033&l1O\033(8U\033(s0p16.66h8.5v0s0b0T",/* Line Printer Landscape */ X "\033&l0O\033(0U\033(s1p14.4v0s3b4T", /* Helv Bold */ X /* Prestige Elite Cartridge */ X "\033&l0O\033(8U\033(s0p12h10v0s0b8T", /* Prestige */ X "\033&l0)\033(8U\033(s0p12h10v0s3b8T", /* Prestige bold */ X "\033&l0O\033(8U\033(s0p12h10v1s0b8T", /* Prestige italic */ X "\033&l1O\033(8U\033(s0p12h10v0s0b8T", /* Prestige landscape */ X "\033&l1O\033(8U\033(s0p12h10v0s3b8T", /* Prestige landscape bold */ X "\033&l1O\033(8U\033(s0p12h10v1s0b8T", /* Prestige landscape ital */ X "\033&l0O\033(8U\033(s0p16.66h7v0s0b8T", /* Prestige 7-point */ X "\033&l1O\033(8U\033(s0p16.66h7v0s0b8T", /* Prestige 7-point lndscp */ X "\033&l0O\033(0B\033(s0p12h12v0s0b8T", /* Line drawing */ X "\033&l1O\033(0B\033(s0p12h12v0s0b8T", }; /* Line drawing landscape */ X X if (fid < 0 || fid > sizeof(c_fonts) / sizeof(c_fonts[0])) { X (void)log_message("invalid font id (%d)\n", fid); X exit(EXITBAD); X } X if (fputs(c_fonts[fid], stdout) == EOF) { X (void)log_message("font select failed\n"); X exit(EXITBAD); X } X} X Xvoid Xlj_codeset (cs) Xint cs; X{ X static char *c_codeset[] = { X "", /* Code Set ... */ X "\033(0U", /* US ASCII */ X "\033(8U", /* Roman-8 */ X "\033(1U", /* Legal */ X "\033(0B", /* Line Draw */ X "\033(1E", /* British */ X "\033(0F", /* French */ X "\033(0G", /* German */ X "\033(0I", /* Italian */ X "\033(1S", /* Spainish */ X "\033(0S", /* Swedish/Finnish */ X "\033(0D", /* Danish/Norwegian */ X "\033(0A", /* Math-7 */ X "\033(8M", /* Math-8 */ X "\033(0Q", /* Math-8a */ X "\033(1Q", /* Math-8b */ X "\03315Q", /* Pi Font */ X "\033(2Q", }; /* Pi Font a */ X X if (cs < 0 || cs > sizeof(c_codeset) / sizeof(c_codeset[0])) { X (void)log_message("invalid symbol set (%d)\n", cs); X exit(EXITBAD); X } X if (fputs(c_codeset[cs], stdout) == EOF) { X (void)log_message("symbol set select failed\n"); X exit(EXITBAD); X } X} X Xvoid Xlj_margins (opts) Xstruct ljopts *opts; X{ X static char *c_pl = "\033&l%dF", /* Text Length */ X *c_tm = "\033&l%dE", /* Top margin */ X *c_lm = "\033&a%dL", /* Left Margin */ X *c_rm = "\033&a%dM"; /* Right Margin */ X X if (opts->pl && fprintf(stdout, c_pl, opts->pl) < 0) { X (void)log_message("text length set failed\n"); X exit(EXITBAD); X } X if (opts->tm && fprintf(stdout, c_tm, opts->tm) < 0) { X (void)log_message("top margin set failed\n"); X exit(EXITBAD); X } X if (opts->lm && fprintf(stdout, c_lm, opts->lm) < 0) { X (void)log_message("left margin set failed\n"); X exit(EXITBAD); X } X if (opts->rm && fprintf(stdout, c_rm, opts->rm) < 0) { X (void)log_message("left margin set failed\n"); X exit(EXITBAD); X } X} X Xvoid Xlj_reset (opts) Xstruct ljopts *opts; X{ X static char *c_reset = "\033E", /* Master Reset */ X *c_debug = "\033&k2G\033&s0C\033Y", /* Display on */ X *c_nodebug = "\033Z\n", /* Display off */ X *c_land = "\033&l1O", /* Landscape */ X *c_wrap = "\033&s0C", /* End of line wrap */ X *c_manual = "\033&l2H", /* Manual Feed */ X *c_pitch = "\033(s%dH", /* Character pitch */ X *c_point = "\033(s%dV", /* Point Size */ X *c_lpi = "\033&l%dD", /* Lines per inch */ X *c_prop = "\033(s%dP", /* Proportional */ X *c_ital = "\033(s1S", /* Italic */ X *c_type = "\033(s%dB", /* Stroke weight */ X *c_weight = "\033(s%dT", /* Typeface */ X *c_lpr = "\033&k2S"; /* Line Printer Font */ X X if (opts->modes & LJDEBUG && fputs(c_debug, stdout) == EOF) { X (void)log_message("debug set failed\n"); X exit(EXITBAD); X } X if (fputs(c_reset, stdout) == EOF) { X (void)log_message("printer init failed\n"); X exit(EXITBAD); X } X lj_line_term(2); X if (opts != (struct ljopts *) 0) { X if (opts->modes & LANDSCAPE && fputs(c_land, stdout) == EOF) { X (void)log_message("landscape set failed\n"); X exit(EXITBAD); X } X if (opts->modes & MANUALFEED && fputs(c_manual, stdout) == EOF) { X (void)log_message("manual feed set failed\n"); X exit(EXITBAD); X } X if (opts->modes & WRAPLINES && fputs(c_wrap, stdout) == EOF) { X (void)log_message("line wrap set failed\n"); X exit(EXITBAD); X } X if (opts->modes & ITALIC && fputs(c_ital, stdout) == EOF) { X (void)log_message("italic set failed\n"); X exit(EXITBAD); X } X if (opts->modes & LPFONT && fputs(c_lpr, stdout) == EOF) { X (void)log_message("line printer font select failed\n"); X exit(EXITBAD); X } X if (opts->prop && fprintf(stdout, c_prop, opts->prop) < 0) { X (void)log_message("proportional spacing set failed\n"); X exit(EXITBAD); X } X if (opts->pitch && fprintf(stdout, c_pitch, opts->pitch) < 0) { X (void)log_message("pitch set failed\n"); X exit(EXITBAD); X } X if (opts->weight && fprintf(stdout, c_weight, opts->weight) < 0) { X (void)log_message("stroke weight set failed\n"); X exit(EXITBAD); X } X if (opts->point && fprintf(stdout, c_point, opts->point) < 0) { X (void)log_message("point set failed\n"); X exit(EXITBAD); X } X if (opts->lpi && fprintf(stdout, c_lpi, opts->lpi) < 0) { X (void)log_message("lpi set failed\n"); X exit(EXITBAD); X } X if (opts->cs) X lj_codeset(opts->cs); X if (opts->face && fprintf(stdout, c_type, opts->face - 1) < 0) { X (void)log_message("typeface select failed\n"); X exit(EXITBAD); X } X if (opts->fid) X lj_font(opts->fid); X lj_margins(opts); X } X if (opts->modes & LJDEBUG && fputs(c_nodebug, stdout) == EOF) { X (void)log_message("debug clear failed\n"); X exit(EXITBAD); X } X} X Xvoid Xlj_exit (sig) Xint sig; X{ X if (fputs("\033E", stdout) == EOF) { X (void)log_message("exit reset failed\n"); X exit(EXITBAD); X } X exit((int)(sig ? EXITSIGNAL : EXITOK)); X} X Xmain (argc, argv) Xint argc; Xchar **argv; X{ X int fd, nc, tc, copies, statusfile = 0; X static struct ljopts ljopts; X char buf[1024]; X struct stat st; X struct lprmode lprmode; X X (void)signal(SIGTERM, lj_exit); X while (--argc && **++argv == '-') { X if (strncmp(*argv, "-statusfile", 11) == 0) { X statusfile++; X if (log_init() == -1) { X (void)log_message("log_init() failed\n"); X exit(EXITBAD); X } X } X else if (strncmp(*argv, "-cs=", 4) == 0) X ljopts.cs = atoi(*argv+4); X else if (strncmp(*argv, "-debug", 6) == 0) X ljopts.modes |= LJDEBUG; X else if (strncmp(*argv, "-fid=", 5) == 0) X ljopts.fid = atoi(*argv+5); X else if (strncmp(*argv, "-fl=", 4) == 0) X ljopts.pl = atoi(*argv+4); X else if (strncmp(*argv, "-fw=", 4) == 0) X ljopts.rm = atoi(*argv+4); X else if (strncmp(*argv, "-ital", 5) == 0) X ljopts.modes |= ITALIC; X else if (strncmp(*argv, "-land", 5) == 0) { X ljopts.modes |= LANDSCAPE; X ljopts.rm = 112; X ljopts.pl = 43; X } X else if (strncmp(*argv, "-lm=", 4) == 0) X ljopts.lm = atoi(*argv+4); X else if (strncmp(*argv, "-lpi=", 5) == 0) X ljopts.lpi = atoi(*argv+5); X else if (strncmp(*argv, "-lpr", 4) == 0) X ljopts.modes |= LPFONT; X else if (strncmp(*argv, "-ph", 4) == 0) X ljopts.modes |= MANUALFEED; X else if (strncmp(*argv, "-pitch=", 7) == 0) X ljopts.pitch = atoi(*argv+7); X else if (strncmp(*argv, "-plot", 5) == 0) X ljopts.modes |= LJRAW; X else if (strncmp(*argv, "-point=", 7) == 0) X ljopts.point = atoi(*argv+7); X else if (strncmp(*argv, "-sp=", 4) == 0) X ljopts.prop = atoi(*argv+4); X else if (strncmp(*argv, "-sw=", 4) == 0) X ljopts.weight = atoi(*argv+4); X else if (strncmp(*argv, "-tm=", 4) == 0) X ljopts.tm = atoi(*argv+4); X else if (strncmp(*argv, "-trunc", 6) == 0) X ljopts.modes &= ~WRAPLINES; X else if (strncmp(*argv, "-wll", 4) == 0) X ljopts.modes |= WRAPLINES; X else if (strncmp(*argv, "-type=", 6) == 0) X ljopts.face = atoi(*argv+6); X else { X (void)log_message("invalid flag \"%s\"\n", *argv); X exit(EXITBAD); X } X } X lprmode.modes = PLOT; X if (ioctl(1, LPRSETV, &lprmode) < 0) { X (void)log_message("ioctl(SETV) failed, error %d\n", errno); X exit(EXITBAD); X } X lj_reset(&ljopts); X burst_page((int(*)())0, ljopts.rm); X while (argc--) { X burst_page((int(*)())0, ljopts.rm); X if (stat(*argv, &st) < 0) { X (void)log_message("stat failed on %s, error %d\n", *argv, errno); X exit(EXITBAD); X } X copies = statusfile ? get_copies() : 1; X st.st_size *= copies; X tc = 0; X if (ljopts.modes & LJRAW) X lj_line_term(0); X while (copies--) { X if ((fd = open(*argv, O_RDONLY)) < 0) { X (void)log_message("open failed on %s, error %d\n", *argv, errno); X exit(EXITBAD); X } X while ((nc = read(fd, buf, sizeof(buf))) > 0) { X if (statusfile) { X tc += nc * 100; X (void)log_progress(0, (int)(tc/st.st_size)); X } X if (fwrite(buf, 1, nc, stdout) != nc) { X (void)log_message("output write fail\n"); X exit(EXITBAD); X } X } X if (close(fd) < 0) { X (void)log_message("close(%s) failed, error %d\n", *argv, errno); X exit(EXITBAD); X } X lj_reset(&ljopts); X if (fflush(stdout) != 0) { X (void)log_message("fflush(stdout) failed\n"); X exit(EXITBAD); X } X } X burst_page((int(*)())0, ljopts.rm); X argv++; X } X lj_exit(0); X return(EXITOK); X} END_OF_FILE if test 10960 -ne `wc -c <'hpljbe.c'`; then echo shar: \"'hpljbe.c'\" unpacked with wrong size! fi # end of 'hpljbe.c' fi if test -f 'hpljbe.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hpljbe.1'\" else echo shar: Extracting \"'hpljbe.1'\" \(5496 characters\) sed "s/^X//" >'hpljbe.1' <<'END_OF_FILE' X.TH hpljbe 1 LOCAL X.SH NAME Xhpljbe \- HP LaserJet printer backend for AIX queueing system X.SH SYNOPSIS X\fBhpljbe [-option(s)] [\fIfile ...\fB]\fR X.SH DESCRIPTION XThe \fBhpljbe\fP command is very simlar to the \fIAIX\fP standard \fBpiobe\fP Xcommand, but it is designed specifically for use the the HP LaserJet family Xof printers. XIn the absence of any \fIfile\fP arguments, \fBhpljbe\fP reads standard input. XThe \fBhpljbe\fP command should normally be called by the \fBqdaemon\fP Xprogram, to process files submitted with the \fBprint\fP command. X.P XThe \fBhpljbe\fP program sends a \fIreset\fP command (\fIESC-E\fP) to the Xprinter before and after every job. XThis ensures that the printer memory has been cleared of any previously Xdownloaded fonts, macros, or other information, and that the memory is Xleft clear after the job is finished. X.SH FLAGS X.IP \fB-cs\fI=value\fR .5i XSpecifies the LaserJet Symbol Set. XValid \fIvalues\fP are given at the end of this document. X.IP \fB-debug\fP .5i XPuts the printer in \fIdisplay mode\fP, so that escape sequences are Xprinted rather than being interpreted. X.IP \fB-fid\fI=value\fR .5i XSpecifies the built-in or cartridge font to be used. XValid \fIvalues\fP are given at the end of this document. X.TE X.IP \fB-fl\fI=num\fR .5i XSets the form length to \fInum\fP lines. X.IP \fB-fw\fI=num\fR .5i XSets the right margin at column \fInum\fP. XColumn position will vary depending on the font selected. X.IP \fB-ital\fP .5i XSelects italics (if available with the selected font). X.IP \fB-land\fP .5i XSelects landscape orientation. XThe fonts available for use in landscape mode are limited. XRefer to the \fB-fid\fP option to see the selections. X.IP \fB-lm\fI=num\fR .5i XSets the left margin at column \fInum\fP. XColumn position will vary depending on the font selected. X.IP \fB-lpi\fI=num\fR .5i XSets the number of lines per inch to \fInum\fP. XValid settings are X.BR 1 , 2 , 3 , X.BR 4 , 6 , 8 , X.BR 12 , 16 , 24 and X.BR 48 . X.IP \fB-lpr\fP .5i XSelects line printer font. X.IP \fB-ph\fP .5i XPuts the printer in manual feed mode. X.IP \fB-pitch\fI=num\fR .5i XSets the character pitch to \fInum\fP. X.IP \fB-plot\fP .5i XSpecifies that the input data be passed through without modification. X.IP \fB-point\fI=num\fR .5i XSets the character height to \fInum\fP points. X.IP \fB-sp\fI=value\fR .5i XSelects proportional spacing mode. XValid \fIvalues\fP are \fB1\fP (proportional spacing), X\fB0\fP (Fixed spacing), and \fB-1\fP (compressed proportional spacing). XCompressed proportional spacing is available only with the Tms Roman font. X.IP \fB-statusfile\fI .5i XTells \fBhpljbe\fP that it is being started by \fBqdaemon\fP, and it should Xupdate the printer queue status information periodically. X.IP \fB-sw\fI=value\fR .5i XSets the printer stroke weight. XValid \fIvalues\fP range from \fB-7\fP (light) to \fB7\fP (Bold). X.IP \fB-tm\fI=num\fR .5i XSets the top margin to \fInum\fP lines. X.IP \fB-trunc\fP .5i XSpecifies that lines exceeding the value set by \fB-fw\fP should be truncated. XThis is the reverse of the \fB-wll\fP flag. X.IP \fB-wll\fP .5i XSpecifies that lines exceeding the value set by \fB-fw\fP should overflow to Xthe next line. XThis is the reverse of the \fB-trunc\fP flag. X.IP \fB-type\fI=value\fR .5i XSelects the LaserJet typeface. XValid \fIvalues\fP are given at the end of this document. X.bp X.SH Symbol Set Values X.TS Xbox, center; Xci|a Xn|a. Xvalue Symbol Set X_ X1 US ASCII X2 Roman-8 X3 Legal X4 Line Draw X5 British X6 French X7 German X8 Italian X9 Spainish X10 Swedish/Finnish X11 Danish/Norwegian X12 Math-7 X13 Math-8 X14 Math-8a X15 Math-8b X16 Pi Font X17 Pi Font a X.TE X.SH Typeface Values X.TS Xbox, center; Xci|a Xn|a. Xvalue Typeface X_ X0 Line printer X1 Pica X2 Elite X3 Courier X4 Helvetica X5 Times Roman X6 Gothic X7 Script X8 Prestige X9 Caslon X10 Orator X.TE X.bp X.SH Font Values X.TS Xbox, center; Xc|s|c|s Xci|a|ci|a Xn|a|n|a. XInternal Prestige Elite Cartridge X= Xvalue Font value Font X_ X1 Courier 16 Prestige X2 Courier Bold 17 Prestige Bold X3 Courier Italic 18 Prestige Italic X4 Courier Landscape 19 Prestige Landscape X5 Tms Roman 20 Prestige Landscape Bold X6 Tms Roman Bold 21 Prestige Landscape Italic X7 Tms Roman Italic 22 Prestige 7-point X8 Tms Roman Compressed 23 Prestige 7-point Landscape X9 Tms Roman Compressed Bold 24 Line Drawing X10 Tms Roman Compressed Italic 25 Line Drawing Landscape X11 Tms Roman 8-point X12 Tms Roman 8-point Compressed X13 Line Printer X14 Line Printer Landscape X15 Helv Bold X.TE X.SH BUGS XThe command line flags attempt to provide as much compatibility as possible Xwith those of the standard AIX \fBpiobe\fP backend, with additions to provide Xcontrol of LaserJet features not covered by the standard options. XThis causes overlap of certain options, such as font, point size, character Xpitch and typestyle selection. X.P XThe \fBstatusfile\fP is updated only with percentage complete information. XNo attempt is made to count output pages, or to do provide any accounting data. X.P XThe font selection option (\fB-fid\fP) requires that the \fBhpljbe\fP program Xhave a specific, built-in knowledge of every available font. X.SH Related Information XA stanza from the \fI/etc/qconfig\fP file which uses this program for Xnormally processed text output to the LaserJet looks like this: X.in .5i Xlj: X device = dlj X.sp Xdlj: X file = /dev/lp0 X access = both X backend = /usr/lpd/hpljbe X.in 0 X.P XA stanza for raw output, such as for use with a \fBditroff\fP backend: X.in .5i Xrlj: X device = rlj X.sp Xdrlj: X file = /dev/lp0 X access = both X backend = /usr/lpd/hpljbe -plot X.in 0 END_OF_FILE if test 5496 -ne `wc -c <'hpljbe.1'`; then echo shar: \"'hpljbe.1'\" unpacked with wrong size! fi # end of 'hpljbe.1' fi echo shar: End of shell archive. exit 0