1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | #ifdef __rtems__ |
---|
4 | #include "rtems-bsd-stty-namespace.h" |
---|
5 | #endif /* __rtems__ */ |
---|
6 | /*- |
---|
7 | * Copyright (c) 1991, 1993, 1994 |
---|
8 | * The Regents of the University of California. All rights reserved. |
---|
9 | * |
---|
10 | * Redistribution and use in source and binary forms, with or without |
---|
11 | * modification, are permitted provided that the following conditions |
---|
12 | * are met: |
---|
13 | * 1. Redistributions of source code must retain the above copyright |
---|
14 | * notice, this list of conditions and the following disclaimer. |
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer in the |
---|
17 | * documentation and/or other materials provided with the distribution. |
---|
18 | * 3. Neither the name of the University nor the names of its contributors |
---|
19 | * may be used to endorse or promote products derived from this software |
---|
20 | * without specific prior written permission. |
---|
21 | * |
---|
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
32 | * SUCH DAMAGE. |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef lint |
---|
36 | #if 0 |
---|
37 | static char sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94"; |
---|
38 | #endif |
---|
39 | #endif /* not lint */ |
---|
40 | #include <sys/cdefs.h> |
---|
41 | __FBSDID("$FreeBSD$"); |
---|
42 | |
---|
43 | #ifdef __rtems__ |
---|
44 | #include <machine/rtems-bsd-program.h> |
---|
45 | #endif /* __rtems__ */ |
---|
46 | #include <sys/types.h> |
---|
47 | |
---|
48 | #include <err.h> |
---|
49 | #include <limits.h> |
---|
50 | #include <stddef.h> |
---|
51 | #include <stdlib.h> |
---|
52 | #include <string.h> |
---|
53 | |
---|
54 | #include "stty.h" |
---|
55 | #include "extern.h" |
---|
56 | #ifdef __rtems__ |
---|
57 | #include "rtems-bsd-stty-cchar-data.h" |
---|
58 | #endif /* __rtems__ */ |
---|
59 | |
---|
60 | static int c_cchar(const void *, const void *); |
---|
61 | |
---|
62 | /* |
---|
63 | * Special control characters. |
---|
64 | * |
---|
65 | * Cchars1 are the standard names, cchars2 are the old aliases. |
---|
66 | * The first are displayed, but both are recognized on the |
---|
67 | * command line. |
---|
68 | */ |
---|
69 | struct cchar cchars1[] = { |
---|
70 | { "discard", VDISCARD, CDISCARD }, |
---|
71 | { "dsusp", VDSUSP, CDSUSP }, |
---|
72 | { "eof", VEOF, CEOF }, |
---|
73 | { "eol", VEOL, CEOL }, |
---|
74 | { "eol2", VEOL2, CEOL }, |
---|
75 | { "erase", VERASE, CERASE }, |
---|
76 | { "erase2", VERASE2, CERASE2 }, |
---|
77 | { "intr", VINTR, CINTR }, |
---|
78 | { "kill", VKILL, CKILL }, |
---|
79 | { "lnext", VLNEXT, CLNEXT }, |
---|
80 | { "min", VMIN, CMIN }, |
---|
81 | { "quit", VQUIT, CQUIT }, |
---|
82 | { "reprint", VREPRINT, CREPRINT }, |
---|
83 | { "start", VSTART, CSTART }, |
---|
84 | { "status", VSTATUS, CSTATUS }, |
---|
85 | { "stop", VSTOP, CSTOP }, |
---|
86 | { "susp", VSUSP, CSUSP }, |
---|
87 | { "time", VTIME, CTIME }, |
---|
88 | { "werase", VWERASE, CWERASE }, |
---|
89 | { NULL, 0, 0}, |
---|
90 | }; |
---|
91 | |
---|
92 | struct cchar cchars2[] = { |
---|
93 | { "brk", VEOL, CEOL }, |
---|
94 | { "flush", VDISCARD, CDISCARD }, |
---|
95 | { "rprnt", VREPRINT, CREPRINT }, |
---|
96 | { NULL, 0, 0 }, |
---|
97 | }; |
---|
98 | |
---|
99 | static int |
---|
100 | c_cchar(const void *a, const void *b) |
---|
101 | { |
---|
102 | |
---|
103 | return (strcmp(((const struct cchar *)a)->name, ((const struct cchar *)b)->name)); |
---|
104 | } |
---|
105 | |
---|
106 | int |
---|
107 | csearch(char ***argvp, struct info *ip) |
---|
108 | { |
---|
109 | struct cchar *cp, tmp; |
---|
110 | long val; |
---|
111 | char *arg, *ep, *name; |
---|
112 | |
---|
113 | name = **argvp; |
---|
114 | |
---|
115 | tmp.name = name; |
---|
116 | if (!(cp = (struct cchar *)bsearch(&tmp, cchars1, |
---|
117 | sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar), |
---|
118 | c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars2, |
---|
119 | sizeof(cchars2)/sizeof(struct cchar) - 1, sizeof(struct cchar), |
---|
120 | c_cchar))) |
---|
121 | return (0); |
---|
122 | |
---|
123 | arg = *++*argvp; |
---|
124 | if (!arg) { |
---|
125 | warnx("option requires an argument -- %s", name); |
---|
126 | usage(); |
---|
127 | } |
---|
128 | |
---|
129 | #define CHK(s) (*arg == s[0] && !strcmp(arg, s)) |
---|
130 | if (CHK("undef") || CHK("<undef>")) |
---|
131 | ip->t.c_cc[cp->sub] = _POSIX_VDISABLE; |
---|
132 | else if (cp->sub == VMIN || cp->sub == VTIME) { |
---|
133 | val = strtol(arg, &ep, 10); |
---|
134 | if (val > UCHAR_MAX) { |
---|
135 | warnx("maximum option value is %d -- %s", |
---|
136 | UCHAR_MAX, name); |
---|
137 | usage(); |
---|
138 | } |
---|
139 | if (*ep != '\0') { |
---|
140 | warnx("option requires a numeric argument -- %s", name); |
---|
141 | usage(); |
---|
142 | } |
---|
143 | ip->t.c_cc[cp->sub] = val; |
---|
144 | } else if (arg[0] == '^') |
---|
145 | ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 : |
---|
146 | (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037; |
---|
147 | else |
---|
148 | ip->t.c_cc[cp->sub] = arg[0]; |
---|
149 | ip->set = 1; |
---|
150 | return (1); |
---|
151 | } |
---|