diff --git a/bin/stty/cchar.c b/bin/stty/cchar.c index 8b0c97004024..600592a0daaf 100644 --- a/bin/stty/cchar.c +++ b/bin/stty/cchar.c @@ -1,142 +1,142 @@ /*- * 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: cchar.c,v 1.3 1995/04/28 19:29:28 ache Exp $ + * $Id: cchar.c,v 1.4 1995/05/30 00:07:25 rgrimes Exp $ */ #ifndef lint -static char sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include #include #include "stty.h" #include "extern.h" /* * Special control characters. * * Cchars1 are the standard names, cchars2 are the old aliases. * The first are displayed, but both are recognized on the * command line. */ struct cchar cchars1[] = { { "discard", VDISCARD, CDISCARD }, { "dsusp", VDSUSP, CDSUSP }, { "eof", VEOF, CEOF }, { "eol", VEOL, CEOL }, { "eol2", VEOL2, CEOL }, { "erase", VERASE, CERASE }, { "intr", VINTR, CINTR }, { "kill", VKILL, CKILL }, { "lnext", VLNEXT, CLNEXT }, { "min", VMIN, CMIN }, { "quit", VQUIT, CQUIT }, { "reprint", VREPRINT, CREPRINT }, { "start", VSTART, CSTART }, { "status", VSTATUS, CSTATUS }, { "stop", VSTOP, CSTOP }, { "susp", VSUSP, CSUSP }, { "time", VTIME, CTIME }, { "werase", VWERASE, CWERASE }, { NULL }, }; struct cchar cchars2[] = { { "brk", VEOL, CEOL }, { "flush", VDISCARD, CDISCARD }, { "rprnt", VREPRINT, CREPRINT }, { NULL }, }; static int c_cchar(a, b) const void *a, *b; { return (strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name)); } int csearch(argvp, ip) char ***argvp; struct info *ip; { struct cchar *cp, tmp; long val; char *arg, *ep, *name; name = **argvp; tmp.name = name; if (!(cp = (struct cchar *)bsearch(&tmp, cchars1, sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar), c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars2, sizeof(cchars2)/sizeof(struct cchar) - 1, sizeof(struct cchar), c_cchar))) return (0); arg = *++*argvp; if (!arg) { warnx("option requires an argument -- %s", name); usage(); } #define CHK(s) (*arg == s[0] && !strcmp(arg, s)) if (CHK("undef") || CHK("")) ip->t.c_cc[cp->sub] = _POSIX_VDISABLE; else if (cp->sub == VMIN || cp->sub == VTIME) { val = strtol(arg, &ep, 10); if (val > UCHAR_MAX) { warnx("maximum option value is %d -- %s", UCHAR_MAX, name); usage(); } if (*ep != '\0') { warnx("option requires a numeric argument -- %s", name); usage(); } ip->t.c_cc[cp->sub] = val; } else if (arg[0] == '^') ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 : (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037; else ip->t.c_cc[cp->sub] = arg[0]; ip->set = 1; return (1); } diff --git a/bin/stty/gfmt.c b/bin/stty/gfmt.c index f6ef0e15c443..62b30dcb4c51 100644 --- a/bin/stty/gfmt.c +++ b/bin/stty/gfmt.c @@ -1,131 +1,131 @@ /*- * 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: gfmt.c,v 1.3 1995/03/19 13:29:23 joerg Exp $ + * $Id: gfmt.c,v 1.4 1995/05/30 00:07:26 rgrimes Exp $ */ #ifndef lint -static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include "stty.h" #include "extern.h" static void gerr(s) char *s; { if (s) errx(1, "illegal gfmt1 option -- %s", s); else errx(1, "illegal gfmt1 option"); } void gprint(tp, wp, ldisc) struct termios *tp; struct winsize *wp; int ldisc; { struct cchar *cp; (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:", tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag); for (cp = cchars1; cp->name; ++cp) (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); (void)printf("ispeed=%ld:ospeed=%ld\n", cfgetispeed(tp), cfgetospeed(tp)); } void gread(tp, s) struct termios *tp; char *s; { struct cchar *cp; char *ep, *p; long tmp; if ((s = strchr(s, ':')) == NULL) gerr(NULL); for (++s; s != NULL;) { p = strsep(&s, ":\0"); if (!p || !*p) break; if (!(ep = strchr(p, '='))) gerr(p); *ep++ = '\0'; (void)sscanf(ep, "%lx", &tmp); #define CHK(s) (*p == s[0] && !strcmp(p, s)) if (CHK("cflag")) { tp->c_cflag = tmp; continue; } if (CHK("iflag")) { tp->c_iflag = tmp; continue; } if (CHK("ispeed")) { (void)sscanf(ep, "%ld", &tmp); tp->c_ispeed = tmp; continue; } if (CHK("lflag")) { tp->c_lflag = tmp; continue; } if (CHK("oflag")) { tp->c_oflag = tmp; continue; } if (CHK("ospeed")) { (void)sscanf(ep, "%ld", &tmp); tp->c_ospeed = tmp; continue; } for (cp = cchars1; cp->name != NULL; ++cp) if (CHK(cp->name)) { if (cp->sub == VMIN || cp->sub == VTIME) (void)sscanf(ep, "%ld", &tmp); tp->c_cc[cp->sub] = tmp; break; } if (cp->name == NULL) gerr(p); } } diff --git a/bin/stty/key.c b/bin/stty/key.c index 58aa60e002b2..d31e846f023b 100644 --- a/bin/stty/key.c +++ b/bin/stty/key.c @@ -1,301 +1,301 @@ /*- * 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: key.c,v 1.4 1995/04/28 19:29:29 ache Exp $ + * $Id: key.c,v 1.5 1996/12/07 11:07:20 bde Exp $ */ #ifndef lint -static char sccsid[] = "@(#)key.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)key.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include #include #include "stty.h" #include "extern.h" __BEGIN_DECLS void f_all __P((struct info *)); void f_cbreak __P((struct info *)); void f_columns __P((struct info *)); void f_dec __P((struct info *)); void f_everything __P((struct info *)); void f_extproc __P((struct info *)); void f_ispeed __P((struct info *)); void f_nl __P((struct info *)); void f_ospeed __P((struct info *)); void f_raw __P((struct info *)); void f_rows __P((struct info *)); void f_sane __P((struct info *)); void f_size __P((struct info *)); void f_speed __P((struct info *)); void f_tty __P((struct info *)); __END_DECLS static struct key { char *name; /* name */ void (*f) __P((struct info *)); /* function */ #define F_NEEDARG 0x01 /* needs an argument */ #define F_OFFOK 0x02 /* can turn off */ int flags; } keys[] = { { "all", f_all, 0 }, { "cbreak", f_cbreak, F_OFFOK }, { "cols", f_columns, F_NEEDARG }, { "columns", f_columns, F_NEEDARG }, { "cooked", f_sane, 0 }, { "dec", f_dec, 0 }, { "everything", f_everything, 0 }, { "extproc", f_extproc, F_OFFOK }, { "ispeed", f_ispeed, F_NEEDARG }, { "new", f_tty, 0 }, { "nl", f_nl, F_OFFOK }, { "old", f_tty, 0 }, { "ospeed", f_ospeed, F_NEEDARG }, { "raw", f_raw, F_OFFOK }, { "rows", f_rows, F_NEEDARG }, { "sane", f_sane, 0 }, { "size", f_size, 0 }, { "speed", f_speed, 0 }, { "tty", f_tty, 0 }, }; static int c_key(a, b) const void *a, *b; { return (strcmp(((struct key *)a)->name, ((struct key *)b)->name)); } int ksearch(argvp, ip) char ***argvp; struct info *ip; { char *name; struct key *kp, tmp; name = **argvp; if (*name == '-') { ip->off = 1; ++name; } else ip->off = 0; tmp.name = name; if (!(kp = (struct key *)bsearch(&tmp, keys, sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key))) return (0); if (!(kp->flags & F_OFFOK) && ip->off) { errx(1, "illegal option -- %s", name); usage(); } if (kp->flags & F_NEEDARG && !(ip->arg = *++*argvp)) { errx(1, "option requires an argument -- %s", name); usage(); } kp->f(ip); return (1); } void f_all(ip) struct info *ip; { print(&ip->t, &ip->win, ip->ldisc, BSD); } void f_cbreak(ip) struct info *ip; { if (ip->off) f_sane(ip); else { ip->t.c_iflag |= BRKINT|IXON|IMAXBEL; ip->t.c_oflag |= OPOST; ip->t.c_lflag |= ISIG|IEXTEN; ip->t.c_lflag &= ~ICANON; ip->set = 1; } } void f_columns(ip) struct info *ip; { ip->win.ws_col = atoi(ip->arg); ip->wset = 1; } void f_dec(ip) struct info *ip; { ip->t.c_cc[VERASE] = (u_char)0177; ip->t.c_cc[VKILL] = CTRL('u'); ip->t.c_cc[VINTR] = CTRL('c'); ip->t.c_lflag &= ~ECHOPRT; ip->t.c_lflag |= ECHOE|ECHOKE|ECHOCTL; ip->t.c_iflag &= ~IXANY; ip->set = 1; } void f_everything(ip) struct info *ip; { print(&ip->t, &ip->win, ip->ldisc, BSD); } void f_extproc(ip) struct info *ip; { - if (!ip->off) { - int tmp = 1; + if (ip->off) { + int tmp = 0; (void)ioctl(ip->fd, TIOCEXT, &tmp); } else { - int tmp = 0; + int tmp = 1; (void)ioctl(ip->fd, TIOCEXT, &tmp); } } void f_ispeed(ip) struct info *ip; { cfsetispeed(&ip->t, atoi(ip->arg)); ip->set = 1; } void f_nl(ip) struct info *ip; { if (ip->off) { ip->t.c_iflag |= ICRNL; ip->t.c_oflag |= ONLCR; } else { ip->t.c_iflag &= ~ICRNL; ip->t.c_oflag &= ~ONLCR; } ip->set = 1; } void f_ospeed(ip) struct info *ip; { cfsetospeed(&ip->t, atoi(ip->arg)); ip->set = 1; } void f_raw(ip) struct info *ip; { if (ip->off) f_sane(ip); else { cfmakeraw(&ip->t); ip->t.c_cflag &= ~(CSIZE|PARENB); ip->t.c_cflag |= CS8; ip->set = 1; } } void f_rows(ip) struct info *ip; { ip->win.ws_row = atoi(ip->arg); ip->wset = 1; } void f_sane(ip) struct info *ip; { ip->t.c_cflag = TTYDEF_CFLAG | (ip->t.c_cflag & CLOCAL); ip->t.c_iflag = TTYDEF_IFLAG; ip->t.c_iflag |= ICRNL; /* preserve user-preference flags in lflag */ #define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH) ip->t.c_lflag = TTYDEF_LFLAG | (ip->t.c_lflag & LKEEP); ip->t.c_oflag = TTYDEF_OFLAG; ip->set = 1; } void f_size(ip) struct info *ip; { (void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col); } void f_speed(ip) struct info *ip; { (void)printf("%ld\n", cfgetospeed(&ip->t)); } void f_tty(ip) struct info *ip; { int tmp; tmp = TTYDISC; if (ioctl(ip->fd, TIOCSETD, &tmp) < 0) err(1, "TIOCSETD"); } diff --git a/bin/stty/modes.c b/bin/stty/modes.c index 0aa7438ae7f2..d86aa70ced18 100644 --- a/bin/stty/modes.c +++ b/bin/stty/modes.c @@ -1,240 +1,240 @@ /*- * 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.2 1994/09/24 02:58:59 davidg Exp $ + * $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"; +static char const sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include "stty.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(s) (*name == s[0] && !strcmp(name, s)) int msearch(argvp, ip) char ***argvp; struct info *ip; { struct modes *mp; char *name; name = **argvp; for (mp = cmodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_cflag &= ~mp->unset; ip->t.c_cflag |= mp->set; ip->set = 1; return (1); } for (mp = imodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_iflag &= ~mp->unset; ip->t.c_iflag |= mp->set; ip->set = 1; return (1); } for (mp = lmodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_lflag &= ~mp->unset; ip->t.c_lflag |= mp->set; ip->set = 1; return (1); } for (mp = omodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_oflag &= ~mp->unset; ip->t.c_oflag |= mp->set; ip->set = 1; return (1); } return (0); } diff --git a/bin/stty/print.c b/bin/stty/print.c index 6df7fea2dc16..d110437c7f07 100644 --- a/bin/stty/print.c +++ b/bin/stty/print.c @@ -1,287 +1,287 @@ /*- * 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: print.c,v 1.4 1995/04/29 15:17:16 bde Exp $ + * $Id: print.c,v 1.5 1995/05/30 00:07:27 rgrimes Exp $ */ #ifndef lint -static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; +static char const sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #endif /* not lint */ #include #include #include #include #include "stty.h" #include "extern.h" #include /* XXX NTTYDISC is too well hidden */ static void binit __P((char *)); static void bput __P((char *)); static char *ccval __P((struct cchar *, int)); void print(tp, wp, ldisc, fmt) struct termios *tp; struct winsize *wp; int ldisc; enum FMT fmt; { struct cchar *p; long tmp; u_char *cc; int cnt, ispeed, ospeed; char buf1[100], buf2[100]; cnt = 0; /* Line discipline. */ if (ldisc != TTYDISC) { switch(ldisc) { case TABLDISC: cnt += printf("tablet disc; "); break; case NTTYDISC: cnt += printf("new tty disc; "); break; case SLIPDISC: cnt += printf("slip disc; "); break; case PPPDISC: cnt += printf("ppp disc; "); break; default: cnt += printf("#%d disc; ", ldisc); break; } } /* Line speed. */ ispeed = cfgetispeed(tp); ospeed = cfgetospeed(tp); if (ispeed != ospeed) cnt += printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed); else cnt += printf("speed %d baud;", ispeed); if (fmt >= BSD) cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col); if (cnt) (void)printf("\n"); #define on(f) ((tmp & (f)) != 0) #define put(n, f, d) \ if (fmt >= BSD || on(f) != (d)) \ bput((n) + on(f)); /* "local" flags */ tmp = tp->c_lflag; binit("lflags"); put("-icanon", ICANON, 1); put("-isig", ISIG, 1); put("-iexten", IEXTEN, 1); put("-echo", ECHO, 1); put("-echoe", ECHOE, 0); put("-echok", ECHOK, 0); put("-echoke", ECHOKE, 0); put("-echonl", ECHONL, 0); put("-echoctl", ECHOCTL, 0); put("-echoprt", ECHOPRT, 0); put("-altwerase", ALTWERASE, 0); put("-noflsh", NOFLSH, 0); put("-tostop", TOSTOP, 0); put("-flusho", FLUSHO, 0); put("-pendin", PENDIN, 0); put("-nokerninfo", NOKERNINFO, 0); put("-extproc", EXTPROC, 0); /* input flags */ tmp = tp->c_iflag; binit("iflags"); put("-istrip", ISTRIP, 0); put("-icrnl", ICRNL, 1); put("-inlcr", INLCR, 0); put("-igncr", IGNCR, 0); put("-ixon", IXON, 1); put("-ixoff", IXOFF, 0); put("-ixany", IXANY, 1); put("-imaxbel", IMAXBEL, 1); put("-ignbrk", IGNBRK, 0); put("-brkint", BRKINT, 1); put("-inpck", INPCK, 0); put("-ignpar", IGNPAR, 0); put("-parmrk", PARMRK, 0); /* output flags */ tmp = tp->c_oflag; binit("oflags"); put("-opost", OPOST, 1); put("-onlcr", ONLCR, 1); put("-oxtabs", OXTABS, 1); /* control flags (hardware state) */ tmp = tp->c_cflag; binit("cflags"); put("-cread", CREAD, 1); switch(tmp&CSIZE) { case CS5: bput("cs5"); break; case CS6: bput("cs6"); break; case CS7: bput("cs7"); break; case CS8: bput("cs8"); break; } bput("-parenb" + on(PARENB)); put("-parodd", PARODD, 0); put("-hupcl", HUPCL, 1); put("-clocal", CLOCAL, 0); put("-cstopb", CSTOPB, 0); switch(tmp & (CCTS_OFLOW | CRTS_IFLOW)) { case CCTS_OFLOW: bput("ctsflow"); break; case CRTS_IFLOW: bput("rtsflow"); break; default: put("-crtscts", CCTS_OFLOW | CRTS_IFLOW, 0); break; } put("-dsrflow", CDSR_OFLOW, 0); put("-dtrflow", CDTR_IFLOW, 0); put("-mdmbuf", MDMBUF, 0); /* XXX mdmbuf == dtrflow */ /* special control characters */ cc = tp->c_cc; if (fmt == POSIX) { binit("cchars"); for (p = cchars1; p->name; ++p) { (void)snprintf(buf1, sizeof(buf1), "%s = %s;", p->name, ccval(p, cc[p->sub])); bput(buf1); } binit(NULL); } else { binit(NULL); for (p = cchars1, cnt = 0; p->name; ++p) { if (fmt != BSD && cc[p->sub] == p->def) continue; #define WD "%-8s" (void)sprintf(buf1 + cnt * 8, WD, p->name); (void)sprintf(buf2 + cnt * 8, WD, ccval(p, cc[p->sub])); if (++cnt == LINELENGTH / 8) { cnt = 0; (void)printf("%s\n", buf1); (void)printf("%s\n", buf2); } } if (cnt) { (void)printf("%s\n", buf1); (void)printf("%s\n", buf2); } } } static int col; static char *label; static void binit(lb) char *lb; { if (col) { (void)printf("\n"); col = 0; } label = lb; } static void bput(s) char *s; { if (col == 0) { col = printf("%s: %s", label, s); return; } if ((col + strlen(s)) > LINELENGTH) { (void)printf("\n\t"); col = printf("%s", s) + 8; return; } col += printf(" %s", s); } static char * ccval(p, c) struct cchar *p; int c; { static char buf[5]; char *bp; if (p->sub == VMIN || p->sub == VTIME) { (void)snprintf(buf, sizeof(buf), "%d", c); return (buf); } if (c == _POSIX_VDISABLE) return (""); bp = buf; if (c & 0200) { *bp++ = 'M'; *bp++ = '-'; c &= 0177; } if (c == 0177) { *bp++ = '^'; *bp++ = '?'; } else if (c < 040) { *bp++ = '^'; *bp++ = c + '@'; } else *bp++ = c; *bp = '\0'; return (buf); } diff --git a/bin/stty/stty.c b/bin/stty/stty.c index 0f5e92582033..c45ed5764aa2 100644 --- a/bin/stty/stty.c +++ b/bin/stty/stty.c @@ -1,164 +1,164 @@ /*- * Copyright (c) 1989, 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: stty.c,v 1.5 1995/07/02 08:54:27 joerg Exp $ + * $Id: stty.c,v 1.6 1995/07/04 08:16:30 bde Exp $ */ #ifndef lint -static char copyright[] = +static char const copyright[] = "@(#) Copyright (c) 1989, 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)stty.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)stty.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include "stty.h" #include "extern.h" int main(argc, argv) int argc; char *argv[]; { struct info i; enum FMT fmt; int ch; fmt = NOTSET; i.fd = STDIN_FILENO; opterr = 0; while (optind < argc && strspn(argv[optind], "-aefg") == strlen(argv[optind]) && (ch = getopt(argc, argv, "aef:g")) != EOF) switch(ch) { case 'a': /* undocumented: POSIX compatibility */ fmt = POSIX; break; case 'e': fmt = BSD; break; case 'f': if ((i.fd = open(optarg, O_RDONLY | O_NONBLOCK)) < 0) err(1, "%s", optarg); break; case 'g': fmt = GFLAG; break; case '?': default: goto args; } args: argc -= optind; argv += optind; if (tcgetattr(i.fd, &i.t) < 0) errx(1, "stdin isn't a terminal"); if (ioctl(i.fd, TIOCGETD, &i.ldisc) < 0) err(1, "TIOCGETD"); if (ioctl(i.fd, TIOCGWINSZ, &i.win) < 0) warn("TIOCGWINSZ: %s\n", strerror(errno)); checkredirect(); /* conversion aid */ switch(fmt) { case NOTSET: if (*argv) break; /* FALLTHROUGH */ case BSD: case POSIX: print(&i.t, &i.win, i.ldisc, fmt); break; case GFLAG: gprint(&i.t, &i.win, i.ldisc); break; } for (i.set = i.wset = 0; *argv; ++argv) { if (ksearch(&argv, &i)) continue; if (csearch(&argv, &i)) continue; if (msearch(&argv, &i)) continue; if (isdigit(**argv)) { int speed; speed = atoi(*argv); cfsetospeed(&i.t, speed); cfsetispeed(&i.t, speed); i.set = 1; continue; } if (!strncmp(*argv, "gfmt1", sizeof("gfmt1") - 1)) { gread(&i.t, *argv + sizeof("gfmt1") - 1); i.set = 1; continue; } warnx("illegal option -- %s", *argv); usage(); } if (i.set && tcsetattr(i.fd, 0, &i.t) < 0) err(1, "tcsetattr"); if (i.wset && ioctl(i.fd, TIOCSWINSZ, &i.win) < 0) warn("TIOCSWINSZ"); exit(0); } void usage() { (void)fprintf(stderr, "usage: stty: [-a|-e|-g] [-f file] [options]\n"); exit (1); } diff --git a/bin/stty/util.c b/bin/stty/util.c index 036c48eb1f16..60768876b7f2 100644 --- a/bin/stty/util.c +++ b/bin/stty/util.c @@ -1,66 +1,66 @@ /*- * 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: util.c,v 1.2 1994/09/24 02:59:05 davidg Exp $ + * $Id: util.c,v 1.3 1995/07/04 08:16:32 bde Exp $ */ #ifndef lint -static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include #include #include "stty.h" #include "extern.h" /* * Gross, but since we're changing the control descriptor from 1 to 0, most * users will be probably be doing "stty > /dev/sometty" by accident. If 1 * and 2 are both ttys, but not the same, assume that 1 was incorrectly * redirected. */ void checkredirect() { struct stat sb1, sb2; if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && !fstat(STDOUT_FILENO, &sb1) && !fstat(STDERR_FILENO, &sb2) && (sb1.st_rdev != sb2.st_rdev)) warnx("stdout appears redirected, but stdin is the control descriptor"); } diff --git a/bin/sync/sync.c b/bin/sync/sync.c index 7e5a387e1a21..70453f24dc4a 100644 --- a/bin/sync/sync.c +++ b/bin/sync/sync.c @@ -1,53 +1,53 @@ /* * Copyright (c) 1987, 1993 * 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$ + * $Id: sync.c,v 1.4 1994/09/24 02:59:09 davidg Exp $ */ #ifndef lint -static char copyright[] = +static char const copyright[] = "@(#) Copyright (c) 1987, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)sync.c 8.1 (Berkeley) 5/31/93"; +static char const sccsid[] = "@(#)sync.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include int main() { sync(); exit(0); } diff --git a/bin/test/operators.c b/bin/test/operators.c index 38d73dab38c3..73568553b282 100644 --- a/bin/test/operators.c +++ b/bin/test/operators.c @@ -1,160 +1,160 @@ /*- * Copyright (c) 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$ + * $Id: operators.c,v 1.3 1994/09/24 02:59:12 davidg Exp $ */ #ifndef lint -static char sccsid[] = "@(#)operators.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)operators.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ /* * Operators used in the test command. */ #include #include "operators.h" const char *const unary_op[] = { "!", "-b", "-c", "-d", "-e", "-f", "-g", "-h", "-k", "-n", "-p", "-r", "-s", "-t", "-u", "-w", "-x", "-z", NULL }; const char *const binary_op[] = { "-o", "|", "-a", "&", "=", "!=", "-eq", "-ne", "-gt", "-lt", "-le", "-ge", NULL }; const char *const andor_op[] = { "-o", "|", "-a", "&", NULL }; const char op_priority[] = { 3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, }; const char op_argflag[] = { 0, OP_FILE, OP_FILE, OP_FILE, OP_FILE, OP_FILE, OP_FILE, OP_FILE, OP_FILE, OP_STRING, OP_FILE, OP_FILE, OP_FILE, OP_INT, OP_FILE, OP_FILE, OP_FILE, OP_STRING, 0, 0, 0, 0, OP_STRING, OP_STRING, OP_INT, OP_INT, OP_INT, OP_INT, OP_INT, OP_INT, }; diff --git a/bin/test/test.c b/bin/test/test.c index 896d8d0d646b..aef3d7e95836 100644 --- a/bin/test/test.c +++ b/bin/test/test.c @@ -1,589 +1,589 @@ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * 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: test.c,v 1.12 1995/10/28 11:54:42 ache Exp $ + * $Id: test.c,v 1.13 1996/03/11 11:01:03 joerg Exp $ */ #ifndef lint -static char copyright[] = +static char const copyright[] = "@(#) Copyright (c) 1992, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)test.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)test.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include "operators.h" #define STACKSIZE 12 #define NESTINCR 16 /* data types */ #define STRING 0 #define INTEGER 1 #define BOOLEAN 2 #define IS_BANG(s) (s[0] == '!' && s[1] == '\0') /* * This structure hold a value. The type keyword specifies the type of * the value, and the union u holds the value. The value of a boolean * is stored in u.num (1 = TRUE, 0 = FALSE). */ struct value { int type; union { char *string; long num; } u; }; struct operator { short op; /* Which operator. */ short pri; /* Priority of operator. */ }; struct filestat { char *name; /* Name of file. */ int rcode; /* Return code from stat. */ struct stat stat; /* Status info on file. */ }; static int expr_is_false __P((struct value *)); static void expr_operator __P((int, struct value *, struct filestat *)); static void get_int __P((char *, long *)); static int lookup_op __P((char *, const char *const *)); static void overflow __P((void)); static int posix_binary_op __P((char **)); static int posix_unary_op __P((char **)); static void syntax __P((void)); int main(argc, argv) int argc; char *argv[]; { struct operator opstack[STACKSIZE]; struct operator *opsp; struct value valstack[STACKSIZE + 1]; struct value *valsp; struct filestat fs; char c, **ap, *opname, *p; int binary, nest, op = 0, pri, ret_val, skipping; if ((p = argv[0]) == NULL) errx(2, "test: argc is zero"); if (*p != '\0' && p[strlen(p) - 1] == '[') { if (strcmp(argv[--argc], "]")) errx(2, "missing ]"); argv[argc] = NULL; } ap = argv + 1; fs.name = NULL; /* * Test(1) implements an inherently ambiguous grammer. In order to * assure some degree of consistency, we special case the POSIX 1003.2 * requirements to assure correct evaluation for POSIX scripts. The * following special cases comply with POSIX P1003.2/D11.2 Section * 4.62.4. */ switch(argc - 1) { case 0: /* % test */ return (1); break; case 1: /* % test arg */ return (argv[1] == NULL || *argv[1] == '\0') ? 1 : 0; break; case 2: /* % test op arg */ opname = argv[1]; if (IS_BANG(opname)) return (*argv[2] == '\0') ? 0 : 1; else { ret_val = posix_unary_op(&argv[1]); if (ret_val >= 0) return (ret_val); } break; case 3: /* % test arg1 op arg2 */ if (IS_BANG(argv[1])) { ret_val = posix_unary_op(&argv[1]); if (ret_val >= 0) return (!ret_val); } else { ret_val = posix_binary_op(&argv[1]); if (ret_val >= 0) return (ret_val); } break; case 4: /* % test ! arg1 op arg2 */ if (IS_BANG(argv[1]) && lookup_op(argv[3], andor_op) < 0 ) { ret_val = posix_binary_op(&argv[2]); if (ret_val >= 0) return (!ret_val); } break; default: break; } /* * We use operator precedence parsing, evaluating the expression as * we parse it. Parentheses are handled by bumping up the priority * of operators using the variable "nest." We use the variable * "skipping" to turn off evaluation temporarily for the short * circuit boolean operators. (It is important do the short circuit * evaluation because under NFS a stat operation can take infinitely * long.) */ opsp = opstack + STACKSIZE; valsp = valstack; nest = skipping = 0; if (*ap == NULL) { valstack[0].type = BOOLEAN; valstack[0].u.num = 0; goto done; } for (;;) { opname = *ap++; if (opname == NULL) syntax(); if (opname[0] == '(' && opname[1] == '\0') { nest += NESTINCR; continue; } else if (*ap && (op = lookup_op(opname, unary_op)) >= 0) { if (opsp == &opstack[0]) overflow(); --opsp; opsp->op = op; opsp->pri = op_priority[op] + nest; continue; } else { valsp->type = STRING; valsp->u.string = opname; valsp++; } for (;;) { opname = *ap++; if (opname == NULL) { if (nest != 0) syntax(); pri = 0; break; } if (opname[0] != ')' || opname[1] != '\0') { if ((op = lookup_op(opname, binary_op)) < 0) syntax(); op += FIRST_BINARY_OP; pri = op_priority[op] + nest; break; } if ((nest -= NESTINCR) < 0) syntax(); } while (opsp < &opstack[STACKSIZE] && opsp->pri >= pri) { binary = opsp->op; for (;;) { valsp--; c = op_argflag[opsp->op]; if (c == OP_INT) { if (valsp->type == STRING) get_int(valsp->u.string, &valsp->u.num); valsp->type = INTEGER; } else if (c >= OP_STRING) { /* OP_STRING or OP_FILE */ if (valsp->type == INTEGER) { if ((p = malloc(32)) == NULL) err(2, NULL); #ifdef SHELL fmtstr(p, 32, "%d", valsp->u.num); #else (void)sprintf(p, "%ld", valsp->u.num); #endif valsp->u.string = p; } else if (valsp->type == BOOLEAN) { if (valsp->u.num) valsp->u.string = "true"; else valsp->u.string = ""; } valsp->type = STRING; if (c == OP_FILE && (fs.name == NULL || strcmp(fs.name, valsp->u.string))) { fs.name = valsp->u.string; fs.rcode = stat(valsp->u.string, &fs.stat); } } if (binary < FIRST_BINARY_OP) break; binary = 0; } if (!skipping) expr_operator(opsp->op, valsp, &fs); else if (opsp->op == AND1 || opsp->op == OR1) skipping--; valsp++; /* push value */ opsp++; /* pop operator */ } if (opname == NULL) break; if (opsp == &opstack[0]) overflow(); if (op == AND1 || op == AND2) { op = AND1; if (skipping || expr_is_false(valsp - 1)) skipping++; } if (op == OR1 || op == OR2) { op = OR1; if (skipping || !expr_is_false(valsp - 1)) skipping++; } opsp--; opsp->op = op; opsp->pri = pri; } done: return (expr_is_false(&valstack[0])); } static int expr_is_false(val) struct value *val; { if (val->type == STRING) { if (val->u.string[0] == '\0') return (1); } else { /* INTEGER or BOOLEAN */ if (val->u.num == 0) return (1); } return (0); } /* * Execute an operator. Op is the operator. Sp is the stack pointer; * sp[0] refers to the first operand, sp[1] refers to the second operand * (if any), and the result is placed in sp[0]. The operands are converted * to the type expected by the operator before expr_operator is called. * Fs is a pointer to a structure which holds the value of the last call * to stat, to avoid repeated stat calls on the same file. */ static void expr_operator(op, sp, fs) int op; struct value *sp; struct filestat *fs; { int i; switch (op) { case NOT: sp->u.num = expr_is_false(sp); sp->type = BOOLEAN; break; case ISEXIST: exist: if (fs == NULL || fs->rcode == -1) goto false; else goto true; case ISREAD: if (geteuid() == 0) goto exist; i = S_IROTH; goto permission; case ISWRITE: if (geteuid() != 0) i = S_IWOTH; else { i = S_IWOTH|S_IWGRP|S_IWUSR; goto filebit; } goto permission; case ISEXEC: if (geteuid() != 0) { i = S_IXOTH; permission: if (fs->stat.st_uid == geteuid()) i <<= 6; else { gid_t grlist[NGROUPS]; int ngroups, j; ngroups = getgroups(NGROUPS, grlist); for (j = 0; j < ngroups; j++) if (fs->stat.st_gid == grlist[j]) { i <<= 3; goto filebit; } } } else i = S_IXOTH|S_IXGRP|S_IXUSR; goto filebit; /* true if (stat.st_mode & i) != 0 */ case ISFILE: i = S_IFREG; goto filetype; case ISDIR: i = S_IFDIR; goto filetype; case ISCHAR: i = S_IFCHR; goto filetype; case ISBLOCK: i = S_IFBLK; goto filetype; case ISSYMLINK: i = S_IFLNK; fs->rcode = lstat(sp->u.string, &fs->stat); goto filetype; case ISFIFO: i = S_IFIFO; goto filetype; filetype: if ((fs->stat.st_mode & S_IFMT) == i && fs->rcode >= 0) true: sp->u.num = 1; else false: sp->u.num = 0; sp->type = BOOLEAN; break; case ISSETUID: i = S_ISUID; goto filebit; case ISSETGID: i = S_ISGID; goto filebit; case ISSTICKY: i = S_ISVTX; filebit: if (fs->stat.st_mode & i && fs->rcode >= 0) goto true; goto false; case ISSIZE: sp->u.num = fs->rcode >= 0 ? fs->stat.st_size : 0L; sp->type = INTEGER; break; case ISTTY: sp->u.num = isatty(sp->u.num); sp->type = BOOLEAN; break; case NULSTR: if (sp->u.string[0] == '\0') goto true; goto false; case STRLEN: sp->u.num = strlen(sp->u.string); sp->type = INTEGER; break; case OR1: case AND1: /* * These operators are mostly handled by the parser. If we * get here it means that both operands were evaluated, so * the value is the value of the second operand. */ *sp = *(sp + 1); break; case STREQ: case STRNE: i = 0; if (!strcmp(sp->u.string, (sp + 1)->u.string)) i++; if (op == STRNE) i = 1 - i; sp->u.num = i; sp->type = BOOLEAN; break; case EQ: if (sp->u.num == (sp + 1)->u.num) goto true; goto false; case NE: if (sp->u.num != (sp + 1)->u.num) goto true; goto false; case GT: if (sp->u.num > (sp + 1)->u.num) goto true; goto false; case LT: if (sp->u.num < (sp + 1)->u.num) goto true; goto false; case LE: if (sp->u.num <= (sp + 1)->u.num) goto true; goto false; case GE: if (sp->u.num >= (sp + 1)->u.num) goto true; goto false; } } static int lookup_op(name, table) char *name; const char *const * table; { const char *const * tp; const char *p; char c; c = name[1]; for (tp = table; (p = *tp) != NULL; tp++) if (p[1] == c && !strcmp(p, name)) return (tp - table); return (-1); } static int posix_unary_op(argv) char **argv; { struct filestat fs; struct value valp; int op, c; char *opname; opname = *argv; if ((op = lookup_op(opname, unary_op)) < 0) return (-1); c = op_argflag[op]; opname = argv[1]; valp.u.string = opname; if (c == OP_FILE) { fs.name = opname; fs.rcode = stat(opname, &fs.stat); } else if (c != OP_STRING) return (-1); expr_operator(op, &valp, &fs); return (valp.u.num == 0); } static int posix_binary_op(argv) char **argv; { struct value v[2]; int op, c; char *opname; opname = argv[1]; if ((op = lookup_op(opname, binary_op)) < 0) return (-1); op += FIRST_BINARY_OP; c = op_argflag[op]; if (c == OP_INT) { get_int(argv[0], &v[0].u.num); get_int(argv[2], &v[1].u.num); } else { v[0].u.string = argv[0]; v[1].u.string = argv[2]; } expr_operator(op, v, NULL); return (v[0].u.num == 0); } /* * Integer type checking. */ static void get_int(v, lp) char *v; long *lp; { long val; char *ep; for (; *v && isspace(*v); ++v); if(!*v) { *lp = 0; return; } if (isdigit(*v) || ((*v == '-' || *v == '+') && isdigit(*(v+1)))) { errno = 0; val = strtol(v, &ep, 10); if (*ep != '\0') errx(2, "%s: trailing non-numeric characters", v); if (errno == ERANGE) { if (val == LONG_MIN) errx(2, "%s: underflow", v); if (val == LONG_MAX) errx(2, "%s: overflow", v); } *lp = val; return; } errx(2, "%s: expected integer", v); } static void syntax() { errx(2, "syntax error"); } static void overflow() { errx(2, "expression is too complex"); }