diff options
author | sef <sef@FreeBSD.org> | 1996-04-03 22:49:15 +0000 |
---|---|---|
committer | sef <sef@FreeBSD.org> | 1996-04-03 22:49:15 +0000 |
commit | 504f00946f86288718f826c4e2d795f2c94c740e (patch) | |
tree | 1d78ea72c73e26d051d48acc39eab9a2d7b576a6 /usr.sbin/lpr/runqueue | |
parent | ad452f9a802d316f1eda3677095db90935a468d1 (diff) | |
download | FreeBSD-src-504f00946f86288718f826c4e2d795f2c94c740e.zip FreeBSD-src-504f00946f86288718f826c4e2d795f2c94c740e.tar.gz |
Makefile: Add new modes.c file to list of objects.
printjob.c: Use termios instead of sgtty structs and ioctls; remove
support for fs/fc/xs/xc capabilities, and replace them with the ms
capability (stty-like words, instead of octal bit patterns).
modes.c: Modified from stty's file, parses comma-seperated list of
tty modes (e.g., "cs8,-paren,-opost").
Reviewed by: rgrimes, joerg
Diffstat (limited to 'usr.sbin/lpr/runqueue')
-rw-r--r-- | usr.sbin/lpr/runqueue/modes.c | 232 | ||||
-rw-r--r-- | usr.sbin/lpr/runqueue/printjob.c | 44 |
2 files changed, 248 insertions, 28 deletions
diff --git a/usr.sbin/lpr/runqueue/modes.c b/usr.sbin/lpr/runqueue/modes.c new file mode 100644 index 0000000..c6fb929 --- /dev/null +++ b/usr.sbin/lpr/runqueue/modes.c @@ -0,0 +1,232 @@ +/*- + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * $Id: modes.c,v 1.3 1995/04/29 15:17:17 bde Exp $ + */ + +#ifndef lint +static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; +#endif /* not lint */ + +#include <stddef.h> +#include <string.h> +#include <termios.h> + +struct modes { + char *name; + long set; + long unset; +}; + +/* + * The code in optlist() depends on minus options following regular + * options, i.e. "foo" must immediately precede "-foo". + */ +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 }, + { "-pass8", PARENB | CS7, PARODD | 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 }, + { "ctsflow", CCTS_OFLOW, 0 }, + { "-ctsflow", 0, CCTS_OFLOW }, + { "dsrflow", CDSR_OFLOW, 0 }, + { "-dsrflow", 0, CDSR_OFLOW }, + { "dtrflow", CDTR_IFLOW, 0 }, + { "-dtrflow", 0, CDTR_IFLOW }, + { "rtsflow", CRTS_IFLOW, 0 }, + { "-rtsflow", 0, CRTS_IFLOW }, + { "mdmbuf", MDMBUF, 0 }, + { "-mdmbuf", 0, MDMBUF }, + { NULL }, +}; + +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 }, +}; + +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 }, + { "altwerase", ALTWERASE, 0 }, + { "-altwerase", 0, ALTWERASE }, + { "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 }, + { "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 }, + { "nokerninfo", NOKERNINFO, 0 }, + { "-nokerninfo",0, NOKERNINFO }, + { "kerninfo", 0, NOKERNINFO }, + { "-kerninfo", NOKERNINFO, 0 }, + { NULL }, +}; + +struct modes omodes[] = { + { "opost", OPOST, 0 }, + { "-opost", 0, OPOST }, + { "litout", 0, OPOST }, + { "-litout", OPOST, 0 }, + { "onlcr", ONLCR, 0 }, + { "-onlcr", 0, ONLCR }, + { "tabs", 0, OXTABS }, /* "preserve" tabs */ + { "-tabs", OXTABS, 0 }, + { "oxtabs", OXTABS, 0 }, + { "-oxtabs", 0, OXTABS }, + { NULL }, +}; + +#define CHK(name, s) (*name == s[0] && !strcmp(name, s)) + +int +msearch(str, ip) + char *str; + struct termios *ip; +{ + struct modes *mp; + + for (mp = cmodes; mp->name; ++mp) + if (CHK(str, mp->name)) { + ip->c_cflag &= ~mp->unset; + ip->c_cflag |= mp->set; + return (1); + } + for (mp = imodes; mp->name; ++mp) + if (CHK(str, mp->name)) { + ip->c_iflag &= ~mp->unset; + ip->c_iflag |= mp->set; + return (1); + } + for (mp = lmodes; mp->name; ++mp) + if (CHK(str, mp->name)) { + ip->c_lflag &= ~mp->unset; + ip->c_lflag |= mp->set; + return (1); + } + for (mp = omodes; mp->name; ++mp) + if (CHK(str, mp->name)) { + ip->c_oflag &= ~mp->unset; + ip->c_oflag |= mp->set; + return (1); + } + return (0); +} diff --git a/usr.sbin/lpr/runqueue/printjob.c b/usr.sbin/lpr/runqueue/printjob.c index 7e6c3c5..ae0b05a 100644 --- a/usr.sbin/lpr/runqueue/printjob.c +++ b/usr.sbin/lpr/runqueue/printjob.c @@ -58,7 +58,6 @@ static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94"; #include <pwd.h> #include <unistd.h> #include <signal.h> -#include <sgtty.h> #include <syslog.h> #include <fcntl.h> #include <dirent.h> @@ -66,6 +65,8 @@ static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94"; #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <sys/ioctl.h> +#include <termios.h> #include "lp.h" #include "lp.local.h" #include "pathnames.h" @@ -1181,6 +1182,7 @@ init() cgetstr(bp, "vf", &VF); cgetstr(bp, "cf", &CF); cgetstr(bp, "tr", &TR); + cgetstr(bp, "ms", &MS); RS = (cgetcap(bp, "rs", ':') != NULL); SF = (cgetcap(bp, "sf", ':') != NULL); @@ -1190,14 +1192,6 @@ init() RW = (cgetcap(bp, "rw", ':') != NULL); cgetnum(bp, "br", &BR); - if (cgetnum(bp, "fc", &FC) < 0) - FC = 0; - if (cgetnum(bp, "fs", &FS) < 0) - FS = 0; - if (cgetnum(bp, "xc", &XC) < 0) - XC = 0; - if (cgetnum(bp, "xs", &XS) < 0) - XS = 0; tof = (cgetcap(bp, "fo", ':') == NULL); } @@ -1317,15 +1311,15 @@ struct bauds { static void setty() { - struct sgttyb ttybuf; - register struct bauds *bp; + struct termios ttybuf; + struct bauds *bp; if (ioctl(pfd, TIOCEXCL, (char *)0) < 0) { syslog(LOG_ERR, "%s: ioctl(TIOCEXCL): %m", printer); exit(1); } - if (ioctl(pfd, TIOCGETP, (char *)&ttybuf) < 0) { - syslog(LOG_ERR, "%s: ioctl(TIOCGETP): %m", printer); + if (tcgetattr(pfd, &ttybuf) < 0) { + syslog(LOG_ERR, "%s: tcgetattr: %m", printer); exit(1); } if (BR > 0) { @@ -1336,24 +1330,18 @@ setty() syslog(LOG_ERR, "%s: illegal baud rate %d", printer, BR); exit(1); } - ttybuf.sg_ispeed = ttybuf.sg_ospeed = bp->speed; + cfsetspeed(&ttybuf, bp->speed); } - ttybuf.sg_flags &= ~FC; - ttybuf.sg_flags |= FS; - if (ioctl(pfd, TIOCSETP, (char *)&ttybuf) < 0) { - syslog(LOG_ERR, "%s: ioctl(TIOCSETP): %m", printer); - exit(1); - } - if (XC) { - if (ioctl(pfd, TIOCLBIC, &XC) < 0) { - syslog(LOG_ERR, "%s: ioctl(TIOCLBIC): %m", printer); - exit(1); + if (MS) { + char *s = strdup(MS), *tmp; + + while (tmp = strsep (&s, ",")) { + msearch(tmp, &ttybuf); } } - if (XS) { - if (ioctl(pfd, TIOCLBIS, &XS) < 0) { - syslog(LOG_ERR, "%s: ioctl(TIOCLBIS): %m", printer); - exit(1); + if (MS || (BR > 0)) { + if (tcsetattr(pfd, TCSAFLUSH, &ttybuf) == -1) { + syslog(LOG_ERR, "%s: tcsetattr: %m", printer); } } } |