This file contains some changes to the version of lpr in the second Berkeley networking distribution. This is available for anonymous ftp from ftp.uu.net in the directory packages/bsd-sources/usr.sbin/lpr. These changes have been tested only under SunOS 4.1.1. Only lpd has been tested. In order to compile this version of lpd under SunOS 4.1.1, you may in addition need lib/libutil/daemon.c, lib/libc/stdio/strerror.c and include/paths.h. You will probably also need to adapt the Makefile. The changes are as follows: 1. Use an int rather than a short to store the baud rate. A short doesn't work too well for 38400 baud. 2. Implement the `ms' capability as in SunOS. This a string valued capability. The value is a comma separated list of tty modes specified as for stty(1). Combination modes are not supported. The implementation is based on code from stty. 3. The code uses `sun' as a variable name in several places, but this is defined as a preprocessor name by cc. Fixed by undefing `sun' where necessary. 4. Add a new `ex' capability. This is a boolean capability. If it's present, then the new options (-j, -p and -s) supported by lprps will be passed to the filter. 5. The SunOS statfs() requires the rather than . 6. In SunOS the fundamental filesystem block size is stored in the f_bsize rather than the f_fsize member of struct stafs. 7. Several pathnames need to be changed for SunOS. James Clark jjc@jclark.com diff -rcN ../dist-lpr/common_source/common.c ./common_source/common.c *** ../dist-lpr/common_source/common.c Tue Jan 28 09:59:25 1992 --- ./common_source/common.c Tue Jan 28 10:43:55 1992 *************** *** 64,69 **** --- 64,70 ---- char *PF; /* name of vrast filter (per job) */ char *FF; /* form feed string */ char *TR; /* trailer string to be output when Q empties */ + char *MS; /* list of tty modes to set or clear */ short SC; /* suppress multiple copies */ short SF; /* suppress FF on each print job */ short SH; /* suppress header page */ *************** *** 74,85 **** short PL; /* page length */ short PX; /* page width in pixels */ short PY; /* page length in pixels */ ! short BR; /* baud rate if lp is a tty */ int FC; /* flags to clear if lp is a tty */ int FS; /* flags to set if lp is a tty */ int XC; /* flags to clear for local mode */ int XS; /* flags to set for local mode */ short RS; /* restricted to those with local accounts */ char line[BUFSIZ]; char pbuf[BUFSIZ/2]; /* buffer for printcap strings */ --- 75,87 ---- short PL; /* page length */ short PX; /* page width in pixels */ short PY; /* page length in pixels */ ! int BR; /* baud rate if lp is a tty */ int FC; /* flags to clear if lp is a tty */ int FS; /* flags to set if lp is a tty */ int XC; /* flags to clear for local mode */ int XS; /* flags to set for local mode */ short RS; /* restricted to those with local accounts */ + short EX; /* use extended interface */ char line[BUFSIZ]; char pbuf[BUFSIZ/2]; /* buffer for printcap strings */ diff -rcN ../dist-lpr/common_source/lp.h ./common_source/lp.h *** ../dist-lpr/common_source/lp.h Tue Jan 28 09:59:50 1992 --- ./common_source/lp.h Tue Jan 28 10:43:28 1992 *************** *** 78,83 **** --- 78,84 ---- extern char *CF; /* name of cifplot filter (per job) */ extern char *FF; /* form feed string */ extern char *TR; /* trailer string to be output when Q empties */ + extern char *MS; /* list of tty modes to set or clear */ extern short SC; /* suppress multiple copies */ extern short SF; /* suppress FF on each print job */ extern short SH; /* suppress header page */ *************** *** 88,99 **** extern short PX; /* page width in pixels */ extern short PY; /* page length in pixels */ extern short PL; /* page length */ ! extern short BR; /* baud rate if lp is a tty */ extern int FC; /* flags to clear if lp is a tty */ extern int FS; /* flags to set if lp is a tty */ extern int XC; /* flags to clear for local mode */ extern int XS; /* flags to set for local mode */ extern short RS; /* restricted to those with local accounts */ extern char line[BUFSIZ]; extern char pbuf[]; /* buffer for printcap entry */ --- 89,101 ---- extern short PX; /* page width in pixels */ extern short PY; /* page length in pixels */ extern short PL; /* page length */ ! extern int BR; /* baud rate if lp is a tty */ extern int FC; /* flags to clear if lp is a tty */ extern int FS; /* flags to set if lp is a tty */ extern int XC; /* flags to clear for local mode */ extern int XS; /* flags to set for local mode */ extern short RS; /* restricted to those with local accounts */ + extern short EX; /* use extended interface */ extern char line[BUFSIZ]; extern char pbuf[]; /* buffer for printcap entry */ diff -rcN ../dist-lpr/common_source/pathnames.h ./common_source/pathnames.h *** ../dist-lpr/common_source/pathnames.h Tue Jan 28 10:00:15 1992 --- ./common_source/pathnames.h Tue Jan 28 11:22:23 1992 *************** *** 36,50 **** #include #define _PATH_DEFDEVLP "/dev/lp" ! #define _PATH_DEFSPOOL "/var/spool/output/lpd" #define _PATH_HOSTSEQUIV "/etc/hosts.equiv" #define _PATH_HOSTSLPD "/etc/hosts.lpd" ! #define _PATH_MASTERLOCK "/var/spool/output/lpd.lock" #define _PATH_PR "/usr/bin/pr" #define _PATH_PRINTCAP "/etc/printcap" ! #define _PATH_SOCKETNAME "/var/run/printer" ! #define _PATH_VFONT "/usr/libdata/vfont/" ! #define _PATH_VFONTB "/usr/libdata/vfont/B" ! #define _PATH_VFONTI "/usr/libdata/vfont/I" ! #define _PATH_VFONTR "/usr/libdata/vfont/R" ! #define _PATH_VFONTS "/usr/libdata/vfont/S" --- 36,50 ---- #include #define _PATH_DEFDEVLP "/dev/lp" ! #define _PATH_DEFSPOOL "/var/spool/lpd" #define _PATH_HOSTSEQUIV "/etc/hosts.equiv" #define _PATH_HOSTSLPD "/etc/hosts.lpd" ! #define _PATH_MASTERLOCK "/var/spool/lpd.lock" #define _PATH_PR "/usr/bin/pr" #define _PATH_PRINTCAP "/etc/printcap" ! #define _PATH_SOCKETNAME "/dev/printer" ! #define _PATH_VFONT "/usr/lib/vfont/" ! #define _PATH_VFONTB "/usr/lib/vfont/B" ! #define _PATH_VFONTI "/usr/lib/vfont/I" ! #define _PATH_VFONTR "/usr/lib/vfont/R" ! #define _PATH_VFONTS "/usr/lib/vfont/S" diff -rcN ../dist-lpr/common_source/startdaemon.c ./common_source/startdaemon.c *** ../dist-lpr/common_source/startdaemon.c Tue Jan 28 10:01:03 1992 --- ./common_source/startdaemon.c Tue Jan 28 10:42:22 1992 *************** *** 46,51 **** --- 46,55 ---- #include "lp.local.h" #include "pathnames.h" + #ifdef sun + #undef sun + #endif + startdaemon(printer) char *printer; { diff -rcN ../dist-lpr/lpd/lpd.c ./lpd/lpd.c *** ../dist-lpr/lpd/lpd.c Tue Jan 28 10:03:22 1992 --- ./lpd/lpd.c Tue Jan 28 10:32:51 1992 *************** *** 72,77 **** --- 72,80 ---- #include "lp.h" #include "pathnames.h" + #ifdef sun + #undef sun + #endif int lflag; /* log requests flag */ int from_remote; /* from remote socket */ diff -rcN ../dist-lpr/lpd/modes.c ./lpd/modes.c *** ../dist-lpr/lpd/modes.c --- ./lpd/modes.c Tue Jan 28 15:25:21 1992 *************** *** 0 **** --- 1,232 ---- + /*- + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + /* This is slightly hacked version of bin/stty/modes.c. */ + + #ifndef lint + static char sccsid[] = "@(#)modes.c 5.4 (Berkeley) 6/10/91"; + #endif /* not lint */ + + #include + #include + + struct modes { + char *name; + long set; + long unset; + }; + + static struct modes cmodes[] = { + "cs5", CS5, CSIZE, + "cs6", CS6, CSIZE, + "cs7", CS7, CSIZE, + "cs8", CS8, CSIZE, + "cstopb", CSTOPB, 0, + "-cstopb", 0, CSTOPB, + "cread", CREAD, 0, + "-cread", 0, CREAD, + "parenb", PARENB, 0, + "-parenb", 0, PARENB, + "parodd", PARODD, 0, + "-parodd", 0, PARODD, + "parity", PARENB | CS7, PARODD | CSIZE, + "-parity", CS8, PARODD | PARENB | CSIZE, + "evenp", PARENB | CS7, PARODD | CSIZE, + "-evenp", CS8, PARODD | PARENB | CSIZE, + "oddp", PARENB | CS7 | PARODD, CSIZE, + "-oddp", CS8, PARODD | PARENB | CSIZE, + "pass8", CS8, PARODD | PARENB | CSIZE, + "hupcl", HUPCL, 0, + "-hupcl", 0, HUPCL, + "hup", HUPCL, 0, + "-hup", 0, HUPCL, + "clocal", CLOCAL, 0, + "-clocal", 0, CLOCAL, + "crtscts", CRTSCTS, 0, + "-crtscts", 0, CRTSCTS, + NULL + }; + + static struct modes imodes[] = { + "ignbrk", IGNBRK, 0, + "-ignbrk", 0, IGNBRK, + "brkint", BRKINT, 0, + "-brkint", 0, BRKINT, + "ignpar", IGNPAR, 0, + "-ignpar", 0, IGNPAR, + "parmrk", PARMRK, 0, + "-parmrk", 0, PARMRK, + "inpck", INPCK, 0, + "-inpck", 0, INPCK, + "istrip", ISTRIP, 0, + "-istrip", 0, ISTRIP, + "inlcr", INLCR, 0, + "-inlcr", 0, INLCR, + "igncr", IGNCR, 0, + "-igncr", 0, IGNCR, + "icrnl", ICRNL, 0, + "-icrnl", 0, ICRNL, + "ixon", IXON, 0, + "-ixon", 0, IXON, + "flow", IXON, 0, + "-flow", 0, IXON, + "ixoff", IXOFF, 0, + "-ixoff", 0, IXOFF, + "tandem", IXOFF, 0, + "-tandem", 0, IXOFF, + "ixany", IXANY, 0, + "-ixany", 0, IXANY, + "decctlq", 0, IXANY, + "-decctlq", IXANY, 0, + "imaxbel", IMAXBEL, 0, + "-imaxbel", 0, IMAXBEL, + NULL + }; + + static struct modes lmodes[] = { + "echo", ECHO, 0, + "-echo", 0, ECHO, + "echoe", ECHOE, 0, + "-echoe", 0, ECHOE, + "crterase", ECHOE, 0, + "-crterase", 0, ECHOE, + "crtbs", ECHOE, 0, /* crtbs not supported, close enough */ + "-crtbs", 0, ECHOE, + "echok", ECHOK, 0, + "-echok", 0, ECHOK, + "echoke", ECHOKE, 0, + "-echoke", 0, ECHOKE, + "crtkill", ECHOKE, 0, + "-crtkill", 0, ECHOKE, + #ifdef ALTWERASE + "altwerase", ALTWERASE, 0, + "-altwerase", 0, ALTWERASE, + #endif + "iexten", IEXTEN, 0, + "-iexten", 0, IEXTEN, + "echonl", ECHONL, 0, + "-echonl", 0, ECHONL, + "echoctl", ECHOCTL, 0, + "-echoctl", 0, ECHOCTL, + "ctlecho", ECHOCTL, 0, + "-ctlecho", 0, ECHOCTL, + "echoprt", ECHOPRT, 0, + "-echoprt", 0, ECHOPRT, + "prterase", ECHOPRT, 0, + "-prterase", 0, ECHOPRT, + "isig", ISIG, 0, + "-isig", 0, ISIG, + "icanon", ICANON, 0, + "-icanon", 0, ICANON, + "noflsh", NOFLSH, 0, + "-noflsh", 0, NOFLSH, + "tostop", TOSTOP, 0, + "-tostop", 0, TOSTOP, + #ifdef MDMBUF + "mdmbuf", MDMBUF, 0, + "-mdmbuf", 0, MDMBUF, + #endif + "flusho", FLUSHO, 0, + "-flusho", 0, FLUSHO, + "pendin", PENDIN, 0, + "-pendin", 0, PENDIN, + "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, + "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL, + "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, + "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL, + #ifdef NOKERNINFO + "nokerninfo", NOKERNINFO, 0, + "-nokerninfo", 0, NOKERNINFO, + "kerninfo", 0, NOKERNINFO, + "-kerninfo", NOKERNINFO, 0, + #endif + NULL + }; + + static struct modes omodes[] = { + "opost", OPOST, 0, + "-opost", 0, OPOST, + "litout", 0, OPOST, + "-litout", OPOST, 0, + "onlcr", ONLCR, 0, + "-onlcr", 0, ONLCR, + #ifdef OXTABS + "tabs", 0, OXTABS, /* "preserve" tabs */ + "-tabs", OXTABS, 0, + "xtabs", OXTABS, 0, + "-xtabs", 0, OXTABS, + "oxtabs", OXTABS, 0, + "-oxtabs", 0, OXTABS, + #else + "tabs", 0, TABDLY, + "-tabs", XTABS, TABDLY, + #endif + NULL + }; + + #define CHK(s) (*name == s[0] && !strcmp(name, s)) + + /* Return 0 for OK, -1 on error (analogous to cfset[oi]speed.) */ + + setmode(tp, name) + struct termios *tp; + char *name; + { + register struct modes *mp; + + for (mp = cmodes; mp->name; ++mp) + if (CHK(mp->name)) { + tp->c_cflag &= ~mp->unset; + tp->c_cflag |= mp->set; + return(0); + } + for (mp = imodes; mp->name; ++mp) + if (CHK(mp->name)) { + tp->c_iflag &= ~mp->unset; + tp->c_iflag |= mp->set; + return(0); + } + for (mp = lmodes; mp->name; ++mp) + if (CHK(mp->name)) { + tp->c_lflag &= ~mp->unset; + tp->c_lflag |= mp->set; + return(0); + } + for (mp = omodes; mp->name; ++mp) + if (CHK(mp->name)) { + tp->c_oflag &= ~mp->unset; + tp->c_oflag |= mp->set; + return(0); + } + return(-1); + } diff -rcN ../dist-lpr/lpd/ms.c ./lpd/ms.c *** ../dist-lpr/lpd/ms.c --- ./lpd/ms.c Tue Jan 28 15:39:30 1992 *************** *** 0 **** --- 1,48 ---- + /* + * Implement ms capability. Uses POSIX termios interface. + */ + + /* + * We don't want to include lp.h because of conflicts between + * and in SunOS. + */ + + #include + #include + + extern char *printer; + extern int pfd; + extern char *MS; + + setms() + { + struct termios t; + char *s; + + if (!MS) + return; + if (tcgetattr(pfd, &t) < 0) { + syslog(LOG_ERR, "%s: tcgetattr: %m", printer); + exit(1); + } + + s = MS; + for (;;) { + char *p; + char saved; + + for (p = s; *p != '\0' && *p != ','; p++) + ; + saved = *p; + *p = '\0'; + if (*s && setmode(&t, s) < 0) + syslog(LOG_ERR, "%s: unknown mode: %s", printer, s); + if ((*p = saved) == '\0') + break; + s = ++p; + } + if (tcsetattr(pfd, TCSADRAIN, &t) < 0) { + syslog(LOG_ERR, "%s: tcsetattr: %m", printer); + exit(1); + } + } diff -rcN ../dist-lpr/lpd/printjob.c ./lpd/printjob.c *** ../dist-lpr/lpd/printjob.c Tue Jan 28 10:04:03 1992 --- ./lpd/printjob.c Tue Jan 28 15:36:41 1992 *************** *** 445,451 **** register char *prog; int fi, fo; FILE *fp; ! char *av[15], buf[BUFSIZ]; int pid, p[2], stopped = 0; union wait status; struct stat stb; --- 445,451 ---- register char *prog; int fi, fo; FILE *fp; ! char *av[21], buf[BUFSIZ]; int pid, p[2], stopped = 0; union wait status; struct stat stb; *************** *** 576,581 **** --- 576,589 ---- av[0]++; else av[0] = prog; + if (EX) { + av[n++] = "-j"; + av[n++] = jobname; + av[n++] = "-p"; + av[n++] = printer; + av[n++] = "-s"; + av[n++] = ST; + } av[n++] = "-n"; av[n++] = logname; av[n++] = "-h"; *************** *** 1102,1107 **** --- 1110,1116 ---- VF = pgetstr("vf", &bp); CF = pgetstr("cf", &bp); TR = pgetstr("tr", &bp); + MS = pgetstr("ms", &bp); RS = pgetflag("rs"); SF = pgetflag("sf"); SH = pgetflag("sh"); *************** *** 1108,1113 **** --- 1117,1123 ---- SB = pgetflag("sb"); HL = pgetflag("hl"); RW = pgetflag("rw"); + EX = pgetflag("ex"); BR = pgetnum("br"); if ((FC = pgetnum("fc")) < 0) FC = 0; *************** *** 1268,1273 **** --- 1278,1284 ---- exit(1); } } + setms(); } /*VARARGS1*/ diff -rcN ../dist-lpr/lpd/recvjob.c ./lpd/recvjob.c *** ../dist-lpr/lpd/recvjob.c Tue Jan 28 10:04:17 1992 --- ./lpd/recvjob.c Fri Jan 31 19:29:30 1992 *************** *** 42,48 **** #include "lp.h" #include "pathnames.h" ! #include char *sp = ""; #define ack() (void) write(1, sp, 1); --- 42,48 ---- #include "lp.h" #include "pathnames.h" ! #include char *sp = ""; #define ack() (void) write(1, sp, 1); *************** *** 251,257 **** syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); return (1); } ! spacefree = sfb.f_bavail * (sfb.f_fsize / 512); size = (size + 511) / 512; if (minfree + size > spacefree) return(0); --- 251,257 ---- syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); return (1); } ! spacefree = sfb.f_bavail * (sfb.f_bsize / 512); size = (size + 511) / 512; if (minfree + size > spacefree) return(0);