add log device ; unused reset routines are nulldev
[unix-history] / usr / src / usr.bin / window / README
CommitLineData
7edc52ec 1@(#)README 3.5 %G%
84a5ea18 2
533eb3f8
EW
3Compilation notes:
4
7c38ad4d 5 There is only one compiler option:
84a5ea18 6
115fa6f8
EW
7 mc68000 use 68000 byte ordering
8 It should already be defined in the preprocessor.
84a5ea18 9
7c38ad4d 10 The file local.h contains locally tunable constants.
84a5ea18 11
533eb3f8
EW
12 The makefile should be updated with mkmf. The only library it needs
13is termcap (and jobs for 4.1).
84a5ea18 14
7c38ad4d 15 Window only runs on 4.2 machines.
84a5ea18 16
84a5ea18 17
533eb3f8
EW
18A few notes about the internals:
19
20 The window package. Windows are opened by calling wwopen().
21Wwwrite() is the primitive for writing to windows. Wwputc(), wwputs(),
22and wwprintf() are also supported. Some of the outputs to windows are
23delayed. Wwupdate() updates the terminal to match the internal screen
24buffer. Wwspawn() spawns a child process on the other end of a window,
25with it's environment tailored to the window. Visible windows are
26doubly linked in the order of their overlap. Wwadd() inserts a window
115fa6f8
EW
27into the list at a given place. Wwdelete() deletes it. Windows not in
28the list are not visible, though wwwrite() still works.
533eb3f8
EW
29
30 Most functions return -1 on error. Wwopen() returns the null
115fa6f8
EW
31pointer. An error number is saved in wwerrno. Wwerror() returns an
32error string based on wwerrno suitable for printing.
533eb3f8
EW
33
34 The terminal drivers perform all output to the physical terminal,
35including special functions like character and line insertion and
36deletion. The window package keeps a list of known terminals. At
37initialization time, the terminal type is matched against the list to
38find the right terminal driver to use. The last driver, the generic
39driver, matches all terminals and uses the termcap database. The
40interface between the window package the terminal driver is the `tt'
41structure. It contains pointers to functions to perform special
42functions and terminal output, as well as flags about the
43characteristics of the terminal.
44
115fa6f8
EW
45 The IO system is semi-synchronous. Terminal input is signal
46driven, and everything else is done synchronously with a single
47select().
533eb3f8 48
115fa6f8
EW
49 Normally, in both conversation mode and command mode, window
50sleeps in a select() in wwiomux() waiting for data from the
51pseudo-terminals. At the same time, terminal input causes SIGIO which
52is caught by wwrint(). The select() returns when at least one of the
53pseudo-terminals becomes ready for reading.
533eb3f8 54
115fa6f8
EW
55 Wwrint() is the interrupt handler for tty input. It reads input
56into a linear buffer accessed through four pointers:
533eb3f8
EW
57
58 +-------+--------------+----------------+
59 | empty | data | empty |
60 +-------+--------------+----------------+
61 ^ ^ ^ ^
62 | | | |
63 wwib wwibp wwibq wwibe
64
115fa6f8
EW
65Wwrint() appends characters at the end and increments wwibq (*wwibq++ =
66c), and characters are taken from the buffer at wwibp using the
67wwgetc() and wwpeekc() macros. As is the convention in C, wwibq and
68wwibe point to one position beyond the end. In addition, wwrint() will
69do a longjmp(wwjmpbuf) if wwsetjmp is true. This is used by wwiomux()
70to interrupt the select() which would otherwise resume after the
533eb3f8
EW
71interrupt. The macro wwinterrupt() returns true if the input buffer is
72non-empty. Wwupdate(), wwwrite(), and wwiomux() check this condition
73and will return at the first convenient opportunity when it becomes
74true. In the case of wwwrite(), the flag ww_nointr in the window
75structure overrides this. This feature allows the user to interrupt
115fa6f8
EW
76lengthy outputs safely. The structure of the input buffer is designed
77to avoid race conditions without blocking interrupts.
533eb3f8
EW
78
79 Wwiomux() copies pseudo-terminal outputs into their corresponding
80windows. Without anything to do, it blocks in a select(), waiting for
81read ready on pseudo-terminals. Reads are done into per-window buffers
82in the window structures. When there is at least one buffer non-empty,
83wwiomux() finds the top most of these windows and writes it using
115fa6f8
EW
84wwwrite(). Then the process is repeated. A non-blocking select() is
85done after a wwwrite() to pick up any output that may have come in
86during the write, which may take a long time. Specifically, we use
87this to stop output or flush buffer when a pseudo-terminal tells us to
88(we use pty packet mode). The select() blocks only when all of the
89windows' buffers are empty. A wwupdate() is done prior to this, which
90is the only time the screen is guaranteed to be completely up to date.
91Wwiomux() loops until wwinterrupt() becomes true.
92
93 The top level routine for all this is mloop(). In conversation
94mode, it simply calls wwiomux(), which only returns when input is
95available. The input buffer is then written to the pseudo-terminal of
96the current window. If the escape character is found in the input,
97command mode is entered. Otherwise, the process is repeated. In
98command mode, control is transferred to docmd() which returns only when
99conversation mode is reentered. Docmd() and other command processing
100routines typically wait for input in a loop:
101
102 while (wwpeekc() < 0)
533eb3f8
EW
103 wwiomux();
104
115fa6f8 105When the loop terminates, wwgetc() is used to read the input buffer.
533eb3f8
EW
106
107 Output to the physical terminal is handled by the lowest level
108routines of the window package, in the files ttoutput.c and tt.h. The
115fa6f8
EW
109standard IO package is not used, to get better control over buffering
110and to use non-blocking reads in wwrint(). The buffer size is set to
533eb3f8
EW
111approximately one second of output time, based on the baudrate.
112
113 The result of all this complexity is faster response time,
114especially in output stopping and flushing. Wwwrite() checks
115wwinterrupt() after every line. It also calls wwupdate() for each line
116it writes. The output buffer is limited to one second of output time.
117Thus, there is usually only a delay of one to two lines plus one second
118after a ^C or ^S. Also, commands that produce lengthy output can be
119aborted without actually showing all of it on the terminal. (Try the
115fa6f8 120'?' command followed by escape immediately.)