2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static char sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
48 static int c_cchar(const void *, const void *);
51 * Special control characters.
53 * Cchars1 are the standard names, cchars2 are the old aliases.
54 * The first are displayed, but both are recognized on the
57 struct cchar cchars1[] = {
58 { "discard", VDISCARD, CDISCARD },
59 { "dsusp", VDSUSP, CDSUSP },
60 { "eof", VEOF, CEOF },
61 { "eol", VEOL, CEOL },
62 { "eol2", VEOL2, CEOL },
63 { "erase", VERASE, CERASE },
64 { "erase2", VERASE2, CERASE2 },
65 { "intr", VINTR, CINTR },
66 { "kill", VKILL, CKILL },
67 { "lnext", VLNEXT, CLNEXT },
68 { "min", VMIN, CMIN },
69 { "quit", VQUIT, CQUIT },
70 { "reprint", VREPRINT, CREPRINT },
71 { "start", VSTART, CSTART },
72 { "status", VSTATUS, CSTATUS },
73 { "stop", VSTOP, CSTOP },
74 { "susp", VSUSP, CSUSP },
75 { "time", VTIME, CTIME },
76 { "werase", VWERASE, CWERASE },
80 struct cchar cchars2[] = {
81 { "brk", VEOL, CEOL },
82 { "flush", VDISCARD, CDISCARD },
83 { "rprnt", VREPRINT, CREPRINT },
88 c_cchar(const void *a, const void *b)
91 return (strcmp(((const struct cchar *)a)->name, ((const struct cchar *)b)->name));
95 csearch(char ***argvp, struct info *ip)
97 struct cchar *cp, tmp;
99 char *arg, *ep, *name;
104 if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
105 sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
106 c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars2,
107 sizeof(cchars2)/sizeof(struct cchar) - 1, sizeof(struct cchar),
113 warnx("option requires an argument -- %s", name);
117 #define CHK(s) (*arg == s[0] && !strcmp(arg, s))
118 if (CHK("undef") || CHK("<undef>"))
119 ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
120 else if (cp->sub == VMIN || cp->sub == VTIME) {
121 val = strtol(arg, &ep, 10);
122 if (val > UCHAR_MAX) {
123 warnx("maximum option value is %d -- %s",
128 warnx("option requires a numeric argument -- %s", name);
131 ip->t.c_cc[cp->sub] = val;
132 } else if (arg[0] == '^')
133 ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
134 (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
136 ip->t.c_cc[cp->sub] = arg[0];