Commit | Line | Data |
---|---|---|
b06ffe83 | 1 | .\" Copyright (c) 1983 Regents of the University of California. |
02d430a1 KM |
2 | .\" All rights reserved. The Berkeley software License Agreement |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
8ddf9ad9 | 5 | .\" @(#)tty.4 6.5 (Berkeley) %G% |
02d430a1 | 6 | .\" |
b06ffe83 | 7 | .TH TTY 4 "" |
02d430a1 KM |
8 | .UC 4 |
9 | .SH NAME | |
10 | tty \- general terminal interface | |
9313e78d KM |
11 | .SH SYNOPSIS |
12 | .B #include <sgtty.h> | |
02d430a1 KM |
13 | .SH DESCRIPTION |
14 | This section describes | |
15 | both a particular special file | |
16 | .B /dev/tty | |
17 | and the terminal drivers used for conversational computing. | |
18 | .LP | |
19 | .B Line disciplines. | |
20 | .PP | |
21 | The system provides different | |
22 | .I "line disciplines" | |
23 | for controlling communications lines. | |
24 | In this version of the system there are three disciplines available: | |
25 | .IP "old" 8 | |
26 | The old (standard) terminal driver. This is used when using the | |
27 | standard shell | |
28 | .IR sh (1) | |
29 | and for compatibility with other standard version 7 UNIX systems. | |
30 | .IP "new" | |
31 | A newer terminal driver, with features for job control; this must | |
32 | be used when using | |
33 | .IR csh (1). | |
02d430a1 KM |
34 | .IP "net" |
35 | A line discipline used for networking and loading data into | |
36 | the system over communications lines. It allows high speed input | |
37 | at very low overhead, and is described in | |
38 | .IR bk (4). | |
39 | .LP | |
40 | Line discipline switching is accomplished with the TIOCSETD | |
3e0098f5 | 41 | .IR ioctl : |
02d430a1 | 42 | .IP |
3e0098f5 KM |
43 | .B "int ldisc = LDISC;" |
44 | .br | |
45 | .B "ioctl(f, TIOCSETD, &ldisc);" | |
02d430a1 KM |
46 | .LP |
47 | where LDISC is OTTYDISC for the standard tty driver, NTTYDISC for the new | |
48 | driver and NETLDISC for the networking discipline. | |
49 | The standard (currently old) tty driver is discipline 0 by convention. | |
3e0098f5 KM |
50 | The current line discipline can be obtained with the TIOCGETD |
51 | .IR ioctl . | |
02d430a1 KM |
52 | Pending input is discarded when the line discipline is changed. |
53 | .PP | |
54 | All of the low-speed asynchronous | |
55 | communications ports can use any | |
56 | of the available line disciplines, no matter what | |
57 | hardware is involved. | |
58 | The remainder of this section discusses the | |
59 | \*(lqold\*(rq and \*(lqnew\*(rq disciplines. | |
60 | .LP | |
61 | .B "The control terminal." | |
62 | .LP | |
63 | When a terminal file is opened, it causes the process to wait until a | |
64 | connection is established. In practice, user programs seldom open | |
65 | these files; they are opened by | |
66 | .IR init (8) | |
67 | and become a user's standard input and output file. | |
68 | .PP | |
69 | If a process which has no control terminal opens a terminal file, then | |
70 | that terminal file becomes the control terminal for that process. | |
71 | The control terminal is thereafter inherited by a child process during a | |
72 | .IR fork (2), | |
73 | even if the control terminal is closed. | |
74 | .LP | |
75 | The file | |
76 | .B /dev/tty | |
77 | is, in each process, a synonym for a | |
78 | .I "control terminal" | |
79 | associated with that process. It is useful for programs that wish to | |
80 | be sure of writing messages on the terminal | |
81 | no matter how output has been redirected. | |
82 | It can also be used for programs that demand a file name | |
83 | for output, when typed output is desired | |
84 | and it is tiresome to find out which terminal | |
85 | is currently in use. | |
86 | .LP | |
3e0098f5 KM |
87 | A process can remove the association it has with its controlling |
88 | terminal by opening the file | |
89 | .B /dev/tty | |
90 | and issuing a | |
91 | .IP | |
92 | .B "ioctl(f, TIOCNOTTY, 0);" | |
93 | .LP | |
94 | This is often desirable in server processes. | |
95 | .LP | |
02d430a1 KM |
96 | .B "Process groups." |
97 | .LP | |
9313e78d | 98 | Command processors such as |
02d430a1 KM |
99 | .IR csh (1) |
100 | can arbitrate the terminal between different | |
101 | .I jobs | |
102 | by placing related jobs in a single process group and associating this | |
3e0098f5 | 103 | process group with the terminal. A terminal's associated process group |
02d430a1 KM |
104 | may be set using the TIOCSPGRP |
105 | .IR ioctl (2): | |
106 | .IP | |
3e0098f5 | 107 | .B "ioctl(fildes, TIOCSPGRP, &pgrp);" |
02d430a1 | 108 | .LP |
3e0098f5 | 109 | or examined using TIOCGPGRP, which returns the current |
02d430a1 | 110 | process group in |
3e0098f5 | 111 | .IR pgrp . |
02d430a1 KM |
112 | The new terminal driver aids in this arbitration by restricting access |
113 | to the terminal by processes which are not in the current process group; | |
114 | see | |
115 | .B "Job access control" | |
116 | below. | |
117 | .LP | |
118 | .B "Modes." | |
119 | .PP | |
120 | The terminal drivers have three major modes, characterized by the | |
121 | amount of processing on the input and output characters: | |
122 | .IP cooked 10 | |
123 | The normal mode. In this mode lines of input are collected and input editing | |
124 | is done. The edited line is made available when it is completed by | |
125 | a newline | |
3e0098f5 | 126 | or when the \fIt_brkc\fP character, normally an EOT (control-D, hereafter ^D), |
02d430a1 KM |
127 | is entered. |
128 | A carriage return is usually made synonymous with newline in this mode, | |
129 | and replaced with a newline whenever it is typed. | |
130 | All driver functions | |
131 | (input editing, interrupt generation, | |
132 | output processing such as delay generation and tab expansion, etc.) | |
133 | are available in this mode. | |
134 | .IP CBREAK 10 | |
135 | This mode eliminates the character, word, and line editing input facilities, | |
136 | making the input character available to the user program as it is typed. | |
137 | Flow control, literal-next and interrupt processing are still done in this mode. | |
138 | Output processing is done. | |
139 | .IP RAW 10 | |
140 | This mode eliminates all input processing and makes all input characters | |
141 | available as they are typed; no output processing is done either. | |
142 | .PP | |
9313e78d KM |
143 | The style of input processing can also be very different when |
144 | the terminal is put in non-blocking i/o mode; see | |
3e0098f5 | 145 | the FNDELAY flag as described in |
9313e78d KM |
146 | .IR fcntl (2). |
147 | In this case a | |
02d430a1 KM |
148 | .IR read (2) |
149 | from the control terminal will never block, but rather | |
9313e78d KM |
150 | return an error indication (EWOULDBLOCK) if there is no |
151 | input available. | |
152 | .PP | |
153 | A process may also request a SIGIO signal be sent it whenever input | |
154 | is present. To enable this mode the FASYNC flag should be set using | |
155 | .IR fcntl (2). | |
02d430a1 KM |
156 | .LP |
157 | .B "Input editing." | |
158 | .LP | |
159 | A UNIX terminal ordinarily operates in full-duplex mode. | |
160 | Characters may be typed at any time, | |
161 | even while output is occurring, and are only lost when the | |
162 | system's character input buffers become completely | |
163 | choked, which is rare, | |
164 | or when the user has accumulated the maximum allowed number of | |
165 | input characters that have not yet been read by some program. | |
166 | Currently this limit is 256 characters. | |
3e0098f5 KM |
167 | In RAW mode, the terminal driver |
168 | throws away all input and output without notice when the limit is reached. | |
169 | In CBREAK or cooked mode it refuses to accept any further input and, | |
170 | if in the new line discipline, rings the terminal bell. | |
02d430a1 KM |
171 | .PP |
172 | Input characters are normally accepted in either even or odd parity | |
173 | with the parity bit being stripped off before the character is given to | |
174 | the program. By clearing either the EVEN or ODD bit in the flags word | |
175 | it is possible to have input characters with that parity discarded (see the | |
176 | \fBSummary\fR below.) | |
177 | .PP | |
178 | In all of the line disciplines, it is possible to simulate terminal | |
3e0098f5 KM |
179 | input using the TIOCSTI |
180 | .IR ioctl , | |
181 | which takes, as its third argument, | |
02d430a1 KM |
182 | the address of a character. The system pretends that this character |
183 | was typed on the argument terminal, which must be the control terminal except | |
9313e78d | 184 | for the super-user (this call is not in standard version 7 UNIX). |
02d430a1 KM |
185 | .PP |
186 | Input characters are normally echoed by putting them in an output queue | |
187 | as they arrive. This may be disabled by clearing the ECHO bit in the | |
188 | flags word using the | |
3e0098f5 KM |
189 | .IR stty (3C) |
190 | call or the TIOCSETN or TIOCSETP | |
191 | .IR ioctl s | |
02d430a1 KM |
192 | (see the \fBSummary\fR below). |
193 | .PP | |
194 | In cooked mode, terminal input is processed in units of lines. | |
195 | A program attempting | |
196 | to read will normally be suspended until an entire line has been | |
197 | received | |
70fd5b48 JL |
198 | (but see the description of SIGTTIN in \fBJob access control\fR |
199 | and of FIONREAD in | |
200 | \fBSummary\fR, both below.) | |
02d430a1 KM |
201 | No matter how many characters are requested |
202 | in the read call, at most one line will be returned. | |
203 | It is not, however, necessary to read a whole line at | |
204 | once; any number of characters may be | |
205 | requested in a read, even one, without losing information. | |
206 | .PP | |
3e0098f5 KM |
207 | During input, line editing is normally done, with the DELETE character |
208 | logically erasing the last character typed and the character ^U (control-U) | |
02d430a1 | 209 | logically erasing the entire current input line. |
02d430a1 KM |
210 | These characters |
211 | never erase beyond the beginning of the current input line or an ^D. | |
212 | These characters may be entered literally by | |
3e0098f5 KM |
213 | preceding them with `\e\|'; the `\e\|' will normally be erased when the |
214 | character is typed. | |
02d430a1 KM |
215 | .PP |
216 | The drivers normally treat either a carriage return or a newline character | |
217 | as terminating an input line, replacing the return with a newline and echoing | |
218 | a return and a line feed. | |
219 | If the CRMOD bit is cleared in the local mode word then the processing | |
220 | for carriage return is disabled, and it is simply echoed as a return, | |
221 | and does not terminate cooked mode input. | |
222 | .PP | |
223 | In the new driver there is a literal-next character ^V which can be typed | |
224 | in both cooked and CBREAK mode preceding | |
3e0098f5 | 225 | .I any |
02d430a1 | 226 | character to prevent its special meaning. This is to be preferred to the |
3e0098f5 KM |
227 | use of `\e\|' escaping erase and kill characters, but `\e\|' is |
228 | retained with its old function in the new line discipline. | |
02d430a1 KM |
229 | .PP |
230 | The new terminal driver also provides two other editing characters in | |
231 | normal mode. The word-erase character, normally ^W, erases the preceding | |
232 | word, but not any spaces before it. For the purposes of ^W, a word | |
233 | is defined as a sequence of non-blank characters, with tabs counted as | |
234 | blanks. | |
235 | Finally, the reprint character, normally ^R, retypes the pending input beginning | |
9313e78d | 236 | on a new line. Retyping occurs automatically in cooked mode if characters |
02d430a1 KM |
237 | which would normally be erased from the screen are fouled by program output. |
238 | .LP | |
239 | .B "Input echoing and redisplay" | |
240 | .LP | |
3e0098f5 KM |
241 | The terminal driver has several modes (not present in standard UNIX |
242 | Version 7 systems) for handling the echoing of | |
02d430a1 KM |
243 | terminal input, controlled by bits in a local mode word. |
244 | .LP | |
245 | .I "Hardcopy terminals." | |
246 | When a hardcopy terminal is in use, the LPRTERA bit is normally set in | |
247 | the local mode word. Characters which are logically erased are | |
248 | then printed out backwards preceded by `\e\|' and followed by `/' in this mode. | |
249 | .LP | |
3e0098f5 KM |
250 | .I "CRT terminals." |
251 | When a CRT terminal is in use, the LCRTBS bit is normally set in the local | |
02d430a1 KM |
252 | mode word. The terminal driver then echoes the proper number of erase |
253 | characters when input is erased; in the normal case where the erase | |
254 | character is a ^H this causes the cursor of the terminal to back up | |
255 | to where it was before the logically erased character was typed. | |
256 | If the input has become fouled due to interspersed asynchronous output, | |
9313e78d | 257 | the input is automatically retyped. |
02d430a1 | 258 | .LP |
3e0098f5 KM |
259 | .I "Erasing characters from a CRT." |
260 | When a CRT terminal is in use, the LCRTERA bit may be set to cause | |
02d430a1 KM |
261 | input to be erased from the screen with a \*(lqbackspace-space-backspace\*(rq |
262 | sequence when character or word deleting sequences are used. | |
263 | A LCRTKIL bit may be set as well, causing the input to | |
264 | be erased in this manner on line kill sequences as well. | |
265 | .LP | |
266 | .I "Echoing of control characters." | |
267 | If the LCTLECH bit is set in the local state word, then non-printing (control) | |
268 | characters are normally echoed as ^X (for some X) | |
269 | rather than being echoed unmodified; delete is echoed as ^?. | |
270 | .LP | |
3e0098f5 | 271 | The normal modes for use on CRT terminals are speed dependent. |
02d430a1 KM |
272 | At speeds less than 1200 baud, the LCRTERA and LCRTKILL processing |
273 | is painfully slow, so | |
274 | .IR stty (1) | |
275 | normally just sets LCRTBS and LCTLECH; at | |
276 | speeds of 1200 baud or greater all of these bits are normally set. | |
277 | .IR Stty (1) | |
278 | summarizes these option settings and the use of the new terminal | |
279 | driver as | |
280 | \*(lqnewcrt.\*(rq | |
281 | .LP | |
282 | .B "Output processing." | |
283 | .PP | |
284 | When one or more | |
285 | characters are written, they are actually transmitted | |
286 | to the terminal as soon as previously-written characters | |
287 | have finished typing. | |
288 | (As noted above, input characters are normally | |
289 | echoed by putting them in the output queue | |
290 | as they arrive.) | |
291 | When a process produces characters more rapidly than they can be typed, | |
292 | it will be suspended when its output queue exceeds some limit. | |
293 | When the queue has drained down to some threshold | |
294 | the program is resumed. | |
295 | Even parity is normally generated on output. | |
296 | The EOT character is not transmitted in cooked mode to prevent terminals | |
3e0098f5 | 297 | that respond to it from hanging up; programs using RAW or CBREAK mode |
02d430a1 KM |
298 | should be careful. |
299 | .PP | |
300 | The terminal drivers provide necessary processing for cooked and CBREAK mode | |
301 | output including delay generation for certain special characters and parity | |
302 | generation. Delays are available after backspaces ^H, form feeds ^L, | |
303 | carriage returns ^M, tabs ^I and newlines ^J. The driver will also optionally | |
304 | expand tabs into spaces, where the tab stops are assumed to be set every | |
3e0098f5 KM |
305 | eight columns, and optionally convert newlines to carriage returns |
306 | followed by newline. These functions are controlled by bits in the tty | |
307 | flags word; see \fBSummary\fR below. | |
02d430a1 KM |
308 | .PP |
309 | The terminal drivers provide for mapping between upper and lower case | |
310 | on terminals lacking lower case, and for other special processing on | |
311 | deficient terminals. | |
312 | .PP | |
313 | Finally, in the new terminal driver, there is a output flush character, | |
314 | normally ^O, which sets the LFLUSHO bit in the local mode word, causing | |
315 | subsequent output to be flushed until it is cleared by a program or more | |
316 | input is typed. This character has effect in both cooked and CBREAK modes | |
317 | and causes pending input to be retyped if there is any pending input. | |
3e0098f5 KM |
318 | An |
319 | .I ioctl | |
320 | to flush the characters in the input or output queues, TIOCFLUSH, | |
9313e78d | 321 | is also available. |
02d430a1 KM |
322 | .LP |
323 | .B "Upper case terminals and Hazeltines" | |
324 | .PP | |
325 | If the LCASE bit is set in the tty flags, then | |
326 | all upper-case letters are mapped into | |
327 | the corresponding lower-case letter. | |
328 | The upper-case letter may be generated by preceding | |
329 | it by `\\'. | |
3e0098f5 | 330 | Upper case letters are preceded by a `\e\|' when output. |
02d430a1 KM |
331 | In addition, the following escape sequences can be generated |
332 | on output and accepted on input: | |
333 | .PP | |
334 | .nf | |
335 | for \` | ~ { } | |
336 | use \e\|\' \e\|! \e\|^ \e\|( \e\|) | |
337 | .fi | |
338 | .PP | |
339 | To deal with Hazeltine terminals, which do not understand that ~ has | |
340 | been made into an ASCII character, the LTILDE bit may be set in the local | |
3e0098f5 | 341 | mode word; in this case the character |
02d430a1 KM |
342 | ~ will be replaced with the character \` on output. |
343 | .LP | |
344 | .B "Flow control." | |
345 | .PP | |
346 | There are two characters (the stop character, normally ^S, and the | |
347 | start character, normally ^Q) which cause output to be suspended and | |
348 | resumed respectively. Extra stop characters typed when output | |
349 | is already stopped have no effect, unless the start and stop characters | |
350 | are made the same, in which case output resumes. | |
351 | .PP | |
352 | A bit in the flags word may be set to put the terminal into TANDEM mode. | |
353 | In this mode the system produces a stop character (default ^S) when | |
354 | the input queue is in danger of overflowing, and a start character (default | |
355 | ^Q) when the input has drained sufficiently. This mode is useful | |
356 | when the terminal is actually another machine that obeys the | |
357 | conventions. | |
358 | .LP | |
359 | .B "Line control and breaks." | |
360 | .LP | |
361 | There are several | |
362 | .I ioctl | |
363 | calls available to control the state of the terminal line. | |
3e0098f5 KM |
364 | The TIOCSBRK |
365 | .I ioctl | |
366 | will set the break bit in the hardware interface | |
02d430a1 KM |
367 | causing a break condition to exist; this can be cleared (usually after a delay |
368 | with | |
369 | .IR sleep (3)) | |
370 | by TIOCCBRK. | |
371 | Break conditions in the input are reflected as a null character in RAW mode | |
372 | or as the interrupt character in cooked or CBREAK mode. | |
3e0098f5 KM |
373 | The TIOCCDTR |
374 | .I ioctl | |
375 | will clear the data terminal ready condition; it can | |
02d430a1 KM |
376 | be set again by TIOCSDTR. |
377 | .PP | |
378 | When the carrier signal from the dataset drops (usually | |
379 | because the user has hung up his terminal) a | |
380 | SIGHUP hangup signal is sent to the processes in the distinguished | |
381 | process group of the terminal; this usually causes them to terminate | |
382 | (the SIGHUP can be suppressed by setting the LNOHANG bit in the local | |
383 | state word of the driver.) | |
384 | Access to the terminal by other processes is then normally revoked, | |
385 | so any further reads will fail, and programs that read a terminal and test for | |
386 | end-of-file on their input will terminate appropriately. | |
387 | .PP | |
388 | When using an ACU | |
389 | it is possible to ask that the phone line be hung up on the last close | |
3e0098f5 KM |
390 | with the TIOCHPCL |
391 | .IR ioctl ; | |
392 | this is normally done on the outgoing line. | |
02d430a1 KM |
393 | .LP |
394 | .B "Interrupt characters." | |
395 | .PP | |
396 | There are several characters that generate interrupts in cooked and CBREAK | |
3e0098f5 KM |
397 | mode; all are sent to the processes in the control group of the terminal, |
398 | as if a TIOCGPGRP | |
399 | .I ioctl | |
400 | were done to get the process group and then a | |
02d430a1 KM |
401 | .IR killpg (2) |
402 | system call were done, | |
403 | except that these characters also flush pending input and output when | |
404 | typed at a terminal | |
405 | (\fI\z'a\`'la\fR TIOCFLUSH). | |
406 | The characters shown here are the defaults; the field names in the structures | |
407 | (given below) | |
408 | are also shown. | |
3e0098f5 KM |
409 | The characters may be changed. |
410 | .IP ^C | |
411 | \fBt_intrc\fR (ETX) generates a SIGINT signal. | |
02d430a1 KM |
412 | This is the normal way to stop a process which is no longer interesting, |
413 | or to regain control in an interactive program. | |
414 | .IP ^\e | |
415 | \fBt_quitc\fR (FS) generates a SIGQUIT signal. | |
416 | This is used to cause a program to terminate and produce a core image, | |
417 | if possible, | |
418 | in the file | |
419 | .B core | |
420 | in the current directory. | |
421 | .IP ^Z | |
422 | \fBt_suspc\fR (EM) generates a SIGTSTP signal, which is used to suspend | |
423 | the current process group. | |
424 | .IP ^Y | |
9313e78d | 425 | \fBt_dsuspc\fR (SUB) generates a SIGTSTP signal as ^Z does, but the |
02d430a1 KM |
426 | signal is sent when a program attempts to read the ^Y, rather than when |
427 | it is typed. | |
428 | .LP | |
429 | .B "Job access control." | |
430 | .PP | |
431 | When using the new terminal driver, | |
432 | if a process which is not in the distinguished process group of its | |
433 | control terminal attempts to read from that terminal its process group is | |
9313e78d KM |
434 | sent a SIGTTIN signal. This signal normally causes the members of |
435 | that process group to stop. | |
436 | If, however, the process is ignoring SIGTTIN, has SIGTTIN blocked, | |
9313e78d | 437 | or is in the middle of process creation using |
02d430a1 | 438 | .IR vfork (2)), |
3e0098f5 KM |
439 | the read will return \-1 and set |
440 | .I errno | |
441 | to EIO. | |
02d430a1 KM |
442 | .PP |
443 | When using the new terminal driver with the LTOSTOP bit set in the local | |
444 | modes, a process is prohibited from writing on its control terminal if it is | |
445 | not in the distinguished process group for that terminal. | |
3e0098f5 KM |
446 | Processes which are holding or ignoring SIGTTOU signals |
447 | or which are in the middle of a | |
02d430a1 KM |
448 | .IR vfork (2) |
449 | are excepted and allowed to produce output. | |
450 | .LP | |
451 | .B "Summary of modes." | |
452 | .LP | |
453 | Unfortunately, due to the evolution of the terminal driver, | |
454 | there are 4 different structures which contain various portions of the | |
455 | driver data. The first of these (\fBsgttyb\fR) | |
456 | contains that part of the information | |
457 | largely common between version 6 and version 7 UNIX systems. | |
458 | The second contains additional control characters added in version 7. | |
3e0098f5 | 459 | The third is a word of local state added in 4BSD, |
02d430a1 KM |
460 | and the fourth is another structure of special characters added for the |
461 | new driver. In the future a single structure may be made available | |
462 | to programs which need to access all this information; most programs | |
463 | need not concern themselves with all this state. | |
464 | .de Ul | |
465 | .ie t \\$1\l'|0\(ul' | |
466 | .el \fI\\$1\fP | |
467 | .. | |
468 | .LP | |
469 | .Ul "Basic modes: sgtty." | |
470 | .PP | |
471 | The basic | |
472 | .IR ioctl s | |
473 | use the structure | |
474 | defined in | |
475 | .IR <sgtty.h> : | |
476 | .PP | |
477 | .ta .5i 1i | |
478 | .nf | |
479 | .ft 3 | |
480 | struct sgttyb { | |
481 | char sg_ispeed; | |
482 | char sg_ospeed; | |
483 | char sg_erase; | |
484 | char sg_kill; | |
485 | short sg_flags; | |
486 | }; | |
487 | .ft R | |
488 | .fi | |
489 | .PP | |
490 | The | |
491 | .I sg_ispeed | |
492 | and | |
493 | .I sg_ospeed | |
494 | fields describe the input and output speeds of the | |
495 | device according to the following table, | |
496 | which corresponds to the DEC DH-11 interface. | |
497 | If other hardware is used, | |
498 | impossible speed changes are ignored. | |
499 | Symbolic values in the table are as defined in | |
500 | .IR <sgtty.h> . | |
501 | .PP | |
502 | .nf | |
503 | .ta \w'B9600 'u +5n | |
504 | B0 0 (hang up dataphone) | |
505 | B50 1 50 baud | |
506 | B75 2 75 baud | |
507 | B110 3 110 baud | |
508 | B134 4 134.5 baud | |
509 | B150 5 150 baud | |
510 | B200 6 200 baud | |
511 | B300 7 300 baud | |
512 | B600 8 600 baud | |
513 | B1200 9 1200 baud | |
514 | B1800 10 1800 baud | |
515 | B2400 11 2400 baud | |
516 | B4800 12 4800 baud | |
517 | B9600 13 9600 baud | |
518 | EXTA 14 External A | |
519 | EXTB 15 External B | |
520 | .fi | |
521 | .DT | |
522 | .PP | |
02d430a1 KM |
523 | Code conversion and line control required for |
524 | IBM 2741's (134.5 baud) | |
525 | must be implemented by the user's | |
526 | program. | |
527 | The half-duplex line discipline | |
528 | required for the 202 dataset (1200 baud) | |
529 | is not supplied; full-duplex 212 datasets work fine. | |
530 | .PP | |
531 | The | |
532 | .I sg_erase | |
533 | and | |
534 | .I sg_kill | |
535 | fields of the argument structure | |
536 | specify the erase and kill characters respectively. | |
3e0098f5 | 537 | (Defaults are DELETE and ^U.) |
02d430a1 KM |
538 | .PP |
539 | The | |
540 | .I sg_flags | |
541 | field of the argument structure | |
542 | contains several bits that determine the | |
543 | system's treatment of the terminal: | |
544 | .PP | |
545 | .ta \w'ALLDELAY 'u +\w'0100000 'u | |
546 | .nf | |
547 | ALLDELAY 0177400 Delay algorithm selection | |
548 | BSDELAY 0100000 Select backspace delays (not implemented): | |
549 | BS0 0 | |
550 | BS1 0100000 | |
551 | VTDELAY 0040000 Select form-feed and vertical-tab delays: | |
552 | FF0 0 | |
8ddf9ad9 | 553 | FF1 0040000 |
02d430a1 KM |
554 | CRDELAY 0030000 Select carriage-return delays: |
555 | CR0 0 | |
556 | CR1 0010000 | |
557 | CR2 0020000 | |
558 | CR3 0030000 | |
559 | TBDELAY 0006000 Select tab delays: | |
560 | TAB0 0 | |
8ddf9ad9 | 561 | TAB1 0002000 |
02d430a1 KM |
562 | TAB2 0004000 |
563 | XTABS 0006000 | |
564 | NLDELAY 0001400 Select new-line delays: | |
565 | NL0 0 | |
566 | NL1 0000400 | |
567 | NL2 0001000 | |
568 | NL3 0001400 | |
3e0098f5 KM |
569 | EVENP 0000200 Even parity allowed on input and generated on output |
570 | ODDP 0000100 Odd parity allowed on input and generated on output | |
02d430a1 | 571 | RAW 0000040 Raw mode: wake up on all characters, 8-bit interface |
3e0098f5 | 572 | CRMOD 0000020 Map CR into LF; output LF as CR-LF |
02d430a1 | 573 | ECHO 0000010 Echo (full duplex) |
3e0098f5 | 574 | LCASE 0000004 Map upper case to lower on input and lower to upper on output |
02d430a1 KM |
575 | CBREAK 0000002 Return each character as soon as typed |
576 | TANDEM 0000001 Automatic flow control | |
577 | .DT | |
578 | .fi | |
579 | .PP | |
580 | The delay bits specify how long | |
581 | transmission stops to allow for mechanical or other movement | |
582 | when certain characters are sent to the terminal. | |
583 | In all cases a value of 0 indicates no delay. | |
584 | .PP | |
585 | Backspace delays are currently ignored but might | |
586 | be used for Terminet 300's. | |
587 | .PP | |
588 | If a form-feed/vertical tab delay is specified, | |
589 | it lasts for about 2 seconds. | |
590 | .PP | |
591 | Carriage-return delay type 1 lasts about .08 seconds | |
592 | and is suitable for the Terminet 300. | |
593 | Delay type 2 lasts about .16 seconds and is suitable | |
594 | for the VT05 and the TI 700. | |
595 | Delay type 3 is suitable for the concept-100 and pads lines | |
596 | to be at least 9 characters at 9600 baud. | |
597 | .PP | |
598 | New-line delay type 1 is dependent on the current column | |
599 | and is tuned for Teletype model 37's. | |
600 | Type 2 is useful for the VT05 and is about .10 seconds. | |
601 | Type 3 is unimplemented and is 0. | |
602 | .PP | |
603 | Tab delay type 1 is dependent on the amount of movement | |
604 | and is tuned to the Teletype model | |
605 | 37. | |
606 | Type 3, called XTABS, | |
607 | is not a delay at all but causes tabs to be replaced | |
608 | by the appropriate number of spaces on output. | |
609 | .PP | |
610 | Input characters with the wrong parity, as determined by bits 200 and | |
611 | 100, are ignored in cooked and CBREAK mode. | |
612 | .PP | |
613 | RAW | |
614 | disables all processing save output flushing with LFLUSHO; | |
615 | full 8 bits of input are given as soon as | |
616 | it is available; all 8 bits are passed on output. | |
617 | A break condition in the input is reported as a null character. | |
3e0098f5 KM |
618 | If the input queue overflows in raw mode all data in the input and output |
619 | queues are discarded; this applies to both new and old drivers. | |
02d430a1 KM |
620 | .PP |
621 | CRMOD causes input carriage returns to be turned into | |
3e0098f5 KM |
622 | new-lines, and output and echoed new-lines to be output as a carriage return |
623 | followed by a line feed. | |
02d430a1 KM |
624 | .PP |
625 | CBREAK is a sort of half-cooked (rare?) mode. | |
626 | Programs can read each character as soon as typed, instead | |
627 | of waiting for a full line; | |
628 | all processing is done except the input editing: | |
629 | character and word erase and line kill, input reprint, | |
3e0098f5 | 630 | and the special treatment of \e and EOT are disabled. |
02d430a1 KM |
631 | .PP |
632 | TANDEM mode causes the system to produce | |
633 | a stop character (default ^S) whenever the input | |
634 | queue is in danger of overflowing, and a start character | |
635 | (default ^Q) | |
636 | when the input queue has drained sufficiently. | |
637 | It is useful for flow control when the `terminal' | |
638 | is really another computer which understands the conventions. | |
639 | .LP | |
3e0098f5 KM |
640 | .B Note: |
641 | The same ``stop'' and ``start'' characters are used for both directions | |
642 | of flow control; the | |
643 | .I t_stopc | |
644 | character is accepted on input as the character that stops output and is | |
645 | produced on output as the character to stop input, and the | |
646 | .I t_startc | |
647 | character is accepted on input as the character that restarts output and is | |
648 | produced on output as the character to restart input. | |
649 | .LP | |
02d430a1 KM |
650 | .Ul "Basic ioctls" |
651 | .PP | |
3e0098f5 | 652 | A large number of |
02d430a1 | 653 | .IR ioctl (2) |
3e0098f5 | 654 | calls apply to terminals. Some have the general form: |
02d430a1 KM |
655 | .PP |
656 | .B #include <sgtty.h> | |
657 | .PP | |
658 | .B ioctl(fildes, code, arg) | |
659 | .br | |
660 | .B struct sgttyb *arg; | |
661 | .PP | |
662 | The applicable codes are: | |
663 | .IP TIOCGETP 15 | |
664 | Fetch the basic parameters associated with the terminal, and store | |
665 | in the pointed-to \fIsgttyb\fR structure. | |
666 | .IP TIOCSETP | |
667 | Set the parameters according to the pointed-to \fIsgttyb\fR structure. | |
668 | The interface delays until output is quiescent, | |
669 | then throws away any unread characters, | |
670 | before changing the modes. | |
671 | .IP TIOCSETN | |
672 | Set the parameters like TIOCSETP but do not delay or flush input. | |
673 | Input is not preserved, however, when changing to or from RAW. | |
674 | .PP | |
3e0098f5 | 675 | With the following codes |
02d430a1 KM |
676 | .I arg |
677 | is ignored. | |
678 | .IP TIOCEXCL 15 | |
679 | Set \*(lqexclusive-use\*(rq mode: | |
680 | no further opens are permitted until the file has been closed. | |
681 | .IP TIOCNXCL | |
682 | Turn off \*(lqexclusive-use\*(rq mode. | |
683 | .IP TIOCHPCL | |
684 | When the file is closed for the last time, | |
685 | hang up the terminal. | |
686 | This is useful when the line is associated | |
687 | with an ACU used to place outgoing calls. | |
3e0098f5 KM |
688 | .PP |
689 | With the following codes | |
690 | .I arg | |
691 | is a pointer to an | |
692 | .BR int . | |
693 | .IP TIOCGETD 15 | |
694 | .I arg | |
695 | is a pointer to an | |
696 | .B int | |
697 | into which is placed the current line discipline number. | |
698 | .IP TIOCSETD | |
699 | .I arg | |
700 | is a pointer to an | |
701 | .B int | |
702 | whose value becomes the current line discipline number. | |
02d430a1 | 703 | .IP TIOCFLUSH |
3e0098f5 KM |
704 | If the |
705 | .B int | |
706 | pointed to by | |
707 | .I arg | |
708 | has a zero value, all characters waiting in input or output queues are flushed. | |
709 | Otherwise, the value of the | |
710 | .B int | |
711 | is treated as the logical OR of the FREAD and FWRITE defined in | |
712 | .BR <sys/file.h> ; | |
713 | if the FREAD bit is set, all characters waiting in input queues are flushed, | |
714 | and if the FWRITE bit is set, all characters waiting in output queues are | |
715 | flushed. | |
02d430a1 KM |
716 | .LP |
717 | The remaining calls are not available in vanilla version 7 UNIX. | |
718 | In cases where arguments are required, they are described; \fIarg\fR | |
719 | should otherwise be given as 0. | |
720 | .IP TIOCSTI 15 | |
3e0098f5 KM |
721 | the argument points to a character which the system |
722 | pretends had been typed on the terminal. | |
02d430a1 KM |
723 | .IP TIOCSBRK 15 |
724 | the break bit is set in the terminal. | |
725 | .IP TIOCCBRK | |
726 | the break bit is cleared. | |
727 | .IP TIOCSDTR | |
728 | data terminal ready is set. | |
729 | .IP TIOCCDTR | |
730 | data terminal ready is cleared. | |
3e0098f5 KM |
731 | .IP TIOCSTOP 15 |
732 | output is stopped as if the ``stop'' character had been typed. | |
733 | .IP TIOCSTART | |
734 | output is restarted as if the ``start'' character had been typed. | |
02d430a1 | 735 | .IP TIOCGPGRP |
3e0098f5 KM |
736 | .I arg |
737 | is a pointer to an | |
738 | .B int | |
739 | into which is placed the process group ID of the process group | |
740 | for which this terminal is the control terminal. | |
02d430a1 | 741 | .IP TIOCSPGRP |
3e0098f5 KM |
742 | .I arg |
743 | is a pointer to an | |
744 | .B int | |
745 | (typically a process ID); the process group whose process group ID | |
746 | is the value of this | |
747 | .B int | |
748 | becomes the process group for which this terminal is the control terminal. | |
749 | .IP TIOCOUTQ | |
750 | returns in the | |
751 | .B int | |
752 | pointed to by | |
753 | .I arg | |
754 | the number of characters queued up to be output to the terminal. | |
02d430a1 | 755 | .IP FIONREAD |
3e0098f5 KM |
756 | returns in the |
757 | .B int | |
758 | pointed to by | |
759 | .I arg | |
760 | the number of immediately readable characters from the argument unit. | |
761 | This works for files, pipes, and terminals. | |
762 | .PP | |
02d430a1 KM |
763 | .Ul Tchars |
764 | .PP | |
765 | The second structure associated with each terminal specifies | |
766 | characters that are special in both the old and new terminal interfaces: | |
767 | The following structure is defined in | |
768 | .IR <sys/ioctl.h> , | |
769 | which is automatically included in | |
770 | .IR <sgtty.h> : | |
771 | .PP | |
772 | .nf | |
773 | .ft 3 | |
774 | .ta .5i 1i 2i | |
775 | struct tchars { | |
776 | char t_intrc; /* interrupt */ | |
777 | char t_quitc; /* quit */ | |
778 | char t_startc; /* start output */ | |
779 | char t_stopc; /* stop output */ | |
780 | char t_eofc; /* end-of-file */ | |
781 | char t_brkc; /* input delimiter (like nl) */ | |
782 | }; | |
783 | .DT | |
784 | .fi | |
785 | .ft R | |
786 | .PP | |
787 | The default values for these characters are | |
8ddf9ad9 | 788 | ^C, ^\e\|, ^Q, ^S, ^D, and \-1. |
02d430a1 KM |
789 | A character value of \-1 |
790 | eliminates the effect of that character. | |
791 | The | |
792 | .I t_brkc | |
793 | character, by default \-1, | |
794 | acts like a new-line in that it terminates a `line,' | |
795 | is echoed, and is passed to the program. | |
796 | The `stop' and `start' characters may be the same, | |
797 | to produce a toggle effect. | |
798 | It is probably counterproductive to make | |
799 | other special characters (including erase and kill) | |
800 | identical. | |
3e0098f5 KM |
801 | The applicable |
802 | .I ioctl | |
803 | calls are: | |
02d430a1 KM |
804 | .IP TIOCGETC 12 |
805 | Get the special characters and put them in the specified structure. | |
806 | .IP TIOCSETC 12 | |
807 | Set the special characters to those given in the structure. | |
808 | .LP | |
809 | .Ul "Local mode" | |
810 | .PP | |
3e0098f5 | 811 | The third structure associated with each terminal is a local mode word. |
02d430a1 KM |
812 | The bits of the local mode word are: |
813 | .sp | |
814 | .nf | |
815 | LCRTBS 000001 Backspace on erase rather than echoing erase | |
816 | LPRTERA 000002 Printing terminal erase mode | |
817 | LCRTERA 000004 Erase character echoes as backspace-space-backspace | |
818 | LTILDE 000010 Convert ~ to \` on output (for Hazeltine terminals) | |
819 | LMDMBUF 000020 Stop/start output when carrier drops | |
820 | LLITOUT 000040 Suppress output translations | |
821 | LTOSTOP 000100 Send SIGTTOU for background output | |
822 | LFLUSHO 000200 Output is being flushed | |
823 | LNOHANG 000400 Don't send hangup when carrier drops | |
824 | LETXACK 001000 Diablo style buffer hacking (unimplemented) | |
825 | LCRTKIL 002000 BS-space-BS erase entire line on line kill | |
b06ffe83 | 826 | LPASS8 004000 Pass all 8 bits through on input, in any mode |
02d430a1 KM |
827 | LCTLECH 010000 Echo input control chars as ^X, delete as ^? |
828 | LPENDIN 020000 Retype pending input at next read or input character | |
829 | LDECCTQ 040000 Only ^Q restarts output after ^S, like DEC systems | |
3e0098f5 | 830 | LNOFLSH 100000 Inhibit flushing of pending I/O when an interrupt character is typed. |
02d430a1 KM |
831 | .fi |
832 | .sp | |
833 | The applicable | |
834 | .I ioctl | |
835 | functions are: | |
836 | .IP TIOCLBIS 15 | |
3e0098f5 KM |
837 | .I arg |
838 | is a pointer to an | |
839 | .B int | |
840 | whose value is a mask containing the bits to be set in the local mode word. | |
02d430a1 | 841 | .IP TIOCLBIC |
3e0098f5 KM |
842 | .I arg |
843 | is a pointer to an | |
844 | .B int | |
845 | whose value is a mask containing the bits to be cleared in the local mode word. | |
02d430a1 | 846 | .IP TIOCLSET |
3e0098f5 KM |
847 | .I arg |
848 | is a pointer to an | |
849 | .B int | |
850 | whose value is stored in the local mode word. | |
02d430a1 | 851 | .IP TIOCLGET |
3e0098f5 KM |
852 | .I arg |
853 | is a pointer to an | |
854 | .B int | |
855 | into which the current local mode word is placed. | |
02d430a1 KM |
856 | .LP |
857 | .Ul "Local special chars" | |
858 | .PP | |
859 | The | |
860 | final structure associated with each terminal is the | |
861 | .I ltchars | |
3e0098f5 | 862 | structure which defines control characters |
02d430a1 KM |
863 | for the new terminal driver. |
864 | Its structure is: | |
865 | .nf | |
866 | .sp | |
867 | .ta .5i 1i 2i | |
868 | .ft B | |
869 | struct ltchars { | |
870 | char t_suspc; /* stop process signal */ | |
9313e78d | 871 | char t_dsuspc; /* delayed stop process signal */ |
02d430a1 KM |
872 | char t_rprntc; /* reprint line */ |
873 | char t_flushc; /* flush output (toggles) */ | |
9313e78d | 874 | char t_werasc; /* word erase */ |
02d430a1 KM |
875 | char t_lnextc; /* literal next character */ |
876 | }; | |
877 | .ft R | |
878 | .fi | |
879 | .sp | |
880 | The default values for these characters are ^Z, ^Y, ^R, ^O, ^W, and ^V. | |
881 | A value of \-1 disables the character. | |
882 | .PP | |
883 | The applicable \fIioctl\fR functions are: | |
884 | .IP TIOCSLTC 12 | |
3e0098f5 KM |
885 | .I arg |
886 | is a pointer to an | |
02d430a1 KM |
887 | .I ltchars |
888 | structure which defines the new local special characters. | |
889 | .IP TIOCGLTC 12 | |
3e0098f5 KM |
890 | .I arg |
891 | is a pointer to an | |
02d430a1 KM |
892 | .I ltchars |
893 | structure into which is placed the current set of local special characters. | |
894 | .SH FILES | |
895 | /dev/tty | |
896 | .br | |
897 | /dev/tty* | |
898 | .br | |
899 | /dev/console | |
900 | .SH SEE ALSO | |
9313e78d KM |
901 | csh(1), |
902 | stty(1), | |
903 | ioctl(2), | |
904 | sigvec(2), | |
905 | stty(3C), | |
906 | getty(8), | |
907 | init(8) | |
02d430a1 KM |
908 | .SH BUGS |
909 | Half-duplex terminals are not supported. |