4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
41 * Standard Streams Terminal Line Discipline module.
44 #include <sys/param.h>
45 #include <sys/types.h>
46 #include <sys/termio.h>
47 #include <sys/stream.h>
49 #include <sys/stropts.h>
50 #include <sys/strsubr.h>
51 #include <sys/strsun.h>
52 #include <sys/strtty.h>
53 #include <sys/signal.h>
55 #include <sys/errno.h>
56 #include <sys/debug.h>
57 #include <sys/cmn_err.h>
59 #include <sys/eucioctl.h>
60 #include <sys/csiioctl.h>
62 #include <sys/ldterm.h>
65 #include <sys/sunddi.h>
67 #include <sys/modctl.h>
69 /* Time limit when draining during a close(9E) invoked by exit(2) */
70 /* Can be set to zero to emulate the old, broken behavior */
71 int ldterm_drain_limit
= 15000000;
85 * The following for EUC handling:
91 * Table indicating character classes to tty driver. In particular,
92 * if the class is ORDINARY, then the character needs no special
93 * processing on output.
95 * Characters in the C1 set are all considered CONTROL; this will
96 * work with terminals that properly use the ANSI/ISO extensions,
97 * but might cause distress with terminals that put graphics in
98 * the range 0200-0237. On the other hand, characters in that
99 * range cause even greater distress to other UNIX terminal drivers....
102 static char typetab
[256] = {
103 /* 000 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
104 /* 004 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
105 /* 010 */ BACKSPACE
, TAB
, NEWLINE
, CONTROL
,
106 /* 014 */ VTAB
, RETURN
, CONTROL
, CONTROL
,
107 /* 020 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
108 /* 024 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
109 /* 030 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
110 /* 034 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
111 /* 040 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
112 /* 044 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
113 /* 050 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
114 /* 054 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
115 /* 060 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
116 /* 064 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
117 /* 070 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
118 /* 074 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
119 /* 100 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
120 /* 104 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
121 /* 110 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
122 /* 114 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
123 /* 120 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
124 /* 124 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
125 /* 130 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
126 /* 134 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
127 /* 140 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
128 /* 144 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
129 /* 150 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
130 /* 154 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
131 /* 160 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
132 /* 164 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
133 /* 170 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
134 /* 174 */ ORDINARY
, ORDINARY
, ORDINARY
, CONTROL
,
135 /* 200 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
136 /* 204 */ CONTROL
, CONTROL
, T_SS2
, T_SS3
,
137 /* 210 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
138 /* 214 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
139 /* 220 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
140 /* 224 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
141 /* 230 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
142 /* 234 */ CONTROL
, CONTROL
, CONTROL
, CONTROL
,
143 /* 240 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
144 /* 244 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
145 /* 250 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
146 /* 254 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
147 /* 260 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
148 /* 264 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
149 /* 270 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
150 /* 274 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
151 /* 300 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
152 /* 304 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
153 /* 310 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
154 /* 314 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
155 /* 320 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
156 /* 324 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
157 /* 330 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
158 /* 334 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
159 /* 340 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
160 /* 344 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
161 /* 350 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
162 /* 354 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
163 /* 360 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
164 /* 364 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
165 /* 370 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
167 * WARNING: For EUC, 0xFF must be an ordinary character. It is used with
168 * single-byte EUC in some of the "ISO Latin Alphabet" codesets, and occupies
169 * a screen position; in those ISO sets where that position isn't used, it
170 * shouldn't make any difference.
172 /* 374 */ ORDINARY
, ORDINARY
, ORDINARY
, ORDINARY
,
176 * Translation table for output without OLCUC. All ORDINARY-class characters
177 * translate to themselves. All other characters have a zero in the table,
178 * which stops the copying.
180 static unsigned char notrantab
[256] = {
181 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
182 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
183 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
184 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
185 /* 040 */ ' ', '!', '"', '#', '$', '%', '&', '\'',
186 /* 050 */ '(', ')', '*', '+', ',', '-', '.', '/',
187 /* 060 */ '0', '1', '2', '3', '4', '5', '6', '7',
188 /* 070 */ '8', '9', ':', ';', '<', '=', '>', '?',
189 /* 100 */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
190 /* 110 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
191 /* 120 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
192 /* 130 */ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
193 /* 140 */ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
194 /* 150 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
195 /* 160 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
196 /* 170 */ 'x', 'y', 'z', '{', '|', '}', '~', 0,
197 /* 200 */ 0, 0, 0, 0, 0, 0, 0, 0,
198 /* 210 */ 0, 0, 0, 0, 0, 0, 0, 0,
199 /* 220 */ 0, 0, 0, 0, 0, 0, 0, 0,
200 /* 230 */ 0, 0, 0, 0, 0, 0, 0, 0,
201 /* 240 */ 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
202 /* 250 */ 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
203 /* 260 */ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
204 /* 270 */ 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
205 /* 300 */ 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
206 /* 310 */ 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
207 /* 320 */ 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
208 /* 330 */ 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
209 /* 340 */ 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
210 /* 350 */ 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
211 /* 360 */ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
213 * WARNING: as for above ISO sets, \377 may be used. Translate it to
216 /* 370 */ 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
220 * Translation table for output with OLCUC. All ORDINARY-class characters
221 * translate to themselves, except for lower-case letters which translate
222 * to their upper-case equivalents. All other characters have a zero in
223 * the table, which stops the copying.
225 static unsigned char lcuctab
[256] = {
226 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
227 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
228 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
229 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
230 /* 040 */ ' ', '!', '"', '#', '$', '%', '&', '\'',
231 /* 050 */ '(', ')', '*', '+', ',', '-', '.', '/',
232 /* 060 */ '0', '1', '2', '3', '4', '5', '6', '7',
233 /* 070 */ '8', '9', ':', ';', '<', '=', '>', '?',
234 /* 100 */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
235 /* 110 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
236 /* 120 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
237 /* 130 */ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
238 /* 140 */ '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
239 /* 150 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
240 /* 160 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
241 /* 170 */ 'X', 'Y', 'Z', '{', '|', '}', '~', 0,
242 /* 200 */ 0, 0, 0, 0, 0, 0, 0, 0,
243 /* 210 */ 0, 0, 0, 0, 0, 0, 0, 0,
244 /* 220 */ 0, 0, 0, 0, 0, 0, 0, 0,
245 /* 230 */ 0, 0, 0, 0, 0, 0, 0, 0,
246 /* 240 */ 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
247 /* 250 */ 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
248 /* 260 */ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
249 /* 270 */ 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
250 /* 300 */ 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
251 /* 310 */ 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
252 /* 320 */ 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
253 /* 330 */ 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
254 /* 340 */ 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
255 /* 350 */ 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
256 /* 360 */ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
258 * WARNING: as for above ISO sets, \377 may be used. Translate it to
261 /* 370 */ 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
265 * Input mapping table -- if an entry is non-zero, and XCASE is set,
266 * when the corresponding character is typed preceded by "\" the escape
267 * sequence is replaced by the table value. Mostly used for
268 * upper-case only terminals.
270 static char imaptab
[256] = {
271 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
272 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
273 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
274 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
275 /* 040 */ 0, '|', 0, 0, 0, 0, 0, '`',
276 /* 050 */ '{', '}', 0, 0, 0, 0, 0, 0,
277 /* 060 */ 0, 0, 0, 0, 0, 0, 0, 0,
278 /* 070 */ 0, 0, 0, 0, 0, 0, 0, 0,
279 /* 100 */ 0, 0, 0, 0, 0, 0, 0, 0,
280 /* 110 */ 0, 0, 0, 0, 0, 0, 0, 0,
281 /* 120 */ 0, 0, 0, 0, 0, 0, 0, 0,
282 /* 130 */ 0, 0, 0, 0, '\\', 0, '~', 0,
283 /* 140 */ 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
284 /* 150 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
285 /* 160 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
286 /* 170 */ 'X', 'Y', 'Z', 0, 0, 0, 0, 0,
287 /* 200-377 aren't mapped */
291 * Output mapping table -- if an entry is non-zero, and XCASE is set,
292 * the corresponding character is printed as "\" followed by the table
293 * value. Mostly used for upper-case only terminals.
295 static char omaptab
[256] = {
296 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
297 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
298 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
299 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
300 /* 040 */ 0, 0, 0, 0, 0, 0, 0, 0,
301 /* 050 */ 0, 0, 0, 0, 0, 0, 0, 0,
302 /* 060 */ 0, 0, 0, 0, 0, 0, 0, 0,
303 /* 070 */ 0, 0, 0, 0, 0, 0, 0, 0,
304 /* 100 */ 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
305 /* 110 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
306 /* 120 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
307 /* 130 */ 'X', 'Y', 'Z', 0, 0, 0, 0, 0,
308 /* 140 */ '\'', 0, 0, 0, 0, 0, 0, 0,
309 /* 150 */ 0, 0, 0, 0, 0, 0, 0, 0,
310 /* 160 */ 0, 0, 0, 0, 0, 0, 0, 0,
311 /* 170 */ 0, 0, 0, '(', '!', ')', '^', 0,
312 /* 200-377 aren't mapped */
316 * Translation table for TS_MEUC output without OLCUC. All printing ASCII
317 * characters translate to themselves. All other _bytes_ have a zero in
318 * the table, which stops the copying. This and the following table exist
319 * only so we can use the existing movtuc processing with or without OLCUC.
320 * Maybe it speeds up something...because we can copy a block of characters
321 * by only looking for zeros in the table.
323 * If we took the simple expedient of DISALLOWING "olcuc" with multi-byte
324 * processing, we could rid ourselves of both these tables and save 512 bytes;
325 * seriously, it doesn't make much sense to use olcuc with multi-byte, and
326 * it will probably never be used. Consideration should be given to disallowing
327 * the combination TS_MEUC & OLCUC.
329 static unsigned char enotrantab
[256] = {
330 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
331 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
332 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
333 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
334 /* 040 */ ' ', '!', '"', '#', '$', '%', '&', '\'',
335 /* 050 */ '(', ')', '*', '+', ',', '-', '.', '/',
336 /* 060 */ '0', '1', '2', '3', '4', '5', '6', '7',
337 /* 070 */ '8', '9', ':', ';', '<', '=', '>', '?',
338 /* 100 */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
339 /* 110 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
340 /* 120 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
341 /* 130 */ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
342 /* 140 */ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
343 /* 150 */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
344 /* 160 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
345 /* 170 */ 'x', 'y', 'z', '{', '|', '}', '~', 0,
346 /* 200 - 377 aren't mapped (they're stoppers). */
350 * Translation table for TS_MEUC output with OLCUC. All printing ASCII
351 * translate to themselves, except for lower-case letters which translate
352 * to their upper-case equivalents. All other bytes have a zero in
353 * the table, which stops the copying. Useless for ISO Latin Alphabet
354 * translations, but *sigh* OLCUC is really only defined for ASCII anyway.
355 * We only have this table so we can use the existing OLCUC processing with
356 * TS_MEUC set (multi-byte mode). Nobody would ever think of actually
357 * _using_ it...would they?
359 static unsigned char elcuctab
[256] = {
360 /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0,
361 /* 010 */ 0, 0, 0, 0, 0, 0, 0, 0,
362 /* 020 */ 0, 0, 0, 0, 0, 0, 0, 0,
363 /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0,
364 /* 040 */ ' ', '!', '"', '#', '$', '%', '&', '\'',
365 /* 050 */ '(', ')', '*', '+', ',', '-', '.', '/',
366 /* 060 */ '0', '1', '2', '3', '4', '5', '6', '7',
367 /* 070 */ '8', '9', ':', ';', '<', '=', '>', '?',
368 /* 100 */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
369 /* 110 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
370 /* 120 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
371 /* 130 */ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
372 /* 140 */ '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
373 /* 150 */ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
374 /* 160 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
375 /* 170 */ 'X', 'Y', 'Z', '{', '|', '}', '~', 0,
376 /* 200 - 377 aren't mapped (they're stoppers). */
379 static struct streamtab ldtrinfo
;
381 static struct fmodsw fsw
= {
387 static struct modlstrmod modlstrmod
= {
388 &mod_strmodops
, "terminal line discipline", &fsw
392 static struct modlinkage modlinkage
= {
393 MODREV_1
, &modlstrmod
, NULL
400 return (mod_install(&modlinkage
));
406 return (mod_remove(&modlinkage
));
410 _info(struct modinfo
*modinfop
)
412 return (mod_info(&modlinkage
, modinfop
));
416 static int ldtermopen(queue_t
*, dev_t
*, int, int, cred_t
*);
417 static int ldtermclose(queue_t
*, int, cred_t
*);
418 static void ldtermrput(queue_t
*, mblk_t
*);
419 static void ldtermrsrv(queue_t
*);
420 static int ldtermrmsg(queue_t
*, mblk_t
*);
421 static void ldtermwput(queue_t
*, mblk_t
*);
422 static void ldtermwsrv(queue_t
*);
423 static int ldtermwmsg(queue_t
*, mblk_t
*);
424 static mblk_t
*ldterm_docanon(unsigned char, mblk_t
*, size_t, queue_t
*,
425 ldtermstd_state_t
*, int *);
426 static int ldterm_unget(ldtermstd_state_t
*);
427 static void ldterm_trim(ldtermstd_state_t
*);
428 static void ldterm_rubout(unsigned char, queue_t
*, size_t,
429 ldtermstd_state_t
*);
430 static int ldterm_tabcols(ldtermstd_state_t
*);
431 static void ldterm_erase(queue_t
*, size_t, ldtermstd_state_t
*);
432 static void ldterm_werase(queue_t
*, size_t, ldtermstd_state_t
*);
433 static void ldterm_kill(queue_t
*, size_t, ldtermstd_state_t
*);
434 static void ldterm_reprint(queue_t
*, size_t, ldtermstd_state_t
*);
435 static mblk_t
*ldterm_dononcanon(mblk_t
*, mblk_t
*, size_t, queue_t
*,
436 ldtermstd_state_t
*);
437 static int ldterm_echo(unsigned char, queue_t
*, size_t,
438 ldtermstd_state_t
*);
439 static void ldterm_outchar(unsigned char, queue_t
*, size_t,
440 ldtermstd_state_t
*);
441 static void ldterm_outstring(unsigned char *, int, queue_t
*, size_t,
442 ldtermstd_state_t
*tp
);
443 static mblk_t
*newmsg(ldtermstd_state_t
*);
444 static void ldterm_msg_upstream(queue_t
*, ldtermstd_state_t
*);
445 static void ldterm_wenable(void *);
446 static mblk_t
*ldterm_output_msg(queue_t
*, mblk_t
*, mblk_t
**,
447 ldtermstd_state_t
*, size_t, int);
448 static void ldterm_flush_output(unsigned char, queue_t
*,
449 ldtermstd_state_t
*);
450 static void ldterm_dosig(queue_t
*, int, unsigned char, int, int);
451 static void ldterm_do_ioctl(queue_t
*, mblk_t
*);
452 static int chgstropts(struct termios
*, ldtermstd_state_t
*, queue_t
*);
453 static void ldterm_ioctl_reply(queue_t
*, mblk_t
*);
454 static void vmin_satisfied(queue_t
*, ldtermstd_state_t
*, int);
455 static void vmin_settimer(queue_t
*);
456 static void vmin_timed_out(void *);
457 static void ldterm_adjust_modes(ldtermstd_state_t
*);
458 static void ldterm_eucwarn(ldtermstd_state_t
*);
459 static void cp_eucwioc(eucioc_t
*, eucioc_t
*, int);
460 static int ldterm_codeset(uchar_t
, uchar_t
);
462 static void ldterm_csi_erase(queue_t
*, size_t, ldtermstd_state_t
*);
463 static void ldterm_csi_werase(queue_t
*, size_t, ldtermstd_state_t
*);
465 static uchar_t
ldterm_utf8_width(uchar_t
*, int);
467 /* Codeset type specific methods for EUC, PCCS, and, UTF-8 codeset types. */
468 static int __ldterm_dispwidth_euc(uchar_t
, void *, int);
469 static int __ldterm_memwidth_euc(uchar_t
, void *);
471 static int __ldterm_dispwidth_pccs(uchar_t
, void *, int);
472 static int __ldterm_memwidth_pccs(uchar_t
, void *);
474 static int __ldterm_dispwidth_utf8(uchar_t
, void *, int);
475 static int __ldterm_memwidth_utf8(uchar_t
, void *);
477 static const ldterm_cs_methods_t cs_methods
[LDTERM_CS_TYPE_MAX
+ 1] = {
483 __ldterm_dispwidth_euc
,
484 __ldterm_memwidth_euc
487 __ldterm_dispwidth_pccs
,
488 __ldterm_memwidth_pccs
491 __ldterm_dispwidth_utf8
,
492 __ldterm_memwidth_utf8
497 * The default codeset is presumably C locale's ISO 646 in EUC but
498 * the data structure at below defined as the default codeset data also
499 * support any single byte (EUC) locales.
501 static const ldterm_cs_data_t default_cs_data
= {
508 '\0', '\0', '\0', '\0',
509 '\0', '\0', '\0', '\0',
510 '\0', '\0', '\0', '\0',
511 '\0', '\0', '\0', '\0',
512 '\0', '\0', '\0', '\0',
513 '\0', '\0', '\0', '\0',
514 '\0', '\0', '\0', '\0',
515 '\0', '\0', '\0', '\0',
516 '\0', '\0', '\0', '\0',
517 '\0', '\0', '\0', '\0'
522 * The following tables are from either u8_textprep.c or uconv.c at
523 * usr/src/common/unicode/. The tables are used to figure out corresponding
524 * UTF-8 character byte lengths and also the validity of given character bytes.
526 extern const int8_t u8_number_of_bytes
[];
527 extern const uchar_t u8_masks_tbl
[];
528 extern const uint8_t u8_valid_min_2nd_byte
[];
529 extern const uint8_t u8_valid_max_2nd_byte
[];
532 * Unicode character width definition tables from uwidth.c:
534 extern const ldterm_unicode_data_cell_t ldterm_ucode
[][16384];
537 int ldterm_debug
= 0;
538 #define DEBUG1(a) if (ldterm_debug == 1) printf a
539 #define DEBUG2(a) if (ldterm_debug >= 2) printf a /* allocations */
540 #define DEBUG3(a) if (ldterm_debug >= 3) printf a /* M_CTL Stuff */
541 #define DEBUG4(a) if (ldterm_debug >= 4) printf a /* M_READ Stuff */
542 #define DEBUG5(a) if (ldterm_debug >= 5) printf a
543 #define DEBUG6(a) if (ldterm_debug >= 6) printf a
544 #define DEBUG7(a) if (ldterm_debug >= 7) printf a
557 * Since most of the buffering occurs either at the stream head or in
558 * the "message currently being assembled" buffer, we have a
559 * relatively small input queue, so that blockages above us get
560 * reflected fairly quickly to the module below us. We also have a
561 * small maximum packet size, since you can put a message of that
562 * size on an empty queue no matter how much bigger than the high
565 static struct module_info ldtermmiinfo
= {
575 static struct qinit ldtermrinit
= {
576 (int (*)())ldtermrput
,
577 (int (*)())ldtermrsrv
,
585 static struct module_info ldtermmoinfo
= {
595 static struct qinit ldtermwinit
= {
596 (int (*)())ldtermwput
,
597 (int (*)())ldtermwsrv
,
605 static struct streamtab ldtrinfo
= {
613 * Dummy qbufcall callback routine used by open and close.
614 * The framework will wake up qwait_sig when we return from
615 * this routine (as part of leaving the perimeters.)
616 * (The framework enters the perimeters before calling the qbufcall() callback
617 * and leaves the perimeters after the callback routine has executed. The
618 * framework performs an implicit wakeup of any thread in qwait/qwait_sig
619 * when it leaves the perimeter. See qwait(9E).)
623 dummy_callback(void *arg
)
628 open_ioctl(queue_t
*q
, uint_t cmd
)
634 while ((mp
= mkiocb(cmd
)) == NULL
) {
635 id
= qbufcall(q
, sizeof (struct iocblk
), BPRI_MED
,
636 dummy_callback
, NULL
);
646 open_mblk(queue_t
*q
, size_t len
)
652 while ((mp
= allocb(len
, BPRI_MED
)) == NULL
) {
653 id
= qbufcall(q
, len
, BPRI_MED
, dummy_callback
, NULL
);
663 * Line discipline open.
667 ldtermopen(queue_t
*q
, dev_t
*devp
, int oflag
, int sflag
, cred_t
*crp
)
669 ldtermstd_state_t
*tp
;
672 struct stroptions
*strop
;
673 struct termios
*termiosp
;
676 if (q
->q_ptr
!= NULL
) {
677 return (0); /* already attached */
680 tp
= (ldtermstd_state_t
*)kmem_zalloc(sizeof (ldtermstd_state_t
),
684 * Get termios defaults. These are stored as
685 * a property in the "options" node.
687 if (ddi_getlongprop(DDI_DEV_T_ANY
, ddi_root_node(), DDI_PROP_NOTPROM
,
688 "ttymodes", (caddr_t
)&termiosp
, &len
) == DDI_PROP_SUCCESS
&&
689 len
== sizeof (struct termios
)) {
690 tp
->t_modes
= *termiosp
;
691 tp
->t_amodes
= *termiosp
;
692 kmem_free(termiosp
, len
);
695 * Gack! Whine about it.
697 cmn_err(CE_WARN
, "ldterm: Couldn't get ttymodes property!");
699 bzero(&tp
->t_dmodes
, sizeof (struct termios
));
709 tp
->t_message
= NULL
;
712 tp
->t_rd_request
= 0;
719 q
->q_ptr
= (caddr_t
)tp
;
720 WR(q
)->q_ptr
= (caddr_t
)tp
;
722 * The following for EUC and also non-EUC codesets:
724 tp
->t_codeset
= tp
->t_eucleft
= tp
->t_eucign
= tp
->t_scratch_len
= 0;
725 bzero(&tp
->eucwioc
, EUCSIZE
);
726 tp
->eucwioc
.eucw
[0] = 1; /* ASCII mem & screen width */
727 tp
->eucwioc
.scrw
[0] = 1;
728 tp
->t_maxeuc
= 1; /* the max len in bytes of an EUC char */
730 tp
->t_eucp_mp
= NULL
;
731 tp
->t_eucwarn
= 0; /* no bad chars seen yet */
733 tp
->t_csdata
= default_cs_data
;
734 tp
->t_csmethods
= cs_methods
[LDTERM_CS_TYPE_EUC
];
739 * Find out if the module below us does canonicalization; if
740 * so, we won't do it ourselves.
743 if ((qryp
= open_ioctl(q
, MC_CANONQUERY
)) == NULL
)
747 * Reformulate as an M_CTL message. The actual data will
748 * be in the b_cont field.
750 qryp
->b_datap
->db_type
= M_CTL
;
754 /* allocate a TCSBRK ioctl in case we'll need it on close */
755 if ((qryp
= open_ioctl(q
, TCSBRK
)) == NULL
)
757 tp
->t_drainmsg
= qryp
;
758 if ((bp
= open_mblk(q
, sizeof (int))) == NULL
)
763 * Find out if the underlying driver supports proper POSIX close
764 * semantics. If not, we'll have to approximate it using TCSBRK. If
765 * it does, it will respond with MC_HAS_POSIX, and we'll catch that in
766 * the ldtermrput routine.
768 * When the ldterm_drain_limit tunable is set to zero, we behave the
769 * same as old ldterm: don't send this new message, and always use
770 * TCSBRK during close.
772 if (ldterm_drain_limit
!= 0) {
773 if ((qryp
= open_ioctl(q
, MC_POSIXQUERY
)) == NULL
)
775 qryp
->b_datap
->db_type
= M_CTL
;
779 /* prepare to clear the water marks on close */
780 if ((bp
= open_mblk(q
, sizeof (struct stroptions
))) == NULL
)
782 tp
->t_closeopts
= bp
;
785 * Set the high-water and low-water marks on the stream head
786 * to values appropriate for a terminal. Also set the "vmin"
787 * and "vtime" values to 1 and 0, turn on message-nondiscard
788 * mode (as we're in ICANON mode), and turn on "old-style
791 if ((bp
= open_mblk(q
, sizeof (struct stroptions
))) == NULL
)
793 strop
= (struct stroptions
*)bp
->b_wptr
;
794 strop
->so_flags
= SO_READOPT
|SO_HIWAT
|SO_LOWAT
|SO_NDELON
|SO_ISTTY
;
795 strop
->so_readopt
= RMSGN
;
796 strop
->so_hiwat
= _TTY_BUFSIZ
;
797 strop
->so_lowat
= LOWAT
;
798 bp
->b_wptr
+= sizeof (struct stroptions
);
799 bp
->b_datap
->db_type
= M_SETOPTS
;
802 return (0); /* this can become a controlling TTY */
808 freemsg(tp
->t_closeopts
);
809 freemsg(tp
->t_drainmsg
);
810 /* Dump the state structure */
811 kmem_free(tp
, sizeof (ldtermstd_state_t
));
817 ldtermstd_state_t
*tp
;
821 drain_timed_out(void *arg
)
823 struct close_timer
*ctp
= arg
;
826 ctp
->tp
->t_state
&= ~TS_IOCWAIT
;
831 ldtermclose(queue_t
*q
, int cflag
, cred_t
*crp
)
833 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)q
->q_ptr
;
834 struct stroptions
*strop
;
836 struct close_timer cltimer
;
839 * If we have an outstanding vmin timeout, cancel it.
841 tp
->t_state
|= TS_CLOSE
;
843 (void) quntimeout(q
, tp
->t_vtid
);
847 * Cancel outstanding qbufcall request.
849 if (tp
->t_wbufcid
!= 0)
850 qunbufcall(q
, tp
->t_wbufcid
);
853 * Reset the high-water and low-water marks on the stream
854 * head (?), turn on byte-stream mode, and turn off
855 * "old-style NODELAY" mode.
857 bp
= tp
->t_closeopts
;
858 strop
= (struct stroptions
*)bp
->b_wptr
;
859 strop
->so_flags
= SO_READOPT
|SO_NDELOFF
;
860 strop
->so_readopt
= RNORM
;
861 bp
->b_wptr
+= sizeof (struct stroptions
);
862 bp
->b_datap
->db_type
= M_SETOPTS
;
865 if (cflag
& (FNDELAY
|FNONBLOCK
)) {
866 freemsg(tp
->t_drainmsg
);
867 } else if ((bp
= tp
->t_drainmsg
) != NULL
) {
871 * If the driver isn't known to have POSIX close semantics,
872 * then we have to emulate this the old way. This is done by
873 * sending down TCSBRK,1 to drain the output and waiting for
876 iocb
= (struct iocblk
*)bp
->b_rptr
;
877 iocb
->ioc_count
= sizeof (int);
878 *(int *)bp
->b_cont
->b_rptr
= 1;
879 bp
->b_cont
->b_wptr
+= sizeof (int);
880 tp
->t_state
|= TS_IOCWAIT
;
881 tp
->t_iocid
= iocb
->ioc_id
;
882 if (!putq(WR(q
), bp
))
886 * If we're not able to receive signals at this point, then
887 * launch a timer. This timer will prevent us from waiting
888 * forever for a signal that won't arrive.
891 if (!ddi_can_receive_sig() && ldterm_drain_limit
!= 0) {
893 cltimer
.id
= qtimeout(q
, drain_timed_out
, &cltimer
,
894 drv_usectohz(ldterm_drain_limit
));
898 * Note that the read side of ldterm and the qtimeout are
899 * protected by D_MTQPAIR, so no additional locking is needed
902 while (tp
->t_state
& TS_IOCWAIT
) {
903 if (qwait_sig(q
) == 0)
907 (void) quntimeout(q
, cltimer
.id
);
911 * From here to the end, the routine does not sleep and does not
912 * reference STREAMS, so it's guaranteed to run to completion.
917 freemsg(tp
->t_message
);
918 freemsg(tp
->t_eucp_mp
);
920 /* Dump the state structure, then unlink it */
921 if (tp
->t_csdata
.locale_name
!= NULL
)
922 kmem_free(tp
->t_csdata
.locale_name
,
923 strlen(tp
->t_csdata
.locale_name
) + 1);
924 kmem_free(tp
, sizeof (ldtermstd_state_t
));
931 * Put procedure for input from driver end of stream (read queue).
934 ldtermrput(queue_t
*q
, mblk_t
*mp
)
936 ldtermstd_state_t
*tp
;
938 queue_t
*wrq
= WR(q
); /* write queue of ldterm mod */
939 queue_t
*nextq
= q
->q_next
; /* queue below us */
942 unsigned char *readp
;
943 unsigned char *writep
;
944 struct termios
*emodes
; /* effective modes set by driver */
947 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
949 * We received our ack from the driver saying there is nothing left to
950 * shovel out, so wake up the close routine.
952 dbtype
= DB_TYPE(mp
);
953 if ((dbtype
== M_IOCACK
|| dbtype
== M_IOCNAK
) &&
954 (tp
->t_state
& (TS_CLOSE
|TS_IOCWAIT
)) == (TS_CLOSE
|TS_IOCWAIT
)) {
955 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
957 if (iocp
->ioc_id
== tp
->t_iocid
) {
958 tp
->t_state
&= ~TS_IOCWAIT
;
971 * Send these up unmolested
983 ldterm_ioctl_reply(q
, mp
);
989 * Parity errors are sent up as M_BREAKS with single
990 * character data (formerly handled in the driver)
992 if (mp
->b_wptr
- mp
->b_rptr
== 1) {
994 * IGNPAR PARMRK RESULT
996 * off on 3 byte sequence
999 if (!(tp
->t_amodes
.c_iflag
& IGNPAR
)) {
1000 mp
->b_wptr
= mp
->b_rptr
;
1001 if (tp
->t_amodes
.c_iflag
& PARMRK
) {
1006 if ((mp
= allocb(3, BPRI_HI
)) == NULL
) {
1008 "ldtermrput: no blocks");
1011 mp
->b_datap
->db_type
= M_DATA
;
1012 *mp
->b_wptr
++ = (uchar_t
)'\377';
1013 *mp
->b_wptr
++ = '\0';
1017 mp
->b_datap
->db_type
= M_DATA
;
1018 *mp
->b_wptr
++ = '\0';
1027 * We look at the apparent modes here instead of the
1028 * effective modes. Effective modes cannot be used if
1029 * IGNBRK, BRINT and PARMRK have been negotiated to
1030 * be handled by the driver. Since M_BREAK should be
1031 * sent upstream only if break processing was not
1032 * already done, it should be ok to use the apparent
1036 if (!(tp
->t_amodes
.c_iflag
& IGNBRK
)) {
1037 if (tp
->t_amodes
.c_iflag
& BRKINT
) {
1038 ldterm_dosig(q
, SIGINT
, '\0', M_PCSIG
, FLUSHRW
);
1040 } else if (tp
->t_amodes
.c_iflag
& PARMRK
) {
1042 * Send '\377','\0', '\0'.
1045 if ((mp
= allocb(3, BPRI_HI
)) == NULL
) {
1047 "ldtermrput: no blocks");
1050 mp
->b_datap
->db_type
= M_DATA
;
1051 *mp
->b_wptr
++ = (uchar_t
)'\377';
1052 *mp
->b_wptr
++ = '\0';
1053 *mp
->b_wptr
++ = '\0';
1057 * Act as if a '\0' came in.
1060 if ((mp
= allocb(1, BPRI_HI
)) == NULL
) {
1062 "ldtermrput: no blocks");
1065 mp
->b_datap
->db_type
= M_DATA
;
1066 *mp
->b_wptr
++ = '\0';
1075 DEBUG3(("ldtermrput: M_CTL received\n"));
1077 * The M_CTL has been standardized to look like an
1081 if ((mp
->b_wptr
- mp
->b_rptr
) != sizeof (struct iocblk
)) {
1083 "Non standard M_CTL received by ldterm module\n"));
1084 /* May be for someone else; pass it on */
1088 qryp
= (struct iocblk
*)mp
->b_rptr
;
1090 switch (qryp
->ioc_cmd
) {
1094 DEBUG3(("ldtermrput: M_CTL Query Reply\n"));
1096 DEBUG3(("No information in Query Message\n"));
1099 if ((mp
->b_cont
->b_wptr
- mp
->b_cont
->b_rptr
) ==
1100 sizeof (struct termios
)) {
1101 DEBUG3(("ldtermrput: M_CTL GrandScheme\n"));
1102 /* elaborate turning off scheme */
1103 emodes
= (struct termios
*)mp
->b_cont
->b_rptr
;
1104 bcopy(emodes
, &tp
->t_dmodes
,
1105 sizeof (struct termios
));
1106 ldterm_adjust_modes(tp
);
1109 DEBUG3(("Incorrect query replysize\n"));
1114 tp
->t_state
|= TS_NOCANON
;
1116 * Note: this is very nasty. It's not clear
1117 * what the right thing to do with a partial
1118 * message is; We throw it out
1120 if (tp
->t_message
!= NULL
) {
1121 freemsg(tp
->t_message
);
1122 tp
->t_message
= NULL
;
1123 tp
->t_endmsg
= NULL
;
1127 if (tp
->t_state
& TS_MEUC
) {
1128 ASSERT(tp
->t_eucp_mp
);
1129 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
1137 tp
->t_state
&= ~TS_NOCANON
;
1141 /* no longer any reason to drain from ldterm */
1142 if (ldterm_drain_limit
!= 0) {
1143 freemsg(tp
->t_drainmsg
);
1144 tp
->t_drainmsg
= NULL
;
1149 DEBUG3(("Unknown M_CTL Message\n"));
1152 putnext(q
, mp
); /* In case anyone else has to see it */
1157 * Flush everything we haven't looked at yet.
1160 if ((tp
->t_state
& TS_ISPTSTTY
) && (*mp
->b_rptr
& FLUSHBAND
))
1161 flushband(q
, *(mp
->b_rptr
+ 1), FLUSHDATA
);
1163 flushq(q
, FLUSHDATA
);
1166 * Flush everything we have looked at.
1168 freemsg(tp
->t_message
);
1169 tp
->t_message
= NULL
;
1170 tp
->t_endmsg
= NULL
;
1174 if (tp
->t_state
& TS_MEUC
) { /* EUC multi-byte */
1175 ASSERT(tp
->t_eucp_mp
);
1176 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
1178 putnext(q
, mp
); /* pass it on */
1181 * Relieve input flow control
1183 if ((tp
->t_modes
.c_iflag
& IXOFF
) &&
1184 (tp
->t_state
& TS_TBLOCK
) &&
1185 !(tp
->t_state
& TS_IFBLOCK
) && q
->q_count
<= TTXOLO
) {
1186 tp
->t_state
&= ~TS_TBLOCK
;
1187 (void) putnextctl(wrq
, M_STARTI
);
1188 DEBUG1(("M_STARTI down\n"));
1195 (void) drv_setparm(SYSRAWC
, msgdsize(mp
));
1198 * Flow control: send "start input" message if blocked and
1199 * our queue is below its low water mark.
1201 if ((tp
->t_modes
.c_iflag
& IXOFF
) && (tp
->t_state
& TS_TBLOCK
) &&
1202 !(tp
->t_state
& TS_IFBLOCK
) && q
->q_count
<= TTXOLO
) {
1203 tp
->t_state
&= ~TS_TBLOCK
;
1204 (void) putnextctl(wrq
, M_STARTI
);
1205 DEBUG1(("M_STARTI down\n"));
1208 * If somebody below us ("intelligent" communications
1209 * board, pseudo-tty controlled by an editor) is doing
1210 * canonicalization, don't scan it for special characters.
1212 if (tp
->t_state
& TS_NOCANON
) {
1221 if (tp
->t_modes
.c_iflag
& (INLCR
|IGNCR
|ICRNL
|IUCLC
|IXON
) ||
1222 tp
->t_modes
.c_lflag
& (ISIG
|ICANON
)) {
1224 * We're doing some sort of non-trivial
1225 * processing of input; look at every
1228 while (readp
< bp
->b_wptr
) {
1231 if (tp
->t_modes
.c_iflag
& ISTRIP
)
1235 * First, check that this hasn't been
1236 * escaped with the "literal next"
1239 if (tp
->t_state
& TS_PLNCH
) {
1240 tp
->t_state
&= ~TS_PLNCH
;
1241 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
1246 * Setting a special character to NUL
1247 * disables it, so if this character
1248 * is NUL, it should not be compared
1249 * with any of the special characters.
1250 * It should, however, restart frozen
1251 * output if IXON and IXANY are set.
1253 if (c
== _POSIX_VDISABLE
) {
1254 if (tp
->t_modes
.c_iflag
& IXON
&&
1255 tp
->t_state
& TS_TTSTOP
&&
1256 tp
->t_modes
.c_lflag
& IEXTEN
&&
1257 tp
->t_modes
.c_iflag
& IXANY
) {
1259 ~(TS_TTSTOP
|TS_OFBLOCK
);
1260 (void) putnextctl(wrq
, M_START
);
1262 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
1267 * If stopped, start if you can; if
1268 * running, stop if you must.
1270 if (tp
->t_modes
.c_iflag
& IXON
) {
1271 if (tp
->t_state
& TS_TTSTOP
) {
1273 tp
->t_modes
.c_cc
[VSTART
] ||
1274 (tp
->t_modes
.c_lflag
&
1276 tp
->t_modes
.c_iflag
&
1281 (void) putnextctl(wrq
,
1286 tp
->t_modes
.c_cc
[VSTOP
]) {
1289 (void) putnextctl(wrq
,
1293 if (c
== tp
->t_modes
.c_cc
[VSTOP
] ||
1294 c
== tp
->t_modes
.c_cc
[VSTART
])
1298 * Check for "literal next" character
1299 * and "flush output" character.
1300 * Note that we omit checks for ISIG
1301 * and ICANON, since the IEXTEN
1302 * setting subsumes them.
1304 if (tp
->t_modes
.c_lflag
& IEXTEN
) {
1305 if (c
== tp
->t_modes
.c_cc
[VLNEXT
]) {
1307 * Remember that we saw a
1308 * "literal next" while
1309 * scanning input, but leave
1310 * leave it in the message so
1311 * that the service routine
1314 tp
->t_state
|= TS_PLNCH
;
1315 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
1319 if (c
== tp
->t_modes
.c_cc
[VDISCARD
]) {
1320 ldterm_flush_output(c
, wrq
, tp
);
1324 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
1327 * Check for signal-generating
1330 if (tp
->t_modes
.c_lflag
& ISIG
) {
1331 if (c
== tp
->t_modes
.c_cc
[VINTR
]) {
1332 ldterm_dosig(q
, SIGINT
, c
,
1336 if (c
== tp
->t_modes
.c_cc
[VQUIT
]) {
1337 ldterm_dosig(q
, SIGQUIT
, c
,
1341 if (c
== tp
->t_modes
.c_cc
[VSWTCH
]) {
1343 * Ancient SXT support; discard
1344 * character without action.
1348 if (c
== tp
->t_modes
.c_cc
[VSUSP
]) {
1349 ldterm_dosig(q
, SIGTSTP
, c
,
1353 if ((tp
->t_modes
.c_lflag
& IEXTEN
) &&
1354 (c
== tp
->t_modes
.c_cc
[VDSUSP
])) {
1355 ldterm_dosig(q
, SIGTSTP
, c
,
1361 * Consumers do not expect the ^T to be
1362 * echoed out when we generate a
1365 if (c
== tp
->t_modes
.c_cc
[VSTATUS
]) {
1366 ldterm_dosig(q
, SIGINFO
, '\0',
1372 * Throw away CR if IGNCR set, or
1373 * turn it into NL if ICRNL set.
1376 if (tp
->t_modes
.c_iflag
& IGNCR
)
1378 if (tp
->t_modes
.c_iflag
& ICRNL
)
1382 * Turn NL into CR if INLCR
1386 tp
->t_modes
.c_iflag
& INLCR
)
1391 * Map upper case input to lower case
1392 * if IUCLC flag set.
1394 if (tp
->t_modes
.c_iflag
& IUCLC
&&
1395 c
>= 'A' && c
<= 'Z')
1399 * Put the possibly-transformed
1400 * character back in the message.
1406 * If we didn't copy some characters because
1407 * we were ignoring them, fix the size of the
1408 * data block by adjusting the write pointer.
1409 * XXX This may result in a zero-length
1410 * block; will this cause anybody gastric
1413 bp
->b_wptr
-= (readp
- writep
);
1416 * We won't be doing anything other than
1417 * possibly stripping the input.
1419 if (tp
->t_modes
.c_iflag
& ISTRIP
) {
1420 while (readp
< bp
->b_wptr
)
1421 *writep
++ = *readp
++ & 0177;
1423 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
1426 } while ((bp
= bp
->b_cont
) != NULL
); /* next block, if any */
1429 * Queue the message for service procedure if the
1430 * queue is not empty or canputnext() fails or
1431 * tp->t_state & TS_RESCAN is true.
1434 if (q
->q_first
!= NULL
|| !bcanputnext(q
, mp
->b_band
) ||
1435 (tp
->t_state
& TS_RESCAN
))
1438 (void) ldtermrmsg(q
, mp
);
1441 * Flow control: send "stop input" message if our queue is
1442 * approaching its high-water mark. The message will be
1443 * dropped on the floor in the service procedure, if we
1444 * cannot ship it up and we have had it upto our neck!
1446 * Set QWANTW to ensure that the read queue service procedure
1447 * gets run when nextq empties up again, so that it can
1450 if ((tp
->t_modes
.c_iflag
& IXOFF
) && !(tp
->t_state
& TS_TBLOCK
) &&
1451 q
->q_count
>= TTXOHI
) {
1452 mutex_enter(QLOCK(nextq
));
1453 nextq
->q_flag
|= QWANTW
;
1454 mutex_exit(QLOCK(nextq
));
1455 tp
->t_state
|= TS_TBLOCK
;
1456 (void) putnextctl(wrq
, M_STOPI
);
1457 DEBUG1(("M_STOPI down\n"));
1463 * Line discipline input server processing. Erase/kill and escape
1464 * ('\') processing, gathering into messages, upper/lower case input
1468 ldtermrsrv(queue_t
*q
)
1470 ldtermstd_state_t
*tp
;
1473 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
1475 if (tp
->t_state
& TS_RESCAN
) {
1477 * Canonicalization was turned on or off. Put the
1478 * message being assembled back in the input queue,
1479 * so that we rescan it.
1481 if (tp
->t_message
!= NULL
) {
1482 DEBUG5(("RESCAN WAS SET; put back in q\n"));
1483 if (tp
->t_msglen
!= 0)
1484 (void) putbq(q
, tp
->t_message
);
1486 freemsg(tp
->t_message
);
1487 tp
->t_message
= NULL
;
1488 tp
->t_endmsg
= NULL
;
1491 if (tp
->t_state
& TS_MEUC
) {
1492 ASSERT(tp
->t_eucp_mp
);
1493 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
1497 tp
->t_state
&= ~TS_RESCAN
;
1500 while ((mp
= getq(q
)) != NULL
) {
1501 if (!ldtermrmsg(q
, mp
))
1506 * Flow control: send start message if blocked and our queue
1507 * is below its low water mark.
1509 if ((tp
->t_modes
.c_iflag
& IXOFF
) && (tp
->t_state
& TS_TBLOCK
) &&
1510 !(tp
->t_state
& TS_IFBLOCK
) && q
->q_count
<= TTXOLO
) {
1511 tp
->t_state
&= ~TS_TBLOCK
;
1512 (void) putctl(WR(q
), M_STARTI
);
1517 * This routine is called from both ldtermrput and ldtermrsrv to
1518 * do the actual work of dealing with mp. Return 1 on sucesss and
1522 ldtermrmsg(queue_t
*q
, mblk_t
*mp
)
1530 ldtermstd_state_t
*tp
;
1534 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
1536 if (mp
->b_datap
->db_type
<= QPCTL
&& !bcanputnext(q
, mp
->b_band
)) {
1538 * Stream head is flow controlled. If echo is
1539 * turned on, flush the read side or send a
1540 * bell down the line to stop input and
1541 * process the current message.
1542 * Otherwise(putbq) the user will not see any
1543 * response to to the typed input. Typically
1544 * happens if there is no reader process.
1545 * Note that you will loose the data in this
1546 * case if the data is coming too fast. There
1547 * is an assumption here that if ECHO is
1548 * turned on its some user typing the data on
1549 * a terminal and its not network.
1551 if (tp
->t_modes
.c_lflag
& ECHO
) {
1552 if ((tp
->t_modes
.c_iflag
& IMAXBEL
) &&
1553 (tp
->t_modes
.c_lflag
& ICANON
)) {
1555 if (canputnext(WR(q
)))
1556 ldterm_outchar(CTRL('g'), WR(q
), 4, tp
);
1560 (void) putctl1(q
, M_FLUSH
, FLUSHR
);
1563 (void) putbq(q
, mp
);
1565 goto out
; /* read side is blocked */
1568 switch (mp
->b_datap
->db_type
) {
1571 putnext(q
, mp
); /* pass it on */
1576 * Flush everything we haven't looked at yet.
1578 flushq(q
, FLUSHDATA
);
1581 * Flush everything we have looked at.
1583 freemsg(tp
->t_message
);
1584 tp
->t_message
= NULL
;
1585 tp
->t_endmsg
= NULL
;
1588 * XXX should we set read request
1589 * tp->t_rd_request to NULL?
1591 tp
->t_rocount
= 0; /* if it hasn't been typed */
1592 tp
->t_rocol
= 0; /* it hasn't been echoed :-) */
1593 if (tp
->t_state
& TS_MEUC
) {
1594 ASSERT(tp
->t_eucp_mp
);
1595 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
1598 * Restart output, since it's probably got
1599 * nowhere to go anyway, and we're probably
1600 * not going to see another ^Q for a while.
1602 if (tp
->t_state
& TS_TTSTOP
) {
1603 tp
->t_state
&= ~(TS_TTSTOP
|TS_OFBLOCK
);
1604 (void) putnextctl(WR(q
), M_START
);
1607 * This message will travel up the read
1608 * queue, flushing as it goes, get turned
1609 * around at the stream head, and travel back
1610 * down the write queue, flushing as it goes.
1612 (void) putnextctl1(q
, M_FLUSH
, FLUSHW
);
1615 * This message will travel down the write
1616 * queue, flushing as it goes, get turned
1617 * around at the driver, and travel back up
1618 * the read queue, flushing as it goes.
1620 (void) putctl1(WR(q
), M_FLUSH
, FLUSHR
);
1623 * Now that that's done, we send a SIGCONT
1624 * upstream, followed by the M_HANGUP.
1626 /* (void) putnextctl1(q, M_PCSIG, SIGCONT); */
1633 * Augment whatever information the driver is
1634 * returning with the information we supply.
1636 ldterm_ioctl_reply(q
, mp
);
1644 * This is an M_DATA message.
1648 * If somebody below us ("intelligent" communications
1649 * board, pseudo-tty controlled by an editor) is
1650 * doing canonicalization, don't scan it for special
1653 if (tp
->t_state
& TS_NOCANON
) {
1659 if ((bpt
= newmsg(tp
)) != NULL
) {
1663 ASSERT(bp
->b_wptr
>= bp
->b_rptr
);
1664 ebsize
= bp
->b_wptr
- bp
->b_rptr
;
1665 if (ebsize
> EBSIZE
)
1670 * By default, free the message once processed
1675 * update sysinfo canch
1676 * character. The value of
1677 * canch may vary as compared
1681 while (bp
->b_rptr
< bp
->b_wptr
) {
1683 if ((bpt
= ldterm_docanon(c
,
1684 bpt
, ebsize
, q
, tp
, &dofree
)) ==
1689 * Release this block or put back on queue.
1694 (void) putbq(q
, bp
);
1698 bpt
= ldterm_dononcanon(bp
, bpt
, ebsize
, q
, tp
);
1701 "ldtermrsrv: out of blocks");
1705 } while ((bp
= bcont
) != NULL
);
1709 * Send whatever we echoed downstream.
1711 if (tp
->t_echomp
!= NULL
) {
1712 if (canputnext(WR(q
)))
1713 putnext(WR(q
), tp
->t_echomp
);
1715 freemsg(tp
->t_echomp
);
1716 tp
->t_echomp
= NULL
;
1725 * Do canonical mode input; check whether this character is to be
1726 * treated as a special character - if so, check whether it's equal
1727 * to any of the special characters and handle it accordingly.
1728 * Otherwise, just add it to the current line.
1731 ldterm_docanon(uchar_t c
, mblk_t
*bpt
, size_t ebsize
, queue_t
*q
,
1732 ldtermstd_state_t
*tp
, int *dofreep
)
1734 queue_t
*wrq
= WR(q
);
1738 * If the previous character was the "literal next"
1739 * character, treat this character as regular input.
1741 if (tp
->t_state
& TS_SLNCH
)
1745 * Setting a special character to NUL disables it, so if this
1746 * character is NUL, it should not be compared with any of
1747 * the special characters.
1749 if (c
== _POSIX_VDISABLE
) {
1750 tp
->t_state
&= ~TS_QUOT
;
1754 * If this character is the literal next character, echo it
1755 * as '^', backspace over it, and record that fact.
1757 if ((tp
->t_modes
.c_lflag
& IEXTEN
) && c
== tp
->t_modes
.c_cc
[VLNEXT
]) {
1758 if (tp
->t_modes
.c_lflag
& ECHO
)
1759 ldterm_outstring((unsigned char *)"^\b", 2, wrq
,
1761 tp
->t_state
|= TS_SLNCH
;
1765 * Check for the editing character. If the display width of
1766 * the last byte at the canonical buffer is not one and also
1767 * smaller than or equal to UNKNOWN_WIDTH, the character at
1768 * the end of the buffer is a multi-byte and/or multi-column
1771 if (c
== tp
->t_modes
.c_cc
[VERASE
] || c
== tp
->t_modes
.c_cc
[VERASE2
]) {
1772 if (tp
->t_state
& TS_QUOT
) {
1774 * Get rid of the backslash, and put the
1775 * erase character in its place.
1777 ldterm_erase(wrq
, ebsize
, tp
);
1781 if ((tp
->t_state
& TS_MEUC
) && tp
->t_msglen
&&
1782 (*(tp
->t_eucp
- 1) != 1 &&
1783 *(tp
->t_eucp
- 1) <= UNKNOWN_WIDTH
))
1784 ldterm_csi_erase(wrq
, ebsize
, tp
);
1786 ldterm_erase(wrq
, ebsize
, tp
);
1791 if ((tp
->t_modes
.c_lflag
& IEXTEN
) && c
== tp
->t_modes
.c_cc
[VWERASE
]) {
1793 * Do "ASCII word" or "multibyte character token/chunk" erase.
1795 if (tp
->t_state
& TS_MEUC
)
1796 ldterm_csi_werase(wrq
, ebsize
, tp
);
1798 ldterm_werase(wrq
, ebsize
, tp
);
1802 if (c
== tp
->t_modes
.c_cc
[VKILL
]) {
1803 if (tp
->t_state
& TS_QUOT
) {
1805 * Get rid of the backslash, and put the kill
1806 * character in its place.
1808 ldterm_erase(wrq
, ebsize
, tp
);
1812 ldterm_kill(wrq
, ebsize
, tp
);
1817 if ((tp
->t_modes
.c_lflag
& IEXTEN
) && c
== tp
->t_modes
.c_cc
[VREPRINT
]) {
1818 ldterm_reprint(wrq
, ebsize
, tp
);
1822 * If the preceding character was a backslash: if the current
1823 * character is an EOF, get rid of the backslash and treat
1824 * the EOF as data; if we're in XCASE mode and the current
1825 * character is part of a backslash-X escape sequence,
1826 * process it; otherwise, just treat the current character
1829 if (tp
->t_state
& TS_QUOT
) {
1830 tp
->t_state
&= ~TS_QUOT
;
1831 if (c
== tp
->t_modes
.c_cc
[VEOF
]) {
1833 * EOF character. Since it's escaped, get rid
1834 * of the backslash and put the EOF character
1837 ldterm_erase(wrq
, ebsize
, tp
);
1841 * If we're in XCASE mode, and the current
1842 * character is part of a backslash-X
1843 * sequence, get rid of the backslash and
1844 * replace the current character with what
1845 * that sequence maps to.
1847 if ((tp
->t_modes
.c_lflag
& XCASE
) &&
1848 imaptab
[c
] != '\0') {
1849 ldterm_erase(wrq
, ebsize
, tp
);
1856 * Previous character wasn't backslash; check whether
1857 * this was the EOF character.
1859 if (c
== tp
->t_modes
.c_cc
[VEOF
]) {
1861 * EOF character. Don't echo it unless
1862 * ECHOCTL is set, don't stuff it in the
1863 * current line, but send the line up the
1866 if ((tp
->t_modes
.c_lflag
& ECHOCTL
) &&
1867 (tp
->t_modes
.c_lflag
& IEXTEN
) &&
1868 (tp
->t_modes
.c_lflag
& ECHO
)) {
1869 i
= ldterm_echo(c
, wrq
, ebsize
, tp
);
1871 ldterm_outchar('\b', wrq
, ebsize
, tp
);
1875 bpt
->b_datap
->db_type
= M_DATA
;
1876 ldterm_msg_upstream(q
, tp
);
1877 if (!canputnext(q
)) {
1890 * First, make sure we can fit one WHOLE multi-byte char in the
1891 * buffer. This is one place where we have overhead even if
1892 * not in multi-byte mode; the overhead is subtracting
1893 * tp->t_maxeuc from MAX_CANON before checking.
1895 * Allows MAX_CANON bytes in the buffer before throwing awaying
1896 * the the overflow of characters.
1898 if ((tp
->t_msglen
> ((_TTY_BUFSIZ
+ 1) - (int)tp
->t_maxeuc
)) &&
1899 !((tp
->t_state
& TS_MEUC
) && tp
->t_eucleft
)) {
1902 * Byte will cause line to overflow, or the next EUC
1903 * won't fit: Ring the bell or discard all input, and
1904 * don't save the byte away.
1906 if (tp
->t_modes
.c_iflag
& IMAXBEL
) {
1907 if (canputnext(wrq
))
1908 ldterm_outchar(CTRL('g'), wrq
, ebsize
, tp
);
1912 * MAX_CANON processing. free everything in
1913 * the current line and start with the
1914 * current character as the first character.
1916 DEBUG7(("ldterm_docanon: MAX_CANON processing\n"));
1917 freemsg(tp
->t_message
);
1918 tp
->t_message
= NULL
;
1919 tp
->t_endmsg
= NULL
;
1921 tp
->t_rocount
= 0; /* if it hasn't been type */
1922 tp
->t_rocol
= 0; /* it hasn't been echoed :-) */
1923 if (tp
->t_state
& TS_MEUC
) {
1924 ASSERT(tp
->t_eucp_mp
);
1925 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
1927 tp
->t_state
&= ~TS_SLNCH
;
1932 * Add the character to the current line.
1934 if (bpt
->b_wptr
>= bpt
->b_datap
->db_lim
) {
1936 * No more room in this mblk; save this one away, and
1937 * allocate a new one.
1939 bpt
->b_datap
->db_type
= M_DATA
;
1940 if ((bpt
= allocb(IBSIZE
, BPRI_MED
)) == NULL
)
1944 * Chain the new one to the end of the old one, and
1945 * mark it as the last block in the current line.
1947 tp
->t_endmsg
->b_cont
= bpt
;
1951 tp
->t_msglen
++; /* message length in BYTES */
1954 * In multi-byte mode, we have to keep track of where we are.
1955 * The first bytes of multi-byte chars get the full count for the
1956 * whole character. We don't do any column calculations
1957 * here, but we need the information for when we do. We could
1958 * come across cases where we are getting garbage on the
1959 * line, but we're in multi-byte mode. In that case, we may
1960 * see ASCII controls come in the middle of what should have been a
1961 * multi-byte character. Call ldterm_eucwarn...eventually, a
1962 * warning message will be printed about it.
1964 if (tp
->t_state
& TS_MEUC
) {
1965 if (tp
->t_eucleft
) { /* if in a multi-byte char already */
1967 *tp
->t_eucp
++ = 0; /* is a subsequent byte */
1968 if (c
< (uchar_t
)0x20)
1970 } else { /* is the first byte of a multi-byte, or is ASCII */
1973 tp
->t_csmethods
.ldterm_dispwidth(c
,
1974 (void *)tp
, tp
->t_modes
.c_lflag
& ECHOCTL
);
1978 tp
->t_csmethods
.ldterm_dispwidth(c
,
1979 (void *)tp
, tp
->t_modes
.c_lflag
& ECHOCTL
);
1981 tp
->t_csmethods
.ldterm_memwidth(c
,
1983 tp
->t_codeset
= ldterm_codeset(
1984 tp
->t_csdata
.codeset_type
, c
);
1989 * AT&T is concerned about the following but we aren't since
1990 * we have already shipped code that works.
1992 * EOL2/XCASE should be conditioned with IEXTEN to be truly
1993 * POSIX conformant. This is going to cause problems for
1994 * pre-SVR4.0 programs that don't know about IEXTEN. Hence
1995 * EOL2/IEXTEN is not conditioned with IEXTEN.
1997 if (!(tp
->t_state
& TS_SLNCH
) &&
1998 (c
== '\n' || (c
!= '\0' && (c
== tp
->t_modes
.c_cc
[VEOL
] ||
1999 (c
== tp
->t_modes
.c_cc
[VEOL2
]))))) {
2001 * || ((tp->t_modes.c_lflag & IEXTEN) && c ==
2002 * tp->t_modes.c_cc[VEOL2]))))) {
2005 * It's a line-termination character; send the line
2008 bpt
->b_datap
->db_type
= M_DATA
;
2009 ldterm_msg_upstream(q
, tp
);
2010 if (tp
->t_state
& TS_MEUC
) {
2011 ASSERT(tp
->t_eucp_mp
);
2012 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
2014 if ((bpt
= newmsg(tp
)) == NULL
)
2018 * Character was escaped with LNEXT.
2020 if (tp
->t_rocount
++ == 0)
2021 tp
->t_rocol
= tp
->t_col
;
2022 tp
->t_state
&= ~(TS_SLNCH
|TS_QUOT
);
2024 * If the current character is a single byte and single
2025 * column character and it is the backslash character and
2026 * IEXTEN, then the state will have TS_QUOT.
2028 if ((c
== '\\') && (tp
->t_modes
.c_lflag
& IEXTEN
) &&
2029 (!(tp
->t_state
& TS_MEUC
) ||
2030 ((tp
->t_state
& TS_MEUC
) && (!tp
->t_eucleft
))))
2031 tp
->t_state
|= TS_QUOT
;
2037 if (tp
->t_state
& TS_ERASE
) {
2038 tp
->t_state
&= ~TS_ERASE
;
2039 if (tp
->t_modes
.c_lflag
& ECHO
)
2040 ldterm_outchar('/', wrq
, ebsize
, tp
);
2042 if (tp
->t_modes
.c_lflag
& ECHO
)
2043 (void) ldterm_echo(c
, wrq
, ebsize
, tp
);
2046 * Echo NL when ECHO turned off, if ECHONL flag is
2049 if (c
== '\n' && (tp
->t_modes
.c_lflag
& ECHONL
))
2050 ldterm_outchar(c
, wrq
, ebsize
, tp
);
2060 ldterm_unget(ldtermstd_state_t
*tp
)
2064 if ((bpt
= tp
->t_endmsg
) == NULL
)
2065 return (-1); /* no buffers */
2066 if (bpt
->b_rptr
== bpt
->b_wptr
)
2067 return (-1); /* zero-length record */
2068 tp
->t_msglen
--; /* one fewer character */
2069 return (*--bpt
->b_wptr
);
2074 ldterm_trim(ldtermstd_state_t
*tp
)
2079 ASSERT(tp
->t_endmsg
);
2082 if (bpt
->b_rptr
== bpt
->b_wptr
) {
2084 * This mblk is now empty. Find the previous mblk;
2085 * throw this one away, unless it's the first one.
2089 while (bp
->b_cont
!= bpt
) {
2095 tp
->t_endmsg
= bp
; /* point to that mblk */
2102 * Rubout one character from the current line being built for tp as
2103 * cleanly as possible. q is the write queue for tp. Most of this
2104 * can't be applied to multi-byte processing. We do our own thing
2105 * for that... See the "ldterm_eucerase" routine. We never call
2106 * ldterm_rubout on a multi-byte or multi-column character.
2109 ldterm_rubout(uchar_t c
, queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2112 static unsigned char crtrubout
[] = "\b \b\b \b";
2113 #define RUBOUT1 &crtrubout[3] /* rub out one position */
2114 #define RUBOUT2 &crtrubout[0] /* rub out two positions */
2116 if (!(tp
->t_modes
.c_lflag
& ECHO
))
2118 if (tp
->t_modes
.c_lflag
& ECHOE
) {
2120 * "CRT rubout"; try erasing it from the screen.
2122 if (tp
->t_rocount
== 0) {
2124 * After the character being erased was
2125 * echoed, some data was written to the
2126 * terminal; we can't erase it cleanly, so we
2127 * just reprint the whole line as if the user
2128 * had typed the reprint character.
2130 ldterm_reprint(q
, ebsize
, tp
);
2134 * XXX what about escaped characters?
2136 switch (typetab
[c
]) {
2139 if ((tp
->t_modes
.c_lflag
& XCASE
) &&
2141 ldterm_outstring(RUBOUT1
, 3, q
, ebsize
,
2143 ldterm_outstring(RUBOUT1
, 3, q
, ebsize
, tp
);
2151 if ((tp
->t_modes
.c_lflag
& ECHOCTL
) &&
2152 (tp
->t_modes
.c_lflag
& IEXTEN
))
2153 ldterm_outstring(RUBOUT2
, 6, q
, ebsize
,
2158 if (tp
->t_rocount
< tp
->t_msglen
) {
2160 * While the tab being erased was
2161 * expanded, some data was written
2162 * to the terminal; we can't erase
2163 * it cleanly, so we just reprint
2164 * the whole line as if the user
2165 * had typed the reprint character.
2167 ldterm_reprint(q
, ebsize
, tp
);
2170 tabcols
= ldterm_tabcols(tp
);
2171 while (--tabcols
>= 0)
2172 ldterm_outchar('\b', q
, ebsize
, tp
);
2176 } else if ((tp
->t_modes
.c_lflag
& ECHOPRT
) &&
2177 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
2179 * "Printing rubout"; echo it between \ and /.
2181 if (!(tp
->t_state
& TS_ERASE
)) {
2182 ldterm_outchar('\\', q
, ebsize
, tp
);
2183 tp
->t_state
|= TS_ERASE
;
2185 (void) ldterm_echo(c
, q
, ebsize
, tp
);
2187 (void) ldterm_echo(tp
->t_modes
.c_cc
[VERASE
], q
, ebsize
, tp
);
2188 tp
->t_rocount
--; /* we "unechoed" this character */
2193 * Find the number of characters the tab we just deleted took up by
2194 * zipping through the current line and recomputing the column
2198 ldterm_tabcols(ldtermstd_state_t
*tp
)
2203 unsigned char *readp
, *endp
;
2207 uchar_t u8
[LDTERM_CS_MAX_BYTE_LENGTH
];
2211 * If we're doing multi-byte stuff, zip through the list of
2212 * widths to figure out where we are (we've kept track in most
2215 if (tp
->t_state
& TS_MEUC
) {
2216 ASSERT(tp
->t_eucp_mp
);
2218 startp
= bp
->b_datap
->db_base
;
2219 readp
= tp
->t_eucp_mp
->b_rptr
;
2222 while (readp
< endp
) {
2224 case EUC_TWIDTH
: /* it's a tab */
2225 col
|= 07; /* bump up */
2228 case EUC_BSWIDTH
: /* backspace */
2232 case EUC_NLWIDTH
: /* newline */
2233 if (tp
->t_modes
.c_oflag
& ONLRET
)
2236 case EUC_CRWIDTH
: /* return */
2239 case UNKNOWN_WIDTH
: /* UTF-8 unknown width */
2240 if (tp
->t_csdata
.codeset_type
!=
2241 LDTERM_CS_TYPE_UTF8
|| errflg
) {
2247 * Collect the current UTF-8 character bytes
2248 * from (possibly multiple) data buffers so
2249 * that we can figure out the display width.
2252 for (i
= 1; (i
< LDTERM_CS_MAX_BYTE_LENGTH
) &&
2253 (*(readp
+ i
) == 0); i
++) {
2255 if (startp
>= bp
->b_datap
->db_lim
) {
2270 /* tp->t_eucp_mp contains wrong info?? */
2274 *readp
= ldterm_utf8_width(u8
, i
);
2285 if (startp
>= bp
->b_datap
->db_lim
) {
2288 startp
= bp
->b_datap
->db_base
;
2291 * This will happen only if
2292 * tp->t_eucp_mp contains wrong
2293 * display width info.
2300 goto eucout
; /* finished! */
2305 while (readp
< bp
->b_wptr
) {
2307 if ((tp
->t_modes
.c_lflag
& ECHOCTL
) &&
2308 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
2309 if (c
<= 037 && c
!= '\t' && c
!= '\n' ||
2316 * Column position calculated here.
2318 switch (typetab
[c
]) {
2321 * Ordinary characters; advance by
2329 * Non-printing characters; nothing
2341 /* Newline; column depends on flags. */
2343 if (tp
->t_modes
.c_oflag
& ONLRET
)
2353 /* vertical motion */
2357 /* carriage return */
2363 } while ((bp
= bp
->b_cont
) != NULL
); /* next block, if any */
2366 * "col" is now the column number before the tab. "tp->t_col"
2367 * is still the column number after the tab, since we haven't
2368 * erased the tab yet. Thus "tp->t_col - col" is the number
2369 * of positions the tab moved.
2372 col
= tp
->t_col
- col
;
2374 col
= 8; /* overflow screw */
2380 * Erase a single character; We ONLY ONLY deal with ASCII or
2381 * single-column single-byte codeset character. For multi-byte characters,
2382 * see "ldterm_csi_erase".
2385 ldterm_erase(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2389 if ((c
= ldterm_unget(tp
)) != -1) {
2390 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2392 if (tp
->t_state
& TS_MEUC
)
2399 * Erase an entire word, single-byte EUC only please.
2402 ldterm_werase(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2407 * Erase trailing white space, if any.
2409 while ((c
= ldterm_unget(tp
)) == ' ' || c
== '\t') {
2410 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2415 * Erase non-white-space characters, if any.
2417 while (c
!= -1 && c
!= ' ' && c
!= '\t') {
2418 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2420 c
= ldterm_unget(tp
);
2424 * We removed one too many characters; put the last
2427 tp
->t_endmsg
->b_wptr
++; /* put 'c' back */
2434 * ldterm_csi_werase - This is multi-byte equivalent of "word erase".
2435 * "Word erase" only makes sense in languages which space between words,
2436 * and it's presumptuous for us to attempt "word erase" when we don't
2437 * know anything about what's really going on. It makes no sense for
2438 * many languages, as the criteria for defining words and tokens may
2439 * be completely different.
2441 * In the TS_MEUC case (which is how we got here), we define a token to
2442 * be space- or tab-delimited, and erase one of them. It helps to
2443 * have this for command lines, but it's otherwise useless for text
2444 * editing applications; you need more sophistication than we can
2448 ldterm_csi_werase(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2453 uchar_t u8
[LDTERM_CS_MAX_BYTE_LENGTH
];
2454 uchar_t u8_2
[LDTERM_CS_MAX_BYTE_LENGTH
];
2457 * ip points to the width of the actual bytes. t_eucp points
2458 * one byte beyond, where the next thing will be inserted.
2460 ip
= tp
->t_eucp
- 1;
2462 * Erase trailing white space, if any.
2464 while ((c
= ldterm_unget(tp
)) == ' ' || c
== '\t') {
2466 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2472 * Erase non-white-space characters, if any. The outer loop
2473 * bops through each byte in the buffer. Multi-byte is removed, as
2474 * is ASCII, one byte at a time. The inner loop (for) is only
2475 * executed for first bytes of multi-byte. The inner loop erases
2476 * the number of columns required for the multi-byte char. We check
2477 * for ASCII first, and ldterm_rubout knows about ASCII.
2480 while (c
!= -1 && c
!= ' ' && c
!= '\t') {
2482 if (len
< LDTERM_CS_MAX_BYTE_LENGTH
) {
2483 u8
[len
++] = (uchar_t
)c
;
2486 * Unlike EUC, except the leading byte, some bytes of
2487 * a non-EUC multi-byte characters are in the ASCII code
2488 * range, esp., 0x41 ~ 0x7a. Thus, we cannot simply check
2490 * Checking the (*ip == 1 || *ip == 2 || *ip > UNKNOWN_WIDTH)
2491 * will ensure that it is a single byte character (even though
2492 * it is on display width not byte length) and can be further
2493 * checked whether it is an ASCII character or not.
2495 * When ECHOCTL is on and 'c' is an ASCII control character,
2498 if ((*ip
== 1 || *ip
== 2 || *ip
> UNKNOWN_WIDTH
) &&
2500 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2503 if (*ip
== UNKNOWN_WIDTH
) {
2504 if (tp
->t_csdata
.codeset_type
==
2505 LDTERM_CS_TYPE_UTF8
) {
2506 for (i
= 0; i
< len
; i
++)
2507 u8_2
[i
] = u8
[len
- i
- 1];
2508 *ip
= ldterm_utf8_width(u8_2
, len
);
2514 * erase for number of columns required for
2515 * this multi-byte character. Hopefully, matches
2518 for (i
= 0; i
< (int)*ip
; i
++)
2519 ldterm_rubout(' ', q
, ebsize
, tp
);
2524 c
= ldterm_unget(tp
);
2528 * We removed one too many characters; put the last
2531 tp
->t_endmsg
->b_wptr
++; /* put 'c' back */
2538 * Kill an entire line, erasing each character one-by-one (if ECHOKE
2539 * is set) or just echoing the kill character, followed by a newline
2540 * (if ECHOK is set). Multi-byte processing is included here.
2544 ldterm_kill(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2549 uchar_t u8
[LDTERM_CS_MAX_BYTE_LENGTH
];
2550 uchar_t u8_2
[LDTERM_CS_MAX_BYTE_LENGTH
];
2552 if ((tp
->t_modes
.c_lflag
& ECHOKE
) &&
2553 (tp
->t_modes
.c_lflag
& IEXTEN
) &&
2554 (tp
->t_msglen
== tp
->t_rocount
)) {
2555 if (tp
->t_state
& TS_MEUC
) {
2556 ip
= tp
->t_eucp
- 1;
2558 * This loop similar to "ldterm_csi_werase" above.
2561 while ((c
= ldterm_unget(tp
)) != (-1)) {
2563 if (len
< LDTERM_CS_MAX_BYTE_LENGTH
) {
2564 u8
[len
++] = (uchar_t
)c
;
2566 if ((*ip
== 1 || *ip
== 2 ||
2567 *ip
> UNKNOWN_WIDTH
) && ISASCII(c
)) {
2568 ldterm_rubout((unsigned char) c
, q
,
2572 if (*ip
== UNKNOWN_WIDTH
) {
2573 if (tp
->t_csdata
.codeset_type
2574 == LDTERM_CS_TYPE_UTF8
) {
2575 for (i
= 0; i
< len
;
2579 *ip
= ldterm_utf8_width(
2585 for (i
= 0; i
< (int)*ip
; i
++)
2586 ldterm_rubout(' ', q
, ebsize
,
2594 while ((c
= ldterm_unget(tp
)) != -1) {
2595 ldterm_rubout((unsigned char) c
, q
, ebsize
, tp
);
2600 (void) ldterm_echo(tp
->t_modes
.c_cc
[VKILL
], q
, ebsize
, tp
);
2601 if (tp
->t_modes
.c_lflag
& ECHOK
)
2602 (void) ldterm_echo('\n', q
, ebsize
, tp
);
2603 while (ldterm_unget(tp
) != -1) {
2604 if (tp
->t_state
& TS_MEUC
)
2609 if (tp
->t_state
& TS_MEUC
)
2610 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
2612 tp
->t_state
&= ~(TS_QUOT
|TS_ERASE
|TS_SLNCH
);
2617 * Reprint the current input line. We assume c_cc has already been
2618 * checked. XXX just the current line, not the whole queue? What
2619 * about DEFECHO mode?
2622 ldterm_reprint(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2625 unsigned char *readp
;
2627 if (tp
->t_modes
.c_cc
[VREPRINT
] != (unsigned char) 0)
2628 (void) ldterm_echo(tp
->t_modes
.c_cc
[VREPRINT
], q
, ebsize
, tp
);
2629 ldterm_outchar('\n', q
, ebsize
, tp
);
2634 while (readp
< bp
->b_wptr
)
2635 (void) ldterm_echo(*readp
++, q
, ebsize
, tp
);
2636 } while ((bp
= bp
->b_cont
) != NULL
); /* next block, if any */
2638 tp
->t_state
&= ~TS_ERASE
;
2639 tp
->t_rocount
= tp
->t_msglen
; /* we reechoed the entire line */
2645 * Non canonical processing. Called with q locked from ldtermrsrv.
2649 ldterm_dononcanon(mblk_t
*bp
, mblk_t
*bpt
, size_t ebsize
, queue_t
*q
,
2650 ldtermstd_state_t
*tp
)
2652 queue_t
*wrq
= WR(q
);
2653 unsigned char *rptr
;
2656 size_t bytes_to_move
;
2659 if (tp
->t_modes
.c_lflag
& (ECHO
|ECHONL
|IEXTEN
)) {
2660 unsigned char *wptr
;
2664 * Either we must echo the characters, or we must
2665 * echo NL, or we must check for VLNEXT. Process
2666 * characters one at a time.
2670 while (rptr
< bp
->b_wptr
) {
2673 * If this character is the literal next
2674 * character, echo it as '^' and backspace
2675 * over it if echoing is enabled, indicate
2676 * that the next character is to be treated
2677 * literally, and remove the LNEXT from the
2680 * If the *previous* character was the literal
2681 * next character, don't check whether this
2682 * is a literal next or not.
2684 if ((tp
->t_modes
.c_lflag
& IEXTEN
) &&
2685 !(tp
->t_state
& TS_SLNCH
) &&
2686 c
!= _POSIX_VDISABLE
&&
2687 c
== tp
->t_modes
.c_cc
[VLNEXT
]) {
2688 if (tp
->t_modes
.c_lflag
& ECHO
)
2690 (unsigned char *)"^\b",
2691 2, wrq
, ebsize
, tp
);
2692 tp
->t_state
|= TS_SLNCH
;
2693 continue; /* and ignore it */
2696 * Not a "literal next" character, so it
2697 * should show up as input. If it was
2698 * literal-nexted, turn off the literal-next
2701 tp
->t_state
&= ~TS_SLNCH
;
2703 if (tp
->t_modes
.c_lflag
& ECHO
) {
2705 * Echo the character.
2707 (void) ldterm_echo(c
, wrq
, ebsize
, tp
);
2708 } else if (tp
->t_modes
.c_lflag
& ECHONL
) {
2710 * Echo NL, even though ECHO is not
2714 ldterm_outchar('\n', wrq
, 1, tp
);
2720 * If there are any characters in this buffer, and
2721 * the first of them was literal-nexted, turn off the
2722 * literal-next flag.
2724 if (bp
->b_rptr
!= bp
->b_wptr
)
2725 tp
->t_state
&= ~TS_SLNCH
;
2728 ASSERT(bp
->b_wptr
>= bp
->b_rptr
);
2729 bytes_in_bp
= bp
->b_wptr
- bp
->b_rptr
;
2731 while (bytes_in_bp
!= 0) {
2732 roomleft
= bpt
->b_datap
->db_lim
- bpt
->b_wptr
;
2733 if (roomleft
== 0) {
2735 * No more room in this mblk; save this one
2736 * away, and allocate a new one.
2738 if ((bpt
= allocb(IBSIZE
, BPRI_MED
)) == NULL
) {
2740 DEBUG4(("ldterm_do_noncanon: allcob failed\n"));
2744 * Chain the new one to the end of the old
2745 * one, and mark it as the last block in the
2748 tp
->t_endmsg
->b_cont
= bpt
;
2752 DEBUG5(("roomleft=%d, bytes_in_bp=%d, tp->t_rd_request=%d\n",
2753 roomleft
, bytes_in_bp
, tp
->t_rd_request
));
2755 * if there is a read pending before this data got
2756 * here move bytes according to the minimum of room
2757 * left in this buffer, bytes in the message and byte
2758 * count requested in the read. If there is no read
2759 * pending, move the minimum of the first two
2761 if (tp
->t_rd_request
== 0)
2762 bytes_to_move
= MIN(roomleft
, bytes_in_bp
);
2765 MIN(MIN(roomleft
, bytes_in_bp
), tp
->t_rd_request
);
2766 DEBUG5(("Bytes to move = %lu\n", bytes_to_move
));
2767 if (bytes_to_move
== 0)
2769 bcopy(rptr
, bpt
->b_wptr
, bytes_to_move
);
2770 bpt
->b_wptr
+= bytes_to_move
;
2771 rptr
+= bytes_to_move
;
2772 tp
->t_msglen
+= bytes_to_move
;
2773 bytes_in_bp
-= bytes_to_move
;
2775 if (bytes_in_bp
== 0) {
2776 DEBUG4(("bytes_in_bp is zero\n"));
2779 free_flag
= 1; /* for debugging olny */
2781 DEBUG4(("ldterm_do_noncanon: VMIN = %d, VTIME = %d, msglen = %d, \
2782 tid = %d\n", V_MIN
, V_TIME
, tp
->t_msglen
, tp
->t_vtid
));
2784 * If there is a pending read request at the stream head we
2785 * need to do VMIN/VTIME processing. The four possible cases
2791 * If we can satisfy VMIN, send it up, and start a new
2792 * timer if necessary. These four cases of VMIN/VTIME
2793 * are also dealt with in the write side put routine
2794 * when the M_READ is first seen.
2797 DEBUG4(("Incoming data while M_READ'ing\n"));
2799 * Case 1: Any data will satisfy the read, so send
2802 if (V_MIN
== 0 && V_TIME
> 0) {
2804 vmin_satisfied(q
, tp
, 1);
2807 DEBUG4(("ldterm_do_noncanon called, but no data!\n"));
2810 * Case 2: This should never time out, so
2811 * until there's enough data, do nothing.
2813 } else if (V_MIN
> 0 && V_TIME
== 0) {
2814 if (tp
->t_msglen
>= (int)V_MIN
)
2815 vmin_satisfied(q
, tp
, 1);
2818 * Case 3: If MIN is satisfied, send it up.
2819 * Also, remember to start a new timer *every*
2820 * time we see something if MIN isn't
2823 } else if (V_MIN
> 0 && V_TIME
> 0) {
2824 if (tp
->t_msglen
>= (int)V_MIN
)
2825 vmin_satisfied(q
, tp
, 1);
2829 * Case 4: Not possible. This request
2830 * should always be satisfied from the write
2831 * side, left here for debugging.
2833 } else { /* V_MIN == 0 && V_TIME == 0 */
2834 vmin_satisfied(q
, tp
, 1);
2839 DEBUG4(("CAUTION message block not freed\n"));
2841 return (newmsg(tp
));
2846 * Echo a typed byte to the terminal. Returns the number of bytes
2847 * printed. Bytes of EUC characters drop through the ECHOCTL stuff
2848 * and are just output as themselves.
2851 ldterm_echo(uchar_t c
, queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
2855 if (!(tp
->t_modes
.c_lflag
& ECHO
))
2860 * Echo control characters (c <= 37) only if the ECHOCTRL
2861 * flag is set as ^X.
2864 if ((tp
->t_modes
.c_lflag
& ECHOCTL
) &&
2865 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
2866 if (c
<= 037 && c
!= '\t' && c
!= '\n') {
2867 ldterm_outchar('^', q
, ebsize
, tp
);
2869 if (tp
->t_modes
.c_oflag
& OLCUC
)
2873 } else if (c
== 0177) {
2874 ldterm_outchar('^', q
, ebsize
, tp
);
2878 ldterm_outchar(c
, q
, ebsize
, tp
);
2880 /* echo only special control character and the Bell */
2881 } else if ((c
> 037 && c
!= 0177) || c
== '\t' || c
== '\n' ||
2882 c
== '\r' || c
== '\b' || c
== 007 ||
2883 c
== tp
->t_modes
.c_cc
[VKILL
]) {
2884 ldterm_outchar(c
, q
, ebsize
, tp
);
2892 * Put a character on the output queue.
2895 ldterm_outchar(uchar_t c
, queue_t
*q
, size_t bsize
, ldtermstd_state_t
*tp
)
2900 * Don't even look at the characters unless we have something
2901 * useful to do with them.
2903 if ((tp
->t_modes
.c_oflag
& OPOST
) ||
2904 ((tp
->t_modes
.c_lflag
& XCASE
) &&
2905 (tp
->t_modes
.c_lflag
& ICANON
))) {
2908 if ((mp
= allocb(4, BPRI_HI
)) == NULL
) {
2910 "ldterm: (ldterm_outchar) out of blocks");
2914 mp
= ldterm_output_msg(q
, mp
, &tp
->t_echomp
, tp
, bsize
, 1);
2919 if ((curbp
= tp
->t_echomp
) != NULL
) {
2920 while (curbp
->b_cont
!= NULL
)
2921 curbp
= curbp
->b_cont
;
2922 if (curbp
->b_datap
->db_lim
== curbp
->b_wptr
) {
2925 if ((newbp
= allocb(bsize
, BPRI_HI
)) == NULL
) {
2927 "ldterm_outchar: out of blocks");
2930 curbp
->b_cont
= newbp
;
2934 if ((curbp
= allocb(bsize
, BPRI_HI
)) == NULL
) {
2936 "ldterm_outchar: out of blocks");
2939 tp
->t_echomp
= curbp
;
2941 *curbp
->b_wptr
++ = c
;
2947 * Copy a string, of length len, to the output queue.
2950 ldterm_outstring(uchar_t
*cp
, int len
, queue_t
*q
, size_t bsize
,
2951 ldtermstd_state_t
*tp
)
2954 ldterm_outchar(*cp
++, q
, bsize
, tp
);
2961 newmsg(ldtermstd_state_t
*tp
)
2966 * If no current message, allocate a block for it.
2968 if ((bp
= tp
->t_endmsg
) == NULL
) {
2969 if ((bp
= allocb(IBSIZE
, BPRI_MED
)) == NULL
) {
2971 "ldterm: (ldtermrsrv/newmsg) out of blocks");
2982 ldterm_msg_upstream(queue_t
*q
, ldtermstd_state_t
*tp
)
2990 putnext(q
, tp
->t_message
);
2993 * update sysinfo canch character.
2996 (void) drv_setparm(SYSCANC
, s
);
2997 tp
->t_message
= NULL
;
2998 tp
->t_endmsg
= NULL
;
3001 tp
->t_rd_request
= 0;
3002 if (tp
->t_state
& TS_MEUC
) {
3003 ASSERT(tp
->t_eucp_mp
);
3004 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
3005 /* can't reset everything, as we may have other input */
3011 * Re-enable the write-side service procedure. When an allocation
3012 * failure causes write-side processing to stall, we disable the
3013 * write side and arrange to call this function when allocation once
3014 * again becomes possible.
3017 ldterm_wenable(void *addr
)
3020 ldtermstd_state_t
*tp
;
3022 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
3024 * The bufcall is no longer pending.
3033 * Line discipline output queue put procedure. Attempts to process
3034 * the message directly and send it on downstream, queueing it only
3035 * if there's already something pending or if its downstream neighbor
3039 ldtermwput(queue_t
*q
, mblk_t
*mp
)
3041 ldtermstd_state_t
*tp
;
3042 unsigned char type
= mp
->b_datap
->db_type
;
3044 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
3047 * Always process priority messages, regardless of whether or
3048 * not our queue is nonempty.
3050 if (type
>= QPCTL
) {
3055 * Get rid of it, see comment in
3058 if ((tp
->t_state
& TS_FLUSHWAIT
) &&
3059 (*mp
->b_rptr
== FLUSHW
)) {
3060 tp
->t_state
&= ~TS_FLUSHWAIT
;
3065 * This is coming from above, so we only
3066 * handle the write queue here. If FLUSHR is
3067 * set, it will get turned around at the
3068 * driver, and the read procedure will see it
3071 if (*mp
->b_rptr
& FLUSHW
) {
3072 if ((tp
->t_state
& TS_ISPTSTTY
) &&
3073 (*mp
->b_rptr
& FLUSHBAND
))
3074 flushband(q
, *(mp
->b_rptr
+ 1),
3077 flushq(q
, FLUSHDATA
);
3082 * If a timed read is interrupted, there is
3083 * no way to cancel an existing M_READ
3084 * request. We kludge by allowing a flush to
3087 if (tp
->t_state
& TS_MREAD
)
3088 vmin_satisfied(RD(q
), tp
, 0);
3092 DEBUG1(("ldtermwmsg:M_READ RECEIVED\n"));
3094 * Stream head needs data to satisfy timed
3095 * read. Has meaning only if ICANON flag is
3096 * off indicating raw mode
3100 "M_READ: RAW_MODE=%d, CNT=%d, VMIN=%d, VTIME=%d\n",
3101 RAW_MODE
, *(unsigned int *)mp
->b_rptr
, V_MIN
,
3104 tp
->t_rd_request
= *(unsigned int *)mp
->b_rptr
;
3107 if (newmsg(tp
) != NULL
) {
3109 * VMIN/VTIME processing...
3110 * The four possible cases are:
3115 * These four conditions must be dealt
3116 * with on the read side as well in
3117 * ldterm_do_noncanon(). Set TS_MREAD
3118 * so that the read side will know
3119 * there is a pending read request
3120 * waiting at the stream head. If we
3121 * can satisfy MIN do it here, rather
3122 * than on the read side. If we can't,
3123 * start timers if necessary and let
3124 * the other side deal with it.
3126 * We got another M_READ before the
3127 * pending one completed, cancel any
3130 if (tp
->t_state
& TS_MREAD
) {
3131 vmin_satisfied(RD(q
),
3134 tp
->t_state
|= TS_MREAD
;
3136 * Case 1: Any data will
3137 * satisfy read, otherwise
3140 if (V_MIN
== 0 && V_TIME
> 0) {
3142 vmin_satisfied(RD(q
),
3145 vmin_settimer(RD(q
));
3148 * Case 2: If we have enough
3149 * data, send up now.
3150 * Otherwise, the read side
3151 * should wait forever until MIN
3154 } else if (V_MIN
> 0 && V_TIME
== 0) {
3155 if (tp
->t_msglen
>= (int)V_MIN
)
3156 vmin_satisfied(RD(q
),
3160 * Case 3: If we can satisfy
3161 * the read, send it up. If we
3162 * don't have enough data, but
3163 * there is at least one char,
3164 * start a timer. Otherwise,
3165 * let the read side start
3168 } else if (V_MIN
> 0 && V_TIME
> 0) {
3169 if (tp
->t_msglen
>= (int)V_MIN
)
3170 vmin_satisfied(RD(q
),
3172 else if (tp
->t_msglen
)
3173 vmin_settimer(RD(q
));
3175 * Case 4: Read returns
3176 * whatever data is available
3179 } else { /* V_MIN == 0 && V_TIME == 0 */
3180 vmin_satisfied(RD(q
), tp
, 1);
3183 } else /* should do bufcall, really! */
3185 "ldtermwmsg: out of blocks");
3194 /* Pass it through unmolested. */
3201 * If our queue is nonempty or there's a traffic jam
3202 * downstream, this message must get in line.
3204 if (q
->q_first
!= NULL
|| !bcanputnext(q
, mp
->b_band
)) {
3206 * Exception: ioctls, except for those defined to
3207 * take effect after output has drained, should be
3208 * processed immediately.
3210 if (type
== M_IOCTL
) {
3211 struct iocblk
*iocp
;
3213 iocp
= (struct iocblk
*)mp
->b_rptr
;
3214 switch (iocp
->ioc_cmd
) {
3227 * Handle all others immediately.
3230 (void) ldtermwmsg(q
, mp
);
3238 * We can take the fast path through, by simply calling
3239 * ldtermwmsg to dispose of mp.
3241 (void) ldtermwmsg(q
, mp
);
3246 * Line discipline output queue service procedure.
3249 ldtermwsrv(queue_t
*q
)
3254 * We expect this loop to iterate at most once, but must be
3255 * prepared for more in case our upstream neighbor isn't
3256 * paying strict attention to what canput tells it.
3258 while ((mp
= getq(q
)) != NULL
) {
3260 * N.B.: ldtermwput has already handled high-priority
3261 * messages, so we don't have to worry about them
3262 * here. Hence, the putbq call is safe.
3264 if (!bcanputnext(q
, mp
->b_band
)) {
3265 (void) putbq(q
, mp
);
3268 if (!ldtermwmsg(q
, mp
)) {
3270 * Couldn't handle the whole thing; give up
3271 * for now and wait to be rescheduled.
3280 * Process the write-side message denoted by mp. If mp can't be
3281 * processed completely (due to allocation failures), put the
3282 * residual unprocessed part on the front of the write queue, disable
3283 * the queue, and schedule a qbufcall to arrange to complete its
3286 * Return 1 if the message was processed completely and 0 if not.
3288 * This routine is called from both ldtermwput and ldtermwsrv to do the
3289 * actual work of dealing with mp. ldtermwput will have already
3290 * dealt with high priority messages.
3293 ldtermwmsg(queue_t
*q
, mblk_t
*mp
)
3295 ldtermstd_state_t
*tp
;
3296 mblk_t
*residmp
= NULL
;
3299 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
3301 switch (mp
->b_datap
->db_type
) {
3304 ldterm_do_ioctl(q
, mp
);
3311 if ((tp
->t_modes
.c_lflag
& FLUSHO
) &&
3312 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
3313 freemsg(mp
); /* drop on floor */
3318 * Don't even look at the characters unless
3319 * we have something useful to do with them.
3321 if (((tp
->t_modes
.c_oflag
& OPOST
) ||
3322 ((tp
->t_modes
.c_lflag
& XCASE
) &&
3323 (tp
->t_modes
.c_lflag
& ICANON
))) &&
3324 (msgdsize(mp
) || !(tp
->t_state
& TS_ISPTSTTY
))) {
3325 unsigned char band
= mp
->b_band
;
3326 short flag
= mp
->b_flag
;
3328 residmp
= ldterm_output_msg(q
, mp
, &omp
,
3330 if ((mp
= omp
) == NULL
)
3335 /* Update sysinfo outch */
3336 (void) drv_setparm(SYSOUTC
, msgdsize(mp
));
3342 putnext(q
, mp
); /* pass it through unmolested */
3346 if (residmp
== NULL
)
3350 * An allocation failure occurred that prevented the message
3351 * from being completely processed. First, disable our
3352 * queue, since it's pointless to attempt further processing
3353 * until the allocation situation is resolved. (This must
3354 * precede the putbq call below, which would otherwise mark
3355 * the queue to be serviced.)
3359 * Stuff the remnant on our write queue so that we can
3360 * complete it later when times become less lean. Note that
3361 * this sets QFULL, so that our upstream neighbor will be
3362 * blocked by flow control.
3364 (void) putbq(q
, residmp
);
3366 * Schedule a qbufcall to re-enable the queue. The failure
3367 * won't have been for an allocation of more than OBSIZE
3368 * bytes, so don't ask for more than that from bufcall.
3370 size
= msgdsize(residmp
);
3374 qunbufcall(q
, tp
->t_wbufcid
);
3375 tp
->t_wbufcid
= qbufcall(q
, size
, BPRI_MED
, ldterm_wenable
, q
);
3382 * Perform output processing on a message, accumulating the output
3383 * characters in a new message.
3386 ldterm_output_msg(queue_t
*q
, mblk_t
*imp
, mblk_t
**omp
,
3387 ldtermstd_state_t
*tp
, size_t bsize
, int echoing
)
3389 mblk_t
*ibp
; /* block we're examining from input message */
3390 mblk_t
*obp
; /* block we're filling in output message */
3391 mblk_t
*cbp
; /* continuation block */
3392 mblk_t
*oobp
; /* old value of obp; valid if NEW_BLOCK fails */
3393 mblk_t
**contpp
; /* where to stuff ptr to newly-allocated blk */
3398 mblk_t
*bp
; /* block to stuff an M_DELAY message in */
3402 * Allocate a new block into which to put bytes. If we can't,
3403 * we just drop the rest of the message on the floor. If x is
3404 * non-zero, just fall thru; failure requires cleanup before
3408 #define NEW_BLOCK(x) \
3411 if ((obp = allocb(bsize, BPRI_MED)) == NULL) { \
3416 contpp = &obp->b_cont; \
3417 bytes_left = obp->b_datap->db_lim - obp->b_wptr; \
3424 * When we allocate the first block of a message, we should
3425 * stuff the pointer to it in "*omp". All subsequent blocks
3426 * should have the pointer to them stuffed into the "b_cont"
3427 * field of the previous block. "contpp" points to the place
3428 * where we should stuff the pointer.
3430 * If we already have a message we're filling in, continue doing
3433 if ((obp
= *omp
) != NULL
) {
3434 while (obp
->b_cont
!= NULL
)
3436 contpp
= &obp
->b_cont
;
3437 bytes_left
= obp
->b_datap
->db_lim
- obp
->b_wptr
;
3444 while (ibp
->b_rptr
< ibp
->b_wptr
) {
3446 * Make sure there's room for one more
3447 * character. At most, we'll need "t_maxeuc"
3450 if ((bytes_left
< (int)tp
->t_maxeuc
)) {
3455 * If doing XCASE processing (not very
3456 * likely, in this day and age), look at each
3457 * character individually.
3459 if ((tp
->t_modes
.c_lflag
& XCASE
) &&
3460 (tp
->t_modes
.c_lflag
& ICANON
)) {
3464 * We need to make sure that this is not
3465 * a following byte of a multibyte character
3466 * before applying an XCASE processing.
3468 * tp->t_eucign will be 0 if and only
3469 * if the current 'c' is an ASCII character
3470 * and also a byte. Otherwise, it will have
3471 * the byte length of a multibyte character.
3473 if ((tp
->t_state
& TS_MEUC
) &&
3474 tp
->t_eucign
== 0 && NOTASCII(c
)) {
3476 tp
->t_csmethods
.ldterm_memwidth(
3478 tp
->t_scratch_len
= tp
->t_eucign
;
3480 if (tp
->t_csdata
.codeset_type
!=
3481 LDTERM_CS_TYPE_UTF8
) {
3487 tp
->t_modes
.c_lflag
&
3493 * If character is mapped on output,
3494 * put out a backslash followed by
3495 * what it is mapped to.
3497 if (tp
->t_eucign
== 0 && omaptab
[c
] != 0 &&
3498 (!echoing
|| c
!= '\\')) {
3499 /* backslash is an ordinary character */
3501 *obp
->b_wptr
++ = '\\';
3503 if (bytes_left
== 0) {
3508 * Allocation failed, make
3509 * state consistent before
3521 * If no other output processing is
3522 * required, push the character into
3523 * the block and get another.
3525 if (!(tp
->t_modes
.c_oflag
& OPOST
)) {
3526 if (tp
->t_eucign
> 0) {
3536 * OPOST output flag is set. Map
3537 * lower case to upper case if OLCUC
3538 * flag is set and the 'c' is a lowercase
3541 if (tp
->t_eucign
== 0 &&
3542 (tp
->t_modes
.c_oflag
& OLCUC
) &&
3543 c
>= 'a' && c
<= 'z')
3547 * Copy all the ORDINARY characters,
3548 * possibly mapping upper case to
3549 * lower case. We use "movtuc",
3550 * STOPPING when we can't move some
3551 * character. For multi-byte or
3552 * multi-column EUC, we can't depend
3553 * on the regular tables. Rather than
3554 * just drop through to the "big
3555 * switch" for all characters, it
3556 * _might_ be faster to let "movtuc"
3557 * move a bunch of characters.
3558 * Chances are, even in multi-byte
3559 * mode we'll have lots of ASCII
3560 * going through. We check the flag
3561 * once, and call movtuc with the
3562 * appropriate table as an argument.
3564 * "movtuc will work for all codeset
3565 * types since it stops at the beginning
3566 * byte of a multibyte character.
3568 size_t bytes_to_move
;
3571 ASSERT(ibp
->b_wptr
>= ibp
->b_rptr
);
3572 bytes_to_move
= ibp
->b_wptr
- ibp
->b_rptr
;
3573 if (bytes_to_move
> bytes_left
)
3574 bytes_to_move
= bytes_left
;
3575 if (tp
->t_state
& TS_MEUC
) {
3576 bytes_moved
= movtuc(bytes_to_move
,
3577 ibp
->b_rptr
, obp
->b_wptr
,
3578 (tp
->t_modes
.c_oflag
& OLCUC
?
3579 elcuctab
: enotrantab
));
3581 bytes_moved
= movtuc(bytes_to_move
,
3582 ibp
->b_rptr
, obp
->b_wptr
,
3583 (tp
->t_modes
.c_oflag
& OLCUC
?
3584 lcuctab
: notrantab
));
3587 * We're save to just do this column
3588 * calculation, because if TS_MEUC is
3589 * set, we used the proper EUC
3590 * tables, and won't have copied any
3593 tp
->t_col
+= bytes_moved
;
3594 ibp
->b_rptr
+= bytes_moved
;
3595 obp
->b_wptr
+= bytes_moved
;
3596 bytes_left
-= bytes_moved
;
3597 if (ibp
->b_rptr
>= ibp
->b_wptr
)
3598 continue; /* moved all of block */
3599 if (bytes_left
== 0) {
3603 c
= *ibp
->b_rptr
++; /* stopper */
3607 * Again, we need to make sure that this is not
3608 * a following byte of a multibyte character at
3611 * 'tp->t_eucign' will be 0 iff the current 'c' is
3612 * an ASCII character. Otherwise, it will have
3613 * the byte length of a multibyte character.
3614 * We also add the display width to 'tp->t_col' if
3615 * the current codeset is not UTF-8 since this is
3616 * a leading byte of a multibyte character.
3617 * For UTF-8 codeset type, we add the display width
3618 * when we get the last byte of a character.
3620 if ((tp
->t_state
& TS_MEUC
) && tp
->t_eucign
== 0 &&
3622 tp
->t_eucign
= tp
->t_csmethods
.ldterm_memwidth(
3624 tp
->t_scratch_len
= tp
->t_eucign
;
3626 if (tp
->t_csdata
.codeset_type
!=
3627 LDTERM_CS_TYPE_UTF8
) {
3629 tp
->t_csmethods
.ldterm_dispwidth(c
,
3631 tp
->t_modes
.c_lflag
& ECHOCTL
);
3636 * If the driver has requested, don't process
3637 * output flags. However, if we're in
3638 * multi-byte mode, we HAVE to look at
3639 * EVERYTHING going out to maintain column
3640 * position properly. Therefore IF the driver
3641 * says don't AND we're not doing multi-byte,
3642 * then don't do it. Otherwise, do it.
3644 * NOTE: Hardware USUALLY doesn't expand tabs
3645 * properly for multi-byte situations anyway;
3646 * that's a known problem with the 3B2
3647 * "PORTS" board firmware, and any other
3648 * hardware that doesn't ACTUALLY know about
3649 * the current EUC mapping that WE are using
3650 * at this very moment. The problem is that
3651 * memory width is INDEPENDENT of screen
3652 * width - no relation - so WE know how wide
3653 * the characters are, but an off-the-host
3654 * board probably doesn't. So, until we're
3655 * SURE that the hardware below us can
3656 * correctly expand tabs in a
3657 * multi-byte/multi-column EUC situation, we
3661 * Map <CR>to<NL> on output if OCRNL flag
3662 * set. ONLCR processing is not done if OCRNL
3665 if (c
== '\r' && (tp
->t_modes
.c_oflag
& OCRNL
)) {
3671 if (tp
->t_csdata
.codeset_type
== LDTERM_CS_TYPE_EUC
) {
3675 * In other codeset types, we safely assume
3676 * any byte of a multibyte character will have
3677 * 'ORDINARY' type. For ASCII characters, we
3678 * still use the typetab[].
3680 if (tp
->t_eucign
== 0)
3687 * Map <NL> to <CR><NL> on output if ONLCR
3690 if (c
== '\n' && (tp
->t_modes
.c_oflag
& ONLCR
)) {
3691 if (!(tp
->t_state
& TS_TTCR
)) {
3692 tp
->t_state
|= TS_TTCR
;
3694 ctype
= typetab
['\r'];
3697 tp
->t_state
&= ~TS_TTCR
;
3700 * Delay values and column position
3701 * calculated here. For EUC chars in
3702 * multi-byte mode, we use "t_eucign" to help
3703 * calculate columns. When we see the first
3704 * byte of an EUC, we set t_eucign to the
3705 * number of bytes that will FOLLOW it, and
3706 * we add the screen width of the WHOLE EUC
3707 * character to the column position. In
3708 * particular, we can't count SS2 or SS3 as
3709 * printing characters. Remember, folks, the
3710 * screen width and memory width are
3711 * independent - no relation. We could have
3712 * dropped through for ASCII, but we want to
3713 * catch any bad characters (i.e., t_eucign
3714 * set and an ASCII char received) and
3715 * possibly report the garbage situation.
3725 if (tp
->t_state
& TS_MEUC
) {
3730 tp
->t_scratch
[tp
->t_scratch_len
3731 - tp
->t_eucign
] = c
;
3735 if (tp
->t_csdata
.codeset_type
3736 == LDTERM_CS_TYPE_UTF8
&&
3737 tp
->t_eucign
<= 0) {
3744 if (tp
->t_modes
.c_oflag
& OLCUC
)
3754 } else { /* ho hum, ASCII mode... */
3755 if (tp
->t_modes
.c_oflag
& OLCUC
)
3768 * If we're doing ECHOCTL, we've
3769 * already mapped the thing during
3770 * the process of canonising. Don't
3771 * bother here, as it's not one that
3780 * This is probably a backspace
3781 * received, not one that we're
3782 * echoing. Let it go as a
3783 * single-column backspace.
3788 if (tp
->t_modes
.c_oflag
& BSDLY
) {
3789 if (tp
->t_modes
.c_oflag
& OFILL
)
3797 if (tp
->t_modes
.c_oflag
& ONLRET
)
3799 if ((tp
->t_modes
.c_oflag
& NLDLY
) == NL1
)
3807 * Map '\t' to spaces if XTABS flag
3808 * is set. The calculation of
3809 * "t_eucign" has probably insured
3810 * that column will be correct, as we
3811 * bumped t_col by the DISP width,
3812 * not the memory width.
3814 if ((tp
->t_modes
.c_oflag
& TABDLY
) == XTABS
) {
3816 *obp
->b_wptr
++ = ' ';
3819 if ((tp
->t_col
& 07) == 0)
3820 break; /* every 8th */
3824 * expand this tab in
3831 obp
->b_datap
->db_lim
) {
3839 if (tp
->t_modes
.c_oflag
& OFILL
) {
3840 if (tp
->t_modes
.c_oflag
&
3844 switch (tp
->t_modes
.c_oflag
&
3851 count
= 1 + (tp
->t_col
|
3864 if ((tp
->t_modes
.c_oflag
& VTDLY
) &&
3865 !(tp
->t_modes
.c_oflag
& OFILL
))
3873 * Ignore <CR> in column 0 if ONOCR
3876 if (tp
->t_col
== 0 &&
3877 (tp
->t_modes
.c_oflag
& ONOCR
))
3881 switch (tp
->t_modes
.c_oflag
& CRDLY
) {
3884 if (tp
->t_modes
.c_oflag
& OFILL
)
3887 count
= tp
->t_col
% 2;
3891 if (tp
->t_modes
.c_oflag
& OFILL
)
3898 if (tp
->t_modes
.c_oflag
& OFILL
)
3911 if (tp
->t_modes
.c_oflag
& OFILL
) {
3913 if (bytes_left
== 0) {
3917 if (tp
->t_modes
.c_oflag
& OFDEL
)
3918 *obp
->b_wptr
++ = CDEL
;
3920 *obp
->b_wptr
++ = CNUL
;
3922 } while (--count
!= 0);
3924 if ((tp
->t_modes
.c_lflag
& FLUSHO
) &&
3925 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
3933 (void) drv_setparm(SYSOUTC
,
3941 allocb(1, BPRI_MED
)) !=
3943 bp
->b_datap
->db_type
=
3952 * We have to start a new
3953 * message; the delay
3954 * introduces a break between
3964 } while ((ibp
= cbp
) != NULL
); /* next block, if any */
3973 movtuc(size_t size
, unsigned char *from
, unsigned char *origto
,
3974 unsigned char *table
)
3976 unsigned char *to
= origto
;
3979 while (size
!= 0 && (c
= table
[*from
++]) != 0) {
3983 return (to
- origto
);
3987 ldterm_flush_output(uchar_t c
, queue_t
*q
, ldtermstd_state_t
*tp
)
3989 /* Already conditioned with IEXTEN during VDISCARD processing */
3990 if (tp
->t_modes
.c_lflag
& FLUSHO
)
3991 tp
->t_modes
.c_lflag
&= ~FLUSHO
;
3993 flushq(q
, FLUSHDATA
); /* flush our write queue */
3994 /* flush ones below us */
3995 (void) putnextctl1(q
, M_FLUSH
, FLUSHW
);
3996 if ((tp
->t_echomp
= allocb(EBSIZE
, BPRI_HI
)) != NULL
) {
3997 (void) ldterm_echo(c
, q
, 1, tp
);
3998 if (tp
->t_msglen
!= 0)
3999 ldterm_reprint(q
, EBSIZE
, tp
);
4000 if (tp
->t_echomp
!= NULL
) {
4001 putnext(q
, tp
->t_echomp
);
4002 tp
->t_echomp
= NULL
;
4005 tp
->t_modes
.c_lflag
|= FLUSHO
;
4011 * Signal generated by the reader: M_PCSIG and M_FLUSH messages sent.
4014 ldterm_dosig(queue_t
*q
, int sig
, uchar_t c
, int mtype
, int mode
)
4016 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)q
->q_ptr
;
4020 * c == \0 is brk case; need to flush on BRKINT even if
4023 if ((!(tp
->t_modes
.c_lflag
& NOFLSH
)) || (c
== '\0')) {
4025 if (tp
->t_state
& TS_TTSTOP
) {
4027 (void) putnextctl1(q
, mtype
, sig
);
4030 * Flush read or write side.
4031 * Restart the input or output.
4033 if (mode
& FLUSHR
) {
4034 flushq(q
, FLUSHDATA
);
4035 (void) putnextctl1(WR(q
), M_FLUSH
, mode
);
4036 if (tp
->t_state
& (TS_TBLOCK
|TS_IFBLOCK
)) {
4037 (void) putnextctl(WR(q
), M_STARTI
);
4038 tp
->t_state
&= ~(TS_TBLOCK
|TS_IFBLOCK
);
4041 if (mode
& FLUSHW
) {
4042 flushq(WR(q
), FLUSHDATA
);
4044 * XXX This is extremely gross.
4045 * Since we can't be sure our M_FLUSH
4046 * will have run its course by the
4047 * time we do the echo below, we set
4048 * state and toss it in the write put
4049 * routine to prevent flushing our
4050 * own data. Note that downstream
4051 * modules on the write side will be
4052 * flushed by the M_FLUSH sent above.
4054 tp
->t_state
|= TS_FLUSHWAIT
;
4055 (void) putnextctl1(q
, M_FLUSH
, FLUSHW
);
4056 if (tp
->t_state
& TS_TTSTOP
) {
4057 (void) putnextctl(WR(q
), M_START
);
4058 tp
->t_state
&= ~(TS_TTSTOP
|TS_OFBLOCK
);
4063 tp
->t_state
&= ~TS_QUOT
;
4065 (void) putnextctl1(q
, mtype
, sig
);
4068 if ((tp
->t_echomp
= allocb(4, BPRI_HI
)) != NULL
) {
4069 (void) ldterm_echo(c
, WR(q
), 4, tp
);
4070 putnext(WR(q
), tp
->t_echomp
);
4071 tp
->t_echomp
= NULL
;
4078 * Called when an M_IOCTL message is seen on the write queue; does
4079 * whatever we're supposed to do with it, and either replies
4080 * immediately or passes it to the next module down.
4083 ldterm_do_ioctl(queue_t
*q
, mblk_t
*mp
)
4085 ldtermstd_state_t
*tp
;
4086 struct iocblk
*iocp
;
4087 struct eucioc
*euciocp
; /* needed for EUC ioctls */
4088 ldterm_cs_data_user_t
*csdp
;
4092 uchar_t maxscreenlen
;
4095 iocp
= (struct iocblk
*)mp
->b_rptr
;
4096 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
4098 switch (iocp
->ioc_cmd
) {
4105 * Set current parameters and special
4109 struct termios oldmodes
;
4111 error
= miocpullup(mp
, sizeof (struct termios
));
4113 miocnak(q
, mp
, 0, error
);
4117 cb
= (struct termios
*)mp
->b_cont
->b_rptr
;
4119 oldmodes
= tp
->t_amodes
;
4121 if ((tp
->t_amodes
.c_lflag
& PENDIN
) &&
4122 (tp
->t_modes
.c_lflag
& IEXTEN
)) {
4124 * Yuk. The C shell file completion
4125 * code actually uses this "feature",
4126 * so we have to support it.
4128 if (tp
->t_message
!= NULL
) {
4129 tp
->t_state
|= TS_RESCAN
;
4132 tp
->t_amodes
.c_lflag
&= ~PENDIN
;
4134 bcopy(tp
->t_amodes
.c_cc
, tp
->t_modes
.c_cc
, NCCS
);
4137 * ldterm_adjust_modes does not deal with
4140 tp
->t_modes
.c_cflag
= tp
->t_amodes
.c_cflag
;
4142 ldterm_adjust_modes(tp
);
4143 if (chgstropts(&oldmodes
, tp
, RD(q
)) == (-1)) {
4144 miocnak(q
, mp
, 0, EAGAIN
);
4148 * The driver may want to know about the
4149 * following iflags: IGNBRK, BRKINT, IGNPAR,
4150 * PARMRK, INPCK, IXON, IXANY.
4160 * Old-style "ioctl" to set current
4161 * parameters and special characters. Don't
4162 * clear out the unset portions, leave them
4166 struct termios oldmodes
;
4168 error
= miocpullup(mp
, sizeof (struct termio
));
4170 miocnak(q
, mp
, 0, error
);
4174 cb
= (struct termio
*)mp
->b_cont
->b_rptr
;
4176 oldmodes
= tp
->t_amodes
;
4177 tp
->t_amodes
.c_iflag
=
4178 (tp
->t_amodes
.c_iflag
& 0xffff0000 | cb
->c_iflag
);
4179 tp
->t_amodes
.c_oflag
=
4180 (tp
->t_amodes
.c_oflag
& 0xffff0000 | cb
->c_oflag
);
4181 tp
->t_amodes
.c_cflag
=
4182 (tp
->t_amodes
.c_cflag
& 0xffff0000 | cb
->c_cflag
);
4183 tp
->t_amodes
.c_lflag
=
4184 (tp
->t_amodes
.c_lflag
& 0xffff0000 | cb
->c_lflag
);
4186 bcopy(cb
->c_cc
, tp
->t_modes
.c_cc
, NCC
);
4187 /* TCGETS returns amodes, so update that too */
4188 bcopy(cb
->c_cc
, tp
->t_amodes
.c_cc
, NCC
);
4190 /* ldterm_adjust_modes does not deal with cflags */
4192 tp
->t_modes
.c_cflag
= tp
->t_amodes
.c_cflag
;
4194 ldterm_adjust_modes(tp
);
4195 if (chgstropts(&oldmodes
, tp
, RD(q
)) == (-1)) {
4196 miocnak(q
, mp
, 0, EAGAIN
);
4200 * The driver may want to know about the
4201 * following iflags: IGNBRK, BRKINT, IGNPAR,
4202 * PARMRK, INPCK, IXON, IXANY.
4209 * Do the flush on the write queue immediately, and
4210 * queue up any flush on the read queue for the
4211 * service procedure to see. Then turn it into the
4212 * appropriate M_FLUSH message, so that the module
4213 * below us doesn't have to know about TCFLSH.
4215 error
= miocpullup(mp
, sizeof (int));
4217 miocnak(q
, mp
, 0, error
);
4221 ASSERT(mp
->b_datap
!= NULL
);
4222 if (*(int *)mp
->b_cont
->b_rptr
== 0) {
4223 ASSERT(mp
->b_datap
!= NULL
);
4224 (void) putnextctl1(q
, M_FLUSH
, FLUSHR
);
4225 (void) putctl1(RD(q
), M_FLUSH
, FLUSHR
);
4226 } else if (*(int *)mp
->b_cont
->b_rptr
== 1) {
4227 flushq(q
, FLUSHDATA
);
4228 ASSERT(mp
->b_datap
!= NULL
);
4229 tp
->t_state
|= TS_FLUSHWAIT
;
4230 (void) putnextctl1(RD(q
), M_FLUSH
, FLUSHW
);
4231 (void) putnextctl1(q
, M_FLUSH
, FLUSHW
);
4232 } else if (*(int *)mp
->b_cont
->b_rptr
== 2) {
4233 flushq(q
, FLUSHDATA
);
4234 ASSERT(mp
->b_datap
!= NULL
);
4235 (void) putnextctl1(q
, M_FLUSH
, FLUSHRW
);
4236 tp
->t_state
|= TS_FLUSHWAIT
;
4237 (void) putnextctl1(RD(q
), M_FLUSH
, FLUSHRW
);
4239 miocnak(q
, mp
, 0, EINVAL
);
4242 ASSERT(mp
->b_datap
!= NULL
);
4244 miocack(q
, mp
, 0, 0);
4248 error
= miocpullup(mp
, sizeof (int));
4250 miocnak(q
, mp
, 0, error
);
4254 switch (*(int *)mp
->b_cont
->b_rptr
) {
4256 if (!(tp
->t_state
& TS_TTSTOP
)) {
4257 (void) putnextctl(q
, M_STOP
);
4258 tp
->t_state
|= (TS_TTSTOP
|TS_OFBLOCK
);
4263 if (tp
->t_state
& TS_TTSTOP
) {
4264 (void) putnextctl(q
, M_START
);
4265 tp
->t_state
&= ~(TS_TTSTOP
|TS_OFBLOCK
);
4270 (void) putnextctl(q
, M_STOPI
);
4271 tp
->t_state
|= (TS_TBLOCK
|TS_IFBLOCK
);
4275 (void) putnextctl(q
, M_STARTI
);
4276 tp
->t_state
&= ~(TS_TBLOCK
|TS_IFBLOCK
);
4280 miocnak(q
, mp
, 0, EINVAL
);
4283 ASSERT(mp
->b_datap
!= NULL
);
4285 miocack(q
, mp
, 0, 0);
4288 * TCSBRK is expected to be handled by the driver.
4289 * The reason its left for the driver is that when
4290 * the argument to TCSBRK is zero driver has to drain
4291 * the data and sending a M_IOCACK from LDTERM before
4292 * the driver drains the data is going to cause
4297 * The following are EUC related ioctls. For
4298 * EUC_WSET, we have to pass the information on, even
4299 * though we ACK the call. It's vital in the EUC
4300 * environment that everybody downstream knows about
4301 * the EUC codeset widths currently in use; we
4302 * therefore pass down the information in an M_CTL
4303 * message. It will bottom out in the driver.
4308 /* only needed for EUC_WSET */
4309 struct iocblk
*riocp
;
4311 mblk_t
*dmp
, *dmp_cont
;
4314 * If the user didn't supply any information,
4317 error
= miocpullup(mp
, sizeof (struct eucioc
));
4319 miocnak(q
, mp
, 0, error
);
4323 euciocp
= (struct eucioc
*)mp
->b_cont
->b_rptr
;
4325 * Check here for something reasonable. If
4326 * anything will take more than EUC_MAXW
4327 * columns or more than EUC_MAXW bytes
4328 * following SS2 or SS3, then just reject it
4329 * out of hand. It's not impossible for us to
4330 * do it, it just isn't reasonable. So far,
4331 * in the world, we've seen the absolute max
4332 * columns to be 2 and the max number of
4333 * bytes to be 3. This allows room for some
4334 * expansion of that, but it probably won't
4335 * even be necessary. At the moment, we
4336 * return a "range" error. If you really
4337 * need to, you can push EUC_MAXW up to over
4338 * 200; it doesn't make sense, though, with
4339 * only a CANBSIZ sized input limit (usually
4342 for (i
= 0; i
< 4; i
++) {
4343 if ((euciocp
->eucw
[i
] > EUC_MAXW
) ||
4344 (euciocp
->scrw
[i
] > EUC_MAXW
)) {
4345 miocnak(q
, mp
, 0, ERANGE
);
4350 * Otherwise, save the information in tp,
4351 * force codeset 0 (ASCII) to be one byte,
4354 cp_eucwioc(euciocp
, &tp
->eucwioc
, EUCIN
);
4355 tp
->eucwioc
.eucw
[0] = tp
->eucwioc
.scrw
[0] = 1;
4357 * Now, check out whether we're doing
4358 * multibyte processing. if we are, we need
4359 * to allocate a block to hold the parallel
4360 * array. By convention, we've been passed
4361 * what amounts to a CSWIDTH definition. We
4362 * actually NEED the number of bytes for
4365 tp
->t_maxeuc
= 0; /* reset to say we're NOT */
4367 tp
->t_state
&= ~TS_MEUC
;
4369 * We'll set TS_MEUC if we're doing
4370 * multi-column OR multi- byte OR both. It
4371 * makes things easier... NOTE: If we fail
4372 * to get the buffer we need to hold display
4373 * widths, then DON'T let the TS_MEUC bit get
4376 for (i
= 0; i
< 4; i
++) {
4377 if (tp
->eucwioc
.eucw
[i
] > tp
->t_maxeuc
)
4378 tp
->t_maxeuc
= tp
->eucwioc
.eucw
[i
];
4379 if (tp
->eucwioc
.scrw
[i
] > 1)
4380 tp
->t_state
|= TS_MEUC
;
4382 if ((tp
->t_maxeuc
> 1) || (tp
->t_state
& TS_MEUC
)) {
4383 if (!tp
->t_eucp_mp
) {
4384 if ((tp
->t_eucp_mp
= allocb(_TTY_BUFSIZ
,
4385 BPRI_HI
)) == NULL
) {
4387 tp
->t_state
&= ~TS_MEUC
;
4389 "Can't allocate eucp_mp");
4390 miocnak(q
, mp
, 0, ENOSR
);
4394 * here, if there's junk in
4395 * the canonical buffer, then
4396 * move the eucp pointer past
4397 * it, so we don't run off
4398 * the beginning. This is a
4399 * total botch, but will
4400 * hopefully keep stuff from
4401 * getting too messed up
4402 * until the user flushes
4407 tp
->t_eucp_mp
->b_rptr
;
4408 for (i
= tp
->t_msglen
; i
; i
--)
4412 tp
->t_eucp_mp
->b_rptr
;
4415 /* doing multi-byte handling */
4416 tp
->t_state
|= TS_MEUC
;
4418 } else if (tp
->t_eucp_mp
) {
4419 freemsg(tp
->t_eucp_mp
);
4420 tp
->t_eucp_mp
= NULL
;
4425 * Save the EUC width data we have at
4426 * the t_csdata, set t_csdata.codeset_type to
4427 * EUC one, and, switch the codeset methods at
4430 bzero(&tp
->t_csdata
.eucpc_data
,
4431 (sizeof (ldterm_eucpc_data_t
) *
4432 LDTERM_CS_MAX_CODESETS
));
4433 tp
->t_csdata
.eucpc_data
[0].byte_length
=
4434 tp
->eucwioc
.eucw
[1];
4435 tp
->t_csdata
.eucpc_data
[0].screen_width
=
4436 tp
->eucwioc
.scrw
[1];
4437 tp
->t_csdata
.eucpc_data
[1].byte_length
=
4438 tp
->eucwioc
.eucw
[2];
4439 tp
->t_csdata
.eucpc_data
[1].screen_width
=
4440 tp
->eucwioc
.scrw
[2];
4441 tp
->t_csdata
.eucpc_data
[2].byte_length
=
4442 tp
->eucwioc
.eucw
[3];
4443 tp
->t_csdata
.eucpc_data
[2].screen_width
=
4444 tp
->eucwioc
.scrw
[3];
4445 tp
->t_csdata
.version
= LDTERM_DATA_VERSION
;
4446 tp
->t_csdata
.codeset_type
= LDTERM_CS_TYPE_EUC
;
4448 * We are not using the 'csinfo_num' anyway if the
4449 * current codeset type is EUC. So, set it to
4450 * the maximum possible.
4452 tp
->t_csdata
.csinfo_num
=
4453 LDTERM_CS_TYPE_EUC_MAX_SUBCS
;
4454 if (tp
->t_csdata
.locale_name
!= NULL
) {
4455 kmem_free(tp
->t_csdata
.locale_name
,
4456 strlen(tp
->t_csdata
.locale_name
) + 1);
4457 tp
->t_csdata
.locale_name
= NULL
;
4459 tp
->t_csmethods
= cs_methods
[LDTERM_CS_TYPE_EUC
];
4462 * If we are able to allocate two blocks (the
4463 * iocblk and the associated data), then pass
4464 * it downstream, otherwise we'll need to NAK
4465 * it, and drop whatever we WERE able to
4468 if ((dmp
= mkiocb(EUC_WSET
)) == NULL
) {
4469 miocnak(q
, mp
, 0, ENOSR
);
4472 if ((dmp_cont
= allocb(EUCSIZE
, BPRI_HI
)) == NULL
) {
4474 miocnak(q
, mp
, 0, ENOSR
);
4479 * We got both buffers. Copy out the EUC
4480 * information (as we received it, not what
4481 * we're using!) & pass it on.
4483 bcopy(mp
->b_cont
->b_rptr
, dmp_cont
->b_rptr
, EUCSIZE
);
4484 dmp_cont
->b_wptr
+= EUCSIZE
;
4485 dmp
->b_cont
= dmp_cont
;
4486 dmp
->b_datap
->db_type
= M_CTL
;
4487 dmp_cont
->b_datap
->db_type
= M_DATA
;
4488 riocp
= (struct iocblk
*)dmp
->b_rptr
;
4489 riocp
->ioc_count
= EUCSIZE
;
4493 * Now ACK the ioctl.
4496 miocack(q
, mp
, 0, 0);
4501 error
= miocpullup(mp
, sizeof (struct eucioc
));
4503 miocnak(q
, mp
, 0, error
);
4506 euciocp
= (struct eucioc
*)mp
->b_cont
->b_rptr
;
4507 cp_eucwioc(&tp
->eucwioc
, euciocp
, EUCOUT
);
4509 miocack(q
, mp
, EUCSIZE
, 0);
4513 error
= miocpullup(mp
, sizeof (ldterm_cs_data_user_t
));
4515 miocnak(q
, mp
, 0, error
);
4519 csdp
= (ldterm_cs_data_user_t
*)mp
->b_cont
->b_rptr
;
4521 /* Validate the codeset data provided. */
4522 if (csdp
->version
> LDTERM_DATA_VERSION
||
4523 csdp
->codeset_type
< LDTERM_CS_TYPE_MIN
||
4524 csdp
->codeset_type
> LDTERM_CS_TYPE_MAX
) {
4525 miocnak(q
, mp
, 0, ERANGE
);
4529 if ((csdp
->codeset_type
== LDTERM_CS_TYPE_EUC
&&
4530 csdp
->csinfo_num
> LDTERM_CS_TYPE_EUC_MAX_SUBCS
) ||
4531 (csdp
->codeset_type
== LDTERM_CS_TYPE_PCCS
&&
4532 (csdp
->csinfo_num
< LDTERM_CS_TYPE_PCCS_MIN_SUBCS
||
4533 csdp
->csinfo_num
> LDTERM_CS_TYPE_PCCS_MAX_SUBCS
))) {
4534 miocnak(q
, mp
, 0, ERANGE
);
4538 maxbytelen
= maxscreenlen
= 0;
4539 if (csdp
->codeset_type
== LDTERM_CS_TYPE_EUC
) {
4540 for (i
= 0; i
< LDTERM_CS_TYPE_EUC_MAX_SUBCS
; i
++) {
4541 if (csdp
->eucpc_data
[i
].byte_length
>
4543 csdp
->eucpc_data
[i
].screen_width
>
4545 miocnak(q
, mp
, 0, ERANGE
);
4549 if (csdp
->eucpc_data
[i
].byte_length
>
4552 csdp
->eucpc_data
[i
].byte_length
;
4553 if (csdp
->eucpc_data
[i
].screen_width
>
4556 csdp
->eucpc_data
[i
].screen_width
;
4558 /* POSIX/C locale? */
4559 if (maxbytelen
== 0 && maxscreenlen
== 0)
4560 maxbytelen
= maxscreenlen
= 1;
4561 } else if (csdp
->codeset_type
== LDTERM_CS_TYPE_PCCS
) {
4562 for (i
= 0; i
< LDTERM_CS_MAX_CODESETS
; i
++) {
4563 if (csdp
->eucpc_data
[i
].byte_length
>
4564 LDTERM_CS_MAX_BYTE_LENGTH
) {
4565 miocnak(q
, mp
, 0, ERANGE
);
4568 if (csdp
->eucpc_data
[i
].byte_length
>
4571 csdp
->eucpc_data
[i
].byte_length
;
4572 if (csdp
->eucpc_data
[i
].screen_width
>
4575 csdp
->eucpc_data
[i
].screen_width
;
4577 } else if (csdp
->codeset_type
== LDTERM_CS_TYPE_UTF8
) {
4583 if (csdp
->locale_name
) {
4584 for (i
= 0; i
< MAXNAMELEN
; i
++)
4585 if (csdp
->locale_name
[i
] == '\0')
4588 * We cannot have any string that is not NULL byte
4591 if (i
>= MAXNAMELEN
) {
4592 miocnak(q
, mp
, 0, ERANGE
);
4596 locale_name_sz
= i
+ 1;
4600 * As the final check, if there was invalid codeset_type
4601 * given, or invalid byte_length was specified, it's an error.
4603 if (maxbytelen
<= 0 || maxscreenlen
<= 0) {
4604 miocnak(q
, mp
, 0, ERANGE
);
4608 /* Do the switching. */
4609 tp
->t_maxeuc
= maxbytelen
;
4610 tp
->t_state
&= ~TS_MEUC
;
4611 if (maxbytelen
> 1 || maxscreenlen
> 1) {
4612 if (!tp
->t_eucp_mp
) {
4613 if (!(tp
->t_eucp_mp
= allocb(_TTY_BUFSIZ
,
4616 "Can't allocate eucp_mp");
4617 miocnak(q
, mp
, 0, ENOSR
);
4621 * If there's junk in the canonical buffer,
4622 * then move the eucp pointer past it,
4623 * so we don't run off the beginning. This is
4624 * a total botch, but will hopefully keep
4625 * stuff from getting too messed up until
4626 * the user flushes this line!
4629 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
4630 for (i
= tp
->t_msglen
; i
; i
--)
4633 tp
->t_eucp
= tp
->t_eucp_mp
->b_rptr
;
4638 * We only set TS_MEUC for a multibyte/multi-column
4641 tp
->t_state
|= TS_MEUC
;
4643 tp
->t_csdata
.version
= csdp
->version
;
4644 tp
->t_csdata
.codeset_type
= csdp
->codeset_type
;
4645 tp
->t_csdata
.csinfo_num
= csdp
->csinfo_num
;
4646 bcopy(csdp
->eucpc_data
, tp
->t_csdata
.eucpc_data
,
4647 sizeof (ldterm_eucpc_data_t
) *
4648 LDTERM_CS_MAX_CODESETS
);
4649 tp
->t_csmethods
= cs_methods
[csdp
->codeset_type
];
4651 if (csdp
->codeset_type
== LDTERM_CS_TYPE_EUC
) {
4652 tp
->eucwioc
.eucw
[0] = 1;
4653 tp
->eucwioc
.scrw
[0] = 1;
4655 tp
->eucwioc
.eucw
[1] =
4656 csdp
->eucpc_data
[0].byte_length
;
4657 tp
->eucwioc
.scrw
[1] =
4658 csdp
->eucpc_data
[0].screen_width
;
4660 tp
->eucwioc
.eucw
[2] =
4661 csdp
->eucpc_data
[1].byte_length
+ 1;
4662 tp
->eucwioc
.scrw
[2] =
4663 csdp
->eucpc_data
[1].screen_width
;
4665 tp
->eucwioc
.eucw
[3] =
4666 csdp
->eucpc_data
[2].byte_length
+ 1;
4667 tp
->eucwioc
.scrw
[3] =
4668 csdp
->eucpc_data
[2].screen_width
;
4671 * We are not going to use this data
4672 * structure. So, clear it. Also, stty(1) will
4673 * make use of the cleared tp->eucwioc when
4674 * it prints out codeset width setting.
4676 bzero(&tp
->eucwioc
, EUCSIZE
);
4680 * If this codeset is a single byte codeset that
4681 * requires only single display column for all
4682 * characters, we switch to default EUC codeset
4683 * methods and data setting.
4686 if (tp
->t_eucp_mp
) {
4687 freemsg(tp
->t_eucp_mp
);
4688 tp
->t_eucp_mp
= NULL
;
4692 bzero(&tp
->eucwioc
, EUCSIZE
);
4693 tp
->eucwioc
.eucw
[0] = 1;
4694 tp
->eucwioc
.scrw
[0] = 1;
4695 if (tp
->t_csdata
.locale_name
!= NULL
) {
4696 kmem_free(tp
->t_csdata
.locale_name
,
4697 strlen(tp
->t_csdata
.locale_name
) + 1);
4699 tp
->t_csdata
= default_cs_data
;
4700 tp
->t_csmethods
= cs_methods
[LDTERM_CS_TYPE_EUC
];
4703 /* Copy over locale_name. */
4704 if (tp
->t_csdata
.locale_name
!= NULL
) {
4705 kmem_free(tp
->t_csdata
.locale_name
,
4706 strlen(tp
->t_csdata
.locale_name
) + 1);
4708 if (locale_name_sz
> 1) {
4709 tp
->t_csdata
.locale_name
= kmem_alloc(
4710 locale_name_sz
, KM_SLEEP
);
4711 (void) strcpy(tp
->t_csdata
.locale_name
,
4714 tp
->t_csdata
.locale_name
= NULL
;
4718 * Now ACK the ioctl.
4721 miocack(q
, mp
, 0, 0);
4725 error
= miocpullup(mp
, sizeof (ldterm_cs_data_user_t
));
4727 miocnak(q
, mp
, 0, error
);
4731 csdp
= (ldterm_cs_data_user_t
*)mp
->b_cont
->b_rptr
;
4733 csdp
->version
= tp
->t_csdata
.version
;
4734 csdp
->codeset_type
= tp
->t_csdata
.codeset_type
;
4735 csdp
->csinfo_num
= tp
->t_csdata
.csinfo_num
;
4736 csdp
->pad
= tp
->t_csdata
.pad
;
4737 if (tp
->t_csdata
.locale_name
) {
4738 (void) strcpy(csdp
->locale_name
,
4739 tp
->t_csdata
.locale_name
);
4741 csdp
->locale_name
[0] = '\0';
4743 bcopy(tp
->t_csdata
.eucpc_data
, csdp
->eucpc_data
,
4744 sizeof (ldterm_eucpc_data_t
) * LDTERM_CS_MAX_CODESETS
);
4746 * If the codeset is an EUC codeset and if it has 2nd and/or
4747 * 3rd supplementary codesets, we subtract one from each
4748 * byte length of the supplementary codesets. This is
4749 * because single shift characters, SS2 and SS3, are not
4750 * included in the byte lengths in the user space.
4752 if (csdp
->codeset_type
== LDTERM_CS_TYPE_EUC
) {
4753 if (csdp
->eucpc_data
[1].byte_length
)
4754 csdp
->eucpc_data
[1].byte_length
-= 1;
4755 if (csdp
->eucpc_data
[2].byte_length
)
4756 csdp
->eucpc_data
[2].byte_length
-= 1;
4759 miocack(q
, mp
, sizeof (ldterm_cs_data_user_t
), 0);
4763 tp
->t_state
|= TS_ISPTSTTY
;
4773 * Send an M_SETOPTS message upstream if any mode changes are being
4774 * made that affect the stream head options. returns -1 if allocb
4775 * fails, else returns 0.
4778 chgstropts(struct termios
*oldmodep
, ldtermstd_state_t
*tp
, queue_t
*q
)
4780 struct stroptions optbuf
;
4783 optbuf
.so_flags
= 0;
4784 if ((oldmodep
->c_lflag
^ tp
->t_modes
.c_lflag
) & ICANON
) {
4786 * Canonical mode is changing state; switch the
4787 * stream head to message-nondiscard or byte-stream
4788 * mode. Also, rerun the service procedure so it can
4789 * change its mind about whether to send data
4792 if (tp
->t_modes
.c_lflag
& ICANON
) {
4793 DEBUG4(("CHANGING TO CANON MODE\n"));
4794 optbuf
.so_flags
= SO_READOPT
|SO_MREADOFF
;
4795 optbuf
.so_readopt
= RMSGN
;
4798 * if there is a pending raw mode timeout,
4803 * Clear VMIN/VTIME state, cancel timers
4805 vmin_satisfied(q
, tp
, 0);
4807 DEBUG4(("CHANGING TO RAW MODE\n"));
4808 optbuf
.so_flags
= SO_READOPT
|SO_MREADON
;
4809 optbuf
.so_readopt
= RNORM
;
4812 if ((oldmodep
->c_lflag
^ tp
->t_modes
.c_lflag
) & TOSTOP
) {
4814 * The "stop on background write" bit is changing.
4816 if (tp
->t_modes
.c_lflag
& TOSTOP
)
4817 optbuf
.so_flags
|= SO_TOSTOP
;
4819 optbuf
.so_flags
|= SO_TONSTOP
;
4821 if (optbuf
.so_flags
!= 0) {
4822 if ((bp
= allocb(sizeof (struct stroptions
), BPRI_HI
)) ==
4826 *(struct stroptions
*)bp
->b_wptr
= optbuf
;
4827 bp
->b_wptr
+= sizeof (struct stroptions
);
4828 bp
->b_datap
->db_type
= M_SETOPTS
;
4829 DEBUG4(("M_SETOPTS to stream head\n"));
4837 * Called when an M_IOCACK message is seen on the read queue;
4838 * modifies the data being returned, if necessary, and passes the
4842 ldterm_ioctl_reply(queue_t
*q
, mblk_t
*mp
)
4844 ldtermstd_state_t
*tp
;
4845 struct iocblk
*iocp
;
4847 iocp
= (struct iocblk
*)mp
->b_rptr
;
4848 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
4850 switch (iocp
->ioc_cmd
) {
4855 * Get current parameters and return them to
4856 * stream head eventually.
4858 struct termios
*cb
=
4859 (struct termios
*)mp
->b_cont
->b_rptr
;
4862 * cflag has cflags sent upstream by the
4865 tcflag_t cflag
= cb
->c_cflag
;
4869 cb
->c_cflag
= cflag
; /* set by driver */
4876 * Old-style "ioctl" to get current
4877 * parameters and return them to stream head
4881 (struct termio
*)mp
->b_cont
->b_rptr
;
4883 cb
->c_iflag
= tp
->t_amodes
.c_iflag
; /* all except the */
4884 cb
->c_oflag
= tp
->t_amodes
.c_oflag
; /* cb->c_cflag */
4885 cb
->c_lflag
= tp
->t_amodes
.c_lflag
;
4887 if (cb
->c_cflag
== 0) /* not set by driver */
4888 cb
->c_cflag
= tp
->t_amodes
.c_cflag
;
4891 bcopy(tp
->t_amodes
.c_cc
, cb
->c_cc
, NCC
);
4900 * A VMIN/VTIME request has been satisfied. Cancel outstanding timers
4901 * if they exist, clear TS_MREAD state, and send upstream. If a NULL
4902 * queue ptr is passed, just reset VMIN/VTIME state.
4905 vmin_satisfied(queue_t
*q
, ldtermstd_state_t
*tp
, int sendup
)
4908 if (tp
->t_vtid
!= 0) {
4909 DEBUG4(("vmin_satisfied: cancelled timer id %d\n", tp
->t_vtid
));
4910 (void) quntimeout(q
, tp
->t_vtid
);
4914 if (tp
->t_msglen
== 0 && V_MIN
) {
4916 DEBUG4(("vmin_satisfied: data swiped, msglen = 0\n"));
4918 if ((!q
->q_first
) ||
4919 (q
->q_first
->b_datap
->db_type
!= M_DATA
) ||
4920 (tp
->t_msglen
>= LDCHUNK
)) {
4921 ldterm_msg_upstream(q
, tp
);
4922 DEBUG4(("vmin_satisfied: delivering data\n"));
4927 DEBUG4(("vmin_satisfied: VMIN/TIME state reset\n"));
4929 tp
->t_state
&= ~TS_MREAD
;
4933 vmin_settimer(queue_t
*q
)
4935 ldtermstd_state_t
*tp
;
4937 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
4940 * Don't start any time bombs.
4942 if (tp
->t_state
& TS_CLOSE
)
4946 * tp->t_vtid should NOT be set here unless VMIN > 0 and
4950 if (V_MIN
&& V_TIME
) {
4952 DEBUG4(("vmin_settimer: timer restarted, old tid=%d\n",
4956 DEBUG4(("vmin_settimer: tid = %d was still active!\n",
4959 (void) quntimeout(q
, tp
->t_vtid
);
4962 tp
->t_vtid
= qtimeout(q
, vmin_timed_out
, q
,
4963 (clock_t)(V_TIME
* (hz
/ 10)));
4964 DEBUG4(("vmin_settimer: timer started, tid = %d\n", tp
->t_vtid
));
4969 * BRRrrringgg!! VTIME was satisfied instead of VMIN
4972 vmin_timed_out(void *arg
)
4975 ldtermstd_state_t
*tp
;
4977 tp
= (ldtermstd_state_t
*)q
->q_ptr
;
4979 DEBUG4(("vmin_timed_out: tid = %d\n", tp
->t_vtid
));
4980 /* don't call untimeout now that we are in the timeout */
4982 vmin_satisfied(q
, tp
, 1);
4987 * Routine to adjust termios flags to be processed by the line
4988 * discipline. Driver below sends a termios structure, with the flags
4989 * the driver intends to process. XOR'ing the driver sent termios
4990 * structure with current termios structure with the default values
4991 * (or set by ioctls from userland), we come up with a new termios
4992 * structrue, the flags of which will be used by the line discipline
4993 * in processing input and output. On return from this routine, we
4994 * will have the following fields set in tp structure -->
4995 * tp->t_modes: modes the line discipline will process tp->t_amodes:
4996 * modes the user process thinks the line discipline is processing
5000 ldterm_adjust_modes(ldtermstd_state_t
*tp
)
5003 DEBUG6(("original iflag = %o\n", tp
->t_modes
.c_iflag
));
5004 tp
->t_modes
.c_iflag
= tp
->t_amodes
.c_iflag
& ~(tp
->t_dmodes
.c_iflag
);
5005 tp
->t_modes
.c_oflag
= tp
->t_amodes
.c_oflag
& ~(tp
->t_dmodes
.c_oflag
);
5006 tp
->t_modes
.c_lflag
= tp
->t_amodes
.c_lflag
& ~(tp
->t_dmodes
.c_lflag
);
5007 DEBUG6(("driver iflag = %o\n", tp
->t_dmodes
.c_iflag
));
5008 DEBUG6(("apparent iflag = %o\n", tp
->t_amodes
.c_iflag
));
5009 DEBUG6(("effective iflag = %o\n", tp
->t_modes
.c_iflag
));
5011 /* No negotiation of clfags c_cc array special characters */
5013 * Copy from amodes to modes already done by TCSETA/TCSETS
5020 * Erase one multi-byte character. If TS_MEUC is set AND this
5021 * is a multi-byte character, then this should be called instead of
5022 * ldterm_erase. "ldterm_erase" will handle ASCII nicely, thank you.
5024 * We'd better be pointing to the last byte. If we aren't, it will get
5028 ldterm_csi_erase(queue_t
*q
, size_t ebsize
, ldtermstd_state_t
*tp
)
5031 uchar_t
*p
, *bottom
;
5032 uchar_t u8
[LDTERM_CS_MAX_BYTE_LENGTH
];
5037 if (tp
->t_eucleft
) {
5038 /* XXX Ick. We're in the middle of an EUC! */
5039 /* What to do now? */
5041 return; /* ignore it??? */
5043 bottom
= tp
->t_eucp_mp
->b_rptr
;
5044 p
= tp
->t_eucp
- 1; /* previous byte */
5047 ung
= 1; /* number of bytes to un-get from buffer */
5049 * go through the buffer until we find the beginning of the
5052 while ((*p
== 0) && (p
> bottom
)) {
5058 * Now, "ung" is the number of bytes to unget from the buffer
5059 * and "*p" is the disp width of it. Fool "ldterm_rubout"
5060 * into thinking we're rubbing out ASCII characters. Do that
5061 * for the display width of the character.
5063 * Also we accumulate bytes of the character so that if the character
5064 * is a UTF-8 character, we will get the display width of the UTF-8
5067 if (ung
>= LDTERM_CS_MAX_BYTE_LENGTH
) {
5068 j
= len
= LDTERM_CS_MAX_BYTE_LENGTH
;
5072 for (i
= 0; i
< ung
; i
++) { /* remove from buf */
5073 if ((c
= ldterm_unget(tp
)) != (-1)) {
5076 u8
[--j
] = (uchar_t
)c
;
5079 if (*p
== UNKNOWN_WIDTH
) {
5080 if (tp
->t_csdata
.codeset_type
== LDTERM_CS_TYPE_UTF8
) {
5081 *p
= ldterm_utf8_width(u8
, len
);
5086 for (i
= 0; i
< (int)*p
; i
++) /* remove from screen */
5087 ldterm_rubout(' ', q
, ebsize
, tp
);
5089 * Adjust the parallel array pointer. Zero out the contents
5090 * of parallel array for this position, just to make sure...
5098 * This is kind of a safety valve. Whenever we see a bad sequence
5099 * come up, we call eucwarn. It just tallies the junk until a
5100 * threshold is reached. Then it prints ONE message on the console
5101 * and not any more. Hopefully, we can catch garbage; maybe it will
5102 * be useful to somebody.
5105 ldterm_eucwarn(ldtermstd_state_t
*tp
)
5109 if ((tp
->t_eucwarn
> EUC_WARNCNT
) && !(tp
->t_state
& TS_WARNED
)) {
5111 "ldterm: tty at addr %p in multi-byte mode --",
5114 "Over %d bad EUC characters this session", EUC_WARNCNT
);
5115 tp
->t_state
|= TS_WARNED
;
5122 * Copy an "eucioc_t" structure. We use the structure with
5123 * incremented values for Codesets 2 & 3. The specification in
5124 * eucioctl is that the sames values as the CSWIDTH definition at
5125 * user level are passed to us. When we copy it "in" to ourselves, we
5126 * do the increment. That allows us to avoid treating each character
5127 * set separately for "t_eucleft" purposes. When we copy it "out" to
5128 * return it to the user, we decrement the values so the user gets
5129 * what it expects, and it matches CSWIDTH in the environment (if
5130 * things are consistent!).
5133 cp_eucwioc(eucioc_t
*from
, eucioc_t
*to
, int dir
)
5135 bcopy(from
, to
, EUCSIZE
);
5136 if (dir
== EUCOUT
) { /* copying out to user */
5141 } else { /* copying in */
5151 * Take the first byte of a multi-byte, or an ASCII char. Return its
5152 * codeset. If it's NOT the first byte of an EUC, then the return
5153 * value may be garbage, as it's probably not SS2 or SS3, and
5154 * therefore must be in codeset 1. Another bizarre catch here is the
5155 * fact that we don't do anything about the "C1" control codes. In
5156 * real life, we should; but nobody's come up with a good way of
5161 ldterm_codeset(uchar_t codeset_type
, uchar_t c
)
5167 if (codeset_type
!= LDTERM_CS_TYPE_EUC
)
5180 /* The following two functions are additional EUC codeset specific methods. */
5182 * ldterm_dispwidth - Take the first byte of an EUC (or ASCII) and
5183 * return the display width. Since this is intended mostly for
5184 * multi-byte handling, it returns EUC_TWIDTH for tabs so they can be
5185 * differentiated from EUC characters (assumption: EUC require fewer
5186 * than 255 columns). Also, if it's a backspace and !flag, it
5187 * returns EUC_BSWIDTH. Newline & CR also depend on flag. This
5188 * routine SHOULD be cleaner than this, but we have the situation
5189 * where we may or may not be counting control characters as having a
5190 * column width. Therefore, the computation of ASCII is pretty messy.
5191 * The caller will be storing the value, and then switching on it
5192 * when it's used. We really should define the EUC_TWIDTH and other
5193 * constants in a header so that the routine could be used in other
5194 * modules in the kernel.
5197 __ldterm_dispwidth_euc(uchar_t c
, void *p
, int mode
)
5199 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5205 return (EUC_TWIDTH
);
5207 return (mode
? 2 : EUC_BSWIDTH
);
5209 return (EUC_NLWIDTH
);
5211 return (mode
? 2 : EUC_CRWIDTH
);
5213 return (mode
? 2 : 0);
5220 return (tp
->eucwioc
.scrw
[2]);
5222 return (tp
->eucwioc
.scrw
[3]);
5224 return (tp
->eucwioc
.scrw
[1]);
5229 * ldterm_memwidth_euc - Take the first byte of an EUC (or an ASCII char)
5230 * and return its memory width. The routine could have been
5231 * implemented to use only the codeset number, but that would require
5232 * the caller to have that value available. Perhaps the user doesn't
5233 * want to make the extra call or keep the value of codeset around.
5234 * Therefore, we use the actual character with which they're
5235 * concerned. This should never be called with anything but the
5236 * first byte of an EUC, otherwise it will return a garbage value.
5239 __ldterm_memwidth_euc(uchar_t c
, void *p
)
5241 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5247 return (tp
->eucwioc
.eucw
[2]);
5249 return (tp
->eucwioc
.eucw
[3]);
5251 return (tp
->eucwioc
.eucw
[1]);
5256 /* The following two functions are PCCS codeset specific methods. */
5258 __ldterm_dispwidth_pccs(uchar_t c
, void *p
, int mode
)
5260 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5267 return (EUC_TWIDTH
);
5269 return (mode
? 2 : EUC_BSWIDTH
);
5271 return (EUC_NLWIDTH
);
5273 return (mode
? 2 : EUC_CRWIDTH
);
5275 return (mode
? 2 : 0);
5281 for (i
= 0; i
< tp
->t_csdata
.csinfo_num
; i
++) {
5282 if (c
>= tp
->t_csdata
.eucpc_data
[i
].msb_start
&&
5283 c
<= tp
->t_csdata
.eucpc_data
[i
].msb_end
)
5284 return (tp
->t_csdata
.eucpc_data
[i
].screen_width
);
5288 * If this leading byte is not in the range list, either provided
5289 * locale data is not sufficient or we encountered an invalid
5290 * character. We return 1 in this case as a fallback value.
5296 __ldterm_memwidth_pccs(uchar_t c
, void *p
)
5298 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5301 for (i
= 0; i
< tp
->t_csdata
.csinfo_num
; i
++) {
5302 if (c
>= tp
->t_csdata
.eucpc_data
[i
].msb_start
&&
5303 c
<= tp
->t_csdata
.eucpc_data
[i
].msb_end
)
5304 return (tp
->t_csdata
.eucpc_data
[i
].byte_length
);
5308 * If this leading byte is not in the range list, either provided
5309 * locale data is not sufficient or we encountered an invalid
5310 * character. We return 1 in this case as a fallback value.
5316 /* The following two functions are UTF-8 codeset specific methods. */
5318 __ldterm_dispwidth_utf8(uchar_t c
, void *p
, int mode
)
5320 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5326 return (EUC_TWIDTH
);
5328 return (mode
? 2 : EUC_BSWIDTH
);
5330 return (EUC_NLWIDTH
);
5332 return (mode
? 2 : EUC_CRWIDTH
);
5334 return (mode
? 2 : 0);
5340 /* This is to silence the lint. */
5341 if (tp
->t_csdata
.codeset_type
!= LDTERM_CS_TYPE_UTF8
)
5345 * If it is a valid leading byte of a UTF-8 character, we set
5346 * the width as 'UNKNOWN_WIDTH' for now. We need to have all
5347 * the bytes to figure out the display width.
5349 if (c
>= (uchar_t
)0xc0 && c
<= (uchar_t
)0xfd)
5350 return (UNKNOWN_WIDTH
);
5353 * If it is an invalid leading byte, we just do our best by
5354 * giving the display width of 1.
5361 __ldterm_memwidth_utf8(uchar_t c
, void *p
)
5363 ldtermstd_state_t
*tp
= (ldtermstd_state_t
*)p
;
5367 * If the codeset type doesn't match, we treat them as
5368 * an illegal character and return 1.
5370 if (tp
->t_csdata
.codeset_type
!= LDTERM_CS_TYPE_UTF8
)
5373 len
= u8_number_of_bytes
[c
];
5376 * If this is a start of an illegal character, we treat
5377 * such as an 1 byte character and screen out.
5379 return ((len
<= 0) ? 1 : len
);
5383 ldterm_utf8_width(uchar_t
*u8
, int length
)
5392 j
= u8_number_of_bytes
[u8
[0]] - 1;
5395 * If the UTF-8 character is out of UTF-16 code range, or,
5396 * if it is either an ASCII character or an invalid leading byte for
5397 * a UTF-8 character, return 1.
5399 if (length
> 4 || j
<= 0)
5402 intcode
= u8
[0] & u8_masks_tbl
[j
];
5403 for (i
= 1; j
> 0; j
--, i
++) {
5405 * The following additional checking is needed to conform to
5406 * the "UTF-8 Corrigendum" introduced at the Unicode 3.1 and
5407 * then updated one more time at the Unicode 3.2.
5410 if (u8
[i
] < u8_valid_min_2nd_byte
[u8
[0]] ||
5411 u8
[i
] > u8_valid_max_2nd_byte
[u8
[0]])
5413 } else if (u8
[i
] < (uchar_t
)LDTERM_CS_TYPE_UTF8_MIN_BYTE
||
5414 u8
[i
] > (uchar_t
)LDTERM_CS_TYPE_UTF8_MAX_BYTE
)
5418 * All subsequent bytes of UTF-8 character has the following
5423 * hence left shift six bits to make space and then get
5424 * six bits from the new byte.
5426 intcode
= (intcode
<< LDTERM_CS_TYPE_UTF8_SHIFT_BITS
) |
5427 (u8
[i
] & LDTERM_CS_TYPE_UTF8_BIT_MASK
);
5431 if (intcode
<= LDTERM_CS_TYPE_UTF8_MAX_P00
) {
5432 /* Basic Multilingual Plane. */
5437 i
= ldterm_ucode
[0][i
].u0
;
5440 i
= ldterm_ucode
[0][i
].u1
;
5443 i
= ldterm_ucode
[0][i
].u2
;
5446 i
= ldterm_ucode
[0][i
].u3
;
5449 } else if (intcode
<= LDTERM_CS_TYPE_UTF8_MAX_P01
) {
5450 /* Secondary Multilingual Plane. */
5451 intcode
= intcode
& (uint_t
)0xffff;
5456 i
= ldterm_ucode
[1][i
].u0
;
5459 i
= ldterm_ucode
[1][i
].u1
;
5462 i
= ldterm_ucode
[1][i
].u2
;
5465 i
= ldterm_ucode
[1][i
].u3
;
5468 } else if ((intcode
>= LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB
&&
5469 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB
) ||
5470 (intcode
>= LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP
&&
5471 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP
) ||
5472 (intcode
>= LDTERM_CS_TYPE_UTF8_MIN_P15
&&
5473 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_P15
) ||
5474 (intcode
>= LDTERM_CS_TYPE_UTF8_MIN_P16
&&
5475 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_P16
)) {
5477 * Supplementary Plane for CJK Ideographs and
5478 * Private Use Planes.
5481 } else if ((intcode
>= LDTERM_CS_TYPE_UTF8_MIN_P14
&&
5482 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_P14
) ||
5483 (intcode
>= LDTERM_CS_TYPE_UTF8_MIN_VARSEL
&&
5484 intcode
<= LDTERM_CS_TYPE_UTF8_MAX_VARSEL
)) {
5486 * Some Special Purpose Plane characters:
5487 * These are like control characters and not printable.
5493 * We return the display width of 1 for all character code points
5494 * that we didn't catch from the above logic and also for combining
5495 * and conjoining characters with width value of zero.
5497 * In particular, the reason why we are returning 1 for combining
5498 * and conjoining characters is because the GUI-based terminal
5499 * emulators are not yet capable of properly handling such characters
5500 * and in most of the cases, they just treat such characters as if
5501 * they occupy a display cell. If the terminal emulators are capable of
5502 * handling the characters correctly, then, this logic of returning
5503 * 1 should be revisited and changed. See CR 6660526 for more
5506 return ((i
== 0) ? '\1' : (uchar_t
)i
);