1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Edward Wang at The University of California, Berkeley. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)README 3.13 (Berkeley) 06/06/90 11 */ 12 13Compilation notes: 14 15 There is only one compiler option: 16 17 BYTE_ORDER (used only in ww.h) 18 It should already be defined in machine/endian.h. 19 The code knows about BIG_ENDIAN, LITTLE_ENDIAN, and PDP_ENDIAN. 20 It only cares about byte order in words, so PDP_ENDIAN 21 is the same as LITTLE_ENDIAN. 22 23 Ok, there's another one, STR_DEBUG. It turns on consistency checks 24 in the string allocator. It's been left on since performace doesn't 25 seem to suffer. There's an abort() somewhere when an inconsistency 26 is found. It hasn't happened in years. 27 28 The file local.h contains locally tunable constants. 29 30 The makefile used to be updated with mkmf; it has been changed 31at various times to use cpp -M and, currently, mkdep. The only library 32it needs is termcap. 33 34 Window, as is, only runs on 4.3 machines. 35 36 On 4.2 machines, at least these modifications must be done: 37 38 delete uses of window size ioctls: TIOCGWINSZ, TIOCSWINSZ, 39 struct winsize 40 add to ww.h 41 typedef int fd_set; 42 #define FD_ZERO(s) (*(s) = 0) 43 #define FD_SET(b, s) (*(s) |= 1 << (b)) 44 #define FD_ISSET(b, s) (*(s) & 1 << (b)) 45 add to ww.h 46 #define sigmask(s) (1 << (s) - 1) 47 48 49A few notes about the internals: 50 51 The window package. Windows are opened by calling wwopen(). 52Wwwrite() is the primitive for writing to windows. Wwputc(), wwputs(), 53and wwprintf() are also supported. Some of the outputs to windows are 54delayed. Wwupdate() updates the terminal to match the internal screen 55buffer. Wwspawn() spawns a child process on the other end of a window, 56with its environment tailored to the window. Visible windows are 57doubly linked in the order of their overlap. Wwadd() inserts a window 58into the list at a given place. Wwdelete() deletes it. Windows not in 59the list are not visible, though wwwrite() still works. Window was 60written before the days of X and Sunview, so some of the terminology 61is not standard. 62 63 Most functions return -1 on error. Wwopen() returns the null 64pointer. An error number is saved in wwerrno. Wwerror() returns an 65error string based on wwerrno suitable for printing. 66 67 The terminal drivers perform all output to the physical terminal, 68including special functions like character and line insertion and 69deletion. The window package keeps a list of known terminals. At 70initialization time, the terminal type is matched against the list to 71find the right terminal driver to use. The last driver, the generic 72driver, matches all terminals and uses the termcap database. The 73interface between the window package the terminal driver is the `tt' 74structure. It contains pointers to functions to perform special 75functions and terminal output, as well as flags about the 76characteristics of the terminal. Most of these ideas are borrowed 77from the Maryland window package, which in turn is based on Goslin's 78Emacs. 79 80 The IO system is semi-synchronous. Terminal input is signal 81driven, and everything else is done synchronously with a single 82select(). It is roughly event-driven, though not in a clean way. 83 84 Normally, in both conversation mode and command mode, window 85sleeps in a select() in wwiomux() waiting for data from the 86pseudo-terminals. At the same time, terminal input causes SIGIO which 87is caught by wwrint(). The select() returns when at least one of the 88pseudo-terminals becomes ready for reading. 89 90 Wwrint() is the interrupt handler for tty input. It reads input 91into a linear buffer accessed through four pointers: 92 93 +-------+--------------+----------------+ 94 | empty | data | empty | 95 +-------+--------------+----------------+ 96 ^ ^ ^ ^ 97 | | | | 98 wwib wwibp wwibq wwibe 99 100Wwrint() appends characters at the end and increments wwibq (*wwibq++ 101= c), and characters are taken off the buffer at wwibp using the 102wwgetc() and wwpeekc() macros. As is the convention in C, wwibq 103and wwibe point to one position beyond the end. In addition, 104wwrint() will do a longjmp(wwjmpbuf) if wwsetjmp is true. This is 105used by wwiomux() to interrupt the select() which would otherwise 106resume after the interrupt. (Actually, I hear this is not true, 107but the longjmp feature is used to avoid a race condition as well. 108Anyway, it means I didn't have to depend on a feature in a 109daily-changing kernel, but that's another story.) The macro 110wwinterrupt() returns true if the input buffer is non-empty. 111Wwupdate(), wwwrite(), and wwiomux() check this condition and will 112return at the first convenient opportunity when it becomes true. 113In the case of wwwrite(), the flag ww_nointr in the window structure 114overrides this. This feature allows the user to interrupt lengthy 115outputs safely. The structure of the input buffer is designed to 116avoid race conditions without blocking interrupts. 117 118 Actually, wwsetjmp and wwinterrupt() are part of a software 119interrupt scheme used by the two interrupt catchers wwrint() and 120wwchild(). Asserting the interrupt lets the synchronous parts of 121the program know that there's an interesting asynchronous condition 122(i.e., got a keyboard character, or a child process died) that they 123might want to process before anything else. The synchronous routines 124can check for this condition with wwinterrupt() or by arranging 125that a longjmp() be done. 126 127 Wwiomux() copies pseudo-terminal output into their corresponding 128windows. Without anything to do, it blocks in a select(), waiting for 129read ready on pseudo-terminals. Reads are done into per-window buffers 130in the window structures. When there is at least one buffer non-empty, 131wwiomux() finds the top most of these windows and writes it using 132wwwrite(). Then the process is repeated. A non-blocking select() is 133done after a wwwrite() to pick up any output that may have come in 134during the write, which may take a long time. Specifically, we use 135this to stop output or flush buffer when a pseudo-terminal tells us to 136(we use pty packet mode). The select() blocks only when all of the 137windows' buffers are empty. A wwupdate() is done prior to this, which 138is the only time the screen is guaranteed to be completely up to date. 139Wwiomux() loops until wwinterrupt() becomes true. 140 141 The top level routine for all this is mloop(). In conversation 142mode, it simply calls wwiomux(), which only returns when input is 143available. The input buffer is then written to the pseudo-terminal of 144the current window. If the escape character is found in the input, 145command mode is entered. Otherwise, the process is repeated. In 146command mode, control is transferred to docmd() which returns only when 147conversation mode is reentered. Docmd() and other command processing 148routines typically wait for input in a loop: 149 150 while (wwpeekc() < 0) 151 wwiomux(); 152 153When the loop terminates, wwgetc() is used to read the input buffer. 154 155 Output to the physical terminal is handled by the lowest level 156routines of the window package, in the files ttoutput.c and tt.h. The 157standard IO package is not used, to get better control over buffering 158and to use non-blocking reads in wwrint(). The buffer size is set to 159approximately one second of output time, based on the baudrate. 160 161 The result of all this complexity is faster response time, 162especially in output stopping and flushing. Wwwrite() checks 163wwinterrupt() after every line. It also calls wwupdate() for each line 164it writes. The output buffer is limited to one second of output time. 165Thus, there is usually only a delay of one to two lines plus one second 166after a ^C or ^S. Also, commands that produce lengthy output can be 167aborted without actually showing all of it on the terminal. (Try the 168'?' command followed by escape immediately.) 169