diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
commit | d6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch) | |
tree | ece253b876159b39c620e62b6c9b1174642e070e /usr.bin/window |
initial import of NetBSD tree
Diffstat (limited to 'usr.bin/window')
106 files changed, 16941 insertions, 0 deletions
diff --git a/usr.bin/window/:tt b/usr.bin/window/:tt new file mode 100644 index 00000000000..7ec4352d884 --- /dev/null +++ b/usr.bin/window/:tt @@ -0,0 +1,11 @@ +./"init"16t"end"n2p ++/"move"16t"insline"16t"delline"16t"delchar"n4p ++/"write"16t"putc"16tn2p ++/"clreol"16t"clreos"16t"clear"n3p ++/"scroll_down"16t"scroll_up"16t"setscroll"n3p ++/"setinsert"16t"setmodes"n2p ++/"modes"8t"nmodes"8t"insert"8t"ninsert"n4b ++/"row"16t"col"16t"scrtop"16t"sclbot"n4D ++/"nrow"16t"ncol"16t"hasins"8t"avlmods"8t"wrap"8t"retain"n2D4b ++/"frame" +*./16b diff --git a/usr.bin/window/:tty b/usr.bin/window/:tty new file mode 100644 index 00000000000..2eb61efb4df --- /dev/null +++ b/usr.bin/window/:tty @@ -0,0 +1,6 @@ +./"sgttyb:"8t"ispeed"8t"ospeed"8t"erase"8t"kill"8t"flags"n8tbbC8tC8tx ++/"tchars:"8t"intrc"8t"quitc"8t"startc"8t"stopc"8t"eofc"8t"brkc" ++/8tC8tC8tC8tC8tC8tC ++/"ltchars:suspc"8t"dsuspc"8t"rprntc"8t"flushc"8t"werasc"8t"lnextc" ++/8tC8tC8tC8tC8tC8tC2+ ++/"lmode"16t"ldisc"16t"fflags"nXDX diff --git a/usr.bin/window/:var b/usr.bin/window/:var new file mode 100644 index 00000000000..ff3de6b81bd --- /dev/null +++ b/usr.bin/window/:var @@ -0,0 +1,2 @@ +./"left"16t"right"16t"v_type"8t"v_val"npp4+b3+x +*(.+8)/"name: "S diff --git a/usr.bin/window/:ww b/usr.bin/window/:ww new file mode 100644 index 00000000000..0e99f0af75f --- /dev/null +++ b/usr.bin/window/:ww @@ -0,0 +1,19 @@ +./"state"8t"oflags"nbb++ ++/"forw"16t"back"16t"index"8t"order"nppbb++ ++/"w.nr"16t"w.nc"nDD ++/"w.t"16t"w.b"16t"w.l"16t"w.r"nDDDD ++/"b.nr"16t"b.nc"nDD ++/"b.t"16t"b.b"16t"b.l"16t"b.r"nDDDD ++/"i.nr"16t"i.nc"nDD ++/"i.t"16t"i.b"16t"i.l"16t"i.r"nDDDD ++/"cur.r"16t"cur.c"nDD ++/"win"16t"buf"16t"fmap"16t"nvis"npppp ++/"wstate"8t"modes"8t"insert"8t"mapnl"8t"noupd"n5b ++/"unctrl"8t"nointr"8t"hascurs"8t"hasframe"n4b ++/"ispty"8t"stopped"8t"pty"16t"socket"16t"pid"nbb+3D ++/"ttyname"n11C+ ++/"ob"16t"obe"16t"obp"16t"obq"n4p ++/"center"8t"id"8t"label"nbb++p ++/"alt.nr"16t"alt.nc"nDD ++/"alt.t"16t"alt.b"16t"alt.l"16t"alt.r"nDDDD ++/t diff --git a/usr.bin/window/Makefile b/usr.bin/window/Makefile new file mode 100644 index 00000000000..aed25c5d122 --- /dev/null +++ b/usr.bin/window/Makefile @@ -0,0 +1,23 @@ +# $NetBSD: Makefile,v 1.5 1995/09/28 10:33:55 tls Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/6/93 + +PROG= window +CFLAGS+= -DVMIN_BUG +SRCS= char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \ + context.c error.c lcmd.c lcmd1.c lcmd2.c main.c mloop.c parser1.c \ + parser2.c parser3.c parser4.c parser5.c scanner.c startup.c string.c \ + ttf100.c ttgeneric.c tth19.c tth29.c ttinit.c ttoutput.c tttermcap.c \ + tttvi925.c ttwyse60.c ttwyse75.c ttzapple.c ttzentec.c var.c win.c \ + wwadd.c wwalloc.c wwbox.c wwchild.c wwclose.c wwclreol.c wwclreos.c \ + wwcursor.c wwdata.c wwdelchar.c wwdelete.c wwdelline.c wwdump.c \ + wwend.c wwenviron.c wwerror.c wwflush.c wwframe.c wwgets.c wwinit.c \ + wwinschar.c wwinsline.c wwiomux.c wwlabel.c wwmisc.c wwmove.c \ + wwopen.c wwprintf.c wwpty.c wwputc.c wwputs.c wwredraw.c \ + wwredrawwin.c wwrint.c wwscroll.c wwsize.c wwspawn.c wwsuspend.c \ + wwterminfo.c wwtty.c wwunframe.c wwupdate.c wwwrite.c xx.c xxflush.c \ + compress.c +MAN= window.1 +DPADD= ${LIBTERMCAP} +LDADD= -ltermcap + +.include <bsd.prog.mk> diff --git a/usr.bin/window/README b/usr.bin/window/README new file mode 100644 index 00000000000..42d45b368a3 --- /dev/null +++ b/usr.bin/window/README @@ -0,0 +1,199 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)README 8.1 (Berkeley) 6/6/93 + */ + +Compilation notes: + + Compiler options: + + BYTE_ORDER (used only in ww.h) + It should already be defined in machine/endian.h. + The code knows about BIG_ENDIAN, LITTLE_ENDIAN, and PDP_ENDIAN. + It only cares about byte order in words, so PDP_ENDIAN + is the same as LITTLE_ENDIAN. + OLD_TTY + If you don't have Posix termios, then define this. + VMIN_BUG + Even if you have Posix termios, define this if the MIN and TIME + feature in noncanonical mode doesn't work correctly. + + Ok, there's another one, STR_DEBUG. It turns on consistency checks + in the string allocator. It's been left on since performace doesn't + seem to suffer. There's an abort() somewhere when an inconsistency + is found. It hasn't happened in years. + + The file local.h contains locally tunable constants. + + The makefile used to be updated with mkmf; it has been changed +at various times to use cpp -M and, currently, mkdep. The only library +it needs is termcap. + + Window, as is, only runs on 4.3 (or later) machines. + + On 4.2 machines, at least these modifications must be done: + + delete uses of window size ioctls: TIOCGWINSZ, TIOCSWINSZ, + struct winsize + add to ww.h + typedef int fd_set; + #define FD_ZERO(s) (*(s) = 0) + #define FD_SET(b, s) (*(s) |= 1 << (b)) + #define FD_ISSET(b, s) (*(s) & 1 << (b)) + add to ww.h + #define sigmask(s) (1 << (s) - 1) + + +A few notes about the internals: + + The window package. Windows are opened by calling wwopen(). +Wwwrite() is the primitive for writing to windows. Wwputc(), wwputs(), +and wwprintf() are also supported. Some of the outputs to windows are +delayed. Wwupdate() updates the terminal to match the internal screen +buffer. Wwspawn() spawns a child process on the other end of a window, +with its environment tailored to the window. Visible windows are +doubly linked in the order of their overlap. Wwadd() inserts a window +into the list at a given place. Wwdelete() deletes it. Windows not in +the list are not visible, though wwwrite() still works. Window was +written before the days of X and Sunview, so some of the terminology +is not standard. + + Most functions return -1 on error. Wwopen() returns the null +pointer. An error number is saved in wwerrno. Wwerror() returns an +error string based on wwerrno suitable for printing. + + The terminal drivers perform all output to the physical terminal, +including special functions like character and line insertion and +deletion. The window package keeps a list of known terminals. At +initialization time, the terminal type is matched against the list to +find the right terminal driver to use. The last driver, the generic +driver, matches all terminals and uses the termcap database. The +interface between the window package the terminal driver is the `tt' +structure. It contains pointers to functions to perform special +functions and terminal output, as well as flags about the +characteristics of the terminal. Most of these ideas are borrowed +from the Maryland window package, which in turn is based on Goslin's +Emacs. + + The IO system is semi-synchronous. Terminal input is signal +driven, and everything else is done synchronously with a single +select(). It is roughly event-driven, though not in a clean way. + + Normally, in both conversation mode and command mode, window +sleeps in a select() in wwiomux() waiting for data from the +pseudo-terminals. At the same time, terminal input causes SIGIO which +is caught by wwrint(). The select() returns when at least one of the +pseudo-terminals becomes ready for reading. + + Wwrint() is the interrupt handler for tty input. It reads input +into a linear buffer accessed through four pointers: + + +-------+--------------+----------------+ + | empty | data | empty | + +-------+--------------+----------------+ + ^ ^ ^ ^ + | | | | + wwib wwibp wwibq wwibe + +Wwrint() appends characters at the end and increments wwibq (*wwibq++ += c), and characters are taken off the buffer at wwibp using the +wwgetc() and wwpeekc() macros. As is the convention in C, wwibq +and wwibe point to one position beyond the end. In addition, +wwrint() will do a longjmp(wwjmpbuf) if wwsetjmp is true. This is +used by wwiomux() to interrupt the select() which would otherwise +resume after the interrupt. (Actually, I hear this is not true, +but the longjmp feature is used to avoid a race condition as well. +Anyway, it means I didn't have to depend on a feature in a +daily-changing kernel, but that's another story.) The macro +wwinterrupt() returns true if the input buffer is non-empty. +Wwupdate(), wwwrite(), and wwiomux() check this condition and will +return at the first convenient opportunity when it becomes true. +In the case of wwwrite(), the flag ww_nointr in the window structure +overrides this. This feature allows the user to interrupt lengthy +outputs safely. The structure of the input buffer is designed to +avoid race conditions without blocking interrupts. + + Actually, wwsetjmp and wwinterrupt() are part of a software +interrupt scheme used by the two interrupt catchers wwrint() and +wwchild(). Asserting the interrupt lets the synchronous parts of +the program know that there's an interesting asynchronous condition +(i.e., got a keyboard character, or a child process died) that they +might want to process before anything else. The synchronous routines +can check for this condition with wwinterrupt() or by arranging +that a longjmp() be done. + + Wwiomux() copies pseudo-terminal output into their corresponding +windows. Without anything to do, it blocks in a select(), waiting for +read ready on pseudo-terminals. Reads are done into per-window buffers +in the window structures. When there is at least one buffer non-empty, +wwiomux() finds the top most of these windows and writes it using +wwwrite(). Then the process is repeated. A non-blocking select() is +done after a wwwrite() to pick up any output that may have come in +during the write, which may take a long time. Specifically, we use +this to stop output or flush buffer when a pseudo-terminal tells us to +(we use pty packet mode). The select() blocks only when all of the +windows' buffers are empty. A wwupdate() is done prior to this, which +is the only time the screen is guaranteed to be completely up to date. +Wwiomux() loops until wwinterrupt() becomes true. + + The top level routine for all this is mloop(). In conversation +mode, it simply calls wwiomux(), which only returns when input is +available. The input buffer is then written to the pseudo-terminal of +the current window. If the escape character is found in the input, +command mode is entered. Otherwise, the process is repeated. In +command mode, control is transferred to docmd() which returns only when +conversation mode is reentered. Docmd() and other command processing +routines typically wait for input in a loop: + + while (wwpeekc() < 0) + wwiomux(); + +When the loop terminates, wwgetc() is used to read the input buffer. + + Output to the physical terminal is handled by the lowest level +routines of the window package, in the files ttoutput.c and tt.h. The +standard IO package is not used, to get better control over buffering +and to use non-blocking reads in wwrint(). The buffer size is set to +approximately one second of output time, based on the baudrate. + + The result of all this complexity is faster response time, +especially in output stopping and flushing. Wwwrite() checks +wwinterrupt() after every line. It also calls wwupdate() for each line +it writes. The output buffer is limited to one second of output time. +Thus, there is usually only a delay of one to two lines plus one second +after a ^C or ^S. Also, commands that produce lengthy output can be +aborted without actually showing all of it on the terminal. (Try the +'?' command followed by escape immediately.) diff --git a/usr.bin/window/alias.h b/usr.bin/window/alias.h new file mode 100644 index 00000000000..0722933aa36 --- /dev/null +++ b/usr.bin/window/alias.h @@ -0,0 +1,54 @@ +/* $NetBSD: alias.h,v 1.3 1995/09/28 10:33:59 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)alias.h 8.1 (Berkeley) 6/6/93 + */ + +#define alias var +#define a_name r_name +#define a_buf r_val.v_str +#define a_flags r_val.v_type + + /* a_flags bits, must not interfere with v_type values */ +#define A_INUSE 0x010 /* already inuse */ + +#define alias_set(n, s) var_setstr1(&alias_head, n, s) +#define alias_walk(f, a) var_walk1(alias_head, f, a) +#define alias_unset(n) var_unset1(&alias_head, n) +#define alias_lookup(n) (*var_lookup1(&alias_head, n)) + +struct var *alias_head; diff --git a/usr.bin/window/char.c b/usr.bin/window/char.c new file mode 100644 index 00000000000..cd93c89c66d --- /dev/null +++ b/usr.bin/window/char.c @@ -0,0 +1,156 @@ +/* $NetBSD: char.c,v 1.3 1995/09/28 10:34:00 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)char.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: char.c,v 1.3 1995/09/28 10:34:00 tls Exp $"; +#endif +#endif /* not lint */ + +#include "char.h" + +char _cmap[] = { + _C|_U, _C|_U, _C|_U, _C|_U, /* ^@ - ^C */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^D - ^G */ + _C, _C|_P, _C, _C|_U, /* ^H - ^K */ + _C|_U, _C, _C|_U, _C|_U, /* ^L - ^O */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^P - ^S */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^T - ^W */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^U - ^[ */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^\ - ^_ */ + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U +}; + +char *_unctrl[] = { + "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", + "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O", + "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", + "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_", + " ", "!", "\"", "#", "$", "%", "&", "'", + "(", ")", "*", "+", ",", "-", ".", "/", + "0", "1", "2", "3", "4", "5", "6", "7", + "8", "9", ":", ";", "<", "=", ">", "?", + "@", "A", "B", "C", "D", "E", "F", "G", + "H", "I", "J", "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", "U", "V", "W", + "X", "Y", "Z", "[", "\\", "]", "^", "_", + "`", "a", "b", "c", "d", "e", "f", "g", + "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", + "x", "y", "z", "{", "|", "}", "~", "^?", + "\\200","\\201","\\202","\\203","\\204","\\205","\\206","\\207", + "\\210","\\211","\\212","\\213","\\214","\\215","\\216","\\217", + "\\220","\\221","\\222","\\223","\\224","\\225","\\226","\\227", + "\\230","\\231","\\232","\\233","\\234","\\235","\\236","\\237", + "\\240","\\241","\\242","\\243","\\244","\\245","\\246","\\247", + "\\250","\\251","\\252","\\253","\\254","\\255","\\256","\\257", + "\\260","\\261","\\262","\\263","\\264","\\265","\\266","\\267", + "\\270","\\271","\\272","\\273","\\274","\\275","\\276","\\277", + "\\300","\\301","\\302","\\303","\\304","\\305","\\306","\\307", + "\\310","\\311","\\312","\\313","\\314","\\315","\\316","\\317", + "\\320","\\321","\\322","\\323","\\324","\\325","\\326","\\327", + "\\330","\\331","\\332","\\333","\\334","\\335","\\336","\\337", + "\\340","\\341","\\342","\\343","\\344","\\345","\\346","\\347", + "\\350","\\351","\\352","\\353","\\354","\\355","\\356","\\357", + "\\360","\\361","\\362","\\363","\\364","\\365","\\366","\\367", + "\\370","\\371","\\372","\\373","\\374","\\375","\\376","\\377" +}; diff --git a/usr.bin/window/char.h b/usr.bin/window/char.h new file mode 100644 index 00000000000..bdfb438ee82 --- /dev/null +++ b/usr.bin/window/char.h @@ -0,0 +1,63 @@ +/* $NetBSD: char.h,v 1.3 1995/09/28 10:34:01 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)char.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Macros and things to deal with control characters. + * + * Unctrl() is just like the standard function, except we don't want + * to include curses. + * Isctrl() returns true for all characters less than space and + * greater than or equal to delete. + * Isprt() is tab and all characters not isctrl(). It's used + * by wwwrite(). + * Isunctrl() includes all characters that should be expanded + * using unctrl() by wwwrite() if ww_unctrl is set. + */ + +extern char *_unctrl[]; +extern char _cmap[]; +#define ctrl(c) (c & 0x1f) +#define unctrl(c) (_unctrl[(unsigned char) (c)]) +#define _C 0x01 +#define _P 0x02 +#define _U 0x04 +#define isctrl(c) (_cmap[(unsigned char) (c)] & _C) +#define isprt(c) (_cmap[(unsigned char) (c)] & _P) +#define isunctrl(c) (_cmap[(unsigned char) (c)] & _U) diff --git a/usr.bin/window/cmd.c b/usr.bin/window/cmd.c new file mode 100644 index 00000000000..f8fe11cb25c --- /dev/null +++ b/usr.bin/window/cmd.c @@ -0,0 +1,306 @@ +/* $NetBSD: cmd.c,v 1.3 1995/09/28 10:34:02 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd.c,v 1.3 1995/09/28 10:34:02 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "char.h" + +docmd() +{ + register char c; + register struct ww *w; + char out = 0; + + while (!out && !quit) { + if ((c = wwgetc()) < 0) { + if (terse) + wwsetcursor(0, 0); + else { + wwputs("Command: ", cmdwin); + wwcurtowin(cmdwin); + } + do + wwiomux(); + while ((c = wwgetc()) < 0); + } + if (!terse) + wwputc('\n', cmdwin); + switch (c) { + default: + if (c != escapec) + break; + case 'h': case 'j': case 'k': case 'l': + case 'y': case 'p': + case ctrl('y'): + case ctrl('e'): + case ctrl('u'): + case ctrl('d'): + case ctrl('b'): + case ctrl('f'): + case ctrl('s'): + case ctrl('q'): + case ctrl('['): + if (selwin == 0) { + error("No window."); + continue; + } + } + switch (c) { + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + if ((w = window[c - '1']) == 0) { + error("%c: No such window.", c); + break; + } + setselwin(w); + if (checkproc(selwin) >= 0) + out = 1; + break; + case '%': + if ((w = getwin()) != 0) + setselwin(w); + break; + case ctrl('^'): + if (lastselwin != 0) { + setselwin(lastselwin); + if (checkproc(selwin) >= 0) + out = 1; + } else + error("No previous window."); + break; + case 'c': + if ((w = getwin()) != 0) + closewin(w); + break; + case 'w': + c_window(); + break; + case 'm': + if ((w = getwin()) != 0) + c_move(w); + break; + case 'M': + if ((w = getwin()) != 0) + movewin(w, w->ww_alt.t, w->ww_alt.l); + break; + case 's': + if ((w = getwin()) != 0) + c_size(w); + break; + case 'S': + if ((w = getwin()) != 0) + sizewin(w, w->ww_alt.nr, w->ww_alt.nc); + break; + case 'y': + c_yank(); + break; + case 'p': + c_put(); + break; + case ':': + c_colon(); + break; + case 'h': + (void) wwwrite(selwin, "\b", 1); + break; + case 'j': + (void) wwwrite(selwin, "\n", 1); + break; + case 'k': + (void) wwwrite(selwin, "\033A", 2); + break; + case 'l': + (void) wwwrite(selwin, "\033C", 2); + break; + case ctrl('e'): + wwscroll(selwin, 1); + break; + case ctrl('y'): + wwscroll(selwin, -1); + break; + case ctrl('d'): + wwscroll(selwin, selwin->ww_w.nr / 2); + break; + case ctrl('u'): + wwscroll(selwin, - selwin->ww_w.nr / 2); + break; + case ctrl('f'): + wwscroll(selwin, selwin->ww_w.nr); + break; + case ctrl('b'): + wwscroll(selwin, - selwin->ww_w.nr); + break; + case ctrl('s'): + stopwin(selwin); + break; + case ctrl('q'): + startwin(selwin); + break; + case ctrl('l'): + wwredraw(); + break; + case '?': + c_help(); + break; + case ctrl('['): + if (checkproc(selwin) >= 0) + out = 1; + break; + case ctrl('z'): + wwsuspend(); + break; + case 'q': + c_quit(); + break; + /* debugging stuff */ + case '&': + if (debug) { + c_debug(); + break; + } + default: + if (c == escapec) { + if (checkproc(selwin) >= 0) { + (void) write(selwin->ww_pty, + &escapec, 1); + out = 1; + } + } else { + if (!terse) + wwbell(); + error("Type ? for help."); + } + } + } + if (!quit) + setcmd(0); +} + +struct ww * +getwin() +{ + register int c; + struct ww *w = 0; + + if (!terse) + wwputs("Which window? ", cmdwin); + wwcurtowin(cmdwin); + while ((c = wwgetc()) < 0) + wwiomux(); + if (debug && c == 'c') + w = cmdwin; + else if (debug && c == 'f') + w = framewin; + else if (debug && c == 'b') + w = boxwin; + else if (c >= '1' && c < NWINDOW + '1') + w = window[c - '1']; + else if (c == '+') + w = selwin; + else if (c == '-') + w = lastselwin; + if (w == 0) + wwbell(); + if (!terse) + wwputc('\n', cmdwin); + return w; +} + +checkproc(w) +struct ww *w; +{ + if (w->ww_state != WWS_HASPROC) { + error("No process in window."); + return -1; + } + return 0; +} + +setcmd(new) +char new; +{ + if (new && !incmd) { + if (!terse) + wwadd(cmdwin, &wwhead); + if (selwin != 0) + wwcursor(selwin, 1); + wwcurwin = 0; + } else if (!new && incmd) { + if (!terse) { + wwdelete(cmdwin); + reframe(); + } + if (selwin != 0) + wwcursor(selwin, 0); + wwcurwin = selwin; + } + incmd = new; +} + +setterse(new) +char new; +{ + if (incmd) + if (new && !terse) { + wwdelete(cmdwin); + reframe(); + } else if (!new && terse) + wwadd(cmdwin, &wwhead); + terse = new; +} + +/* + * Set the current window. + */ +setselwin(w) +struct ww *w; +{ + if (selwin == w) + return; + if (selwin != 0) + lastselwin = selwin; + if ((selwin = w) != 0) + front(selwin, 1); +} diff --git a/usr.bin/window/cmd1.c b/usr.bin/window/cmd1.c new file mode 100644 index 00000000000..e26da273c12 --- /dev/null +++ b/usr.bin/window/cmd1.c @@ -0,0 +1,178 @@ +/* $NetBSD: cmd1.c,v 1.3 1995/09/28 10:34:03 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd1.c,v 1.3 1995/09/28 10:34:03 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "char.h" + +c_window() +{ + int col, row, xcol, xrow; + int id; + + if ((id = findid()) < 0) + return; + if (!terse) + wwputs("New window (upper left corner): ", cmdwin); + col = 0; + row = 1; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, row - 1, col - 1, 3, 3); + wwsetcursor(row, col); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, row > 1, 0, + wwnrow - 1, wwncol - 1)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + if (!terse) + wwputs("\nNew window (lower right corner): ", cmdwin); + xcol = col; + xrow = row; + for (;;) { + wwbox(boxwin, row - 1, col - 1, + xrow - row + 3, xcol - col + 3); + wwsetcursor(xrow, xcol); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1)) + { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline, + (char *) 0, 1, 1, default_shellfile, default_shell); +} + +getpos(row, col, minrow, mincol, maxrow, maxcol) +register int *row, *col; +int minrow, mincol; +int maxrow, maxcol; +{ + static int scount; + int count; + char c; + int oldrow = *row, oldcol = *col; + + while ((c = wwgetc()) >= 0) { + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + scount = scount * 10 + c - '0'; + continue; + } + count = scount ? scount : 1; + scount = 0; + switch (c) { + case 'h': + if ((*col -= count) < mincol) + *col = mincol; + break; + case 'H': + *col = mincol; + break; + case 'l': + if ((*col += count) > maxcol) + *col = maxcol; + break; + case 'L': + *col = maxcol; + break; + case 'j': + if ((*row += count) > maxrow) + *row = maxrow; + break; + case 'J': + *row = maxrow; + break; + case 'k': + if ((*row -= count) < minrow) + *row = minrow; + break; + case 'K': + *row = minrow; + break; + case ctrl('['): + if (!terse) + wwputs("\nCancelled. ", cmdwin); + return 3; + case '\r': + return 2; + default: + if (!terse) + wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin); + wwbell(); + } + } + return oldrow != *row || oldcol != *col; +} diff --git a/usr.bin/window/cmd2.c b/usr.bin/window/cmd2.c new file mode 100644 index 00000000000..c986cd89277 --- /dev/null +++ b/usr.bin/window/cmd2.c @@ -0,0 +1,160 @@ +/* $NetBSD: cmd2.c,v 1.3 1995/09/28 10:34:05 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd2.c,v 1.3 1995/09/28 10:34:05 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" + +char *help_shortcmd[] = { + "# Select window # and return to conversation mode", + "%# Select window # but stay in command mode", + "escape Return to conversation mode without changing window", + "^^ Return to conversation mode and change to previous window", + "c# Close window #", + "w Open a new window", + "m# Move window #", + "M# Move window # to its previous position", + "s# Change the size of window #", + "S# Change window # to its previous size", + "^Y Scroll up one line", + "^E Scroll down one line", + "^U Scroll up half a window", + "^D Scroll down half a window", + "^B Scroll up a full window", + "^F Scroll down a full window", + "h Move cursor left", + "j Move cursor down", + "k Move cursor up", + "l Move cursor right", + "y Yank", + "p Put", + "^S Stop output in current window", + "^Q Restart output in current window", + "^L Redraw screen", + "^Z Suspend", + "q Quit", + ": Enter a long command", + 0 +}; +char *help_longcmd[] = { + ":alias name string ... Make `name' an alias for `string ...'", + ":alias Show all aliases", + ":close # ... Close windows", + ":close all Close all windows", + ":cursor modes Set the cursor modes", + ":echo # string ... Print `string ...' in window #", + ":escape c Set escape character to `c'", + ":foreground # flag Make # a foreground window, if `flag' is true", + ":label # string Set label of window # to `string'", + ":list List all open windows", + ":default_nline lines Set default window buffer size to `lines'", + ":default_shell string ...", + " Set default shell to `string ...'", + ":default_smooth flag Set default smooth scroll flag", + ":select # Select window #", + ":smooth # flag Set window # to smooth scroll mode", + ":source filename Execute commands in `filename'", + ":terse flag Set terse mode", + ":unalias name Undefine `name' as an alias", + ":unset variable Deallocate `variable'", + ":variable List all variables", + ":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]", + " Open a window at `row', `col' of size `nrow', `ncol',", + " with `nline' lines in the buffer, and `label'", + ":write # string ... Write `string ...' to window # as input", + 0 +}; + +c_help() +{ + register struct ww *w; + + if ((w = openiwin(wwnrow - 3, "Help")) == 0) { + error("Can't open help window: %s.", wwerror()); + return; + } + wwprintf(w, "The escape character is %c.\n", escapec); + wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n"); + if (help_print(w, "Short commands", help_shortcmd) >= 0) + (void) help_print(w, "Long commands", help_longcmd); + closeiwin(w); +} + +help_print(w, name, list) +register struct ww *w; +char *name; +register char **list; +{ + wwprintf(w, "%s:\n\n", name); + while (*list) + switch (more(w, 0)) { + case 0: + wwputs(*list++, w); + wwputc('\n', w); + break; + case 1: + wwprintf(w, "%s: (continued)\n\n", name); + break; + case 2: + return -1; + } + return more(w, 1) == 2 ? -1 : 0; +} + +c_quit() +{ + char oldterse = terse; + + setterse(0); + wwputs("Really quit [yn]? ", cmdwin); + wwcurtowin(cmdwin); + while (wwpeekc() < 0) + wwiomux(); + if (wwgetc() == 'y') { + wwputs("Yes", cmdwin); + quit++; + } else + wwputc('\n', cmdwin); + setterse(!quit && oldterse); +} diff --git a/usr.bin/window/cmd3.c b/usr.bin/window/cmd3.c new file mode 100644 index 00000000000..d89fa5eca05 --- /dev/null +++ b/usr.bin/window/cmd3.c @@ -0,0 +1,71 @@ +/* $NetBSD: cmd3.c,v 1.3 1995/09/28 10:34:07 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd3.c,v 1.3 1995/09/28 10:34:07 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "string.h" + +setescape(esc) +register char *esc; +{ + if (*esc == '^') { + if (esc[1] != 0) + escapec = esc[1] & 0x1f; + else + escapec = '^'; + } else + escapec = *esc; +} + +setlabel(w, label) +register struct ww *w; +char *label; +{ + if (w->ww_label != 0) + str_free(w->ww_label); + if ((w->ww_label = str_cpy(label)) == 0) + return -1; + return 0; +} diff --git a/usr.bin/window/cmd4.c b/usr.bin/window/cmd4.c new file mode 100644 index 00000000000..23930c8271b --- /dev/null +++ b/usr.bin/window/cmd4.c @@ -0,0 +1,62 @@ +/* $NetBSD: cmd4.c,v 1.3 1995/09/28 10:34:08 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd4.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd4.c,v 1.3 1995/09/28 10:34:08 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" + +c_colon() +{ + char oldterse = terse; + char buf[512]; + + setterse(0); + wwputc(':', cmdwin); + wwgets(buf, wwncol - 3, cmdwin); + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + setterse(oldterse); + if (dolongcmd(buf, (struct value *)0, 0) < 0) + error("Out of memory."); +} diff --git a/usr.bin/window/cmd5.c b/usr.bin/window/cmd5.c new file mode 100644 index 00000000000..45f3815cca7 --- /dev/null +++ b/usr.bin/window/cmd5.c @@ -0,0 +1,135 @@ +/* $NetBSD: cmd5.c,v 1.3 1995/09/28 10:34:09 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd5.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd5.c,v 1.3 1995/09/28 10:34:09 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" + +/* + * Window movement. + */ + +c_move(w) +register struct ww *w; +{ + int col, row; + int mincol, minrow; + int maxcol, maxrow; + int curcol, currow; + + if (!terse) + wwputs("New window position: ", cmdwin); + col = w->ww_w.l; + row = w->ww_w.t; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, row - 1, col - 1, w->ww_w.nr + 2, w->ww_w.nc + 2); + getminmax(row, w->ww_w.nr, 1, wwnrow, + &currow, &minrow, &maxrow); + getminmax(col, w->ww_w.nc, 0, wwncol, + &curcol, &mincol, &maxcol); + wwsetcursor(currow, curcol); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + movewin(w, row, col); +} + +movewin(w, row, col) +register struct ww *w; +{ + struct ww *back = w->ww_back; + + w->ww_alt.t = w->ww_w.t; + w->ww_alt.l = w->ww_w.l; + wwdelete(w); + wwmove(w, row, col); + wwadd(w, back); + reframe(); +} + +/* + * Weird stufff, don't ask. + */ +getminmax(x, n, a, b, curx, minx, maxx) +register x, n, a, b; +int *curx, *minx, *maxx; +{ + if (x < 0) + *curx = x + n - 1; + else + *curx = x; + + if (x <= a) + *minx = 1 - n; + else if (x <= b - n) + *minx = a; + else + *minx = b - n; + + if (x >= b - n) + *maxx = b - 1; + else if (x >= a) + *maxx = b - n; + else + *maxx = a; +} diff --git a/usr.bin/window/cmd6.c b/usr.bin/window/cmd6.c new file mode 100644 index 00000000000..66dc5a1ba2f --- /dev/null +++ b/usr.bin/window/cmd6.c @@ -0,0 +1,116 @@ +/* $NetBSD: cmd6.c,v 1.3 1995/09/28 10:34:10 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd6.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd6.c,v 1.3 1995/09/28 10:34:10 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "string.h" +#include "char.h" + +/* + * Debugging commands. + */ + +c_debug() +{ + register struct ww *w; + + if (!terse) + wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin); + wwcurtowin(cmdwin); + while (wwpeekc() < 0) + wwiomux(); + if (!terse) + wwputc('\n', cmdwin); + switch (wwgetc()) { + case 'm': + wwdumpsmap(); + break; + case 'n': + wwdumpns(); + break; + case 'o': + wwdumpos(); + break; + case 's': + debug_str(); + break; + case 'v': + if ((w = getwin()) != 0) + wwdumpnvis(w); + break; + case 'w': + if ((w = getwin()) != 0) + wwdumpwin(w); + break; + default: + wwbell(); + } +} + +#ifdef STR_DEBUG +debug_str() +{ + register struct ww *w; + struct string *s; + + if ((w = openiwin(wwnrow - 3, "Allocated Strings")) == 0) { + error("Can't open string window: %s.", wwerror()); + return; + } + for (s = str_head.s_forw; s != &str_head; s = s->s_forw) { + if (more(w, 0) == 2) + goto out; + wwprintf(w, "(0x%x)\t\"%s\"\n", s->s_data, s->s_data); + } + waitnl(w); +out: + closeiwin(w); +} +#else +debug_str() +{ + error("No string debugging."); +} +#endif diff --git a/usr.bin/window/cmd7.c b/usr.bin/window/cmd7.c new file mode 100644 index 00000000000..4884b20a7f3 --- /dev/null +++ b/usr.bin/window/cmd7.c @@ -0,0 +1,277 @@ +/* $NetBSD: cmd7.c,v 1.3 1995/09/28 10:34:12 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd7.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: cmd7.c,v 1.3 1995/09/28 10:34:12 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "string.h" + +/* + * Window size. + */ + +c_size(w) +register struct ww *w; +{ + int col, row; + + if (!terse) + wwputs("New window size (lower right corner): ", cmdwin); + col = MIN(w->ww_w.r, wwncol) - 1; + row = MIN(w->ww_w.b, wwnrow) - 1; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1, + row - w->ww_w.t + 3, col - w->ww_w.l + 3); + wwsetcursor(row, col); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l, + wwnrow - 1, wwncol - 1)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1); +} + +/* + * Yank and put + */ + +struct yb { + char *line; + int length; + struct yb *link; +}; +struct yb *yb_head, *yb_tail; + +c_yank() +{ + struct ww *w = selwin; + int col1, row1; + int col2, row2; + int r, c; + + if (!terse) + wwputs("Yank starting position: ", cmdwin); + wwcursor(w, 0); + row1 = w->ww_cur.r; + col1 = w->ww_cur.c; + for (;;) { + wwsetcursor(row1, col1); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l, + w->ww_i.b - 1, w->ww_i.r - 1)) { + case 3: + goto out; + case 2: + break; + case 1: + case 0: + continue; + } + break; + } + if (!terse) + wwputs("\nYank ending position: ", cmdwin); + row2 = row1; + col2 = col1; + for (;;) { + wwsetcursor(row2, col2); + while (wwpeekc() < 0) + wwiomux(); + r = row2; + c = col2; + switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l, + w->ww_i.b - 1, w->ww_i.r - 1)) { + case 3: + yank_highlight(row1, col1, r, c); + goto out; + case 2: + break; + case 1: + yank_highlight(row1, col1, r, c); + yank_highlight(row1, col1, row2, col2); + case 0: + continue; + } + break; + } + if (row2 < row1 || row2 == row1 && col2 < col1) { + r = row1; + c = col1; + row1 = row2; + col1 = col2; + row2 = r; + col2 = c; + } + unyank(); + c = col1; + for (r = row1; r < row2; r++) { + yank_line(r, c, w->ww_b.r); + c = w->ww_b.l; + } + yank_line(r, c, col2); + yank_highlight(row1, col1, row2, col2); + if (!terse) + wwputc('\n', cmdwin); +out: + wwcursor(w, 1); +} + +yank_highlight(row1, col1, row2, col2) +{ + struct ww *w = selwin; + int r, c; + + if ((wwavailmodes & WWM_REV) == 0) + return; + if (row2 < row1 || row2 == row1 && col2 < col1) { + r = row1; + c = col1; + row1 = row2; + col1 = col2; + row2 = r; + col2 = c; + } + c = col1; + for (r = row1; r < row2; r++) { + yank_highlight_line(r, c, w->ww_b.r); + c = w->ww_b.l; + } + yank_highlight_line(r, c, col2); +} + +yank_highlight_line(r, c, cend) +{ + struct ww *w = selwin; + char *win; + + if (r < w->ww_i.t || r >= w->ww_i.b) + return; + if (c < w->ww_i.l) + c = w->ww_i.l; + if (cend >= w->ww_i.r) + cend = w->ww_i.r; + for (win = w->ww_win[r] + c; c < cend; c++, win++) { + *win ^= WWM_REV; + if (wwsmap[r][c] == w->ww_index) { + if (*win == 0) + w->ww_nvis[r]++; + else if (*win == WWM_REV) + w->ww_nvis[r]--; + wwns[r][c].c_m ^= WWM_REV; + wwtouched[r] |= WWU_TOUCHED; + } + } +} + +unyank() +{ + struct yb *yp, *yq; + + for (yp = yb_head; yp; yp = yq) { + yq = yp->link; + str_free(yp->line); + free((char *) yp); + } + yb_head = yb_tail = 0; +} + +yank_line(r, c, cend) +{ + struct yb *yp; + int nl = 0; + int n; + union ww_char *bp; + char *cp; + + if (c == cend) + return; + if ((yp = (struct yb *) malloc(sizeof *yp)) == 0) + return; + yp->link = 0; + nl = cend == selwin->ww_b.r; + bp = selwin->ww_buf[r]; + for (cend--; cend >= c; cend--) + if (bp[cend].c_c != ' ') + break; + yp->length = n = cend - c + 1; + if (nl) + yp->length++; + yp->line = str_alloc(yp->length + 1); + for (bp += c, cp = yp->line; --n >= 0;) + *cp++ = bp++->c_c; + if (nl) + *cp++ = '\n'; + *cp = 0; + if (yb_head) + yb_tail = yb_tail->link = yp; + else + yb_head = yb_tail = yp; +} + +c_put() +{ + struct yb *yp; + + for (yp = yb_head; yp; yp = yp->link) + (void) write(selwin->ww_pty, yp->line, yp->length); +} diff --git a/usr.bin/window/compress.c b/usr.bin/window/compress.c new file mode 100644 index 00000000000..ba77458501f --- /dev/null +++ b/usr.bin/window/compress.c @@ -0,0 +1,905 @@ +/* $NetBSD: compress.c,v 1.3 1995/09/28 10:34:13 tls Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)compress.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: compress.c,v 1.3 1995/09/28 10:34:13 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + + /* special */ +#include <stdio.h> +#include <fcntl.h> +int cc_trace = 0; +FILE *cc_trace_fp; + + /* tunable parameters */ + +int cc_reverse = 1; +int cc_sort = 0; +int cc_chop = 0; + +int cc_token_max = 8; /* <= TOKEN_MAX */ +int cc_token_min = 2; /* > tt.tt_put_token_cost */ +int cc_npass0 = 1; +int cc_npass1 = 1; + +int cc_bufsize = 1024 * 3; /* XXX, or 80 * 24 * 2 */ + +int cc_ntoken = 8192; + +#define cc_weight XXX +#ifndef cc_weight +int cc_weight = 0; +#endif + +#define TOKEN_MAX 16 + +struct cc { + char string[TOKEN_MAX]; + char length; + char flag; +#ifndef cc_weight + short weight; +#endif + long time; /* time last seen */ + short bcount; /* count in this buffer */ + short ccount; /* count in compression */ + short places; /* places in the buffer */ + short code; /* token code */ + struct cc *qforw, *qback; + struct cc *hforw, **hback; +}; + +short cc_thresholds[TOKEN_MAX + 1]; +#define thresh(length) (cc_thresholds[length]) +#define threshp(code, count, length) \ + ((code) >= 0 || (short) (count) >= cc_thresholds[length]) + +#ifndef cc_weight +short cc_wthresholds[TOKEN_MAX + 1]; +#define wthresh(length) (cc_wthresholds[length]) +#define wthreshp(weight, length) ((short) (weight) >= cc_wthresholds[length]) +#else +#define wthreshp(weight, length) (0) +#endif + +#ifndef cc_weight +short cc_wlimits[TOKEN_MAX + 1]; +#define wlimit(length) (cc_wlimits[length]) +#endif + +#define put_token_score(length) ((length) - tt.tt_put_token_cost) + +int cc_score_adjustments[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */ +#define score_adjust(score, p) \ + do { \ + int length = (p)->length; \ + int ccount = (p)->ccount; \ + if (threshp((p)->code, ccount, length) || \ + wthreshp((p)->weight, length)) /* XXX */ \ + (score) -= length - tt.tt_put_token_cost; \ + else \ + (score) += cc_score_adjustments[length][ccount]; \ + } while (0) + +int cc_initial_scores[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */ + +struct cc cc_q0a, cc_q0b, cc_q1a, cc_q1b; + +#define qinsert(p1, p2) \ + do { \ + register struct cc *forw = (p1)->qforw; \ + register struct cc *back = (p1)->qback; \ + back->qforw = forw; \ + forw->qback = back; \ + forw = (p2)->qforw; \ + (p1)->qforw = forw; \ + forw->qback = (p1); \ + (p2)->qforw = (p1); \ + (p1)->qback = (p2); \ + } while (0) + +#define qinsertq(q, p) \ + ((q)->qforw == (q) ? 0 : \ + ((q)->qback->qforw = (p)->qforw, \ + (p)->qforw->qback = (q)->qback, \ + (q)->qforw->qback = (p), \ + (p)->qforw = (q)->qforw, \ + (q)->qforw = (q), \ + (q)->qback = (q))) + +#define H (14) +#define HSIZE (1 << H) +#define hash(h, c) ((((h) >> H - 8 | (h) << 8) ^ (c)) & HSIZE - 1) + +char *cc_buffer; +struct cc **cc_output; /* the output array */ +short *cc_places[TOKEN_MAX + 1]; +short *cc_hashcodes; /* for computing hashcodes */ +struct cc **cc_htab; /* the hash table */ +struct cc **cc_tokens; /* holds all the active tokens */ +struct cc_undo { + struct cc **pos; + struct cc *val; +} *cc_undo; + +long cc_time, cc_time0; + +char *cc_tt_ob, *cc_tt_obe; + +ccinit() +{ + register i, j; + register struct cc *p; + + if (tt.tt_token_max > cc_token_max) + tt.tt_token_max = cc_token_max; + if (tt.tt_token_min < cc_token_min) + tt.tt_token_min = cc_token_min; + if (tt.tt_token_min > tt.tt_token_max) { + tt.tt_ntoken = 0; + return 0; + } + if (tt.tt_ntoken > cc_ntoken / 2) /* not likely */ + tt.tt_ntoken = cc_ntoken / 2; +#define C(x) (sizeof (x) / sizeof *(x)) + for (i = 0; i < C(cc_thresholds); i++) { + int h = i - tt.tt_put_token_cost; + if (h > 0) + cc_thresholds[i] = + (tt.tt_set_token_cost + 1 + h - 1) / h + 1; + else + cc_thresholds[i] = 0; + } + for (i = 0; i < C(cc_score_adjustments); i++) { + int t = cc_thresholds[i]; + for (j = 0; j < C(*cc_score_adjustments); j++) { + if (j >= t) + cc_score_adjustments[i][j] = + - (i - tt.tt_put_token_cost); + else if (j < t - 1) + cc_score_adjustments[i][j] = 0; + else + /* + * cost now is + * length * (ccount + 1) a + * cost before was + * set-token-cost + length + + * ccount * put-token-cost b + * the score adjustment is (b - a) + */ + cc_score_adjustments[i][j] = + tt.tt_set_token_cost + i + + j * tt.tt_put_token_cost - + i * (j + 1); + if (j >= t) + cc_initial_scores[i][j] = 0; + else + /* + * - (set-token-cost + + * (length - put-token-cost) - + * (length - put-token-cost) * ccount) + */ + cc_initial_scores[i][j] = + - (tt.tt_set_token_cost + + (i - tt.tt_put_token_cost) - + (i - tt.tt_put_token_cost) * j); + } + } +#ifndef cc_weight + for (i = 1; i < C(cc_wthresholds); i++) { + cc_wthresholds[i] = + ((tt.tt_set_token_cost + tt.tt_put_token_cost) / i + + i / 5 + 1) * + cc_weight + 1; + cc_wlimits[i] = cc_wthresholds[i] + cc_weight; + } +#endif +#undef C + if ((cc_output = (struct cc **) + malloc((unsigned) cc_bufsize * sizeof *cc_output)) == 0) + goto nomem; + if ((cc_hashcodes = (short *) + malloc((unsigned) cc_bufsize * sizeof *cc_hashcodes)) == 0) + goto nomem; + if ((cc_htab = (struct cc **) malloc(HSIZE * sizeof *cc_htab)) == 0) + goto nomem; + if ((cc_tokens = (struct cc **) + malloc((unsigned) + (cc_ntoken + tt.tt_token_max - tt.tt_token_min + 1) * + sizeof *cc_tokens)) == 0) + goto nomem; + if ((cc_undo = (struct cc_undo *) + malloc((unsigned) cc_bufsize * sizeof *cc_undo)) == 0) + goto nomem; + for (i = tt.tt_token_min; i <= tt.tt_token_max; i++) + if ((cc_places[i] = (short *) + malloc((unsigned) cc_bufsize * sizeof **cc_places)) == 0) + goto nomem; + cc_q0a.qforw = cc_q0a.qback = &cc_q0a; + cc_q0b.qforw = cc_q0b.qback = &cc_q0b; + cc_q1a.qforw = cc_q1a.qback = &cc_q1a; + cc_q1b.qforw = cc_q1b.qback = &cc_q1b; + if ((p = (struct cc *) malloc((unsigned) cc_ntoken * sizeof *p)) == 0) + goto nomem; + for (i = 0; i < tt.tt_ntoken; i++) { + p->code = i; + p->time = -1; + p->qback = cc_q0a.qback; + p->qforw = &cc_q0a; + p->qback->qforw = p; + cc_q0a.qback = p; + p++; + } + for (; i < cc_ntoken; i++) { + p->code = -1; + p->time = -1; + p->qback = cc_q1a.qback; + p->qforw = &cc_q1a; + p->qback->qforw = p; + cc_q1a.qback = p; + p++; + } + cc_tt_ob = tt_ob; + cc_tt_obe = tt_obe; + if ((cc_buffer = malloc((unsigned) cc_bufsize)) == 0) + goto nomem; + return 0; +nomem: + wwerrno = WWE_NOMEM; + return -1; +} + +ccstart() +{ + int ccflush(); + + ttflush(); + tt_obp = tt_ob = cc_buffer; + tt_obe = tt_ob + cc_bufsize; + tt.tt_flush = ccflush; + if (cc_trace) { + cc_trace_fp = fopen("window-trace", "a"); + (void) fcntl(fileno(cc_trace_fp), F_SETFD, 1); + } + ccreset(); +} + +ccreset() +{ + register struct cc *p; + + bzero((char *) cc_htab, HSIZE * sizeof *cc_htab); + for (p = cc_q0a.qforw; p != &cc_q0a; p = p->qforw) + p->hback = 0; + for (p = cc_q1a.qforw; p != &cc_q1a; p = p->qforw) + p->hback = 0; +} + +ccend() +{ + + ttflush(); + tt_obp = tt_ob = cc_tt_ob; + tt_obe = cc_tt_obe; + tt.tt_flush = 0; + if (cc_trace_fp != NULL) { + (void) fclose(cc_trace_fp); + cc_trace_fp = NULL; + } +} + +ccflush() +{ + int bufsize = tt_obp - tt_ob; + int n; + + if (tt_ob != cc_buffer) + abort(); + if (cc_trace_fp != NULL) { + (void) fwrite(tt_ob, 1, bufsize, cc_trace_fp); + (void) putc(-1, cc_trace_fp); + } + tt.tt_flush = 0; + (*tt.tt_compress)(1); + if (bufsize < tt.tt_token_min) { + ttflush(); + goto out; + } + tt_obp = tt_ob = cc_tt_ob; + tt_obe = cc_tt_obe; + cc_time0 = cc_time; + cc_time += bufsize; + n = cc_sweep_phase(cc_buffer, bufsize, cc_tokens); + cc_compress_phase(cc_output, bufsize, cc_tokens, n); + cc_output_phase(cc_buffer, cc_output, bufsize); + ttflush(); + tt_obp = tt_ob = cc_buffer; + tt_obe = cc_buffer + cc_bufsize; +out: + (*tt.tt_compress)(0); + tt.tt_flush = ccflush; +} + +cc_sweep_phase(buffer, bufsize, tokens) + char *buffer; + struct cc **tokens; +{ + register struct cc **pp = tokens; + register i, n; +#ifdef STATS + int nn, ii; +#endif + +#ifdef STATS + if (verbose >= 0) + time_begin(); + if (verbose > 0) + printf("Sweep:"); +#endif + cc_sweep0(buffer, bufsize, tt.tt_token_min - 1); +#ifdef STATS + ntoken_stat = 0; + nn = 0; + ii = 0; +#endif + for (i = tt.tt_token_min; i <= tt.tt_token_max; i++) { +#ifdef STATS + if (verbose > 0) { + if (ii > 7) { + printf("\n "); + ii = 0; + } + ii++; + printf(" (%d", i); + (void) fflush(stdout); + } +#endif + n = cc_sweep(buffer, bufsize, pp, i); + pp += n; +#ifdef STATS + if (verbose > 0) { + if (--n > 0) { + printf(" %d", n); + nn += n; + } + putchar(')'); + } +#endif + } + qinsertq(&cc_q1b, &cc_q1a); +#ifdef STATS + if (verbose > 0) + printf("\n %d tokens, %d candidates\n", + ntoken_stat, nn); + if (verbose >= 0) + time_end(); +#endif + return pp - tokens; +} + +cc_sweep0(buffer, n, length) + char *buffer; +{ + register char *p; + register short *hc; + register i; + register short c; + register short pc = tt.tt_padc; + + /* n and length are at least 1 */ + p = buffer++; + hc = cc_hashcodes; + i = n; + do { + if ((*hc++ = *p++) == pc) + hc[-1] = -1; + } while (--i); + while (--length) { + p = buffer++; + hc = cc_hashcodes; + for (i = n--; --i;) { + if ((c = *p++) == pc || *hc < 0) + c = -1; + else + c = hash(*hc, c); + *hc++ = c; + } + } +} + +cc_sweep(buffer, bufsize, tokens, length) + char *buffer; + struct cc **tokens; + register length; +{ + register struct cc *p; + register char *cp; + register i; + short *hc; + short *places = cc_places[length]; + struct cc **pp = tokens; + short threshold = thresh(length); +#ifndef cc_weight + short wthreshold = wthresh(length); + short limit = wlimit(length); +#endif + int time; + short pc = tt.tt_padc; + + i = length - 1; + bufsize -= i; + cp = buffer + i; + hc = cc_hashcodes; + time = cc_time0; + for (i = 0; i < bufsize; i++, time++) { + struct cc **h; + + { + register short *hc1 = hc; + register short c = *cp++; + register short hh; + if ((hh = *hc1) < 0 || c == pc) { + *hc1++ = -1; + hc = hc1; + continue; + } + h = cc_htab + (*hc1++ = hash(hh, c)); + hc = hc1; + } + for (p = *h; p != 0; p = p->hforw) + if (p->length == (char) length) { + register char *p1 = p->string; + register char *p2 = cp - length; + register n = length; + do + if (*p1++ != *p2++) + goto fail; + while (--n); + break; + fail:; + } + if (p == 0) { + p = cc_q1a.qback; + if (p == &cc_q1a || + p->time >= cc_time0 && p->length == (char) length) + continue; + if (p->hback != 0) + if ((*p->hback = p->hforw) != 0) + p->hforw->hback = p->hback; + { + register char *p1 = p->string; + register char *p2 = cp - length; + register n = length; + do + *p1++ = *p2++; + while (--n); + } + p->length = length; +#ifndef cc_weight + p->weight = cc_weight; +#endif + p->time = time; + p->bcount = 1; + p->ccount = 0; + p->flag = 0; + if ((p->hforw = *h) != 0) + p->hforw->hback = &p->hforw; + *h = p; + p->hback = h; + qinsert(p, &cc_q1a); + places[i] = -1; + p->places = i; +#ifdef STATS + ntoken_stat++; +#endif + } else if (p->time < cc_time0) { +#ifndef cc_weight + if ((p->weight += p->time - time) < 0) + p->weight = cc_weight; + else if ((p->weight += cc_weight) > limit) + p->weight = limit; +#endif + p->time = time; + p->bcount = 1; + p->ccount = 0; + if (p->code >= 0) { + p->flag = 1; + *pp++ = p; + } else +#ifndef cc_weight + if (p->weight >= wthreshold) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } else +#endif + { + p->flag = 0; + qinsert(p, &cc_q1a); + } + places[i] = -1; + p->places = i; +#ifdef STATS + ntoken_stat++; +#endif + } else if (p->time + length > time) { + /* + * overlapping token, don't count as two and + * don't update time, but do adjust weight to offset + * the difference + */ +#ifndef cc_weight + if (cc_weight != 0) { /* XXX */ + p->weight += time - p->time; + if (!p->flag && p->weight >= wthreshold) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } + } +#endif + places[i] = p->places; + p->places = i; + } else { +#ifndef cc_weight + if ((p->weight += p->time - time) < 0) + p->weight = cc_weight; + else if ((p->weight += cc_weight) > limit) + p->weight = limit; +#endif + p->time = time; + p->bcount++; + if (!p->flag && + /* code must be < 0 if flag false here */ + (p->bcount >= threshold +#ifndef cc_weight + || p->weight >= wthreshold +#endif + )) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } + places[i] = p->places; + p->places = i; + } + } + if ((i = pp - tokens) > 0) { + *pp = 0; + if (cc_reverse) + cc_sweep_reverse(tokens, places); + if (cc_sort && i > 1) { + int cc_token_compare(); + qsort((char *) tokens, i, sizeof *tokens, + cc_token_compare); + } + if (cc_chop) { + if ((i = i * cc_chop / 100) == 0) + i = 1; + tokens[i] = 0; + } + i++; + } + return i; +} + +cc_sweep_reverse(pp, places) + register struct cc **pp; + register short *places; +{ + register struct cc *p; + register short front, back, t; + + while ((p = *pp++) != 0) { + back = -1; + t = p->places; + /* the list is never empty */ + do { + front = places[t]; + places[t] = back; + back = t; + } while ((t = front) >= 0); + p->places = back; + } +} + +cc_compress_phase(output, bufsize, tokens, ntoken) + struct cc **output; + struct cc **tokens; +{ + register i; + + bzero((char *) output, bufsize * sizeof *output); + for (i = 0; i < cc_npass0; i++) + cc_compress_phase1(output, tokens, ntoken, 0); + for (i = 0; i < cc_npass1; i++) + cc_compress_phase1(output, tokens, ntoken, 1); + cc_compress_cleanup(output, bufsize); +} + +cc_compress_phase1(output, tokens, ntoken, flag) + register struct cc **output; + struct cc **tokens; +{ + register struct cc **pp; +#ifdef STATS + register int i = 0; + int nt = 0, cc = 0, nc = 0; +#endif + +#ifdef STATS + if (verbose >= 0) + time_begin(); + if (verbose > 0) + printf("Compress:"); +#endif + pp = tokens; + while (pp < tokens + ntoken) { +#ifdef STATS + if (verbose > 0) { + ntoken_stat = 0; + ccount_stat = 0; + ncover_stat = 0; + if (i > 2) { + printf("\n "); + i = 0; + } + i++; + printf(" (%d", (*pp)->length); + (void) fflush(stdout); + } +#endif + pp += cc_compress(output, pp, flag); +#ifdef STATS + if (verbose > 0) { + printf(" %dt %du %dc)", ntoken_stat, ccount_stat, + ncover_stat); + nt += ntoken_stat; + cc += ccount_stat; + nc += ncover_stat; + } +#endif + } +#ifdef STATS + if (verbose > 0) + printf("\n total: (%dt %du %dc)\n", nt, cc, nc); + if (verbose >= 0) + time_end(); +#endif +} + +cc_compress_cleanup(output, bufsize) + register struct cc **output; +{ + register struct cc **end; + + /* the previous output phase may have been interrupted */ + qinsertq(&cc_q0b, &cc_q0a); + for (end = output + bufsize; output < end;) { + register struct cc *p; + register length; + if ((p = *output) == 0) { + output++; + continue; + } + length = p->length; + if (!p->flag) { + } else if (p->code >= 0) { + qinsert(p, &cc_q0b); + p->flag = 0; + } else if (p->ccount == 0) { + *output = 0; + } else if (p->ccount >= thresh(length) +#ifndef cc_weight + || wthreshp(p->weight, length) +#endif + ) { + p->flag = 0; + } else { + p->ccount = 0; + *output = 0; + } + output += length; + } +} + +cc_compress(output, tokens, flag) + struct cc **output; + struct cc **tokens; + char flag; +{ + struct cc **pp = tokens; + register struct cc *p = *pp++; + int length = p->length; + int threshold = thresh(length); +#ifndef cc_weight + short wthreshold = wthresh(length); +#endif + short *places = cc_places[length]; + int *initial_scores = cc_initial_scores[length]; + int initial_score0 = put_token_score(length); + + do { + int score; + register struct cc_undo *undop; + int ccount; +#ifdef STATS + int ncover; +#endif + int i; + + ccount = p->ccount; + if ((short) ccount >= p->bcount) + continue; + if (p->code >= 0 || ccount >= threshold) + score = 0; +#ifndef cc_weight + else if (p->weight >= wthreshold) + /* allow one fewer match than normal */ + /* XXX, should adjust for ccount */ + score = - tt.tt_set_token_cost; +#endif + else + score = initial_scores[ccount]; + undop = cc_undo; +#ifdef STATS + ncover = 0; +#endif + for (i = p->places; i >= 0; i = places[i]) { + register struct cc **jp; + register struct cc *x; + register struct cc **ip = output + i; + register score0 = initial_score0; + struct cc **iip = ip + length; + struct cc_undo *undop1 = undop; + + if ((x = *(jp = ip)) != 0) + goto z; + while (--jp >= output) + if ((x = *jp) != 0) { + if (jp + x->length > ip) + goto z; + break; + } + jp = ip + 1; + while (jp < iip) { + if ((x = *jp) == 0) { + jp++; + continue; + } + z: + if (x == p) + goto undo; +#ifdef STATS + ncover++; +#endif + undop->pos = jp; + undop->val = x; + undop++; + *jp = 0; + x->ccount--; + score_adjust(score0, x); + if (score0 < 0 && flag) + goto undo; + jp += x->length; + } + undop->pos = ip; + undop->val = 0; + undop++; + *ip = p; + ccount++; + score += score0; + continue; + undo: + while (--undop >= undop1) + if (*undop->pos = x = undop->val) + x->ccount++; + undop++; + } + if (score > 0) { +#ifdef STATS + ccount_stat += ccount - p->ccount; + ntoken_stat++; + ncover_stat += ncover; +#endif + p->ccount = ccount; + } else { + register struct cc_undo *u = cc_undo; + while (--undop >= u) { + register struct cc *x; + if (*undop->pos = x = undop->val) + x->ccount++; + } + } + } while ((p = *pp++) != 0); + return pp - tokens; +} + +cc_output_phase(buffer, output, bufsize) + register char *buffer; + register struct cc **output; + register bufsize; +{ + register i; + register struct cc *p, *p1; + + for (i = 0; i < bufsize;) { + if ((p = output[i]) == 0) { + ttputc(buffer[i]); + i++; + } else if (p->code >= 0) { + if (--p->ccount == 0) + qinsert(p, &cc_q0a); + (*tt.tt_put_token)(p->code, p->string, p->length); + wwntokuse++; + wwntoksave += put_token_score(p->length); + i += p->length; + } else if ((p1 = cc_q0a.qback) != &cc_q0a) { + p->code = p1->code; + p1->code = -1; + qinsert(p1, &cc_q1a); + if (--p->ccount == 0) + qinsert(p, &cc_q0a); + else + qinsert(p, &cc_q0b); + (*tt.tt_set_token)(p->code, p->string, p->length); + wwntokdef++; + wwntoksave -= tt.tt_set_token_cost; + i += p->length; + } else { + p->ccount--; + ttwrite(p->string, p->length); + wwntokbad++; + i += p->length; + } + } + wwntokc += bufsize; +} + +cc_token_compare(p1, p2) + struct cc **p1, **p2; +{ + return (*p2)->bcount - (*p1)->bcount; +} diff --git a/usr.bin/window/context.c b/usr.bin/window/context.c new file mode 100644 index 00000000000..1251ebd589a --- /dev/null +++ b/usr.bin/window/context.c @@ -0,0 +1,137 @@ +/* $NetBSD: context.c,v 1.3 1995/09/28 10:34:15 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)context.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: context.c,v 1.3 1995/09/28 10:34:15 tls Exp $"; +#endif +#endif /* not lint */ + +#include "value.h" +#include "string.h" +#include "context.h" +#include <fcntl.h> + +/* + * Context push/pop for nested command files. + */ + +char *malloc(); + +cx_alloc() +{ + register struct context *xp; + + if (cx.x_type != 0) { + xp = (struct context *) + malloc((unsigned) sizeof (struct context)); + if (xp == 0) + return -1; + *xp = cx; + cx.x_link = xp; + cx.x_type = 0; + } + cx.x_erred = 0; + cx.x_synerred = 0; + cx.x_abort = 0; + return 0; +} + +cx_free() +{ + struct context *xp; + + if ((xp = cx.x_link) != 0) { + cx = *xp; + free((char *)xp); + } else + cx.x_type = 0; +} + +cx_beginfile(filename) +char *filename; +{ + if (cx_alloc() < 0) + return -1; + cx.x_type = X_FILE; + if ((cx.x_filename = str_cpy(filename)) == 0) + goto bad; + cx.x_fp = fopen(filename, "r"); + if (cx.x_fp == 0) + goto bad; + (void) fcntl(fileno(cx.x_fp), F_SETFD, 1); + cx.x_bol = 1; + cx.x_lineno = 0; + cx.x_errwin = 0; + cx.x_noerr = 0; + return 0; +bad: + if (cx.x_filename != 0) + str_free(cx.x_filename); + cx_free(); + return -1; +} + +cx_beginbuf(buf, arg, narg) +char *buf; +struct value *arg; +int narg; +{ + if (cx_alloc() < 0) + return -1; + cx.x_type = X_BUF; + cx.x_bufp = cx.x_buf = buf; + cx.x_arg = arg; + cx.x_narg = narg; + return 0; +} + +cx_end() +{ + switch (cx.x_type) { + case X_BUF: + break; + case X_FILE: + (void) fclose(cx.x_fp); + str_free(cx.x_filename); + break; + } + cx_free(); +} diff --git a/usr.bin/window/context.h b/usr.bin/window/context.h new file mode 100644 index 00000000000..a38cb80b989 --- /dev/null +++ b/usr.bin/window/context.h @@ -0,0 +1,85 @@ +/* $NetBSD: context.h,v 1.3 1995/09/28 10:34:17 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)context.h 8.1 (Berkeley) 6/6/93 + */ + +#include <stdio.h> + +struct context { + struct context *x_link; /* nested contexts */ + char x_type; /* tag for union */ + union { + struct { /* input is a file */ + char *X_filename; /* input file name */ + FILE *X_fp; /* input stream */ + short X_lineno; /* current line number */ + char X_bol; /* at beginning of line */ + char X_noerr; /* don't report errors */ + struct ww *X_errwin; /* error window */ + } x_f; + struct { /* input is a buffer */ + char *X_buf; /* input buffer */ + char *X_bufp; /* current position in buf */ + struct value *X_arg; /* argument for alias */ + int X_narg; /* number of arguments */ + } x_b; + } x_un; + /* holding place for current token */ + int x_token; /* the token */ + struct value x_val; /* values associated with token */ + /* parser error flags */ + unsigned x_erred :1; /* had an error */ + unsigned x_synerred :1; /* had syntax error */ + unsigned x_abort :1; /* fatal error */ +}; +#define x_buf x_un.x_b.X_buf +#define x_bufp x_un.x_b.X_bufp +#define x_arg x_un.x_b.X_arg +#define x_narg x_un.x_b.X_narg +#define x_filename x_un.x_f.X_filename +#define x_fp x_un.x_f.X_fp +#define x_lineno x_un.x_f.X_lineno +#define x_bol x_un.x_f.X_bol +#define x_errwin x_un.x_f.X_errwin +#define x_noerr x_un.x_f.X_noerr + + /* x_type values, 0 is reserved */ +#define X_FILE 1 /* input is a file */ +#define X_BUF 2 /* input is a buffer */ + +struct context cx; /* the current context */ diff --git a/usr.bin/window/defs.h b/usr.bin/window/defs.h new file mode 100644 index 00000000000..24f06e64b98 --- /dev/null +++ b/usr.bin/window/defs.h @@ -0,0 +1,73 @@ +/* $NetBSD: defs.h,v 1.3 1995/09/28 10:34:19 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)defs.h 8.1 (Berkeley) 6/6/93 + */ + +#include "ww.h" +#include <sys/time.h> + +#define NWINDOW 9 + +struct timeval starttime; + +struct ww *window[NWINDOW]; /* the windows */ +struct ww *selwin; /* the selected window */ +struct ww *lastselwin; /* the last selected window */ +struct ww *cmdwin; /* the command window */ +struct ww *framewin; /* the window for framing */ +struct ww *boxwin; /* the window for the box */ +struct ww *fgwin; /* the last foreground window */ + +#define isfg(w) ((w)->ww_order <= fgwin->ww_order) + +char *default_shell[128]; /* default shell argv */ +char *default_shellfile; /* default shell program */ +int default_nline; /* default buffer size for new windows */ +int default_smooth; /* default "smooth" parameter */ +char escapec; /* the escape character */ + + /* flags */ +char quit; /* quit command issued */ +char terse; /* terse mode */ +char debug; /* debug mode */ +char incmd; /* in command mode */ + +struct ww *getwin(); +struct ww *openwin(); +struct ww *vtowin(); +struct ww *openiwin(); diff --git a/usr.bin/window/error.c b/usr.bin/window/error.c new file mode 100644 index 00000000000..acfbd27a487 --- /dev/null +++ b/usr.bin/window/error.c @@ -0,0 +1,101 @@ +/* $NetBSD: error.c,v 1.3 1995/09/28 10:34:20 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: error.c,v 1.3 1995/09/28 10:34:20 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "value.h" +#include "context.h" +#include "char.h" + +#define ERRLINES 10 /* number of lines for errwin */ + +/*VARARGS1*/ +error(fmt, a, b, c, d, e, f, g, h) +char *fmt; +{ + register struct context *x; + register struct ww *w; + + for (x = &cx; x != 0 && x->x_type != X_FILE; x = x->x_link) + ; + if (x == 0) { + if (terse) + wwbell(); + else { + wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h); + wwputs(" ", cmdwin); + } + return; + } + if (x->x_noerr) + return; + if ((w = x->x_errwin) == 0) { + char buf[512]; + + (void) sprintf(buf, "Errors from %s", x->x_filename); + if ((w = x->x_errwin = openiwin(ERRLINES, buf)) == 0) { + wwputs("Can't open error window. ", cmdwin); + x->x_noerr = 1; + return; + } + } + if (more(w, 0) == 2) { + x->x_noerr = 1; + return; + } + wwprintf(w, "line %d: ", x->x_lineno); + wwprintf(w, fmt, a, b, c, d, e, f, g, h); + wwputc('\n', w); +} + +err_end() +{ + if (cx.x_type == X_FILE && cx.x_errwin != 0) { + if (!cx.x_noerr) + waitnl(cx.x_errwin); + closeiwin(cx.x_errwin); + cx.x_errwin = 0; + } +} diff --git a/usr.bin/window/lcmd.c b/usr.bin/window/lcmd.c new file mode 100644 index 00000000000..69b275e12f3 --- /dev/null +++ b/usr.bin/window/lcmd.c @@ -0,0 +1,160 @@ +/* $NetBSD: lcmd.c,v 1.3 1995/09/28 10:34:21 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: lcmd.c,v 1.3 1995/09/28 10:34:21 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "value.h" +#include "lcmd.h" + +int l_alias(); +int l_close(); +int l_cursormodes(); +int l_debug(); +int l_def_nline(); +int l_def_shell(); +int l_def_smooth(); +int l_echo(); +int l_escape(); +int l_foreground(); +int l_iostat(); +int l_label(); +int l_list(); +int l_select(); +int l_smooth(); +int l_source(); +int l_terse(); +int l_time(); +int l_unalias(); +int l_unset(); +int l_variable(); +int l_window(); +int l_write(); + +extern struct lcmd_arg arg_alias[]; +extern struct lcmd_arg arg_cursormodes[]; +extern struct lcmd_arg arg_debug[]; +extern struct lcmd_arg arg_echo[]; +extern struct lcmd_arg arg_escape[]; +extern struct lcmd_arg arg_foreground[]; +extern struct lcmd_arg arg_label[]; +extern struct lcmd_arg arg_def_nline[]; +extern struct lcmd_arg arg_def_shell[]; +extern struct lcmd_arg arg_def_smooth[]; +extern struct lcmd_arg arg_close[]; +extern struct lcmd_arg arg_select[]; +extern struct lcmd_arg arg_smooth[]; +extern struct lcmd_arg arg_source[]; +extern struct lcmd_arg arg_terse[]; +extern struct lcmd_arg arg_time[]; +extern struct lcmd_arg arg_unalias[]; +extern struct lcmd_arg arg_unset[]; +extern struct lcmd_arg arg_window[]; +extern struct lcmd_arg arg_write[]; +struct lcmd_arg arg_null[1] = { { 0 } }; + +struct lcmd_tab lcmd_tab[] = { + "alias", 1, l_alias, arg_alias, + "close", 2, l_close, arg_close, + "cursormodes", 2, l_cursormodes, arg_cursormodes, + "debug", 1, l_debug, arg_debug, + "default_nlines", 9, l_def_nline, arg_def_nline, + "default_shell", 10, l_def_shell, arg_def_shell, + "default_smooth", 10, l_def_smooth, arg_def_smooth, + "echo", 2, l_echo, arg_echo, + "escape", 2, l_escape, arg_escape, + "foreground", 1, l_foreground, arg_foreground, + "iostat", 1, l_iostat, arg_null, + "label", 2, l_label, arg_label, + "list", 2, l_list, arg_null, + "nlines", 1, l_def_nline, arg_def_nline, + "select", 2, l_select, arg_select, + "shell", 2, l_def_shell, arg_def_shell, + "smooth", 2, l_smooth, arg_smooth, + "source", 2, l_source, arg_source, + "terse", 2, l_terse, arg_terse, + "time", 2, l_time, arg_time, + "unalias", 3, l_unalias, arg_unalias, + "unset", 3, l_unset, arg_unset, + "variable", 1, l_variable, arg_null, + "window", 2, l_window, arg_window, + "write", 2, l_write, arg_write, + 0 +}; + +struct lcmd_tab * +lcmd_lookup(name) +char *name; +{ + register struct lcmd_tab *p; + + for (p = lcmd_tab; p->lc_name != 0; p++) + if (str_match(name, p->lc_name, p->lc_minlen)) + return p; + return 0; +} + +dosource(filename) +char *filename; +{ + if (cx_beginfile(filename) < 0) + return -1; + p_start(); + err_end(); + cx_end(); + return 0; +} + +dolongcmd(buffer, arg, narg) +char *buffer; +struct value *arg; +int narg; +{ + if (cx_beginbuf(buffer, arg, narg) < 0) + return -1; + p_start(); + err_end(); + cx_end(); + return 0; +} diff --git a/usr.bin/window/lcmd.h b/usr.bin/window/lcmd.h new file mode 100644 index 00000000000..d50f4fed0ae --- /dev/null +++ b/usr.bin/window/lcmd.h @@ -0,0 +1,63 @@ +/* $NetBSD: lcmd.h,v 1.3 1995/09/28 10:34:22 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)lcmd.h 8.1 (Berkeley) 6/6/93 + */ + +#define LCMD_NARG 20 /* maximum number of arguments */ + +struct lcmd_tab { + char *lc_name; + int lc_minlen; + int (*lc_func)(); + struct lcmd_arg *lc_arg; +}; + +struct lcmd_arg { + char *arg_name; + int arg_minlen; + int arg_flags; +}; + + /* arg_flags bits */ +#define ARG_TYPE 0x0f /* type of arg */ +#define ARG_ANY 0x00 /* any type */ +#define ARG_NUM 0x01 /* must be a number */ +#define ARG_STR 0x02 /* must be a string */ +#define ARG_LIST 0x10 /* this arg can be a list */ + +struct lcmd_tab *lcmd_lookup(); diff --git a/usr.bin/window/lcmd1.c b/usr.bin/window/lcmd1.c new file mode 100644 index 00000000000..3167f96275c --- /dev/null +++ b/usr.bin/window/lcmd1.c @@ -0,0 +1,436 @@ +/* $NetBSD: lcmd1.c,v 1.5 1995/09/29 00:44:02 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd1.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: lcmd1.c,v 1.5 1995/09/29 00:44:02 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "string.h" +#include "value.h" +#include "lcmd.h" +#include "var.h" +#include <string.h> + +struct lcmd_arg arg_window[] = { + { "row", 1, ARG_NUM }, + { "column", 1, ARG_NUM }, + { "nrows", 2, ARG_NUM }, + { "ncols", 2, ARG_NUM }, + { "nlines", 2, ARG_NUM }, + { "label", 1, ARG_STR }, + { "pty", 1, ARG_ANY }, + { "frame", 1, ARG_ANY }, + { "mapnl", 1, ARG_ANY }, + { "keepopen", 1, ARG_ANY }, + { "smooth", 1, ARG_ANY }, + { "shell", 1, ARG_STR|ARG_LIST }, + 0 +}; + +l_window(v, a) +struct value *v; +register struct value *a; +{ + struct ww *w; + int col, row, ncol, nrow, id, nline; + char *label; + char haspty, hasframe, mapnl, keepopen, smooth; + char *shf, **sh; + char *argv[sizeof default_shell / sizeof *default_shell]; + register char **pp; + + if ((id = findid()) < 0) + return; + row = a->v_type == V_ERR ? 1 : a->v_num; + a++; + col = a->v_type == V_ERR ? 0 : a->v_num; + a++; + nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num; + a++; + ncol = a->v_type == V_ERR ? wwncol - col : a->v_num; + a++; + nline = a->v_type == V_ERR ? default_nline : a->v_num; + a++; + label = a->v_type == V_ERR ? 0 : a->v_str; + if ((haspty = vtobool(++a, 1, -1)) < 0) + return; + if ((hasframe = vtobool(++a, 1, -1)) < 0) + return; + if ((mapnl = vtobool(++a, !haspty, -1)) < 0) + return; + if ((keepopen = vtobool(++a, 0, -1)) < 0) + return; + if ((smooth = vtobool(++a, default_smooth, -1)) < 0) + return; + if ((++a)->v_type != V_ERR) { + for (pp = argv; a->v_type != V_ERR && + pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++) + *pp = a->v_str; + *pp = 0; + shf = *(sh = argv); + if (*sh = rindex(shf, '/')) + (*sh)++; + else + *sh = shf; + } else { + sh = default_shell; + shf = default_shellfile; + } + if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty, + hasframe, shf, sh)) == 0) + return; + w->ww_mapnl = mapnl; + w->ww_keepopen = keepopen; + w->ww_noupdate = !smooth; + v->v_type = V_NUM; + v->v_num = id + 1; +} + +struct lcmd_arg arg_def_nline[] = { + { "nlines", 1, ARG_NUM }, + 0 +}; + +l_def_nline(v, a) +register struct value *v, *a; +{ + v->v_num = default_nline; + v->v_type = V_NUM; + if (a->v_type != V_ERR) + default_nline = a->v_num; +} + +struct lcmd_arg arg_smooth[] = { + { "window", 1, ARG_NUM }, + { "flag", 1, ARG_ANY }, + 0 +}; + +l_smooth(v, a) +register struct value *v, *a; +{ + struct ww *w; + + v->v_type = V_NUM; + v->v_num = 0; + if ((w = vtowin(a++, selwin)) == 0) + return; + v->v_num = !w->ww_noupdate; + w->ww_noupdate = !vtobool(a, v->v_num, v->v_num); +} + +struct lcmd_arg arg_def_smooth[] = { + { "flag", 1, ARG_ANY }, + 0 +}; + +l_def_smooth(v, a) +register struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = default_smooth; + default_smooth = vtobool(a, v->v_num, v->v_num); +} + +struct lcmd_arg arg_select[] = { + { "window", 1, ARG_NUM }, + 0 +}; + +l_select(v, a) +register struct value *v, *a; +{ + struct ww *w; + + v->v_type = V_NUM; + v->v_num = selwin ? selwin->ww_id + 1 : -1; + if (a->v_type == V_ERR) + return; + if ((w = vtowin(a, (struct ww *)0)) == 0) + return; + setselwin(w); +} + +struct lcmd_arg arg_debug[] = { + { "flag", 1, ARG_ANY }, + 0 +}; + +l_debug(v, a) +register struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = debug; + debug = vtobool(a, debug, debug); +} + +struct lcmd_arg arg_escape[] = { + { "escapec", 1, ARG_STR }, + 0 +}; + +l_escape(v, a) +register struct value *v, *a; +{ + char buf[2]; + + buf[0] = escapec; + buf[1] = 0; + if ((v->v_str = str_cpy(buf)) == 0) { + error("Out of memory."); + return; + } + v->v_type = V_STR; + if (a->v_type != V_ERR) + setescape(a->v_str); +} + +struct lcmd_arg arg_label[] = { + { "window", 1, ARG_NUM }, + { "label", 1, ARG_STR }, + 0 +}; + +/*ARGSUSED*/ +l_label(v, a) +struct value *v; +register struct value *a; +{ + struct ww *w; + + if ((w = vtowin(a, selwin)) == 0) + return; + if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0) + error("Out of memory."); + reframe(); +} + +struct lcmd_arg arg_foreground[] = { + { "window", 1, ARG_NUM }, + { "flag", 1, ARG_ANY }, + 0 +}; + +l_foreground(v, a) +register struct value *v, *a; +{ + struct ww *w; + char flag; + + if ((w = vtowin(a, selwin)) == 0) + return; + v->v_type = V_NUM; + v->v_num = isfg(w); + flag = vtobool(++a, v->v_num, v->v_num); + if (flag == v->v_num) + return; + deletewin(w); + addwin(w, flag); + reframe(); +} + +struct lcmd_arg arg_terse[] = { + { "flag", 1, ARG_ANY }, + 0 +}; + +l_terse(v, a) +register struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = terse; + setterse(vtobool(a, terse, terse)); +} + +struct lcmd_arg arg_source[] = { + { "filename", 1, ARG_STR }, + 0 +}; + +l_source(v, a) +register struct value *v, *a; +{ + v->v_type = V_NUM; + if (a->v_type != V_ERR && dosource(a->v_str) < 0) { + error("Can't open %s.", a->v_str); + v->v_num = -1; + } else + v->v_num = 0; +} + +struct lcmd_arg arg_write[] = { + { "window", 1, ARG_NUM }, + { "", 0, ARG_ANY|ARG_LIST }, + 0 +}; + +/*ARGSUSED*/ +l_write(v, a) +struct value *v; +register struct value *a; +{ + char buf[20]; + struct ww *w; + + if ((w = vtowin(a++, selwin)) == 0) + return; + while (a->v_type != V_ERR) { + if (a->v_type == V_NUM) { + (void) sprintf(buf, "%d", a->v_num); + (void) write(w->ww_pty, buf, strlen(buf)); + } else + (void) write(w->ww_pty, a->v_str, strlen(a->v_str)); + if ((++a)->v_type != V_ERR) + (void) write(w->ww_pty, " ", 1); + } +} + +struct lcmd_arg arg_close[] = { + { "window", 1, ARG_ANY|ARG_LIST }, + 0 +}; + +/*ARGSUSED*/ +l_close(v, a) +struct value *v; +register struct value *a; +{ + struct ww *w; + + if (a->v_type == V_STR && str_match(a->v_str, "all", 3)) + closewin((struct ww *)0); + else + for (; a->v_type != V_ERR; a++) + if ((w = vtowin(a, (struct ww *)0)) != 0) + closewin(w); +} + +struct lcmd_arg arg_cursormodes[] = { + { "modes", 1, ARG_NUM }, + 0 +}; + +l_cursormodes(v, a) +register struct value *v, *a; +{ + + v->v_type = V_NUM; + v->v_num = wwcursormodes; + if (a->v_type != V_ERR) + wwsetcursormodes(a->v_num); +} + +struct lcmd_arg arg_unset[] = { + { "variable", 1, ARG_ANY }, + 0 +}; + +l_unset(v, a) +register struct value *v, *a; +{ + v->v_type = V_NUM; + switch (a->v_type) { + case V_ERR: + v->v_num = -1; + return; + case V_NUM: + if ((a->v_str = str_itoa(a->v_num)) == 0) { + error("Out of memory."); + v->v_num = -1; + return; + } + a->v_type = V_STR; + break; + } + v->v_num = var_unset(a->v_str); +} + +struct ww * +vtowin(v, w) +register struct value *v; +struct ww *w; +{ + switch (v->v_type) { + case V_ERR: + if (w != 0) + return w; + error("No window specified."); + return 0; + case V_STR: + error("%s: No such window.", v->v_str); + return 0; + } + if (v->v_num < 1 || v->v_num > NWINDOW + || (w = window[v->v_num - 1]) == 0) { + error("%d: No such window.", v->v_num); + return 0; + } + return w; +} + +vtobool(v, def, err) +register struct value *v; +char def, err; +{ + switch (v->v_type) { + case V_NUM: + return v->v_num != 0; + case V_STR: + if (str_match(v->v_str, "true", 1) + || str_match(v->v_str, "on", 2) + || str_match(v->v_str, "yes", 1)) + return 1; + else if (str_match(v->v_str, "false", 1) + || str_match(v->v_str, "off", 2) + || str_match(v->v_str, "no", 1)) + return 0; + else { + error("%s: Illegal boolean value.", v->v_str); + return err; + } + /*NOTREACHED*/ + case V_ERR: + return def; + } + /*NOTREACHED*/ +} diff --git a/usr.bin/window/lcmd2.c b/usr.bin/window/lcmd2.c new file mode 100644 index 00000000000..027086eb025 --- /dev/null +++ b/usr.bin/window/lcmd2.c @@ -0,0 +1,400 @@ +/* $NetBSD: lcmd2.c,v 1.7 1995/09/29 00:44:04 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd2.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: lcmd2.c,v 1.7 1995/09/29 00:44:04 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "string.h" +#include "value.h" +#include "var.h" +#include "lcmd.h" +#include "alias.h" +#include <sys/types.h> +#include <sys/resource.h> +#include <string.h> + +/*ARGSUSED*/ +l_iostat(v, a) +struct value *v, *a; +{ + register struct ww *w; + + if ((w = openiwin(16, "IO Statistics")) == 0) { + error("Can't open statistics window: %s.", wwerror()); + return; + } + wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\n", + wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc); + wwprintf(w, "token\tuse\tbad\tsaving\ttotal\tbaud\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n", + wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc, + wwntokc - wwntoksave ? + (int) ((float) wwbaud * wwntokc / + (wwntokc - wwntoksave)) : + wwbaud, + wwnwrc ? (int) ((float) wwbaud * (wwnwrc + wwntoksave) / + wwnwrc) : + wwbaud, + wwntokc - wwntoksave ? + (float) wwntokc / (wwntokc - wwntoksave) : 1.0, + wwnwrc ? (float) (wwnwrc + wwntoksave) / wwnwrc : 1.0); + wwprintf(w, "wwwrite\tattempt\tchar\n"); + wwprintf(w, "%d\t%d\t%d\n", + wwnwwr, wwnwwra, wwnwwrc); + wwprintf(w, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", + wwnupdate, wwnupdline, wwnupdmiss, wwnupdscan, wwnupdclreol, + wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline); + wwprintf(w, "select\terror\tzero\n"); + wwprintf(w, "%d\t%d\t%d\n", + wwnselect, wwnselecte, wwnselectz); + wwprintf(w, "read\terror\tzero\tchar\tack\tnack\tstat\terrorc\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", + wwnread, wwnreade, wwnreadz, wwnreadc, wwnreadack, wwnreadnack, + wwnreadstat, wwnreadec); + wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n", + wwnwread, wwnwreade, wwnwreadz, + wwnwreadp, wwnwreadd, wwnwreadc); + waitnl(w); + closeiwin(w); +} + +struct lcmd_arg arg_time[] = { + { "who", 1, ARG_STR }, + 0 +}; + +/*ARGSUSED*/ +l_time(v, a) +struct value *v; +register struct value *a; +{ + register struct ww *w; + struct rusage rusage; + struct timeval timeval; + char *strtime(); + + if ((w = openiwin(8, "Timing and Resource Usage")) == 0) { + error("Can't open time window: %s.", wwerror()); + return; + } + + (void) gettimeofday(&timeval, (struct timezone *)0); + timersub(&timeval, &starttime, &timeval); + (void) getrusage(a->v_type == V_STR + && str_match(a->v_str, "children", 1) + ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage); + + wwprintf(w, "%-15s %-15s %-15s\n", + "time", "utime", "stime"); + wwprintf(w, "%-15s ", strtime(&timeval)); + wwprintf(w, "%-15s ", strtime(&rusage.ru_utime)); + wwprintf(w, "%-15s\n", strtime(&rusage.ru_stime)); + wwprintf(w, "%-15s %-15s %-15s %-15s\n", + "maxrss", "ixrss", "idrss", "isrss"); + wwprintf(w, "%-15ld %-15ld %-15ld %-15ld\n", + rusage.ru_maxrss, rusage.ru_ixrss, + rusage.ru_idrss, rusage.ru_isrss); + wwprintf(w, "%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n", + "minflt", "majflt", "nswap", "inblk", "oublk", + "msgsnd", "msgrcv", "nsigs", "nvcsw", "nivcsw"); + wwprintf(w, "%-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld\n", + rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap, + rusage.ru_inblock, rusage.ru_oublock, + rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals, + rusage.ru_nvcsw, rusage.ru_nivcsw); + + waitnl(w); + closeiwin(w); +} + +char * +strtime(t) +register struct timeval *t; +{ + char fill = 0; + static char buf[20]; + register char *p = buf; + + if (t->tv_sec > 60*60) { + (void) sprintf(p, "%ld:", t->tv_sec / (60*60)); + while (*p++) + ; + p--; + t->tv_sec %= 60*60; + fill++; + } + if (t->tv_sec > 60) { + (void) sprintf(p, fill ? "%02ld:" : "%ld:", t->tv_sec / 60); + while (*p++) + ; + p--; + t->tv_sec %= 60; + fill++; + } + (void) sprintf(p, fill ? "%02ld.%02d" : "%ld.%02ld", + t->tv_sec, t->tv_usec / 10000); + return buf; +} + +/*ARGSUSED*/ +l_list(v, a) +struct value *v, *a; +{ + register struct ww *w, *wp; + register i; + int n; + + for (n = 0, i = 0; i < NWINDOW; i++) + if (window[i] != 0) + n++; + if (n == 0) { + error("No windows."); + return; + } + if ((w = openiwin(n + 2, "Windows")) == 0) { + error("Can't open listing window: %s.", wwerror()); + return; + } + for (i = 0; i < NWINDOW; i++) { + if ((wp = window[i]) == 0) + continue; + wwprintf(w, "%c %c %-13s %-.*s\n", + wp == selwin ? '+' : (wp == lastselwin ? '-' : ' '), + i + '1', + wp->ww_state == WWS_HASPROC ? "" : "(No process)", + wwncol - 20, + wp->ww_label ? wp->ww_label : "(No label)"); + } + waitnl(w); + closeiwin(w); +} + +/*ARGSUSED*/ +l_variable(v, a) +struct value *v, *a; +{ + register struct ww *w; + int printvar(); + + if ((w = openiwin(wwnrow - 3, "Variables")) == 0) { + error("Can't open variable window: %s.", wwerror()); + return; + } + if (var_walk(printvar, (long)w) >= 0) + waitnl(w); + closeiwin(w); +} + +printvar(w, r) +register struct ww *w; +register struct var *r; +{ + if (more(w, 0) == 2) + return -1; + wwprintf(w, "%16s ", r->r_name); + switch (r->r_val.v_type) { + case V_STR: + wwprintf(w, "%s\n", r->r_val.v_str); + break; + case V_NUM: + wwprintf(w, "%d\n", r->r_val.v_num); + break; + case V_ERR: + wwprintf(w, "ERROR\n"); + break; + } + return 0; +} + +struct lcmd_arg arg_def_shell[] = { + { "", 0, ARG_ANY|ARG_LIST }, + 0 +}; + +l_def_shell(v, a) + struct value *v, *a; +{ + register char **pp; + register struct value *vp; + + if (a->v_type == V_ERR) { + if ((v->v_str = str_cpy(default_shellfile)) != 0) + v->v_type = V_STR; + return; + } + if (v->v_str = default_shellfile) { + v->v_type = V_STR; + for (pp = default_shell + 1; *pp; pp++) { + str_free(*pp); + *pp = 0; + } + } + for (pp = default_shell, vp = a; + vp->v_type != V_ERR && + pp < &default_shell[sizeof default_shell/sizeof *default_shell-1]; + pp++, vp++) + if ((*pp = vp->v_type == V_STR ? + str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) { + /* just leave default_shell[] the way it is */ + p_memerror(); + break; + } + if (default_shellfile = *default_shell) + if (*default_shell = rindex(default_shellfile, '/')) + (*default_shell)++; + else + *default_shell = default_shellfile; +} + +struct lcmd_arg arg_alias[] = { + { "", 0, ARG_STR }, + { "", 0, ARG_STR|ARG_LIST }, + 0 +}; + +l_alias(v, a) + struct value *v, *a; +{ + if (a->v_type == V_ERR) { + register struct ww *w; + int printalias(); + + if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) { + error("Can't open alias window: %s.", wwerror()); + return; + } + if (alias_walk(printalias, (long)w) >= 0) + waitnl(w); + closeiwin(w); + } else { + register struct alias *ap = 0; + + if (ap = alias_lookup(a->v_str)) { + if ((v->v_str = str_cpy(ap->a_buf)) == 0) { + p_memerror(); + return; + } + v->v_type = V_STR; + } + if (a[1].v_type == V_STR) { + register struct value *vp; + register char *p, *q; + char *str; + register n; + + for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++) + for (p = vp->v_str; *p; p++, n++) + ; + if ((str = str_alloc(n)) == 0) { + p_memerror(); + return; + } + for (q = str, vp = a + 1; vp->v_type != V_ERR; + vp++, q[-1] = ' ') + for (p = vp->v_str; *q++ = *p++;) + ; + q[-1] = 0; + if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) { + p_memerror(); + str_free(str); + return; + } + ap->a_buf = str; + } + } +} + +printalias(w, a) +register struct ww *w; +register struct alias *a; +{ + if (more(w, 0) == 2) + return -1; + wwprintf(w, "%16s %s\n", a->a_name, a->a_buf); + return 0; +} + +struct lcmd_arg arg_unalias[] = { + { "alias", 1, ARG_STR }, + 0 +}; + +l_unalias(v, a) +struct value *v, *a; +{ + if (a->v_type == ARG_STR) + v->v_num = alias_unset(a->v_str); + v->v_type = V_NUM; +} + +struct lcmd_arg arg_echo[] = { + { "window", 1, ARG_NUM }, + { "", 0, ARG_ANY|ARG_LIST }, + 0 +}; + +/*ARGSUSED*/ +l_echo(v, a) +struct value *v; +register struct value *a; +{ + char buf[20]; + struct ww *w; + + if ((w = vtowin(a++, selwin)) == 0) + return; + while (a->v_type != V_ERR) { + if (a->v_type == V_NUM) { + (void) sprintf(buf, "%d", a->v_num); + (void) wwwrite(w, buf, strlen(buf)); + } else + (void) wwwrite(w, a->v_str, strlen(a->v_str)); + if ((++a)->v_type != V_ERR) + (void) wwwrite(w, " ", 1); + } + (void) wwwrite(w, "\r\n", 2); +} diff --git a/usr.bin/window/local.h b/usr.bin/window/local.h new file mode 100644 index 00000000000..435b5facc1c --- /dev/null +++ b/usr.bin/window/local.h @@ -0,0 +1,53 @@ +/* $NetBSD: local.h,v 1.3 1995/09/28 10:34:26 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)local.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Things of local interest. + */ + +#define RUNCOM ".windowrc" +#define ESCAPEC ctrl('p') +#define NLINE 48 /* default text buffer size */ + +#ifdef TERMINFO +#define _PATH_CAPTOINFO "/usr/5bin/captoinfo" +#define _PATH_TIC "/usr/5bin/tic" +#define _PATH_RM "/bin/rm" +#endif diff --git a/usr.bin/window/main.c b/usr.bin/window/main.c new file mode 100644 index 00000000000..fba9936dfb8 --- /dev/null +++ b/usr.bin/window/main.c @@ -0,0 +1,208 @@ +/* $NetBSD: main.c,v 1.4 1995/09/28 10:34:27 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +char copyright[] = +"@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/2/94"; +#else +static char rcsid[] = "$NetBSD: main.c,v 1.4 1995/09/28 10:34:27 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include <paths.h> +#include <stdio.h> +#include "string.h" +#include "char.h" +#include "local.h" + +#define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)(long)usage())) + +/*ARGSUSED*/ +main(argc, argv) +char **argv; +{ + register char *p; + char fflag = 0; + char dflag = 0; + char xflag = 0; + char *cmd = 0; + char tflag = 0; + + escapec = ESCAPEC; + if (p = rindex(*argv, '/')) + p++; + else + p = *argv; + debug = strcmp(p, "a.out") == 0; + while (*++argv) { + if (**argv == '-') { + switch (*++*argv) { + case 'f': + fflag++; + break; + case 'c': + if (cmd != 0) { + (void) fprintf(stderr, + "Only one -c allowed.\n"); + (void) usage(); + } + cmd = next(argv); + break; + case 'e': + setescape(next(argv)); + break; + case 't': + tflag++; + break; + case 'd': + dflag++; + break; + case 'D': + debug = !debug; + break; + case 'x': + xflag++; + break; + default: + (void) usage(); + } + } else + (void) usage(); + } + if ((p = getenv("SHELL")) == 0) + p = _PATH_BSHELL; + if ((default_shellfile = str_cpy(p)) == 0) { + (void) fprintf(stderr, "Out of memory.\n"); + exit(1); + } + if (p = rindex(default_shellfile, '/')) + p++; + else + p = default_shellfile; + default_shell[0] = p; + default_shell[1] = 0; + default_nline = NLINE; + default_smooth = 1; + (void) gettimeofday(&starttime, (struct timezone *)0); + if (wwinit() < 0) { + (void) fprintf(stderr, "%s.\n", wwerror()); + exit(1); + } + +#ifdef OLD_TTY + if (debug) + wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; + if (xflag) { + wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; + wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; + } +#else + if (debug) { + wwnewtty.ww_termios.c_cc[VQUIT] = + wwoldtty.ww_termios.c_cc[VQUIT]; + wwnewtty.ww_termios.c_lflag |= ISIG; + } + if (xflag) { + wwnewtty.ww_termios.c_cc[VSTOP] = + wwoldtty.ww_termios.c_cc[VSTOP]; + wwnewtty.ww_termios.c_cc[VSTART] = + wwoldtty.ww_termios.c_cc[VSTART]; + wwnewtty.ww_termios.c_iflag |= IXON; + } +#endif + if (debug || xflag) + (void) wwsettty(0, &wwnewtty); + + if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, + 0, 0, 0)) == 0) { + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); + goto bad; + } + cmdwin->ww_mapnl = 1; + cmdwin->ww_nointr = 1; + cmdwin->ww_noupdate = 1; + cmdwin->ww_unctrl = 1; + if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) + == 0) { + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); + goto bad; + } + wwadd(framewin, &wwhead); + if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); + goto bad; + } + fgwin = framewin; + + wwupdate(); + wwflush(); + setvars(); + + setterse(tflag); + setcmd(1); + if (cmd != 0) + (void) dolongcmd(cmd, (struct value *)0, 0); + if (!fflag) + if (dflag || doconfig() < 0) + dodefault(); + if (selwin != 0) + setcmd(0); + + mloop(); + +bad: + wwend(1); + return 0; +} + +usage() +{ + (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n"); + exit(1); + return 0; /* for lint */ +} diff --git a/usr.bin/window/mloop.c b/usr.bin/window/mloop.c new file mode 100644 index 00000000000..bb6f867be6c --- /dev/null +++ b/usr.bin/window/mloop.c @@ -0,0 +1,90 @@ +/* $NetBSD: mloop.c,v 1.3 1995/09/28 10:34:28 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)mloop.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: mloop.c,v 1.3 1995/09/28 10:34:28 tls Exp $"; +#endif +#endif /* not lint */ + +#include <sys/param.h> +#include "defs.h" + +mloop() +{ + while (!quit) { + if (incmd) { + docmd(); + } else if (wwcurwin->ww_state != WWS_HASPROC) { + if (!wwcurwin->ww_keepopen) + closewin(wwcurwin); + setcmd(1); + if (wwpeekc() == escapec) + (void) wwgetc(); + error("Process died."); + } else { + register struct ww *w = wwcurwin; + register char *p; + register n; + + if (wwibp >= wwibq) + wwiomux(); + for (p = wwibp; p < wwibq && wwmaskc(*p) != escapec; + p++) + ; + if ((n = p - wwibp) > 0) { + if (!w->ww_ispty && w->ww_stopped) + startwin(w); +#if defined(sun) && !defined(BSD) + /* workaround for SunOS pty bug */ + while (--n >= 0) + (void) write(w->ww_pty, wwibp++, 1); +#else + (void) write(w->ww_pty, wwibp, n); + wwibp = p; +#endif + } + if (wwpeekc() == escapec) { + (void) wwgetc(); + setcmd(1); + } + } + } +} diff --git a/usr.bin/window/parser.h b/usr.bin/window/parser.h new file mode 100644 index 00000000000..4626d288122 --- /dev/null +++ b/usr.bin/window/parser.h @@ -0,0 +1,49 @@ +/* $NetBSD: parser.h,v 1.3 1995/09/28 10:34:29 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)parser.h 8.1 (Berkeley) 6/6/93 + */ + +#include "value.h" +#include "context.h" +#include "token.h" +#include "string.h" + +#define p_erred() (cx.x_erred) +#define p_synerred() (cx.x_synerred) +#define p_clearerr() (cx.x_erred = cx.x_synerred = 0) +#define p_abort() (cx.x_abort) diff --git a/usr.bin/window/parser1.c b/usr.bin/window/parser1.c new file mode 100644 index 00000000000..d0d145f5e1c --- /dev/null +++ b/usr.bin/window/parser1.c @@ -0,0 +1,228 @@ +/* $NetBSD: parser1.c,v 1.3 1995/09/28 10:34:31 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser1.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: parser1.c,v 1.3 1995/09/28 10:34:31 tls Exp $"; +#endif +#endif /* not lint */ + +#include "parser.h" + +p_start() +{ + char flag = 1; + + (void) s_gettok(); + for (;;) { + p_statementlist(flag); + if (token == T_EOF || p_abort()) + break; + flag = 0; + p_synerror(); + while (token != T_EOL && token != T_EOF) { + if (token == T_STR) + str_free(token_str); + (void) s_gettok(); + } + if (token == T_EOL) + (void) s_gettok(); + p_clearerr(); + } +} + +p_statementlist(flag) +char flag; +{ + for (; p_statement(flag) >= 0; p_clearerr()) + ; +} + +p_statement(flag) +char flag; +{ + switch (token) { + case T_EOL: + (void) s_gettok(); + return 0; + case T_IF: + return p_if(flag); + default: + return p_expression(flag); + } +} + +p_if(flag) +char flag; +{ + struct value t; + char true = 0; + +top: + (void) s_gettok(); + + if (p_expr(&t, flag) < 0) { + p_synerror(); + return -1; + } + switch (t.v_type) { + case V_NUM: + true = !true && t.v_num != 0; + break; + case V_STR: + p_error("if: Numeric value required."); + str_free(t.v_str); + case V_ERR: + flag = 0; + break; + } + + if (token != T_THEN) { + p_synerror(); + return -1; + } + + (void) s_gettok(); + p_statementlist(flag && true); + if (p_erred()) + return -1; + + if (token == T_ELSIF) + goto top; + + if (token == T_ELSE) { + (void) s_gettok(); + p_statementlist(flag && !true); + if (p_erred()) + return -1; + } + + if (token == T_ENDIF) { + (void) s_gettok(); + return 0; + } + + p_synerror(); + return -1; +} + +p_expression(flag) +char flag; +{ + struct value t; + char *cmd; + int p_function(), p_assign(); + + switch (token) { + case T_NUM: + t.v_type = V_NUM; + t.v_num = token_num; + (void) s_gettok(); + break; + case T_STR: + t.v_type = V_STR; + t.v_str = token_str; + (void) s_gettok(); + break; + default: + if (p_expr(&t, flag) < 0) + return -1; + if (token == T_EOF) { + val_free(t); + return 0; + } + } + if (token != T_ASSIGN && p_convstr(&t) < 0) + return -1; + cmd = t.v_type == V_STR ? t.v_str : 0; + if ((*(token == T_ASSIGN ? p_assign : p_function))(cmd, &t, flag) < 0) { + if (cmd) + str_free(cmd); + return -1; + } + if (cmd) + str_free(cmd); + val_free(t); + if (token == T_EOL) + (void) s_gettok(); + else if (token != T_EOF) { + p_synerror(); + return -1; + } + return 0; +} + +p_convstr(v) +register struct value *v; +{ + if (v->v_type != V_NUM) + return 0; + if ((v->v_str = str_itoa(v->v_num)) == 0) { + p_memerror(); + v->v_type = V_ERR; + return -1; + } + v->v_type = V_STR; + return 0; +} + +p_synerror() +{ + if (!cx.x_synerred) { + cx.x_synerred = cx.x_erred = 1; + error("Syntax error."); + } +} + +/*VARARGS1*/ +p_error(msg, a, b, c) +char *msg; +{ + if (!cx.x_erred) { + cx.x_erred = 1; + error(msg, a, b, c); + } +} + +p_memerror() +{ + cx.x_erred = cx.x_abort = 1; + error("Out of memory."); +} diff --git a/usr.bin/window/parser2.c b/usr.bin/window/parser2.c new file mode 100644 index 00000000000..286f15ced68 --- /dev/null +++ b/usr.bin/window/parser2.c @@ -0,0 +1,237 @@ +/* $NetBSD: parser2.c,v 1.3 1995/09/28 10:34:32 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser2.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: parser2.c,v 1.3 1995/09/28 10:34:32 tls Exp $"; +#endif +#endif /* not lint */ + +#include "parser.h" +#include "var.h" +#include "lcmd.h" +#include "alias.h" + +/* + * name == 0 means we don't have a function name but + * want to parse the arguments anyway. flag == 0 in this case. + */ +p_function(name, v, flag) +char *name; +register struct value *v; +{ + struct value t; + register struct lcmd_tab *c = 0; + register struct alias *a = 0; + register struct lcmd_arg *ap; /* this arg */ + struct lcmd_arg *lp = 0; /* list arg */ + register i; + struct value av[LCMD_NARG + 1]; + register struct value *vp; + + if (name != 0) + if (c = lcmd_lookup(name)) + name = c->lc_name; + else if (a = alias_lookup(name)) + name = a->a_name; + else { + p_error("%s: No such command or alias.", name); + flag = 0; + } + + for (vp = av; vp < &av[LCMD_NARG + 1]; vp++) + vp->v_type = V_ERR; + + if (token == T_LP) + (void) s_gettok(); + i = 0; + for (;;) { + ap = 0; + vp = 0; + if (token == T_COMMA) /* null argument */ + t.v_type = V_ERR; + else { + if (p_expr0(&t, flag) < 0) + break; + if (t.v_type == V_ERR) + flag = 0; + } + if (token != T_ASSIGN) { + if (i >= LCMD_NARG || + c != 0 && (ap = lp) == 0 && + (ap = c->lc_arg + i)->arg_name == 0) { + p_error("%s: Too many arguments.", name); + flag = 0; + } else + vp = &av[i++]; + } else { + char *tmp; + if (p_convstr(&t) < 0) + goto abort; + tmp = t.v_type == V_STR ? t.v_str : 0; + (void) s_gettok(); + if (p_expr(&t, flag) < 0) { + if (tmp) + str_free(tmp); + p_synerror(); + goto abort; + } + if (t.v_type == V_ERR) + flag = 0; + if (tmp) { + if (c == 0) { + /* an aliase */ + p_error("%s: Bad alias syntax.", name); + flag = 0; + } else { + for (ap = c->lc_arg, vp = av; + ap != 0 && ap->arg_name != 0 && + (*ap->arg_name == '\0' || + !str_match(tmp, ap->arg_name, + ap->arg_minlen)); + ap++, vp++) + ; + if (ap == 0 || ap->arg_name == 0) { + p_error("%s: Unknown argument \"%s\".", + name, tmp); + flag = 0; + ap = 0; + vp = 0; + } + } + str_free(tmp); + } + } + if (ap != 0) { + if (ap->arg_flags & ARG_LIST) { + i = vp - av + 1; + lp = ap; + } + if (vp->v_type != V_ERR) { + if (*ap->arg_name) + p_error("%s: Argument %d (%s) duplicated.", + name, vp - av + 1, + ap->arg_name); + else + p_error("%s: Argument %d duplicated.", + name, vp - av + 1); + flag = 0; + vp = 0; + } else if (t.v_type == V_ERR) { + /* do nothing */ + } else if ((ap->arg_flags&ARG_TYPE) == ARG_NUM && + t.v_type != V_NUM || + (ap->arg_flags&ARG_TYPE) == ARG_STR && + t.v_type != V_STR) { + if (*ap->arg_name) + p_error("%s: Argument %d (%s) type mismatch.", + name, vp - av + 1, + ap->arg_name); + else + p_error("%s: Argument %d type mismatch.", + name, vp - av + 1); + flag = 0; + vp = 0; + } + } + if (vp != 0) + *vp = t; + else + val_free(t); + if (token == T_COMMA) + (void) s_gettok(); + } + + if (p_erred()) + flag = 0; + if (token == T_RP) + (void) s_gettok(); + else if (token != T_EOL && token != T_EOF) + flag = 0; /* look for legal follow set */ + v->v_type = V_ERR; + if (flag) + if (c != 0) + (*c->lc_func)(v, av); + else + if (a->a_flags & A_INUSE) + p_error("%s: Recursive alias.", a->a_name); + else { + a->a_flags |= A_INUSE; + if (dolongcmd(a->a_buf, av, i) < 0) + p_memerror(); + a->a_flags &= ~A_INUSE; + } + if (p_abort()) { + val_free(*v); + v->v_type = V_ERR; + goto abort; + } + for (vp = av; vp < &av[LCMD_NARG]; vp++) + val_free(*vp); + return 0; +abort: + for (vp = av; vp < &av[LCMD_NARG]; vp++) + val_free(*vp); + return -1; +} + +p_assign(name, v, flag) +char *name; +struct value *v; +char flag; +{ + (void) s_gettok(); + + if (p_expr(v, flag) < 0) { + p_synerror(); + return -1; + } + switch (v->v_type) { + case V_STR: + case V_NUM: + if (flag && var_set(name, v) == 0) { + p_memerror(); + val_free(*v); + return -1; + } + break; + } + return 0; +} diff --git a/usr.bin/window/parser3.c b/usr.bin/window/parser3.c new file mode 100644 index 00000000000..74140c01582 --- /dev/null +++ b/usr.bin/window/parser3.c @@ -0,0 +1,197 @@ +/* $NetBSD: parser3.c,v 1.3 1995/09/28 10:34:33 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser3.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: parser3.c,v 1.3 1995/09/28 10:34:33 tls Exp $"; +#endif +#endif /* not lint */ + +#include "parser.h" + +/* + * = + * ? : + * || + * && + * | + * ^ + * & + * == != + * <= >= + * << >> + * + - + * * / % + * unary - + ~ ! + */ +p_expr(v, flag) +register struct value *v; +char flag; +{ + struct value t; + int ret; + + if (p_expr0(&t, flag) < 0) + return -1; + + if (token != T_ASSIGN) { + *v = t; + return 0; + } + switch (t.v_type) { + case V_NUM: + p_error("%d: Not a variable.", t.v_num); + case V_ERR: + t.v_str = 0; + break; + } + ret = p_assign(t.v_str, v, flag); + if (t.v_str != 0) + str_free(t.v_str); + return ret; +} + +/* + * ? : + */ +p_expr0(v, flag) +register struct value *v; +char flag; +{ + struct value t; + char true; + + if (p_expr1(v, flag) < 0) + return -1; + if (token != T_QUEST) + return 0; + switch (v->v_type) { + case V_NUM: + true = v->v_num != 0; + break; + case V_STR: + p_error("?: Numeric left operand required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + (void) s_gettok(); + v->v_type = V_ERR; + if ((flag && true ? p_expr1(v, 1) : p_expr1(&t, 0)) < 0) + return -1; + if (token != T_COLON) { + val_free(*v); + p_synerror(); + return -1; + } + (void) s_gettok(); + return flag && !true ? p_expr1(v, 1) : p_expr1(&t, 0); +} + +/* + * || + */ +p_expr1(v, flag) +register struct value *v; +char flag; +{ + char true = 0; + + if (p_expr2(v, flag) < 0) + return -1; + if (token != T_OROR) + return 0; + for (;;) { + switch (v->v_type) { + case V_NUM: + v->v_num = true = true || v->v_num != 0; + break; + case V_STR: + p_error("||: Numeric operands required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + if (token != T_OROR) + return 0; + (void) s_gettok(); + if (p_expr2(v, flag && !true) < 0) + return -1; + } +} + +/* + * && + */ +p_expr2(v, flag) +register struct value *v; +char flag; +{ + char true = 1; + + if (p_expr3_10(3, v, flag) < 0) + return -1; + if (token != T_ANDAND) + return 0; + for (;;) { + switch (v->v_type) { + case V_NUM: + v->v_num = true = true && v->v_num != 0; + break; + case V_STR: + p_error("&&: Numeric operands required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + if (token != T_ANDAND) + return 0; + (void) s_gettok(); + if (p_expr3_10(3, v, flag && true) < 0) + return -1; + } + /*NOTREACHED*/ +} diff --git a/usr.bin/window/parser4.c b/usr.bin/window/parser4.c new file mode 100644 index 00000000000..c2a0dac28d1 --- /dev/null +++ b/usr.bin/window/parser4.c @@ -0,0 +1,303 @@ +/* $NetBSD: parser4.c,v 1.5 1995/09/29 00:44:05 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser4.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: parser4.c,v 1.5 1995/09/29 00:44:05 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "parser.h" +#include <string.h> + +/* + * | 3 + * ^ 4 + * & 5 + * == != 6 + * < <= > >= 7 + * << >> 8 + * + - 9 + * * / % 10 + */ +p_expr3_10(level, v, flag) +register struct value *v; +char flag; +{ + struct value l, r; + int op; + char *opname; + + if ((level == 10 ? p_expr11(v, flag) + : p_expr3_10(level + 1, v, flag)) < 0) + return -1; + for (;;) { + switch (level) { + case 3: + if (token != T_OR) + return 0; + opname = "|"; + break; + case 4: + if (token != T_XOR) + return 0; + opname = "^"; + break; + case 5: + if (token != T_AND) + return 0; + opname = "&"; + break; + case 6: + if (token == T_EQ) + opname = "=="; + else if (token == T_NE) + opname = "!="; + else + return 0; + break; + case 7: + switch (token) { + case T_LT: + opname = "<"; + break; + case T_LE: + opname = "<="; + break; + case T_GT: + opname = ">"; + break; + case T_GE: + opname = ">="; + break; + default: + return 0; + } + break; + case 8: + if (token == T_LS) + opname = "<<"; + else if (token == T_RS) + opname = ">>"; + else + return 0; + break; + case 9: + if (token == T_PLUS) + opname = "+"; + else if (token == T_MINUS) + opname = "-"; + else + return 0; + break; + case 10: + switch (token) { + case T_MUL: + opname = "*"; + break; + case T_DIV: + opname = "/"; + break; + case T_MOD: + opname = "%"; + break; + default: + return 0; + } + break; + } + l = *v; + if (l.v_type == V_ERR) + flag = 0; + + op = token; + (void) s_gettok(); + if ((level == 10 ? p_expr11(&r, flag) + : p_expr3_10(level + 1, &r, flag)) < 0) { + p_synerror(); + val_free(l); + return -1; + } + + if (r.v_type == V_ERR) + flag = 0; + else switch (op) { + case T_EQ: + case T_NE: + case T_LT: + case T_LE: + case T_GT: + case T_GE: + case T_PLUS: + if (l.v_type == V_STR) { + if (r.v_type == V_NUM) + if (p_convstr(&r) < 0) + flag = 0; + } else + if (r.v_type == V_STR) + if (p_convstr(&l) < 0) + flag = 0; + break; + case T_LS: + case T_RS: + if (r.v_type == V_STR) { + char *p = r.v_str; + r.v_type = V_NUM; + r.v_num = strlen(p); + str_free(p); + } + break; + case T_OR: + case T_XOR: + case T_AND: + case T_MINUS: + case T_MUL: + case T_DIV: + case T_MOD: + default: + if (l.v_type == V_STR || r.v_type == V_STR) { + p_error("%s: Numeric operands required.", + opname); + flag = 0; + } + } + if (!flag) { + val_free(l); + val_free(r); + v->v_type = V_ERR; + if (p_abort()) + return -1; + continue; + } + + v->v_type = V_NUM; + switch (op) { + case T_EQ: + case T_NE: + case T_LT: + case T_LE: + case T_GT: + case T_GE: + if (l.v_type == V_STR) { + int tmp = strcmp(l.v_str, r.v_str); + str_free(l.v_str); + str_free(r.v_str); + l.v_type = V_NUM; + l.v_num = tmp; + r.v_type = V_NUM; + r.v_num = 0; + } + break; + } + switch (op) { + case T_OR: + v->v_num = l.v_num | r.v_num; + break; + case T_XOR: + v->v_num = l.v_num ^ r.v_num; + break; + case T_AND: + v->v_num = l.v_num & r.v_num; + break; + case T_EQ: + v->v_num = l.v_num == r.v_num; + break; + case T_NE: + v->v_num = l.v_num != r.v_num; + break; + case T_LT: + v->v_num = l.v_num < r.v_num; + break; + case T_LE: + v->v_num = l.v_num <= r.v_num; + break; + case T_GT: + v->v_num = l.v_num > r.v_num; + break; + case T_GE: + v->v_num = l.v_num >= r.v_num; + break; + case T_LS: + if (l.v_type == V_STR) { + int i; + if ((i = strlen(l.v_str)) > r.v_num) + i = r.v_num; + v->v_str = str_ncpy(l.v_str, i); + v->v_type = V_STR; + } else + v->v_num = l.v_num << r.v_num; + break; + case T_RS: + if (l.v_type == V_STR) { + int i; + if ((i = strlen(l.v_str)) > r.v_num) + i -= r.v_num; + else + i = 0; + v->v_str = str_cpy(l.v_str + i); + v->v_type = V_STR; + } else + v->v_num = l.v_num >> r.v_num; + break; + case T_PLUS: + if (l.v_type == V_STR) { + v->v_str = str_cat(l.v_str, r.v_str); + v->v_type = V_STR; + } else + v->v_num = l.v_num + r.v_num; + break; + case T_MINUS: + v->v_num = l.v_num - r.v_num; + break; + case T_MUL: + v->v_num = l.v_num * r.v_num; + break; + case T_DIV: + v->v_num = l.v_num / r.v_num; + break; + case T_MOD: + v->v_num = l.v_num % r.v_num; + break; + } + val_free(l); + val_free(r); + } + /*NOTREACHED*/ +} diff --git a/usr.bin/window/parser5.c b/usr.bin/window/parser5.c new file mode 100644 index 00000000000..7ff5eb89536 --- /dev/null +++ b/usr.bin/window/parser5.c @@ -0,0 +1,207 @@ +/* $NetBSD: parser5.c,v 1.3 1995/09/28 10:34:35 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser5.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: parser5.c,v 1.3 1995/09/28 10:34:35 tls Exp $"; +#endif +#endif /* not lint */ + +#include "parser.h" +#include "var.h" + +/* + * unary $ $? + - ! ~ + */ +p_expr11(v, flag) +register struct value *v; +char flag; +{ + int op; + char *opname; + + switch (token) { + case T_DOLLAR: + opname = "$"; + break; + case T_DQ: + opname = "$?"; + break; + case T_PLUS: + opname = "unary +"; + break; + case T_MINUS: + opname = "unary -"; + break; + case T_NOT: + opname = "!"; + break; + case T_COMP: + opname = "~"; + break; + default: + return p_expr12(v, flag); + } + op = token; + (void) s_gettok(); + if (p_expr11(v, flag) < 0) + return -1; + switch (v->v_type) { + case V_NUM: + break; + case V_STR: + switch (op) { + case T_MINUS: + case T_NOT: + case T_COMP: + p_error("%s: Numeric operand required.", opname); + str_free(v->v_str); + v->v_type = V_ERR; + return 0; + } + break; + case V_ERR: + return 0; + } + switch (op) { + case T_DOLLAR: + case T_DQ: + if (v->v_type == V_NUM) { + int tmp = cx.x_type == X_BUF && cx.x_arg != 0 && + v->v_num > 0 && v->v_num <= cx.x_narg; + if (op == T_DQ) + v->v_num = tmp; + else if (tmp) + *v = cx.x_arg[v->v_num - 1]; + else { + p_error("%d: No such argument.", v->v_num); + v->v_type = V_ERR; + } + } else { + char *name = v->v_str; + struct var *r = var_lookup(name); + if (op == T_DQ) { + v->v_type = V_NUM; + v->v_num = r != 0; + } else if (r != 0) + *v = r->r_val; + else { + p_error("%s: Undefined variable.", name); + v->v_type = V_ERR; + } + str_free(name); + } + if (v->v_type == V_STR && (v->v_str = str_cpy(v->v_str)) == 0) { + p_memerror(); + return -1; + } + break; + case T_MINUS: + v->v_num = - v->v_num; + break; + case T_NOT: + v->v_num = ! v->v_num; + break; + case T_COMP: + v->v_num = ~ v->v_num; + break; + } + return 0; +} + +/* + * string, number, ( expr ) + * Plus function calls. + * + * Always return v_type == V_ERR when flag == 0. + */ +p_expr12(v, flag) +register struct value *v; +char flag; +{ + v->v_type = V_ERR; + switch (token) { + case T_NUM: + if (flag) { + v->v_type = V_NUM; + v->v_num = token_num; + } + (void) s_gettok(); + break; + case T_STR: + if (flag) { + v->v_type = V_STR; + v->v_str = token_str; + } else + str_free(token_str); + (void) s_gettok(); + break; + case T_LP: + (void) s_gettok(); + if (p_expr(v, flag) < 0) { + p_synerror(); + return -1; + } + if (token != T_RP) { + p_synerror(); + val_free(*v); + return -1; + } + (void) s_gettok(); + break; + default: + return -1; + } + while (token == T_LP) { + char *cmd; + + if (p_convstr(v) < 0) + return -1; + cmd = v->v_type == V_STR ? v->v_str : 0; + if (p_function(cmd, v, flag) < 0) { + if (cmd) + str_free(cmd); + return -1; + } + if (cmd) + str_free(cmd); + } + return 0; +} diff --git a/usr.bin/window/scanner.c b/usr.bin/window/scanner.c new file mode 100644 index 00000000000..7d3029cc61f --- /dev/null +++ b/usr.bin/window/scanner.c @@ -0,0 +1,578 @@ +/* $NetBSD: scanner.c,v 1.3 1995/09/28 10:34:36 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)scanner.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: scanner.c,v 1.3 1995/09/28 10:34:36 tls Exp $"; +#endif +#endif /* not lint */ + +#include "value.h" +#include "token.h" +#include "context.h" +#include "string.h" + +s_getc() +{ + register c; + + switch (cx.x_type) { + case X_FILE: + c = getc(cx.x_fp); + if (cx.x_bol && c != EOF) { + cx.x_bol = 0; + cx.x_lineno++; + } + if (c == '\n') + cx.x_bol = 1; + return c; + case X_BUF: + if (*cx.x_bufp != 0) + return *cx.x_bufp++ & 0xff; + else + return EOF; + } + /*NOTREACHED*/ +} + +s_ungetc(c) +{ + if (c == EOF) + return EOF; + switch (cx.x_type) { + case X_FILE: + cx.x_bol = 0; + return ungetc(c, cx.x_fp); + case X_BUF: + if (cx.x_bufp > cx.x_buf) + return *--cx.x_bufp = c; + else + return EOF; + } + /*NOTREACHED*/ +} + +s_gettok() +{ + char buf[100]; + register char *p = buf; + register c; + register state = 0; + +loop: + c = s_getc(); + switch (state) { + case 0: + switch (c) { + case ' ': + case '\t': + break; + case '\n': + case ';': + cx.x_token = T_EOL; + state = -1; + break; + case '#': + state = 1; + break; + case EOF: + cx.x_token = T_EOF; + state = -1; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': case '.': + *p++ = c; + state = 2; + break; + case '"': + state = 3; + break; + case '\'': + state = 4; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + break; + case -2: + state = 0; + break; + default: + *p++ = c; + state = 2; + } + break; + case '0': + cx.x_val.v_num = 0; + state = 10; + break; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = c - '0'; + state = 11; + break; + case '>': + state = 20; + break; + case '<': + state = 21; + break; + case '=': + state = 22; + break; + case '!': + state = 23; + break; + case '&': + state = 24; + break; + case '|': + state = 25; + break; + case '$': + state = 26; + break; + case '~': + cx.x_token = T_COMP; + state = -1; + break; + case '+': + cx.x_token = T_PLUS; + state = -1; + break; + case '-': + cx.x_token = T_MINUS; + state = -1; + break; + case '*': + cx.x_token = T_MUL; + state = -1; + break; + case '/': + cx.x_token = T_DIV; + state = -1; + break; + case '%': + cx.x_token = T_MOD; + state = -1; + break; + case '^': + cx.x_token = T_XOR; + state = -1; + break; + case '(': + cx.x_token = T_LP; + state = -1; + break; + case ')': + cx.x_token = T_RP; + state = -1; + break; + case ',': + cx.x_token = T_COMMA; + state = -1; + break; + case '?': + cx.x_token = T_QUEST; + state = -1; + break; + case ':': + cx.x_token = T_COLON; + state = -1; + break; + case '[': + cx.x_token = T_LB; + state = -1; + break; + case ']': + cx.x_token = T_RB; + state = -1; + break; + default: + cx.x_val.v_num = c; + cx.x_token = T_CHAR; + state = -1; + break; + } + break; + case 1: /* got # */ + if (c == '\n' || c == EOF) { + (void) s_ungetc(c); + state = 0; + } + break; + case 2: /* unquoted string */ + switch (c) { + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': case '.': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + case '"': + state = 3; + break; + case '\'': + state = 4; + break; + case '\\': + switch (c = s_gettok1()) { + case -2: + (void) s_ungetc(' '); + case -1: + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + (void) s_ungetc(c); + case EOF: + *p = 0; + cx.x_token = T_STR; + switch (*buf) { + case 'i': + if (buf[1] == 'f' && buf[2] == 0) + cx.x_token = T_IF; + break; + case 't': + if (buf[1] == 'h' && buf[2] == 'e' + && buf[3] == 'n' && buf[4] == 0) + cx.x_token = T_THEN; + break; + case 'e': + if (buf[1] == 'n' && buf[2] == 'd' + && buf[3] == 'i' && buf[4] == 'f' + && buf[5] == 0) + cx.x_token = T_ENDIF; + else if (buf[1] == 'l' && buf[2] == 's') + if (buf[3] == 'i' && buf[4] == 'f' + && buf[5] == 0) + cx.x_token = T_ELSIF; + else if (buf[3] == 'e' && buf[4] == 0) + cx.x_token = T_ELSE; + break; + } + if (cx.x_token == T_STR + && (cx.x_val.v_str = str_cpy(buf)) == 0) { + p_memerror(); + cx.x_token = T_EOF; + } + state = -1; + break; + } + break; + case 3: /* " quoted string */ + switch (c) { + case '\n': + (void) s_ungetc(c); + case EOF: + case '"': + state = 2; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + case -2: /* newlines are invisible */ + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + } + break; + case 4: /* ' quoted string */ + switch (c) { + case '\n': + (void) s_ungetc(c); + case EOF: + case '\'': + state = 2; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + case -2: /* newlines are invisible */ + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + } + break; + case 10: /* got 0 */ + switch (c) { + case 'x': + case 'X': + cx.x_val.v_num = 0; + state = 12; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + cx.x_val.v_num = c - '0'; + state = 13; + break; + case '8': case '9': + cx.x_val.v_num = c - '0'; + state = 11; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 11: /* decimal number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = cx.x_val.v_num * 10 + c - '0'; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 12: /* hex number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - '0'; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'a' + 10; + break; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'A' + 10; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 13: /* octal number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + cx.x_val.v_num = cx.x_val.v_num * 8 + c - '0'; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 20: /* got > */ + switch (c) { + case '=': + cx.x_token = T_GE; + state = -1; + break; + case '>': + cx.x_token = T_RS; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_GT; + state = -1; + } + break; + case 21: /* got < */ + switch (c) { + case '=': + cx.x_token = T_LE; + state = -1; + break; + case '<': + cx.x_token = T_LS; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_LT; + state = -1; + } + break; + case 22: /* got = */ + switch (c) { + case '=': + cx.x_token = T_EQ; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_ASSIGN; + state = -1; + } + break; + case 23: /* got ! */ + switch (c) { + case '=': + cx.x_token = T_NE; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_NOT; + state = -1; + } + break; + case 24: /* got & */ + switch (c) { + case '&': + cx.x_token = T_ANDAND; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_AND; + state = -1; + } + break; + case 25: /* got | */ + switch (c) { + case '|': + cx.x_token = T_OROR; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_OR; + state = -1; + } + break; + case 26: /* got $ */ + switch (c) { + case '?': + cx.x_token = T_DQ; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_DOLLAR; + state = -1; + } + break; + default: + abort(); + } + if (state >= 0) + goto loop; + return cx.x_token; +} + +s_gettok1() +{ + register c; + register n; + + c = s_getc(); /* got \ */ + switch (c) { + case EOF: + return -1; + case '\n': + return -2; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + default: + return c; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + break; + } + n = c - '0'; + c = s_getc(); /* got \[0-7] */ + if (c < '0' || c > '7') { + (void) s_ungetc(c); + return n; + } + n = n * 8 + c - '0'; + c = s_getc(); /* got \[0-7][0-7] */ + if (c < '0' || c > '7') { + (void) s_ungetc(c); + return n; + } + return n * 8 + c - '0'; +} diff --git a/usr.bin/window/startup.c b/usr.bin/window/startup.c new file mode 100644 index 00000000000..5accf8bad44 --- /dev/null +++ b/usr.bin/window/startup.c @@ -0,0 +1,98 @@ +/* $NetBSD: startup.c,v 1.3 1995/09/28 10:34:38 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)startup.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: startup.c,v 1.3 1995/09/28 10:34:38 tls Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "value.h" +#include "var.h" +#include "char.h" +#include "local.h" + +doconfig() +{ + char buf[100]; + char *home; + static char runcom[] = RUNCOM; + + if ((home = getenv("HOME")) == 0) + home = "."; + (void) sprintf(buf, "%.*s/%s", + (sizeof buf - sizeof runcom) / sizeof (char) - 1, + home, runcom); + return dosource(buf); +} + +/* + * The default is two windows of equal size. + */ +dodefault() +{ + struct ww *w; + register r = wwnrow / 2 - 1; + + if (openwin(1, r + 2, 0, wwnrow - r - 2, wwncol, default_nline, + (char *) 0, 1, 1, default_shellfile, default_shell) == 0) + return; + if ((w = openwin(0, 1, 0, r, wwncol, default_nline, + (char *) 0, 1, 1, default_shellfile, default_shell)) == 0) + return; + wwprintf(w, "Escape character is %s.\r\n", unctrl(escapec)); +} + +setvars() +{ + /* try to use a random ordering to balance the tree */ + (void) var_setnum("nrow", wwnrow); + (void) var_setnum("ncol", wwncol); + (void) var_setnum("baud", wwbaud); + (void) var_setnum("m_rev", WWM_REV); + (void) var_setnum("m_blk", WWM_BLK); + (void) var_setnum("m_ul", WWM_UL); + (void) var_setnum("m_grp", WWM_GRP); + (void) var_setnum("m_dim", WWM_DIM); + (void) var_setnum("m_usr", WWM_USR); + (void) var_setstr("term", wwterm); + (void) var_setnum("modes", wwavailmodes); +} diff --git a/usr.bin/window/string.c b/usr.bin/window/string.c new file mode 100644 index 00000000000..2f5bee41dc1 --- /dev/null +++ b/usr.bin/window/string.c @@ -0,0 +1,159 @@ +/* $NetBSD: string.c,v 1.5 1995/09/29 00:44:06 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)string.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: string.c,v 1.5 1995/09/29 00:44:06 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "string.h" +#include <stdlib.h> +#include <string.h> + +char * +str_cpy(s) +register char *s; +{ + char *str; + register char *p; + + str = p = str_alloc(strlen(s) + 1); + if (p == 0) + return 0; + while (*p++ = *s++) + ; + return str; +} + +char * +str_ncpy(s, n) +register char *s; +register n; +{ + int l = strlen(s); + char *str; + register char *p; + + if (n > l) + n = l; + str = p = str_alloc(n + 1); + if (p == 0) + return 0; + while (--n >= 0) + *p++ = *s++; + *p = 0; + return str; +} + +char * +str_itoa(i) +int i; +{ + char buf[30]; + + (void) sprintf(buf, "%d", i); + return str_cpy(buf); +} + +char * +str_cat(s1, s2) +char *s1, *s2; +{ + char *str; + register char *p, *q; + + str = p = str_alloc(strlen(s1) + strlen(s2) + 1); + if (p == 0) + return 0; + for (q = s1; *p++ = *q++;) + ; + for (q = s2, p--; *p++ = *q++;) + ; + return str; +} + +/* + * match s against p. + * s can be a prefix of p with at least min characters. + */ +str_match(s, p, min) +register char *s, *p; +register min; +{ + for (; *s && *p && *s == *p; s++, p++, min--) + ; + return *s == *p || *s == 0 && min <= 0; +} + +#ifdef STR_DEBUG +char * +str_alloc(l) +int l; +{ + register struct string *s; + + s = (struct string *) malloc((unsigned)l + str_offset); + if (s == 0) + return 0; + if (str_head.s_forw == 0) + str_head.s_forw = str_head.s_back = &str_head; + s->s_forw = str_head.s_forw; + s->s_back = &str_head; + str_head.s_forw = s; + s->s_forw->s_back = s; + return s->s_data; +} + +str_free(str) +char *str; +{ + register struct string *s; + + for (s = str_head.s_forw; s != &str_head && s->s_data != str; + s = s->s_forw) + ; + if (s == &str_head) + abort(); + s->s_back->s_forw = s->s_forw; + s->s_forw->s_back = s->s_back; + free((char *)s); +} +#endif diff --git a/usr.bin/window/string.h b/usr.bin/window/string.h new file mode 100644 index 00000000000..a26b2bc30c6 --- /dev/null +++ b/usr.bin/window/string.h @@ -0,0 +1,67 @@ +/* $NetBSD: string.h,v 1.3 1995/09/28 10:34:40 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)string.h 8.1 (Berkeley) 6/6/93 + */ + +#define STR_DEBUG + +char *str_cpy(); +char *str_ncpy(); +char *str_cat(); +char *str_itoa(); + +#define str_cmp(a, b) strcmp(a, b) + +#ifdef STR_DEBUG +struct string { + struct string *s_forw; + struct string *s_back; + char s_data[1]; +}; + +struct string str_head; + +#define str_offset ((unsigned)str_head.s_data - (unsigned)&str_head) +#define str_stos(s) ((struct string *)((unsigned)(s) - str_offset)) + +char *str_alloc(); +int str_free(); +#else +#define str_free(s) free(s) +#define str_alloc(s) malloc(s) +#endif diff --git a/usr.bin/window/token.h b/usr.bin/window/token.h new file mode 100644 index 00000000000..aa002230520 --- /dev/null +++ b/usr.bin/window/token.h @@ -0,0 +1,85 @@ +/* $NetBSD: token.h,v 1.3 1995/09/28 10:34:41 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)token.h 8.1 (Berkeley) 6/6/93 + */ + +#define token (cx.x_token) +#define token_num (cx.x_val.v_num) +#define token_str (cx.x_val.v_str) + +#define T_EOL 1 +#define T_EOF 2 +#define T_COMP 3 +#define T_PLUS 4 +#define T_MINUS 5 +#define T_MUL 6 +#define T_DIV 7 +#define T_LP 8 +#define T_RP 9 +#define T_LB 10 +#define T_RB 11 +#define T_DOLLAR 12 +#define T_COMMA 13 +#define T_QUEST 14 +#define T_COLON 15 +#define T_CHAR 16 +#define T_STR 17 +#define T_NUM 18 +#define T_MOD 19 +#define T_XOR 20 +#define T_DQ 21 /* $? */ +#define T_GE 22 +#define T_RS 23 +#define T_GT 24 +#define T_LE 25 +#define T_LS 26 +#define T_LT 27 +#define T_EQ 28 +#define T_ASSIGN 29 +#define T_NE 30 +#define T_NOT 31 +#define T_ANDAND 32 +#define T_AND 33 +#define T_OROR 34 +#define T_OR 35 + +#define T_IF 40 +#define T_THEN 41 +#define T_ELSIF 42 +#define T_ELSE 43 +#define T_ENDIF 44 diff --git a/usr.bin/window/tt.h b/usr.bin/window/tt.h new file mode 100644 index 00000000000..ed4c13b8335 --- /dev/null +++ b/usr.bin/window/tt.h @@ -0,0 +1,155 @@ +/* $NetBSD: tt.h,v 1.3 1995/09/28 10:34:42 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)tt.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Interface structure for the terminal drivers. + */ +struct tt { + /* startup and cleanup */ + int (*tt_start)(); + int (*tt_reset)(); + int (*tt_end)(); + + /* terminal functions */ + int (*tt_move)(); + int (*tt_insline)(); + int (*tt_delline)(); + int (*tt_inschar)(); + int (*tt_insspace)(); + int (*tt_delchar)(); + int (*tt_write)(); /* write a whole block */ + int (*tt_putc)(); /* write one character */ + int (*tt_clreol)(); + int (*tt_clreos)(); + int (*tt_clear)(); + int (*tt_scroll_down)(); + int (*tt_scroll_up)(); + int (*tt_setscroll)(); /* set scrolling region */ + int (*tt_setmodes)(); /* set display modes */ + int (*tt_set_token)(); /* define a token */ + int (*tt_put_token)(); /* refer to a defined token */ + int (*tt_compress)(); /* begin, end compression */ + int (*tt_checksum)(); /* compute checksum */ + int (*tt_checkpoint)(); /* checkpoint protocol */ + int (*tt_rint)(); /* input processing */ + + /* internal variables */ + char tt_modes; /* the current display modes */ + char tt_nmodes; /* the new modes for next write */ + char tt_insert; /* currently in insert mode */ + int tt_row; /* cursor row */ + int tt_col; /* cursor column */ + int tt_scroll_top; /* top of scrolling region */ + int tt_scroll_bot; /* bottom of scrolling region */ + + /* terminal info */ + int tt_nrow; /* number of display rows */ + int tt_ncol; /* number of display columns */ + char tt_availmodes; /* the display modes supported */ + char tt_wrap; /* has auto wrap around */ + char tt_retain; /* can retain below (db flag) */ + short tt_padc; /* the pad character */ + int tt_ntoken; /* number of compression tokens */ + int tt_token_min; /* minimun token size */ + int tt_token_max; /* maximum token size */ + int tt_set_token_cost; /* cost in addition to string */ + int tt_put_token_cost; /* constant cost */ + int tt_ack; /* checkpoint ack-nack flag */ + + /* the frame characters */ + short *tt_frame; + + /* ttflush() hook */ + int (*tt_flush)(); +}; +struct tt tt; + +/* + * tt_padc is used by the compression routine. + * It is a short to allow the driver to indicate that there is no padding. + */ +#define TT_PADC_NONE 0x100 + +/* + * List of terminal drivers. + */ +struct tt_tab { + char *tt_name; + int tt_len; + int (*tt_func)(); +}; +extern struct tt_tab tt_tab[]; + +/* + * Clean interface to termcap routines. + * Too may t's. + */ +char tt_strings[1024]; /* string buffer */ +char *tt_strp; /* pointer for it */ + +struct tt_str { + char *ts_str; + int ts_n; +}; + +struct tt_str *tttgetstr(); +struct tt_str *ttxgetstr(); /* tgetstr() and expand delays */ + +int tttputc(); +#define tttputs(s, n) tputs((s)->ts_str, (n), tttputc) +#define ttxputs(s) ttwrite((s)->ts_str, (s)->ts_n) + +/* + * Buffered output without stdio. + * These variables have different meanings from the ww_ob* variables. + * But I'm too lazy to think up different names. + */ +char *tt_ob; +char *tt_obp; +char *tt_obe; +#define ttputc(c) (tt_obp < tt_obe ? (*tt_obp++ = (c)) \ + : (ttflush(), *tt_obp++ = (c))) + +/* + * Convenience macros for the drivers + * They require char.h + */ +#define ttctrl(c) ttputc(ctrl(c)) +#define ttesc(c) (ttctrl('['), ttputc(c)) diff --git a/usr.bin/window/ttf100.c b/usr.bin/window/ttf100.c new file mode 100644 index 00000000000..b9c14b69f43 --- /dev/null +++ b/usr.bin/window/ttf100.c @@ -0,0 +1,75 @@ +/* $NetBSD: ttf100.c,v 1.3 1995/09/28 10:34:44 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttf100.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttf100.c,v 1.3 1995/09/28 10:34:44 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Freedom 100 + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short f100_frame[16] = { + ' ', 'J'|G, 'K'|G, 'A'|G, + 'J'|G, 'J'|G, 'B'|G, 'M'|G, + 'K'|G, 'D'|G, 'K'|G, 'O'|G, + 'C'|G, 'L'|G, 'N'|G, 'I'|G +}; +extern struct tt_str *gen_AE, *gen_AS; + +tt_f100() +{ + static struct tt_str ae = { "\033%", 2 }; + static struct tt_str as = { "\033$", 2 }; + + if (tt_generic() < 0) + return -1; + tt.tt_frame = f100_frame; + tt.tt_availmodes |= WWM_GRP; + gen_AS = &as; + gen_AE = &ae; + return 0; +} diff --git a/usr.bin/window/ttgeneric.c b/usr.bin/window/ttgeneric.c new file mode 100644 index 00000000000..640758e42a0 --- /dev/null +++ b/usr.bin/window/ttgeneric.c @@ -0,0 +1,555 @@ +/* $NetBSD: ttgeneric.c,v 1.3 1995/09/28 10:34:45 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttgeneric.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttgeneric.c,v 1.3 1995/09/28 10:34:45 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +char PC, *BC, *UP; +short ospeed; + + /* normal frame */ +short gen_frame[16] = { + ' ', '|', '-', '+', + '|', '|', '+', '+', + '-', '+', '-', '+', + '+', '+', '+', '+' +}; + + /* ANSI graphics frame */ +#define G (WWM_GRP << WWC_MSHIFT) +short ansi_frame[16] = { + ' ', 'x'|G, 'Q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'n'|G +}; +struct tt_str ansi_AS = { + "\033(0", 3 +}; + +struct tt_str *gen_PC; +struct tt_str *gen_CM; +struct tt_str *gen_IM; +struct tt_str *gen_IC; +struct tt_str *gen_ICn; +struct tt_str *gen_IP; +struct tt_str *gen_EI; +struct tt_str *gen_DC; +struct tt_str *gen_DCn; +struct tt_str *gen_AL; +struct tt_str *gen_ALn; +struct tt_str *gen_DL; +struct tt_str *gen_DLn; +struct tt_str *gen_CE; +struct tt_str *gen_CD; +struct tt_str *gen_CL; +struct tt_str *gen_VS; +struct tt_str *gen_VE; +struct tt_str *gen_TI; +struct tt_str *gen_TE; +struct tt_str *gen_SO; +struct tt_str *gen_SE; +struct tt_str *gen_US; +struct tt_str *gen_UE; +struct tt_str *gen_LE; +struct tt_str *gen_ND; +struct tt_str *gen_UP; +struct tt_str *gen_DO; +struct tt_str *gen_BC; +struct tt_str *gen_NL; +struct tt_str *gen_CR; +struct tt_str *gen_HO; +struct tt_str *gen_AS; +struct tt_str *gen_AE; +struct tt_str *gen_XS; +struct tt_str *gen_XE; +struct tt_str *gen_SF; +struct tt_str *gen_SFn; +struct tt_str *gen_SR; +struct tt_str *gen_SRn; +struct tt_str *gen_CS; +char gen_MI; +char gen_MS; +char gen_AM; +char gen_OS; +char gen_BS; +char gen_DA; +char gen_DB; +char gen_NS; +char gen_XN; +int gen_CO; +int gen_LI; +int gen_UG; +int gen_SG; + +gen_setinsert(new) +char new; +{ + if (new) { + if (gen_IM) + ttxputs(gen_IM); + } else + if (gen_EI) + ttxputs(gen_EI); + tt.tt_insert = new; +} + +gen_setmodes(new) +register new; +{ + register diff; + + diff = new ^ tt.tt_modes; + if (diff & WWM_REV) { + if (new & WWM_REV) { + if (gen_SO) + ttxputs(gen_SO); + } else + if (gen_SE) + ttxputs(gen_SE); + } + if (diff & WWM_UL) { + if (new & WWM_UL) { + if (gen_US) + ttxputs(gen_US); + } else + if (gen_UE) + ttxputs(gen_UE); + } + if (diff & WWM_GRP) { + if (new & WWM_GRP) { + if (gen_AS) + ttxputs(gen_AS); + } else + if (gen_AE) + ttxputs(gen_AE); + } + if (diff & WWM_USR) { + if (new & WWM_USR) { + if (gen_XS) + ttxputs(gen_XS); + } else + if (gen_XE) + ttxputs(gen_XE); + } + tt.tt_modes = new; +} + +gen_insline(n) +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + if (gen_ALn) + ttpgoto(gen_ALn, 0, n, gen_LI - tt.tt_row); + else + while (--n >= 0) + tttputs(gen_AL, gen_LI - tt.tt_row); +} + +gen_delline(n) +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + if (gen_DLn) + ttpgoto(gen_DLn, 0, n, gen_LI - tt.tt_row); + else + while (--n >= 0) + tttputs(gen_DL, gen_LI - tt.tt_row); +} + +gen_putc(c) +register char c; +{ + if (tt.tt_insert) + gen_setinsert(0); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + ttputc(c); + if (++tt.tt_col == gen_CO) + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; +} + +gen_write(p, n) + register char *p; + register n; +{ + if (tt.tt_insert) + gen_setinsert(0); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == gen_CO) + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; +} + +gen_move(row, col) +register int row, col; +{ + if (tt.tt_row == row && tt.tt_col == col) + return; + if (!gen_MI && tt.tt_insert) + gen_setinsert(0); + if (!gen_MS && tt.tt_modes) + gen_setmodes(0); + if (row < tt.tt_scroll_top || row > tt.tt_scroll_bot) + gen_setscroll(0, tt.tt_nrow - 1); + if (tt.tt_row == row) { + if (col == 0) { + ttxputs(gen_CR); + goto out; + } + if (tt.tt_col == col - 1) { + if (gen_ND) { + ttxputs(gen_ND); + goto out; + } + } else if (tt.tt_col == col + 1) { + if (gen_LE) { + ttxputs(gen_LE); + goto out; + } + } + } + if (tt.tt_col == col) { + if (tt.tt_row == row + 1) { + if (gen_UP) { + ttxputs(gen_UP); + goto out; + } + } else if (tt.tt_row == row - 1) { + ttxputs(gen_DO); + goto out; + } + } + if (gen_HO && col == 0 && row == 0) { + ttxputs(gen_HO); + goto out; + } + tttgoto(gen_CM, col, row); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +gen_start() +{ + if (gen_VS) + ttxputs(gen_VS); + if (gen_TI) + ttxputs(gen_TI); + ttxputs(gen_CL); + tt.tt_col = tt.tt_row = 0; + tt.tt_insert = 0; + tt.tt_nmodes = tt.tt_modes = 0; +} + +gen_end() +{ + if (tt.tt_insert) + gen_setinsert(0); + if (gen_TE) + ttxputs(gen_TE); + if (gen_VE) + ttxputs(gen_VE); +} + +gen_clreol() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + tttputs(gen_CE, gen_CO - tt.tt_col); +} + +gen_clreos() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + tttputs(gen_CD, gen_LI - tt.tt_row); +} + +gen_clear() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + ttxputs(gen_CL); +} + +gen_inschar(c) +register char c; +{ + if (!tt.tt_insert) + gen_setinsert(1); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + if (gen_IC) + tttputs(gen_IC, gen_CO - tt.tt_col); + ttputc(c); + if (gen_IP) + tttputs(gen_IP, gen_CO - tt.tt_col); + if (++tt.tt_col == gen_CO) + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; +} + +gen_insspace(n) +{ + if (gen_ICn) + ttpgoto(gen_ICn, 0, n, gen_CO - tt.tt_col); + else + while (--n >= 0) + tttputs(gen_IC, gen_CO - tt.tt_col); +} + +gen_delchar(n) +{ + if (gen_DCn) + ttpgoto(gen_DCn, 0, n, gen_CO - tt.tt_col); + else + while (--n >= 0) + tttputs(gen_DC, gen_CO - tt.tt_col); +} + +gen_scroll_down(n) +{ + gen_move(tt.tt_scroll_bot, 0); + if (gen_SFn) + ttpgoto(gen_SFn, 0, n, n); + else + while (--n >= 0) + ttxputs(gen_SF); +} + +gen_scroll_up(n) +{ + gen_move(tt.tt_scroll_top, 0); + if (gen_SRn) + ttpgoto(gen_SRn, 0, n, n); + else + while (--n >= 0) + ttxputs(gen_SR); +} + +gen_setscroll(top, bot) +{ + tttgoto(gen_CS, bot, top); + tt.tt_scroll_top = top; + tt.tt_scroll_bot = bot; + tt.tt_row = tt.tt_col = -10; +} + +tt_generic() +{ + gen_PC = tttgetstr("pc"); + PC = gen_PC ? *gen_PC->ts_str : 0; + ospeed = wwospeed; + + gen_CM = ttxgetstr("cm"); /* may not work */ + gen_IM = ttxgetstr("im"); + gen_IC = tttgetstr("ic"); + gen_ICn = tttgetstr("IC"); + gen_IP = tttgetstr("ip"); + gen_EI = ttxgetstr("ei"); + gen_DC = tttgetstr("dc"); + gen_DCn = tttgetstr("DC"); + gen_AL = tttgetstr("al"); + gen_ALn = tttgetstr("AL"); + gen_DL = tttgetstr("dl"); + gen_DLn = tttgetstr("DL"); + gen_CE = tttgetstr("ce"); + gen_CD = tttgetstr("cd"); + gen_CL = ttxgetstr("cl"); + gen_VS = ttxgetstr("vs"); + gen_VE = ttxgetstr("ve"); + gen_TI = ttxgetstr("ti"); + gen_TE = ttxgetstr("te"); + gen_SO = ttxgetstr("so"); + gen_SE = ttxgetstr("se"); + gen_US = ttxgetstr("us"); + gen_UE = ttxgetstr("ue"); + gen_LE = ttxgetstr("le"); + gen_ND = ttxgetstr("nd"); + gen_UP = ttxgetstr("up"); + gen_DO = ttxgetstr("do"); + gen_BC = ttxgetstr("bc"); + gen_NL = ttxgetstr("nl"); + gen_CR = ttxgetstr("cr"); + gen_HO = ttxgetstr("ho"); + gen_AS = ttxgetstr("as"); + gen_AE = ttxgetstr("ae"); + gen_XS = ttxgetstr("XS"); + gen_XE = ttxgetstr("XE"); + gen_SF = ttxgetstr("sf"); + gen_SFn = ttxgetstr("SF"); + gen_SR = ttxgetstr("sr"); + gen_SRn = ttxgetstr("SR"); + gen_CS = ttxgetstr("cs"); + gen_MI = tgetflag("mi"); + gen_MS = tgetflag("ms"); + gen_AM = tgetflag("am"); + gen_OS = tgetflag("os"); + gen_BS = tgetflag("bs"); + gen_DA = tgetflag("da"); + gen_DB = tgetflag("db"); + gen_NS = tgetflag("ns"); + gen_XN = tgetflag("xn"); + gen_CO = tgetnum("co"); + gen_LI = tgetnum("li"); + gen_UG = tgetnum("ug"); + gen_SG = tgetnum("sg"); + if (gen_CL == 0 || gen_OS || gen_CM == 0) + return -1; + + /* + * Deal with obsolete termcap fields. + */ + if (gen_LE == 0) + if (gen_BC) + gen_LE = gen_BC; + else if (gen_BS) { + static struct tt_str bc = { "\b", 1 }; + gen_BC = &bc; + } + if (gen_NL == 0) { + static struct tt_str nl = { "\n", 1 }; + gen_NL = &nl; + } + if (gen_DO == 0) + gen_DO = gen_NL; + if (gen_CR == 0) { + static struct tt_str cr = { "\r", 1 }; + gen_CR = &cr; + } + /* + * Most terminal will scroll with "nl", but very few specify "sf". + * We shouldn't use "do" here. + */ + if (gen_SF == 0 && !gen_NS) + gen_SF = gen_NL; + BC = gen_LE ? gen_LE->ts_str : 0; + UP = gen_UP ? gen_UP->ts_str : 0; + /* + * Fix up display attributes that we can't handle, or don't + * really exist. + */ + if (gen_SG > 0) + gen_SO = 0; + if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0) + gen_US = 0; + + if (gen_IM && gen_IM->ts_n == 0) { + free((char *) gen_IM); + gen_IM = 0; + } + if (gen_EI && gen_EI->ts_n == 0) { + free((char *) gen_EI); + gen_EI = 0; + } + if (gen_IC && gen_IC->ts_n == 0) { + free((char *) gen_IC); + gen_IC = 0; + } + if (gen_IM) + tt.tt_inschar = gen_inschar; + else if (gen_IC) + tt.tt_insspace = gen_insspace; + if (gen_DC) + tt.tt_delchar = gen_delchar; + if (gen_AL) + tt.tt_insline = gen_insline; + if (gen_DL) + tt.tt_delline = gen_delline; + if (gen_CE) + tt.tt_clreol = gen_clreol; + if (gen_CD) + tt.tt_clreos = gen_clreos; + if (gen_SF) + tt.tt_scroll_down = gen_scroll_down; + /* + * Don't allow scroll_up if da or db but not cs. + * See comment in wwscroll.c. + */ + if (gen_SR && (gen_CS || !gen_DA && !gen_DB)) + tt.tt_scroll_up = gen_scroll_up; + if (gen_CS) + tt.tt_setscroll = gen_setscroll; + if (gen_SO) + tt.tt_availmodes |= WWM_REV; + if (gen_US) + tt.tt_availmodes |= WWM_UL; + if (gen_AS) + tt.tt_availmodes |= WWM_GRP; + if (gen_XS) + tt.tt_availmodes |= WWM_USR; + tt.tt_wrap = gen_AM; + tt.tt_retain = gen_DB; + tt.tt_ncol = gen_CO; + tt.tt_nrow = gen_LI; + tt.tt_start = gen_start; + tt.tt_end = gen_end; + tt.tt_write = gen_write; + tt.tt_putc = gen_putc; + tt.tt_move = gen_move; + tt.tt_clear = gen_clear; + tt.tt_setmodes = gen_setmodes; + tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ? + ansi_frame : gen_frame; + return 0; +} diff --git a/usr.bin/window/tth19.c b/usr.bin/window/tth19.c new file mode 100644 index 00000000000..edeed049cc4 --- /dev/null +++ b/usr.bin/window/tth19.c @@ -0,0 +1,284 @@ +/* $NetBSD: tth19.c,v 1.3 1995/09/28 10:34:47 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tth19.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: tth19.c,v 1.3 1995/09/28 10:34:47 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* +kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith: + cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK: + cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB: + ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms: + ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4: + kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH: + kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW: + l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER: + es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1: +*/ + +#define NCOL 80 +#define NROW 24 + +#define G (WWM_GRP << WWC_MSHIFT) +short h19_frame[16] = { + ' ', '`'|G, 'a'|G, 'e'|G, + '`'|G, '`'|G, 'f'|G, 'v'|G, + 'a'|G, 'd'|G, 'a'|G, 'u'|G, + 'c'|G, 't'|G, 's'|G, 'b'|G +}; + +extern struct tt_str *gen_VS; +extern struct tt_str *gen_VE; + +int h19_msp10c; + +#define PAD(ms10) { \ + register i; \ + for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \ + ttputc('\0'); \ +} +#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */ +#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */ + +#define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O') + +h19_setmodes(new) +register new; +{ + register diff; + + diff = new ^ tt.tt_modes; + if (diff & WWM_REV) + ttesc(new & WWM_REV ? 'p' : 'q'); + if (diff & WWM_GRP) + ttesc(new & WWM_REV ? 'F' : 'G'); + tt.tt_modes = new; +} + +h19_insline(n) +{ + while (--n >= 0) { + ttesc('L'); + ILPAD(); + } +} + +h19_delline(n) +{ + while (--n >= 0) { + ttesc('M'); + ILPAD(); + } +} + +h19_putc(c) +register char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (tt.tt_insert) + H19_SETINSERT(0); + ttputc(c); + if (++tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +h19_write(p, n) +register char *p; +register n; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (tt.tt_insert) + H19_SETINSERT(0); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +h19_move(row, col) +register char row, col; +{ + if (tt.tt_row == row) { + if (tt.tt_col == col) + return; + if (col == 0) { + ttctrl('m'); + goto out; + } + if (tt.tt_col == col - 1) { + ttesc('C'); + goto out; + } + if (tt.tt_col == col + 1) { + ttctrl('h'); + goto out; + } + } + if (tt.tt_col == col) { + if (tt.tt_row == row + 1) { + ttesc('A'); + goto out; + } + if (tt.tt_row == row - 1) { + ttctrl('j'); + goto out; + } + } + if (col == 0 && row == 0) { + ttesc('H'); + goto out; + } + ttesc('Y'); + ttputc(' ' + row); + ttputc(' ' + col); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +h19_start() +{ + if (gen_VS) + ttxputs(gen_VS); + ttesc('w'); + ttesc('E'); + tt.tt_col = tt.tt_row = 0; + tt.tt_insert = 0; + tt.tt_nmodes = tt.tt_modes = 0; +} + +h19_end() +{ + if (tt.tt_insert) + H19_SETINSERT(0); + if (gen_VE) + ttxputs(gen_VE); + ttesc('v'); +} + +h19_clreol() +{ + ttesc('K'); +} + +h19_clreos() +{ + ttesc('J'); +} + +h19_clear() +{ + ttesc('E'); +} + +h19_inschar(c) +register char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (!tt.tt_insert) + H19_SETINSERT(1); + ttputc(c); + if (tt.tt_insert) + ICPAD(); + if (++tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +h19_delchar(n) +{ + while (--n >= 0) + ttesc('N'); +} + +h19_scroll_down(n) +{ + h19_move(NROW - 1, 0); + while (--n >= 0) + ttctrl('j'); +} + +h19_scroll_up(n) +{ + h19_move(0, 0); + while (--n >= 0) + ttesc('I'); +} + +tt_h19() +{ + float cpms = (float) wwbaud / 10000; /* char per ms */ + + h19_msp10c = 10 / cpms; /* ms per 10 char */ + gen_VS = ttxgetstr("vs"); + gen_VE = ttxgetstr("ve"); + + tt.tt_start = h19_start; + tt.tt_end = h19_end; + + tt.tt_insline = h19_insline; + tt.tt_delline = h19_delline; + tt.tt_inschar = h19_inschar; + tt.tt_delchar = h19_delchar; + tt.tt_clreol = h19_clreol; + tt.tt_clreos = h19_clreos; + tt.tt_clear = h19_clear; + tt.tt_move = h19_move; + tt.tt_write = h19_write; + tt.tt_putc = h19_putc; + tt.tt_scroll_down = h19_scroll_down; + tt.tt_scroll_up = h19_scroll_up; + tt.tt_setmodes = h19_setmodes; + + tt.tt_ncol = NCOL; + tt.tt_nrow = NROW; + tt.tt_availmodes = WWM_REV|WWM_GRP; + tt.tt_frame = h19_frame; + return 0; +} diff --git a/usr.bin/window/tth29.c b/usr.bin/window/tth29.c new file mode 100644 index 00000000000..127abb08f6d --- /dev/null +++ b/usr.bin/window/tth29.c @@ -0,0 +1,100 @@ +/* $NetBSD: tth29.c,v 1.3 1995/09/28 10:34:48 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tth29.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: tth29.c,v 1.3 1995/09/28 10:34:48 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* + * H29 Driver + * + * WWM_USR mode is alternate character set. + * +kC|h29|heath-29|z29|zenith-29:\ + :am:bc=\ED:bt=\E-:cr=^M:do=^J:nl=^J:bl=^G:\ + :al=\EL:le=^H:bs:cd=\EJ:ce=\EK:cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:\ + :dl=1*\EM:do=\EB:ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:\ + :ms:ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:\ + :kb=^H:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:kn#1:k0=\E~:l0=HOME:\ + :k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:k6=\EP:k7=\EQ:k8=\ER:k9=\E01:\ + :es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:us=\Es8:ue=\Es0: + * + */ + +h29_setmodes(new) +register new; +{ + register modes = '0'; + + if (new & WWM_REV) + modes += 0x01; + if (new & WWM_BLK) + modes += 0x02; + if (new & WWM_DIM) + modes += 0x04; + if (new & WWM_UL) + modes += 0x08; + if (new & WWM_USR) + modes += 0x10; + ttesc('s'); + ttputc(modes); + if (new & WWM_GRP) { + if ((tt.tt_modes & WWM_GRP) == 0) + ttesc('F'); + } else + if (tt.tt_modes & WWM_GRP) + ttesc('G'); + tt.tt_modes = new; +} + +tt_h29() +{ + if (tt_h19() < 0) + return -1; + tt.tt_setmodes = h29_setmodes; + tt.tt_availmodes |= WWM_BLK|WWM_UL|WWM_DIM|WWM_USR; + return 0; +} diff --git a/usr.bin/window/ttinit.c b/usr.bin/window/ttinit.c new file mode 100644 index 00000000000..8ec1fd42a29 --- /dev/null +++ b/usr.bin/window/ttinit.c @@ -0,0 +1,125 @@ +/* $NetBSD: ttinit.c,v 1.3 1995/09/28 10:34:50 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttinit.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttinit.c,v 1.3 1995/09/28 10:34:50 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +int tt_h19(); +int tt_h29(); +int tt_f100(); +int tt_tvi925(); +int tt_wyse75(); +int tt_wyse60(); +int tt_zapple(); +int tt_zentec(); +int tt_generic(); +struct tt_tab tt_tab[] = { + { "h19", 3, tt_h19 }, + { "h29", 3, tt_h29 }, + { "f100", 4, tt_f100 }, + { "tvi925", 6, tt_tvi925 }, + { "wyse75", 6, tt_wyse75 }, + { "wyse60", 6, tt_wyse60 }, + { "w60", 3, tt_wyse60 }, + { "zapple", 6, tt_zapple }, + { "zentec", 6, tt_zentec }, + { "generic", 0, tt_generic }, + 0 +}; + +ttinit() +{ + int i; + register struct tt_tab *tp; + register char *p, *q; + register char *t; + + tt_strp = tt_strings; + + /* + * Set output buffer size to about 1 second of output time. + */ + i = MIN(wwbaud/10, 512); + if ((tt_ob = malloc((unsigned) i)) == 0) { + wwerrno = WWE_NOMEM; + return -1; + } + tt_obp = tt_ob; + tt_obe = tt_ob + i; + + /* + * Use the standard name of the terminal (i.e. the second + * name in termcap). + */ + for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++) + ; + if (*p == '|') + p++; + for (q = p; *q && *q != '|' && *q != ':'; q++) + ; + if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) { + wwterm = t; + while (p < q) + *t++ = *p++; + *t = 0; + } + for (tp = tt_tab; tp->tt_name != 0; tp++) + if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0) + break; + if (tp->tt_name == 0) { + wwerrno = WWE_BADTERM; + return -1; + } + if ((*tp->tt_func)() < 0) { + wwerrno = WWE_CANTDO; + return -1; + } + if (wwgetttysize(0, &tt.tt_nrow, &tt.tt_ncol) < 0) + return -1; + tt.tt_scroll_top = 0; + tt.tt_scroll_bot = tt.tt_nrow - 1; + return 0; +} diff --git a/usr.bin/window/ttoutput.c b/usr.bin/window/ttoutput.c new file mode 100644 index 00000000000..28f4980f09b --- /dev/null +++ b/usr.bin/window/ttoutput.c @@ -0,0 +1,152 @@ +/* $NetBSD: ttoutput.c,v 1.3 1995/09/28 10:34:51 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttoutput.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttoutput.c,v 1.3 1995/09/28 10:34:51 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include <sys/errno.h> + +/* + * Buffered output package. + * We need this because stdio fails on non-blocking writes. + */ + +ttflush() +{ + register char *p; + register n = tt_obp - tt_ob; + extern errno; + + if (n == 0) + return; + if (tt.tt_checksum) + (*tt.tt_checksum)(tt_ob, n); + if (tt.tt_flush) { + (*tt.tt_flush)(); + return; + } + wwnflush++; + for (p = tt_ob; p < tt_obp;) { + wwnwr++; + n = write(1, p, tt_obp - p); + if (n < 0) { + wwnwre++; + if (errno != EWOULDBLOCK) { + /* can't deal with this */ + p = tt_obp; + } + } else if (n == 0) { + /* what to do? */ + wwnwrz++; + } else { + wwnwrc += n; + p += n; + } + } + tt_obp = tt_ob; +} + +ttputs(s) +register char *s; +{ + while (*s) + ttputc(*s++); +} + +ttwrite(s, n) + register char *s; + register n; +{ + switch (n) { + case 0: + break; + case 1: + ttputc(*s); + break; + case 2: + if (tt_obe - tt_obp < 2) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 3: + if (tt_obe - tt_obp < 3) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 4: + if (tt_obe - tt_obp < 4) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 5: + if (tt_obe - tt_obp < 5) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + default: + while (n > 0) { + register m; + + while ((m = tt_obe - tt_obp) == 0) + ttflush(); + if ((m = tt_obe - tt_obp) > n) + m = n; + bcopy(s, tt_obp, m); + tt_obp += m; + s += m; + n -= m; + } + } +} diff --git a/usr.bin/window/tttermcap.c b/usr.bin/window/tttermcap.c new file mode 100644 index 00000000000..0a057a3dd0e --- /dev/null +++ b/usr.bin/window/tttermcap.c @@ -0,0 +1,123 @@ +/* $NetBSD: tttermcap.c,v 1.3 1995/09/28 10:34:52 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tttermcap.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: tttermcap.c,v 1.3 1995/09/28 10:34:52 tls Exp $"; +#endif +#endif /* not lint */ + +#include "tt.h" + +char *tgetstr(); +char *tgoto(); +char *malloc(); + +tttputc(c) +{ + ttputc(c); +} + +ttxputc(c) +{ + *tt_strp++ = c; +} + +struct tt_str * +tttgetstr(str) + char *str; +{ + register struct tt_str *s; + + if ((str = tgetstr(str, &tt_strp)) == 0) + return 0; + if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) + return 0; + s->ts_str = str; + s->ts_n = tt_strp - s->ts_str - 1; + return s; +} + +struct tt_str * +ttxgetstr(str) + char *str; +{ + register struct tt_str *s; + char buf[100]; + char *bufp = buf; + + if (tgetstr(str, &bufp) == 0) + return 0; + if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) + return 0; + s->ts_str = tt_strp; + tputs(buf, 1, ttxputc); + s->ts_n = tt_strp - s->ts_str; + *tt_strp++ = 0; + return s; +} + +tttgoto(s, col, row) + struct tt_str *s; +{ + register char *p = s->ts_str; + + ttputs(tgoto(p, col, row)); + for (p += s->ts_n; *--p == 0;) + ttputc(0); +} + +ttpgoto(s, col, row, n) + struct tt_str *s; +{ + + tputs(tgoto(s->ts_str, col, row), n, tttputc); +} + +ttstrcmp(a, b) + register struct tt_str *a, *b; +{ + int n, r; + + if (r = bcmp(a->ts_str, b->ts_str, + (n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n)) + return r; + return n; +} diff --git a/usr.bin/window/tttvi925.c b/usr.bin/window/tttvi925.c new file mode 100644 index 00000000000..7897230b764 --- /dev/null +++ b/usr.bin/window/tttvi925.c @@ -0,0 +1,70 @@ +/* $NetBSD: tttvi925.c,v 1.3 1995/09/28 10:34:54 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David Barto at Celerity Computer Corp. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tttvi925.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: tttvi925.c,v 1.3 1995/09/28 10:34:54 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Televideo 925 as emulated by Microterm. + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short tvi925_frame[16] = { + ' ', '~'|G, '|'|G, 'c'|G, + '~'|G, '~'|G, '`'|G, 'e'|G, + '|'|G, 'a'|G, '|'|G, 'g'|G, + 'b'|G, 'f'|G, 'h'|G, 'd'|G +}; + +tt_tvi925() +{ + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = tvi925_frame; + return 0; +} diff --git a/usr.bin/window/ttwyse60.c b/usr.bin/window/ttwyse60.c new file mode 100644 index 00000000000..c75dd4de2f7 --- /dev/null +++ b/usr.bin/window/ttwyse60.c @@ -0,0 +1,82 @@ +/* $NetBSD: ttwyse60.c,v 1.3 1995/09/28 10:34:55 tls Exp $ */ + +/* + * Copyright 1987 by David C. Elliott, MIPS Computer Systems. + * + * Unlimited redistribution allowed as long as this notice + * is kept intact. + */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David C. Elliott, of MIPS Computer Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttwyse60.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttwyse60.c,v 1.3 1995/09/28 10:34:55 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define G (WWM_GRP << WWC_MSHIFT) +short wyse60_frame[16] = { + ' ', '6'|G, ':'|G, '1'|G, + '6'|G, '6'|G, '2'|G, '4'|G, + ':'|G, '5'|G, ':'|G, '='|G, + '3'|G, '9'|G, '0'|G, '0'|G +}; + +extern struct tt_str *gen_AS; +extern struct tt_str *gen_AE; + +tt_wyse60() +{ + static struct tt_str ae = { "\033H\003", 3 }; + static struct tt_str as = { "\033H\002", 3 }; + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = wyse60_frame; + if (gen_AS == 0) + gen_AS = &as; + if (gen_AE == 0) + gen_AE = &ae; + return 0; +} diff --git a/usr.bin/window/ttwyse75.c b/usr.bin/window/ttwyse75.c new file mode 100644 index 00000000000..014eb6df1d3 --- /dev/null +++ b/usr.bin/window/ttwyse75.c @@ -0,0 +1,82 @@ +/* $NetBSD: ttwyse75.c,v 1.3 1995/09/28 10:34:56 tls Exp $ */ + +/* + * Copyright 1987 by David C. Elliott, MIPS Computer Systems. + * + * Unlimited redistribution allowed as long as this notice + * is kept intact. + */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David C. Elliott, of MIPS Computer Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttwyse75.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttwyse75.c,v 1.3 1995/09/28 10:34:56 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define G (WWM_GRP << WWC_MSHIFT) +short wyse75_frame[16] = { + ' ', 'x'|G, 'q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'v'|G +}; + +extern struct tt_str *gen_AS; +extern struct tt_str *gen_AE; + +tt_wyse75() +{ + static struct tt_str ae = { "\033(B", 3 }; + static struct tt_str as = { "\033(0", 3 }; + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = wyse75_frame; + if (gen_AS == 0) + gen_AS = &as; + if (gen_AE == 0) + gen_AE = &ae; + return 0; +} diff --git a/usr.bin/window/ttzapple.c b/usr.bin/window/ttzapple.c new file mode 100644 index 00000000000..8e7857de30f --- /dev/null +++ b/usr.bin/window/ttzapple.c @@ -0,0 +1,489 @@ +/* $NetBSD: ttzapple.c,v 1.3 1995/09/28 10:34:57 tls Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttzapple.c,v 1.3 1995/09/28 10:34:57 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* +zz|zapple|perfect apple:\ + :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\ + :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\ + :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\ + :so=\E+:se=\E-:\ + :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\ + :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\ + :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\ + :is=\E-\ET : +*/ + +#define NCOL 80 +#define NROW 24 +#define TOKEN_MAX 32 + +extern short gen_frame[]; + + /* for error correction */ +int zz_ecc; +int zz_lastc; + + /* for checkpointing */ +int zz_sum; + +zz_setmodes(new) +{ + if (new & WWM_REV) { + if ((tt.tt_modes & WWM_REV) == 0) + ttesc('+'); + } else + if (tt.tt_modes & WWM_REV) + ttesc('-'); + tt.tt_modes = new; +} + +zz_insline(n) +{ + if (n == 1) + ttesc('a'); + else { + ttesc('A'); + ttputc(n + ' '); + } +} + +zz_delline(n) +{ + if (n == 1) + ttesc('d'); + else { + ttesc('D'); + ttputc(n + ' '); + } +} + +zz_putc(c) + char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + ttputc(c); + if (++tt.tt_col == NCOL) + tt.tt_col = 0, tt.tt_row++; +} + +zz_write(p, n) + register char *p; + register n; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == NCOL) + tt.tt_col = 0, tt.tt_row++; +} + +zz_move(row, col) + register row, col; +{ + register x; + + if (tt.tt_row == row) { +same_row: + if ((x = col - tt.tt_col) == 0) + return; + if (col == 0) { + ttctrl('m'); + goto out; + } + switch (x) { + case 2: + ttctrl('f'); + case 1: + ttctrl('f'); + goto out; + case -2: + ttctrl('h'); + case -1: + ttctrl('h'); + goto out; + } + if ((col & 7) == 0 && x > 0 && x <= 16) { + ttctrl('i'); + if (x > 8) + ttctrl('i'); + goto out; + } + ttesc('<'); + ttputc(col + ' '); + goto out; + } + if (tt.tt_col == col) { + switch (row - tt.tt_row) { + case 2: + ttctrl('j'); + case 1: + ttctrl('j'); + goto out; + case -2: + ttctrl('k'); + case -1: + ttctrl('k'); + goto out; + } + if (col == 0) { + if (row == 0) + goto home; + if (row == NROW - 1) + goto ll; + } + ttesc('>'); + ttputc(row + ' '); + goto out; + } + if (col == 0) { + if (row == 0) { +home: + ttesc('0'); + goto out; + } + if (row == tt.tt_row + 1) { + /* + * Do newline first to match the sequence + * for scroll down and return + */ + ttctrl('j'); + ttctrl('m'); + goto out; + } + if (row == NROW - 1) { +ll: + ttesc('1'); + goto out; + } + } + /* favor local motion for better compression */ + if (row == tt.tt_row + 1) { + ttctrl('j'); + goto same_row; + } + if (row == tt.tt_row - 1) { + ttctrl('k'); + goto same_row; + } + ttesc('='); + ttputc(' ' + row); + ttputc(' ' + col); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +zz_start() +{ + ttesc('T'); + ttputc(TOKEN_MAX + ' '); + ttesc('U'); + ttputc('!'); + zz_ecc = 1; + zz_lastc = -1; + ttesc('v'); + ttflush(); + zz_sum = 0; + zz_setscroll(0, NROW - 1); + zz_clear(); + zz_setmodes(0); +} + +zz_reset() +{ + zz_setscroll(0, NROW - 1); + tt.tt_modes = WWM_REV; + zz_setmodes(0); + tt.tt_col = tt.tt_row = -10; +} + +zz_end() +{ + ttesc('T'); + ttputc(' '); + ttesc('U'); + ttputc(' '); + zz_ecc = 0; +} + +zz_clreol() +{ + ttesc('2'); +} + +zz_clreos() +{ + ttesc('3'); +} + +zz_clear() +{ + ttesc('4'); + tt.tt_col = tt.tt_row = 0; +} + +zz_insspace(n) +{ + if (n == 1) + ttesc('i'); + else { + ttesc('I'); + ttputc(n + ' '); + } +} + +zz_delchar(n) +{ + if (n == 1) + ttesc('c'); + else { + ttesc('C'); + ttputc(n + ' '); + } +} + +zz_scroll_down(n) +{ + if (n == 1) + if (tt.tt_row == NROW - 1) + ttctrl('j'); + else + ttesc('f'); + else { + ttesc('F'); + ttputc(n + ' '); + } +} + +zz_scroll_up(n) +{ + if (n == 1) + ttesc('r'); + else { + ttesc('R'); + ttputc(n + ' '); + } +} + +zz_setscroll(top, bot) +{ + ttesc('?'); + ttputc(top + ' '); + ttputc(bot + ' '); + tt.tt_scroll_top = top; + tt.tt_scroll_bot = bot; +} + +int zz_debug = 0; + +zz_set_token(t, s, n) + char *s; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + if (zz_debug) { + char buf[100]; + zz_setmodes(WWM_REV); + (void) sprintf(buf, "%02x=", t); + ttputs(buf); + tt.tt_col += 3; + } + ttputc(0x80); + ttputc(t + 1); + s[n - 1] |= 0x80; + ttwrite(s, n); + s[n - 1] &= ~0x80; +} + +/*ARGSUSED*/ +zz_put_token(t, s, n) + char *s; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + if (zz_debug) { + char buf[100]; + zz_setmodes(WWM_REV); + (void) sprintf(buf, "%02x>", t); + ttputs(buf); + tt.tt_col += 3; + } + ttputc(t + 0x81); +} + +zz_rint(p, n) + char *p; +{ + register i; + register char *q; + + if (!zz_ecc) + return n; + for (i = n, q = p; --i >= 0;) { + register c = (unsigned char) *p++; + + if (zz_lastc == 0) { + switch (c) { + case 0: + *q++ = 0; + zz_lastc = -1; + break; + case 1: /* start input ecc */ + zz_ecc = 2; + zz_lastc = -1; + wwnreadstat++; + break; + case 2: /* ack checkpoint */ + tt.tt_ack = 1; + zz_lastc = -1; + wwnreadack++; + break; + case 3: /* nack checkpoint */ + tt.tt_ack = -1; + zz_lastc = -1; + wwnreadnack++; + break; + default: + zz_lastc = c; + wwnreadec++; + } + } else if (zz_ecc == 1) { + if (c) + *q++ = c; + else + zz_lastc = 0; + } else { + if (zz_lastc < 0) { + zz_lastc = c; + } else if (zz_lastc == c) { + *q++ = zz_lastc; + zz_lastc = -1; + } else { + wwnreadec++; + zz_lastc = c; + } + } + } + return q - (p - n); +} + +zz_checksum(p, n) + register char *p; + register n; +{ + while (--n >= 0) { + register c = *p++ & 0x7f; + c ^= zz_sum; + zz_sum = c << 1 | c >> 11 & 1; + } +} + +zz_compress(flag) +{ + if (flag) + tt.tt_checksum = 0; + else + tt.tt_checksum = zz_checksum; +} + +zz_checkpoint() +{ + static char x[] = { ctrl('['), 'V', 0, 0 }; + + zz_checksum(x, sizeof x); + ttesc('V'); + ttputc(' ' + (zz_sum & 0x3f)); + ttputc(' ' + (zz_sum >> 6 & 0x3f)); + ttflush(); + zz_sum = 0; +} + +tt_zapple() +{ + tt.tt_insspace = zz_insspace; + tt.tt_delchar = zz_delchar; + tt.tt_insline = zz_insline; + tt.tt_delline = zz_delline; + tt.tt_clreol = zz_clreol; + tt.tt_clreos = zz_clreos; + tt.tt_scroll_down = zz_scroll_down; + tt.tt_scroll_up = zz_scroll_up; + tt.tt_setscroll = zz_setscroll; + tt.tt_availmodes = WWM_REV; + tt.tt_wrap = 1; + tt.tt_retain = 0; + tt.tt_ncol = NCOL; + tt.tt_nrow = NROW; + tt.tt_start = zz_start; + tt.tt_reset = zz_reset; + tt.tt_end = zz_end; + tt.tt_write = zz_write; + tt.tt_putc = zz_putc; + tt.tt_move = zz_move; + tt.tt_clear = zz_clear; + tt.tt_setmodes = zz_setmodes; + tt.tt_frame = gen_frame; + tt.tt_padc = TT_PADC_NONE; + tt.tt_ntoken = 127; + tt.tt_set_token = zz_set_token; + tt.tt_put_token = zz_put_token; + tt.tt_token_min = 1; + tt.tt_token_max = TOKEN_MAX; + tt.tt_set_token_cost = 2; + tt.tt_put_token_cost = 1; + tt.tt_compress = zz_compress; + tt.tt_checksum = zz_checksum; + tt.tt_checkpoint = zz_checkpoint; + tt.tt_reset = zz_reset; + tt.tt_rint = zz_rint; + return 0; +} diff --git a/usr.bin/window/ttzentec.c b/usr.bin/window/ttzentec.c new file mode 100644 index 00000000000..bec398be3f8 --- /dev/null +++ b/usr.bin/window/ttzentec.c @@ -0,0 +1,72 @@ +/* $NetBSD: ttzentec.c,v 1.3 1995/09/28 10:34:58 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttzentec.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: ttzentec.c,v 1.3 1995/09/28 10:34:58 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Zentec 1021 + * + * We let the termcap entry specify how to enter and exit graphics mode, + * since it varies with what the terminal is emulating. + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short zentec_frame[16] = { + ' ', 'x'|G, 'q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'n'|G +}; + +tt_zentec() +{ + if (tt_generic() < 0) + return -1; + if (tt.tt_availmodes | WWM_GRP) + tt.tt_frame = zentec_frame; + return 0; +} diff --git a/usr.bin/window/value.h b/usr.bin/window/value.h new file mode 100644 index 00000000000..d6b051f84b7 --- /dev/null +++ b/usr.bin/window/value.h @@ -0,0 +1,55 @@ +/* $NetBSD: value.h,v 1.3 1995/09/28 10:35:00 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)value.h 8.1 (Berkeley) 6/6/93 + */ + +struct value { + char v_type; + union { + int V_num; + char *V_str; + } v_un; +}; +#define v_num v_un.V_num +#define v_str v_un.V_str + +#define V_NUM 1 +#define V_STR 2 +#define V_ERR 3 + +#define val_free(v) ((v).v_type == V_STR ? str_free((v).v_str) : 0) diff --git a/usr.bin/window/var.c b/usr.bin/window/var.c new file mode 100644 index 00000000000..3f034b64cd2 --- /dev/null +++ b/usr.bin/window/var.c @@ -0,0 +1,163 @@ +/* $NetBSD: var.c,v 1.4 1995/09/28 10:35:01 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)var.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: var.c,v 1.4 1995/09/28 10:35:01 tls Exp $"; +#endif +#endif /* not lint */ + +#include "value.h" +#include "var.h" +#include "string.h" +#include <stdlib.h> + +struct var * +var_set1(head, name, v) +struct var **head; +char *name; +struct value *v; +{ + register struct var **p; + register struct var *r; + struct value val; + + /* do this first, easier to recover */ + val = *v; + if (val.v_type == V_STR && val.v_str != 0 && + (val.v_str = str_cpy(val.v_str)) == 0) + return 0; + if (*(p = var_lookup1(head, name)) == 0) { + r = (struct var *) malloc(sizeof (struct var)); + if (r == 0) { + val_free(val); + return 0; + } + if ((r->r_name = str_cpy(name)) == 0) { + val_free(val); + free((char *) r); + return 0; + } + r->r_left = r->r_right = 0; + *p = r; + } else { + r = *p; + val_free(r->r_val); + } + r->r_val = val; + return r; +} + +struct var * +var_setstr1(head, name, str) +struct var **head; +char *name; +char *str; +{ + struct value v; + + v.v_type = V_STR; + v.v_str = str; + return var_set1(head, name, &v); +} + +struct var * +var_setnum1(head, name, num) +struct var **head; +char *name; +int num; +{ + struct value v; + + v.v_type = V_NUM; + v.v_num = num; + return var_set1(head, name, &v); +} + +var_unset1(head, name) +struct var **head; +char *name; +{ + register struct var **p; + register struct var *r; + + if (*(p = var_lookup1(head, name)) == 0) + return -1; + r = *p; + *p = r->r_left; + while (*p != 0) + p = &(*p)->r_right; + *p = r->r_right; + val_free(r->r_val); + str_free(r->r_name); + free((char *) r); + return 0; +} + +struct var ** +var_lookup1(p, name) +register struct var **p; +register char *name; +{ + register cmp; + + while (*p != 0) { + if ((cmp = strcmp(name, (*p)->r_name)) < 0) + p = &(*p)->r_left; + else if (cmp > 0) + p = &(*p)->r_right; + else + break; + } + return p; +} + +var_walk1(r, func, a) +register struct var *r; +int (*func)(); +long a; +{ + if (r == 0) + return 0; + if (var_walk1(r->r_left, func, a) < 0 || (*func)(a, r) < 0 + || var_walk1(r->r_right, func, a) < 0) + return -1; + return 0; +} diff --git a/usr.bin/window/var.h b/usr.bin/window/var.h new file mode 100644 index 00000000000..1038e496c5a --- /dev/null +++ b/usr.bin/window/var.h @@ -0,0 +1,60 @@ +/* $NetBSD: var.h,v 1.3 1995/09/28 10:35:02 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)var.h 8.1 (Berkeley) 6/6/93 + */ + +struct var { + struct var *r_left; + struct var *r_right; + char *r_name; + struct value r_val; +}; + +struct var *var_set1(); +struct var *var_setstr1(); +struct var *var_setnum1(); +struct var **var_lookup1(); + +#define var_set(n, v) var_set1(&var_head, n, v) +#define var_setstr(n, s) var_setstr1(&var_head, n, s) +#define var_setnum(n, i) var_setnum1(&var_head, n, i) +#define var_unset(n) var_unset1(&var_head, n) +#define var_lookup(n) (*var_lookup1(&var_head, n)) +#define var_walk(f, a) var_walk1(var_head, f, a) + +struct var *var_head; /* secret, shhh */ diff --git a/usr.bin/window/win.c b/usr.bin/window/win.c new file mode 100644 index 00000000000..da31a4c186f --- /dev/null +++ b/usr.bin/window/win.c @@ -0,0 +1,377 @@ +/* $NetBSD: win.c,v 1.5 1995/09/29 00:44:08 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: win.c,v 1.5 1995/09/29 00:44:08 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "defs.h" +#include "char.h" +#include <string.h> + +/* + * Higher level routines for dealing with windows. + * + * There are two types of windows: user window, and information window. + * User windows are the ones with a pty and shell. Information windows + * are for displaying error messages, and other information. + * + * The windows are doubly linked in overlapping order and divided into + * two groups: foreground and normal. Information + * windows are always foreground. User windows can be either. + * Addwin() adds a window to the list at the top of one of the two groups. + * Deletewin() deletes a window. Front() moves a window to the front + * of its group. Wwopen(), wwadd(), and wwdelete() should never be called + * directly. + */ + +/* + * Open a user window. + */ +struct ww * +openwin(id, row, col, nrow, ncol, nline, label, haspty, hasframe, shf, sh) +char *label; +char haspty, hasframe; +char *shf, **sh; +{ + register struct ww *w; + + if (id < 0 && (id = findid()) < 0) + return 0; + if (row + nrow <= 0 || row > wwnrow - 1 + || col + ncol <= 0 || col > wwncol - 1) { + error("Illegal window position."); + return 0; + } + w = wwopen(haspty ? WWO_PTY : WWO_SOCKET, nrow, ncol, row, col, nline); + if (w == 0) { + error("Can't open window: %s.", wwerror()); + return 0; + } + w->ww_id = id; + window[id] = w; + w->ww_hasframe = hasframe; + w->ww_alt = w->ww_w; + if (label != 0 && setlabel(w, label) < 0) + error("No memory for label."); + wwcursor(w, 1); + /* + * We have to do this little maneuver to make sure + * addwin() puts w at the top, so we don't waste an + * insert and delete operation. + */ + setselwin((struct ww *)0); + addwin(w, 0); + setselwin(w); + if (wwspawn(w, shf, sh) < 0) { + error("Can't execute %s: %s.", shf, wwerror()); + closewin(w); + return 0; + } + return w; +} + +findid() +{ + register i; + + for (i = 0; i < NWINDOW && window[i] != 0; i++) + ; + if (i >= NWINDOW) { + error("Too many windows."); + return -1; + } + return i; +} + +struct ww * +findselwin() +{ + register struct ww *w, *s = 0; + register i; + + for (i = 0; i < NWINDOW; i++) + if ((w = window[i]) != 0 && w != selwin && + (s == 0 || + !isfg(w) && (w->ww_order < s->ww_order || isfg(s)))) + s = w; + return s; +} + +/* + * Close a user window. Close all if w == 0. + */ +closewin(w) +register struct ww *w; +{ + char didit = 0; + register i; + + if (w != 0) { + closewin1(w); + didit++; + } else + for (i = 0; i < NWINDOW; i++) { + if ((w = window[i]) == 0) + continue; + closewin1(w); + didit++; + } + if (didit) { + if (selwin == 0) + if (lastselwin != 0) { + setselwin(lastselwin); + lastselwin = 0; + } else if (w = findselwin()) + setselwin(w); + if (lastselwin == 0 && selwin) + if (w = findselwin()) + lastselwin = w; + reframe(); + } +} + +/* + * Open an information (display) window. + */ +struct ww * +openiwin(nrow, label) +char *label; +{ + register struct ww *w; + + if ((w = wwopen(0, nrow, wwncol, 2, 0, 0)) == 0) + return 0; + w->ww_mapnl = 1; + w->ww_hasframe = 1; + w->ww_nointr = 1; + w->ww_noupdate = 1; + w->ww_unctrl = 1; + w->ww_id = -1; + w->ww_center = 1; + (void) setlabel(w, label); + addwin(w, 1); + reframe(); + return w; +} + +/* + * Close an information window. + */ +closeiwin(w) +struct ww *w; +{ + closewin1(w); + reframe(); +} + +closewin1(w) +register struct ww *w; +{ + if (w == selwin) + selwin = 0; + if (w == lastselwin) + lastselwin = 0; + if (w->ww_id >= 0 && w->ww_id < NWINDOW) + window[w->ww_id] = 0; + if (w->ww_label) + str_free(w->ww_label); + deletewin(w); + wwclose(w); +} + +/* + * Move the window to the top of its group. + * Don't do it if already fully visible. + * Wwvisible() doesn't work for tinted windows. + * But anything to make it faster. + * Always reframe() if doreframe is true. + */ +front(w, doreframe) +register struct ww *w; +char doreframe; +{ + if (w->ww_back != (isfg(w) ? framewin : fgwin) && !wwvisible(w)) { + deletewin(w); + addwin(w, isfg(w)); + doreframe = 1; + } + if (doreframe) + reframe(); +} + +/* + * Add a window at the top of normal windows or foreground windows. + * For normal windows, we put it behind the current window. + */ +addwin(w, fg) +register struct ww *w; +char fg; +{ + if (fg) { + wwadd(w, framewin); + if (fgwin == framewin) + fgwin = w; + } else + wwadd(w, selwin != 0 && selwin != w && !isfg(selwin) + ? selwin : fgwin); +} + +/* + * Delete a window. + */ +deletewin(w) +register struct ww *w; +{ + if (fgwin == w) + fgwin = w->ww_back; + wwdelete(w); +} + +reframe() +{ + register struct ww *w; + + wwunframe(framewin); + for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back) + if (w->ww_hasframe) { + wwframe(w, framewin); + labelwin(w); + } +} + +labelwin(w) +register struct ww *w; +{ + int mode = w == selwin ? WWM_REV : 0; + + if (!w->ww_hasframe) + return; + if (w->ww_id >= 0) { + char buf[2]; + + buf[0] = w->ww_id + '1'; + buf[1] = 0; + wwlabel(w, framewin, 1, buf, mode); + } + if (w->ww_label) { + int col; + + if (w->ww_center) { + col = (w->ww_w.nc - strlen(w->ww_label)) / 2; + col = MAX(3, col); + } else + col = 3; + wwlabel(w, framewin, col, w->ww_label, mode); + } +} + +stopwin(w) + register struct ww *w; +{ + if (w->ww_pty >= 0 && w->ww_ispty && wwstoptty(w->ww_pty) < 0) + error("Can't stop output: %s.", wwerror()); + else + w->ww_stopped = 1; +} + +startwin(w) + register struct ww *w; +{ + if (w->ww_pty >= 0 && w->ww_ispty && wwstarttty(w->ww_pty) < 0) + error("Can't start output: %s.", wwerror()); + else + w->ww_stopped = 0; +} + +sizewin(w, nrow, ncol) +register struct ww *w; +{ + struct ww *back = w->ww_back; + + w->ww_alt.nr = w->ww_w.nr; + w->ww_alt.nc = w->ww_w.nc; + wwdelete(w); + if (wwsize(w, nrow, ncol) < 0) + error("Can't resize window: %s.", wwerror()); + wwadd(w, back); + reframe(); +} + +waitnl(w) +struct ww *w; +{ + (void) waitnl1(w, "[Type any key to continue]"); +} + +more(w, always) +register struct ww *w; +char always; +{ + int c; + char uc = w->ww_unctrl; + + if (!always && w->ww_cur.r < w->ww_w.b - 2) + return 0; + c = waitnl1(w, "[Type escape to abort, any other key to continue]"); + w->ww_unctrl = 0; + wwputs("\033E", w); + w->ww_unctrl = uc; + return c == ctrl('[') ? 2 : 1; +} + +waitnl1(w, prompt) +register struct ww *w; +char *prompt; +{ + char uc = w->ww_unctrl; + + w->ww_unctrl = 0; + front(w, 0); + wwprintf(w, "\033Y%c%c\033sA%s\033rA ", + w->ww_w.nr - 1 + ' ', ' ', prompt); /* print on last line */ + wwcurtowin(w); + while (wwpeekc() < 0) + wwiomux(); + w->ww_unctrl = uc; + return wwgetc(); +} diff --git a/usr.bin/window/window.1 b/usr.bin/window/window.1 new file mode 100644 index 00000000000..46dea8dc812 --- /dev/null +++ b/usr.bin/window/window.1 @@ -0,0 +1,949 @@ +.\" $NetBSD: window.1,v 1.3 1995/09/28 10:35:05 tls Exp $ +.\" +.\" Copyright (c) 1985, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Edward Wang at The University of California, Berkeley. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)window.1 8.2 (Berkeley) 12/30/93 +.\" +.Dd December 30, 1993 +.Dt WINDOW 1 +.Os BSD 4.3 +.Sh NAME +.Nm window +.Nd window environment +.Sh SYNOPSIS +.Nm window +.Op Fl t +.Op Fl f +.Op Fl d +.Op Fl e Ar escape-char +.Op Fl c Ar command +.Sh DESCRIPTION +.Nm Window +implements a window environment on +.Tn ASCII +terminals. +.Pp +A window is a rectangular portion of the physical terminal +screen associated with a set of processes. Its size and +position can be changed by the user at any time. Processes +communicate with their window in the same way they normally +interact with a terminal\-through their standard input, output, +and diagnostic file descriptors. The window program handles the +details of redirecting input and output to and from the +windows. At any one time, only one window can receive +input from the keyboard, but all windows can simultaneously send output +to the display. +.Pp +When +.Nm window +starts up, the commands (see long commands below) +contained in the file +.Pa .windowrc +in the user's home directory are +executed. If it does not exist, two equal sized windows spanning +the terminal screen are created by default. +.Pp +The command line options are +.Bl -tag -width Fl +.It Fl t +Turn on terse mode (see +.Ic terse +command below). +.It Fl f +Fast. Don't perform any startup action. +.It Fl d +Ignore +.Pa .windowrc +and create the two default +windows instead. +.It Fl e Ar escape-char +Set the escape character to +.Ar escape-char . +.Ar Escape-char +can be a single character, or in the form +.Ic ^X +where +.Ar X +is any character, meaning +.No control\- Ns Ar X . +.It Fl c Ar command +Execute the string +.Ar command +as a long command (see below) +before doing anything else. +.El +.Pp +Windows can overlap and are framed as necessary. Each window +is named by one of the digits ``1'' to ``9''. This one-character +identifier, as well as a user definable label string, are displayed +with the window on the top edge of its frame. A window can be +designated to be in the +.Ar foreground , +in which case it will always be +on top of all normal, non-foreground windows, and can be covered +only by other foreground windows. A window need not be completely +within the edges of the terminal screen. Thus a large window +(possibly larger than the screen) may be positioned to show only +a portion of its full size. +.Pp +Each window has a cursor and a set of control functions. Most intelligent +terminal operations such as line and +character deletion and insertion are supported. Display modes +such as underlining and reverse video are available if they are +supported by the terminal. In addition, +similar to terminals with multiple pages of memory, +each window has a text buffer which can have more lines than the window +itself. +.Ss Process Environment +With each newly created window, a shell program is spawned with its +process environment tailored to that window. Its standard input, +output, and diagnostic file descriptors are bound to one end of either +a pseudo-terminal +.Xr (pty 4 ) +or a +.Ux +domain socket +.Xr (socketpair 4 ) . +If a pseudo-terminal is used, then its special +characters and modes (see +.Xr stty 1 ) +are copied from the physical +terminal. A +.Xr termcap 5 +entry tailored to this window is created +and passed as environment +.Xr (environ 5 ) +variable +.Ev TERMCAP . +The termcap entry contains the window's size and +characteristics as well as information from the physical terminal, +such as the existence of underline, reverse video, and other display +modes, and the codes produced by the terminal's function keys, +if any. In addition, the window size attributes of the pseudo-terminal +are set to reflect the size of this window, and updated whenever +it is changed by the user. In particular, the editor +.Xr vi 1 +uses +this information to redraw its display. +.Ss Operation +During normal execution, +.Nm window +can be in one of two states: +conversation mode and command mode. In conversation mode, the +terminal's real cursor is placed at the cursor position of a particular +window--called the current window--and input from the keyboard is sent +to the process in that window. The current window is always +on top of all other windows, except those in foreground. In addition, +it is set apart by highlighting its identifier and label in reverse video. +.Pp +Typing +.Nm window Ns 's +escape character (normally +.Ic ^P ) +in conversation +mode switches it into command mode. In command mode, the top line of +the terminal screen becomes the command prompt window, and +.Nm window +interprets input from the keyboard as commands to manipulate windows. +.Pp +There are two types of commands: short commands are usually one or two +key strokes; long commands are strings either typed by the user in the +command window (see the +.Dq Ic \&: +command below), or read from a file (see +.Ic source +below). +.Ss Short Commands +Below, +.Ar \&# +represents one of the digits ``1'' to ``9'' +corresponding to the windows 1 to 9. +.Ic ^X +means +.No control\- Ns Ar X , +where +.Ar X +is any character. In particular, +.Ic ^^ +is +.Li control\-^. +.Ar Escape +is the escape key, or +.Ic ^\&[ . +.Bl -tag -width Ds +.It Ar # +Select window +.Ar # +as the current window +and return to conversation mode. +.It Ic \&% Ns Ar # +Select window +.Ar # +but stay in command mode. +.It Ic ^^ +Select the previous window and return to conversation +mode. This is useful for toggling between two windows. +.It Ic escape +Return to conversation mode. +.It Ic ^P +Return to conversation mode and write +.Ic ^P +to the +current window. Thus, typing two +.Ic ^P Ns 's +in conversation +mode sends one to the current window. If the +.Nm window +escape is changed to some other character, that +character takes the place of +.Ic ^P +here. +.It Ic ? +List a short summary of commands. +.It Ic ^L +Refresh the screen. +.It Ic q +Exit +.Nm window . +Confirmation is requested. +.It Ic ^Z +Suspend +.Nm window . +.It Ic w +Create a new window. The user is prompted for the positions +of the upper left and lower right corners of the window. +The cursor is placed on the screen and the keys ``h'', ``j'', +``k'', and ``l'' +move the cursor left, down, up, and right, respectively. +The keys ``H'', ``J'', ``K'', and ``L'' move the cursor to the respective +limits of the screen. Typing a number before the movement keys +repeats the movement that number of times. Return enters the cursor position +as the upper left corner of the window. The lower right corner +is entered in the same manner. During this process, +the placement of the new window is indicated by a rectangular +box drawn on the screen, corresponding to where the new window +will be framed. Typing escape at any point +cancels this command. +.Pp +This window becomes the current window, +and is given the first available ID. The default buffer size +is used (see +.Ar default_nline +command below). +.Pp +Only fully visible windows can be created this way. +.It Ic c Ns Ar # +Close window +.Ar # . +The process in the window is sent +the hangup signal (see +.Xr kill 1 ) . +.Xr Csh 1 +should +handle this signal correctly and cause no problems. +.It Ic m Ns Ar # +Move window +.Ar # +to another location. A box in the shape +of the window is drawn on +the screen to indicate the new position of the window, and the same keys as +those for the +.Ic w +command are used to position the box. The +window can be moved partially off-screen. +.It Ic M Ns Ar # +Move window +.Ar # +to its previous position. +.It Ic s Ns Ar # +Change the size of window +.Ar # . +The user is prompted +to enter the new lower right corner of the window. A box +is drawn to indicate the new window size. The same +keys used in +.Ic w +and +.Ic m +are used to enter the position. +.It Ic S Ns Ar # +Change window +.Ar # +to its previous size. +.It Ic ^Y +Scroll the current window up by one line. +.It Ic ^E +Scroll the current window down by one line. +.It Ic ^U +Scroll the current window up by half the window size. +.It Ic ^D +Scroll the current window down by half the window size. +.It Ic ^B +Scroll the current window up by the full window size. +.It Ic ^F +Scroll the current window down by the full window size. +.It Ic h +Move the cursor of the current window left by one column. +.It Ic j +Move the cursor of the current window down by one line. +.It Ic k +Move the cursor of the current window up by one line. +.It Ic l +Move the cursor of the current window right by one column. +.It Ic y +Yank. The user is prompted to enter two points within the current +window. Then the content of the current window between those two points +is saved in the yank buffer. +.It Ic p +Put. The content of the yank buffer is written to the current +window as input. +.It Ic ^S +Stop output in the current window. +.It Ic ^Q +Start output in the current window. +.It Ic : +Enter a line to be executed as long commands. +Normal line +editing characters (erase character, erase word, erase line) +are supported. +.El +.Ss Long Commands +Long commands are a sequence of statements +parsed much like a programming language, with a syntax +similar to that of C. Numeric and string expressions and variables +are supported, as well as conditional statements. +.Pp +There are two data types: string and number. A string is a sequence +of letters or digits beginning with a letter. ``_'' and ``.'' are +considered letters. Alternately, non-alphanumeric characters can +be included in strings by quoting them in ``"'' or escaping them +with ``\\''. In addition, the ``\\'' sequences of C are supported, +both inside and outside quotes (e.g., ``\\n'' is a new line, +``\\r'' a carriage return). For example, these are legal strings: +abcde01234, "&#$^*&#", ab"$#"cd, ab\\$\\#cd, "/usr/ucb/window". +.Pp +A number is an integer value in one of three forms: +a decimal number, an octal number preceded by ``0'', +or a hexadecimal number preceded by ``0x'' or ``0X''. The natural +machine integer size is used (i.e., the signed integer type +of the C compiler). As in C, a non-zero number represents +a boolean true. +.Pp +The character ``#'' begins a comment which terminates at the +end of the line. +.Pp +A statement is either a conditional or an expression. Expression +statements are terminated with a new line or ``;''. To continue +an expression on the next line, terminate the first line with ``\\''. +.Ss Conditional Statement +.Nm Window +has a single control structure: +the fully bracketed if statement in the form +.Pp +.Bd -literal -offset indent -compact +if <expr> then +\t<statement> +\t... +elsif <expr> then +\t<statement> +\t... +else +\t<statement> +\t... +endif +.Ed +.Pp +The +.Ic else +and +.Ic elsif +parts are optional, and the latter can +be repeated any number of times. +<Expr> +must be numeric. +.Ss Expressions +Expressions in +.Nm window +are similar to those in the +C language, with most C operators supported on numeric +operands. In addition, some are overloaded to operate on strings. +.Pp +When an expression is used as a statement, its value is discarded +after evaluation. Therefore, only expressions with side +effects (assignments and function calls) are useful as statements. +.Pp +Single valued (no arrays) variables are supported, of both +numeric and string values. Some variables are predefined. They +are listed below. +.Pp +The operators in order of increasing precedence: +.Bl -tag -width Fl +.It Xo +.Aq Va expr1 +.Ic = +.Aq Va expr2 +.Xc +Assignment. The variable of name +.Aq Va expr1 , +which must be string valued, +is assigned the result of +.Aq Va expr2 . +Returns the value of +.Aq Va expr2 . +.It Xo +.Aq Va expr1 +.Ic ? +.Aq Va expr2 +.Ic : +.Aq Va expr3 +.Xc +Returns the value of +.Aq Va expr2 +if +.Aq Va expr1 +evaluates true +(non-zero numeric value); returns the value of +.Aq Va expr3 +otherwise. Only +one of +.Aq Va expr2 +and +.Aq Va expr3 +is evaluated. +.Aq Va Expr1 +must +be numeric. +.It Xo +.Aq Va expr1 +.Ic \&|\&| +.Aq Va expr2 +.Xc +Logical or. Numeric values only. Short circuit evaluation is supported +(i.e., if +.Aq Va expr1 +evaluates true, then +.Aq Va expr2 +is not evaluated). +.It Xo +.Aq Va expr1 +.Ic \&&\&& +.Aq Va expr2 +.Xc +Logical and with short circuit evaluation. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic \&| +.Aq Va expr2 +.Xc +Bitwise or. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic ^ +.Aq Va expr2 +.Xc +Bitwise exclusive or. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic \&& +.Aq Va expr2 +.Xc +Bitwise and. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic == +.Aq Va expr2 , +.Aq Va expr1 +.Ic != +.Aq expr2 +.Xc +Comparison (equal and not equal, respectively). The boolean +result (either 1 or 0) of the comparison is returned. The +operands can be numeric or string valued. One string operand +forces the other to be converted to a string in necessary. +.It Xo +.Aq Va expr1 +.Ic < +.Aq Va expr2 , +.Aq Va expr1 +.Ic > +.Aq Va expr2 , +.Aq Va expr1 +.Ic <= +.Aq Va expr2 , +.Xc +Less than, greater than, less than or equal to, +greater than or equal to. Both numeric and string values, with +automatic conversion as above. +.It Xo +.Aq Va expr1 +.Ic << +.Aq Va expr2 , +.Aq Va expr1 +.Ic >> +.Aq Va expr2 +.Xc +If both operands are numbers, +.Aq Va expr1 +is bit +shifted left (or right) by +.Aq Va expr2 +bits. If +.Aq Va expr1 +is +a string, then its first (or last) +.Aq Va expr2 +characters are +returns (if +.Aq Va expr2 +is also a string, then its length is used +in place of its value). +.It Xo +.Aq Va expr1 +.Ic + +.Aq Va expr2 , +.Aq Va expr1 +.Ic - +.Aq Va expr2 +.Xc +Addition and subtraction on numbers. For ``+'', if one +argument is a string, then the other is converted to a string, +and the result is the concatenation of the two strings. +.It Xo +.Aq Va expr1 +.Ic \&* +.Aq Va expr2 , +.Aq Va expr1 +.Ic \&/ +.Aq Va expr2 , +.Aq Va expr1 +.Ic \&% +.Aq Va expr2 +.Xc +Multiplication, division, modulo. Numbers only. +.It Xo +.Ic \- Ns Aq Va expr , +.Ic ~ Ns Aq Va expr , +.Ic \&! Ns Aq Va expr , +.Ic \&$ Ns Aq Va expr , +.Ic \&$? Ns Aq Va expr +.Xc +The first three are unary minus, bitwise complement and logical complement +on numbers only. The operator, ``$'', takes +.Aq Va expr +and returns +the value of the variable of that name. If +.Aq Va expr +is numeric +with value +.Ar n +and it appears within an alias macro (see below), +then it refers to the nth argument of the alias invocation. ``$?'' +tests for the existence of the variable +.Aq Va expr , +and returns 1 +if it exists or 0 otherwise. +.It Xo +.Ao Va expr Ac Ns Pq Aq Ar arglist +.Xc +Function call. +.Aq Va Expr +must be a string that is the unique +prefix of the name of a builtin +.Nm window +function +or the full name of a user defined alias macro. In the case of a builtin +function, +.Aq Ar arglist +can be in one of two forms: +.Bd -literal -offset indent +<expr1>, <expr2>, ... +argname1 = <expr1>, argname2 = <expr2>, ... +.Ed +.Pp +The two forms can in fact be intermixed, but the result is +unpredictable. Most arguments can be omitted; default values will +be supplied for them. The +.Ar argnames +can be unique prefixes +of the argument names. The commas separating +arguments are used only to disambiguate, and can usually be omitted. +.Pp +Only the first argument form is valid for user defined aliases. Aliases +are defined using the +.Ic alias +builtin function (see below). Arguments +are accessed via a variant of the variable mechanism (see ``$'' operator +above). +.Pp +Most functions return value, but some are used for side effect +only and so must be used as statements. When a function or an alias is used +as a statement, the parentheses surrounding +the argument list may be omitted. Aliases return no value. +.El +.Ss Builtin Functions +The arguments are listed by name in their natural +order. Optional arguments are in square brackets +.Sq Op . +Arguments +that have no names are in angle brackets +.Sq <> . +An argument meant to be a boolean flag (often named +.Ar flag ) +can be one of +.Ar on , +.Ar off , +.Ar yes , +.Ar no , +.Ar true , +or +.Ar false , +with +obvious meanings, or it can be a numeric expression, +in which case a non-zero value is true. +.Bl -tag -width Fl +.It Xo +.Ic alias Ns Po Bq Aq Ar string , +.Bq Aq Ar string\-list Pc +.Xc +If no argument is given, all currently defined alias macros are +listed. Otherwise, +.Aq Ar string +is defined as an alias, +with expansion +.Aq Ar string\-list > . +The previous definition of +.Aq Ar string , +if any, is returned. Default for +.Aq Ar string\-list +is no change. +.It Ic close Ns Pq Aq Ar window\-list +Close the windows specified in +.Aq Ar window\-list . +If +.Aq Ar window\-list +is the word +.Ar all , +than all windows are closed. No value is returned. +.It Ic cursormodes Ns Pq Bq Ar modes +Set the window cursor to +.Ar modes . +.Ar Modes +is the bitwise +or of the mode bits defined as the variables +.Ar m_ul +(underline), +.Ar m_rev +(reverse video), +.Ar m_blk +(blinking), +and +.Ar m_grp +(graphics, terminal dependent). Return +value is the previous modes. Default is no change. +For example, +.Li cursor($m_rev$m_blk) +sets the window cursors to blinking +reverse video. +.It Ic default_nline Ns Pq Bq Ar nline +Set the default buffer size to +.Ar nline . +Initially, it is +48 lines. Returns the old default buffer size. Default is +no change. Using a very large buffer can slow the program down +considerably. +.It Ic default_shell Ns Pq Bq Aq Ar string\-list +Set the default window shell program to +.Aq Ar string\-list . +Returns +the first string in the old shell setting. Default is no change. Initially, +the default shell is taken from the environment variable +.Ev SHELL . +.It Ic default_smooth Ns Pq Bq Ar flag +Set the default value of the +.Ar smooth +argument +to the command +.Nm window +(see below). The argument +is a boolean flag (one of +.Ar on , +.Ar off , +.Ar yes , +.Ar no , +.Ar true , +.Ar false , +or a number, +as described above). Default is no change. +The old value (as a number) is returned. +The initial value is 1 (true). +.It Xo +.Ic echo Ns ( Op Ar window , +.Bq Aq Ar string\-list ) +.Xc +Write the list of strings, +.Aq Ar string-list , +to +.Nm window , +separated +by spaces and terminated with a new line. The strings are only +displayed in the window, the processes in the window are not +involved (see +.Ic write +below). No value is returned. Default +is the current window. +.It Ic escape Ns Pq Bq Ar escapec +Set the escape character to +.Ar escape-char . +Returns the old +escape character as a one-character string. Default is no +change. +.Ar Escapec +can be a string of a single character, or +in the form +.Fl ^X , +meaning +.No control\- Ns Ar X . +.It Xo +.Ic foreground Ns ( Bq Ar window , +.Bq Ar flag ) +.Xc +Move +.Nm window +in or out of foreground. +.Ar Flag +is a boolean value. The old foreground flag +is returned. Default for +.Nm window +is the current window, +default for +.Ar flag +is no change. +.It Xo +.Ic label Ns ( Bq Ar window , +.Bq Ar label ) +.Xc +Set the label of +.Nm window +to +.Ar label . +Returns the old +label as a string. Default for +.Nm window +is the current +window, default for +.Ar label +is no change. To turn +off a label, set it to an empty string (""). +.It Ic list Ns Pq +No arguments. List the identifiers and labels of all windows. No +value is returned. +.It Ic select Ns Pq Bq Ar window +Make +.Nm window +the current window. The previous current window +is returned. Default is no change. +.It Ic source Ns Pq Ar filename +Read and execute the long commands in +.Ar filename . +Returns \-1 if the file cannot be read, 0 otherwise. +.It Ic terse Ns Pq Bq flag +Set terse mode to +.Ar flag . +In terse mode, the command window +stays hidden even in command mode, and errors are reported by +sounding the terminal's bell. +.Ar Flag +can take on the same +values as in +.Ar foreground +above. Returns the old terse flag. +Default is no change. +.It Ic unalias Ns Pq Ar alias +Undefine +.Ar alias . +Returns -1 if +.Ar alias +does not exist, +0 otherwise. +.It Ic unset Ns Pq Ar variable +Undefine +.Ar variable . +Returns -1 if +.Ar variable +does not exist, +0 otherwise. +.It Ic variables Ns Pq +No arguments. List all variables. No value is returned. +.It Xo +.Ic window Ns ( Bq Ar row , +.Bq Ar column , +.Bq Ar nrow , +.Bq Ar ncol , +.Bq Ar nline , +.Bq Ar label , +.Bq Ar pty , +.Bq Ar frame , +.Bq Ar mapnl , +.Bq Ar keepopen , +.Bq Ar smooth , +.Bq Ar shell ) . +.Xc +Open a window with upper left corner at +.Ar row , +.Ar column +and size +.Ar nrow , +.Ar ncol . +If +.Ar nline +is specified, +then that many lines are allocated for the text buffer. Otherwise, +the default buffer size is used. Default values for +.Ar row , +.Ar column , +.Ar nrow , +and +.Ar ncol +are, respectively, +the upper, left-most, lower, or right-most extremes of the +screen. +.Ar Label +is the label string. +.Ar Frame , +.Ar pty , +and +.Ar mapnl +are flag values +interpreted in the same way as the argument to +.Ar foreground +(see above); +they mean, respectively, put a frame around this window (default true), +allocate pseudo-terminal for this window rather than socketpair (default +true), and map new line characters in this window to carriage return +and line feed (default true if socketpair is used, false otherwise). +Normally, a window is automatically closed when its process +exits. Setting +.Ar keepopen +to true (default false) prevents this +action. When +.Ar smooth +is true, the screen is updated more frequently +(for this window) to produce a more terminal-like behavior. +The default value of +.Ar smooth +is set by the +.Ar default_smooth +command (see above). +.Ar Shell +is a list of strings that will be used as the shell +program to place in the window (default is the program specified +by +.Ar default_shell , +see above). The created window's identifier +is returned as a number. +.It Xo +.Ic write Ns ( Bq Ar window , +.Bq Aq Ar string\-list ) +.Xc +Send the list of strings, +.Aq Ar string-list , +to +.Nm window , +separated +by spaces but not terminated with a new line. The strings are actually +given to the window as input. No value is returned. Default +is the current window. +.El +.Ss Predefined Variables +These variables are for information only. Redefining them does +not affect the internal operation of +.Nm window . +.Bl -tag -width modes +.It Ar baud +The baud rate as a number between 50 and 38400. +.It Ar modes +The display modes (reverse video, underline, blinking, graphics) +supported by the physical terminal. The value of +.Ar modes +is the bitwise or of some of the one bit values, +.Ar m_blk , +.Ar m_grp , +.Ar m_rev , +and +.Ar m_ul +(see below). +These values are useful +in setting the window cursors' modes (see +.Ar cursormodes +above). +.It Ar m_blk +The blinking mode bit. +.It Ar m_grp +The graphics mode bit (not very useful). +.It Ar m_rev +The reverse video mode bit. +.It Ar m_ul +The underline mode bit. +.It Ar ncol +The number of columns on the physical screen. +.It Ar nrow +The number of rows on the physical screen. +.It Ar term +The terminal type. The standard name, found in the second name +field of the terminal's +.Ev TERMCAP +entry, is used. +.Sh ENVIRONMENT +.Nm Window +utilizes these environment variables: +.Ev HOME , +.Ev SHELL , +.Ev TERM , +.Ev TERMCAP , +.Ev WINDOW_ID . +.Sh FILES +.Bl -tag -width /dev/[pt]ty[pq]? -compact +.It Pa ~/.windowrc +startup command file. +.It Pa /dev/[pt]ty[pq]? +pseudo-terminal devices. +.El +.Sh HISTORY +The +.Nm window +command appeared in +.Bx 4.3 . +.Sh DIAGNOSTICS +Should be self explanatory. diff --git a/usr.bin/window/windowrc b/usr.bin/window/windowrc new file mode 100644 index 00000000000..57c695a7223 --- /dev/null +++ b/usr.bin/window/windowrc @@ -0,0 +1,85 @@ +# Copyright (c) 1983, 1993 +# The Regents of the University of California. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of +# California, Berkeley and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)windowrc 8.1 (Berkeley) 6/6/93 +# + +# Configuration file example for window manager +# To be installed in ~/.windowrc +# +# Create two unequal sized windows of full screen width, +# and set up some useful aliases. +# + +# +# Optional settings +# +# terse on # set terse mode +# escape "^A" # set escape character +# nline 100 # set default buffer size + # initially, this is 48 + +# +# Make two windows +# The bottom one is MIN(24, total lines * 3 / 4) lines +# The top one is the rest of the screen. +# +three_fourth = $nrow - ((_ = $nrow * 3 / 4) > 24 ? 24 : $_) +unset _ +window row = 0, nrow = $three_fourth - 1, label = "Top" +window row = $three_fourth, label = "Local" + +# +# Useful aliases +# +# +# Standard window +# +alias std "window r = $three_fourth, l = $?1 ? $1 : ''" +# +# Sysline, add your own options +# +alias sysline "_ = select();" \ + "foreground window(r = 0, nr = 1, nc = $ncol + 1, nl = 0," \ + "l = sysline, pty = no, frame = no, sh = sysline \\-w), 1;" \ + "select $_; unset _" +# +# Rlogin +# +alias rlogin "window r = $three_fourth, l = $1, pty = no, mapnl = no," \ + "sh = sh \\-c 'echo $TERMCAP | rsh ' + $1 + ' \\'cat > .TERMCAP\\' ;" \ + "exec rlogin ' + $1" +alias rl rlogin \$1 +# +# Two equal windows +# +alias two "window r = 1, nr = $nrow / 2 - 1, l = top;" \ + "window r = $nrow / 2 + 1, l = bottom" diff --git a/usr.bin/window/ww.h b/usr.bin/window/ww.h new file mode 100644 index 00000000000..51a7abca719 --- /dev/null +++ b/usr.bin/window/ww.h @@ -0,0 +1,323 @@ +/* $NetBSD: ww.h,v 1.3 1995/09/28 10:35:07 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ww.h 8.1 (Berkeley) 6/6/93 + */ + +#ifdef OLD_TTY +#include <sgtty.h> +#else +#include <termios.h> +#endif +#include <setjmp.h> +#include <machine/endian.h> + +#define NWW 30 /* maximum number of windows */ + + /* a rectangle */ +struct ww_dim { + int nr; /* number of rows */ + int nc; /* number of columns */ + int t, b; /* top, bottom */ + int l, r; /* left, right */ +}; + + /* a coordinate */ +struct ww_pos { + int r; /* row */ + int c; /* column */ +}; + + /* the window structure */ +struct ww { + /* general flags and states */ + char ww_state; /* state of window */ + char ww_oflags; /* wwopen flags */ + + /* information for overlap */ + struct ww *ww_forw; /* doubly linked list, for overlapping info */ + struct ww *ww_back; + char ww_index; /* the window index, for wwindex[] */ + char ww_order; /* the overlapping order */ + + /* sizes and positions */ + struct ww_dim ww_w; /* window size and pos */ + struct ww_dim ww_b; /* buffer size and pos */ + struct ww_dim ww_i; /* the part inside the screen */ + struct ww_pos ww_cur; /* the cursor position, relative to ww_w */ + + /* arrays */ + char **ww_win; /* the window */ + union ww_char **ww_buf; /* the buffer */ + char **ww_fmap; /* map for frame and box windows */ + short *ww_nvis; /* how many ww_buf chars are visible per row */ + + /* information for wwwrite() and company */ + char ww_wstate; /* state for outputting characters */ + char ww_modes; /* current display modes */ + char ww_insert; /* insert mode */ + char ww_mapnl; /* map \n to \r\n */ + char ww_noupdate; /* don't do updates in wwwrite() */ + char ww_unctrl; /* expand control characters */ + char ww_nointr; /* wwwrite() not interruptable */ + char ww_hascursor; /* has fake cursor */ + + /* things for the window process and io */ + char ww_ispty; /* ww_pty is really a pty, not socket pair */ + char ww_stopped; /* output stopped */ + int ww_pty; /* file descriptor of pty or socket pair */ + int ww_socket; /* other end of socket pair */ + int ww_pid; /* pid of process, if WWS_HASPROC true */ + char ww_ttyname[11]; /* "/dev/ttyp?" */ + char *ww_ob; /* output buffer */ + char *ww_obe; /* end of ww_ob */ + char *ww_obp; /* current read position in ww_ob */ + char *ww_obq; /* current write position in ww_ob */ + + /* things for the user, they really don't belong here */ + char ww_id; /* the user window id */ + char ww_center; /* center the label */ + char ww_hasframe; /* frame it */ + char ww_keepopen; /* keep it open after the process dies */ + char *ww_label; /* the user supplied label */ + struct ww_dim ww_alt; /* alternate position and size */ +}; + + /* state of a tty */ +struct ww_tty { +#ifdef OLD_TTY + struct sgttyb ww_sgttyb; + struct tchars ww_tchars; + struct ltchars ww_ltchars; + int ww_lmode; + int ww_ldisc; +#else + struct termios ww_termios; +#endif + int ww_fflags; +}; + +union ww_char { + short c_w; /* as a word */ + struct { +#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN + char C_c; /* the character part */ + char C_m; /* the mode part */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + char C_m; /* the mode part */ + char C_c; /* the character part */ +#endif + } c_un; +}; +#define c_c c_un.C_c +#define c_m c_un.C_m + + /* for display update */ +struct ww_update { + int best_gain; + int best_col; + int gain; +}; + + /* parts of ww_char */ +#define WWC_CMASK 0x00ff +#define WWC_MMASK 0xff00 +#define WWC_MSHIFT 8 + + /* c_m bits */ +#define WWM_REV 0x01 /* reverse video */ +#define WWM_BLK 0x02 /* blinking */ +#define WWM_UL 0x04 /* underlined */ +#define WWM_GRP 0x08 /* graphics */ +#define WWM_DIM 0x10 /* half intensity */ +#define WWM_USR 0x20 /* user specified mode */ +#define WWM_GLS 0x40 /* window only, glass, i.e., transparent */ + + /* ww_state values */ +#define WWS_INITIAL 0 /* just opened */ +#define WWS_HASPROC 1 /* has process on pty */ +#define WWS_DEAD 3 /* child died */ + + /* flags for ww_fmap */ +#define WWF_U 0x01 +#define WWF_R 0x02 +#define WWF_D 0x04 +#define WWF_L 0x08 +#define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L) +#define WWF_LABEL 0x40 +#define WWF_TOP 0x80 + + /* flags to wwopen() */ +#define WWO_PTY 0x01 /* want pty */ +#define WWO_SOCKET 0x02 /* want socket pair */ +#define WWO_REVERSE 0x04 /* make it all reverse video */ +#define WWO_GLASS 0x08 /* make it all glass */ +#define WWO_FRAME 0x10 /* this is a frame window */ + + /* special ww_index value */ +#define WWX_NOBODY NWW + + /* error codes */ +#define WWE_NOERR 0 +#define WWE_SYS 1 /* system error */ +#define WWE_NOMEM 2 /* out of memory */ +#define WWE_TOOMANY 3 /* too many windows */ +#define WWE_NOPTY 4 /* no more ptys */ +#define WWE_SIZE 5 /* bad window size */ +#define WWE_BADTERM 6 /* bad terminal type */ +#define WWE_CANTDO 7 /* dumb terminal */ + + /* wwtouched[] bits, there used to be more than one */ +#define WWU_TOUCHED 0x01 /* touched */ + + /* the window structures */ +struct ww wwhead; +struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */ +struct ww wwnobody; + + /* tty things */ +struct ww_tty wwoldtty; /* the old (saved) terminal settings */ +struct ww_tty wwnewtty; /* the new (current) terminal settings */ +struct ww_tty wwwintty; /* the terminal settings for windows */ +char *wwterm; /* the terminal name */ +char wwtermcap[1024]; /* place for the termcap */ + + /* generally useful variables */ +int wwnrow, wwncol; /* the screen size */ +char wwavailmodes; /* actually supported modes */ +char wwcursormodes; /* the modes for the fake cursor */ +char wwwrap; /* terminal has auto wrap around */ +int wwdtablesize; /* result of getdtablesize() call */ +char **wwsmap; /* the screen map */ +union ww_char **wwos; /* the old (current) screen */ +union ww_char **wwns; /* the new (desired) screen */ +union ww_char **wwcs; /* the checkpointed screen */ +char *wwtouched; /* wwns changed flags */ +struct ww_update *wwupd; /* for display update */ +int wwospeed; /* output baud rate, copied from wwoldtty */ +int wwbaud; /* wwospeed converted into actual number */ +int wwcursorrow, wwcursorcol; /* where we want the cursor to be */ +int wwerrno; /* error number */ + + /* statistics */ +int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc; +int wwnwwr, wwnwwra, wwnwwrc; +int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc; +int wwnupdate, wwnupdline, wwnupdmiss; +int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline; +int wwnread, wwnreade, wwnreadz; +int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec; +int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp; +int wwnselect, wwnselecte, wwnselectz; + + /* quicky macros */ +#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c)) +#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c) +#define wwunbox(w) wwunframe(w) +#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0) +#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0) +#define wwupdate() wwupdate1(0, wwnrow); + + /* things for handling input */ +void wwrint(); /* interrupt handler */ +struct ww *wwcurwin; /* window to copy input into */ +char *wwib; /* input (keyboard) buffer */ +char *wwibe; /* wwib + sizeof buffer */ +char *wwibp; /* current read position in buffer */ +char *wwibq; /* current write position in buffer */ +#define wwmaskc(c) ((c) & 0x7f) +#define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1) +#define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1) +#define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1) + + /* things for short circuiting wwiomux() */ +char wwintr; /* interrupting */ +char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */ +jmp_buf wwjmpbuf; /* jmpbuf for above */ +#define wwinterrupt() wwintr +#define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \ + while (0) +#define wwclrintr() (wwintr = 0) + + /* checkpointing */ +int wwdocheckpoint; + + /* the window virtual terminal */ +#define WWT_TERM "window-v2" +#define WWT_TERMCAP "WW|window-v2|window program version 2:\ + :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\ + :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\ + :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:" +#define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:" +#define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:" +#define WWT_UL "ue=\\ErD:us=\\EsD:" +#define WWT_GRP "ae=\\ErH:as=\\EsH:" +#define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:" +#define WWT_USR "XE=\\Er`:XS=\\Es`:" +#define WWT_ALDL "al=\\EL:dl=\\EM:" +#define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */ +#define WWT_IC "ic=\\EP:" +#define WWT_DC "dc=\\EN:" +char wwwintermcap[1024]; /* terminal-specific but window-independent + part of the window termcap */ +#ifdef TERMINFO + /* where to put the temporary terminfo directory */ +char wwterminfopath[1024]; +#endif + + /* our functions */ +struct ww *wwopen(); +void wwchild(); +void wwalarm(); +void wwquit(); +char **wwalloc(); +char *wwerror(); + + /* c library functions */ +char *malloc(); +char *calloc(); +char *getenv(); +char *tgetstr(); +char *rindex(); +char *strcpy(); +char *strcat(); + +#undef MIN +#undef MAX +#define MIN(x, y) ((x) > (y) ? (y) : (x)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) diff --git a/usr.bin/window/wwadd.c b/usr.bin/window/wwadd.c new file mode 100644 index 00000000000..2377314b6fa --- /dev/null +++ b/usr.bin/window/wwadd.c @@ -0,0 +1,94 @@ +/* $NetBSD: wwadd.c,v 1.3 1995/09/28 10:35:09 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwadd.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwadd.c,v 1.3 1995/09/28 10:35:09 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Stick w1 behind w2. + */ +wwadd(w1, w2) +register struct ww *w1; +struct ww *w2; +{ + register i; + register struct ww *w; + + w1->ww_order = w2->ww_order + 1; + w1->ww_back = w2; + w1->ww_forw = w2->ww_forw; + w2->ww_forw->ww_back = w1; + w2->ww_forw = w1; + + for (w = w1->ww_forw; w != &wwhead; w = w->ww_forw) + w->ww_order++; + for (i = w1->ww_i.t; i < w1->ww_i.b; i++) { + register j; + register char *smap = wwsmap[i]; + register char *win = w1->ww_win[i]; + union ww_char *ns = wwns[i]; + union ww_char *buf = w1->ww_buf[i]; + int nvis = 0; + int nchanged = 0; + + for (j = w1->ww_i.l; j < w1->ww_i.r; j++) { + w = wwindex[smap[j]]; + if (w1->ww_order > w->ww_order) + continue; + if (win[j] & WWM_GLS) + continue; + if (w != &wwnobody && w->ww_win[i][j] == 0) + w->ww_nvis[i]--; + smap[j] = w1->ww_index; + if (win[j] == 0) + nvis++; + ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT; + nchanged++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w1->ww_nvis[i] = nvis; + } +} diff --git a/usr.bin/window/wwalloc.c b/usr.bin/window/wwalloc.c new file mode 100644 index 00000000000..31e81a18d8d --- /dev/null +++ b/usr.bin/window/wwalloc.c @@ -0,0 +1,77 @@ +/* $NetBSD: wwalloc.c,v 1.3 1995/09/28 10:35:10 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwalloc.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwalloc.c,v 1.3 1995/09/28 10:35:10 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +char ** +wwalloc(row, col, nrow, ncol, size) +{ + register char *p, **pp; + register int i; + + /* fast, call malloc only once */ + pp = (char **) + malloc((unsigned) sizeof (char **) * nrow + size * nrow * ncol); + if (pp == 0) { + wwerrno = WWE_NOMEM; + return 0; + } + p = (char *)&pp[nrow]; + col *= size; + size /= sizeof (char); /* paranoid */ + size *= ncol; + for (i = 0; i < nrow; i++) { + pp[i] = p - col; + p += size; + } + return pp - row; +} + +wwfree(p, row) +register char **p; +{ + free((char *)(p + row)); +} diff --git a/usr.bin/window/wwbox.c b/usr.bin/window/wwbox.c new file mode 100644 index 00000000000..91862d70881 --- /dev/null +++ b/usr.bin/window/wwbox.c @@ -0,0 +1,72 @@ +/* $NetBSD: wwbox.c,v 1.3 1995/09/28 10:35:11 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwbox.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwbox.c,v 1.3 1995/09/28 10:35:11 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwbox(w, r, c, nr, nc) +register struct ww *w; +register r, c; +int nr, nc; +{ + register r1, c1; + register i; + + r1 = r + nr - 1; + c1 = c + nc - 1; + wwframec(w, r, c, WWF_D|WWF_R); + for (i = c + 1; i < c1; i++) + wwframec(w, r, i, WWF_L|WWF_R); + wwframec(w, r, i, WWF_L|WWF_D); + for (i = r + 1; i < r1; i++) + wwframec(w, i, c1, WWF_U|WWF_D); + wwframec(w, i, c1, WWF_U|WWF_L); + for (i = c1 - 1; i > c; i--) + wwframec(w, r1, i, WWF_R|WWF_L); + wwframec(w, r1, i, WWF_R|WWF_U); + for (i = r1 - 1; i > r; i--) + wwframec(w, i, c, WWF_D|WWF_U); +} diff --git a/usr.bin/window/wwchild.c b/usr.bin/window/wwchild.c new file mode 100644 index 00000000000..0b1cfac43f6 --- /dev/null +++ b/usr.bin/window/wwchild.c @@ -0,0 +1,77 @@ +/* $NetBSD: wwchild.c,v 1.3 1995/09/28 10:35:13 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwchild.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwchild.c,v 1.3 1995/09/28 10:35:13 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <sys/types.h> +#include <sys/wait.h> + +void +wwchild() +{ + extern errno; + int olderrno; + register struct ww **wp; + union wait w; + int pid; + char collected = 0; + + olderrno = errno; + while ((pid = + wait3((int *)&w, WNOHANG|WUNTRACED, (struct rusage *)0)) > 0) { + for (wp = wwindex; wp < &wwindex[NWW]; wp++) { + if (*wp && (*wp)->ww_state == WWS_HASPROC + && (*wp)->ww_pid == pid) { + (*wp)->ww_state = WWS_DEAD; + collected = 1; + break; + } + } + } + errno = olderrno; + /* jump out of wwiomux when somebody dies */ + if (collected) + wwsetintr(); +} diff --git a/usr.bin/window/wwclose.c b/usr.bin/window/wwclose.c new file mode 100644 index 00000000000..a0d4bc78636 --- /dev/null +++ b/usr.bin/window/wwclose.c @@ -0,0 +1,65 @@ +/* $NetBSD: wwclose.c,v 1.3 1995/09/28 10:35:14 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclose.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwclose.c,v 1.3 1995/09/28 10:35:14 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwclose(w) +register struct ww *w; +{ + wwindex[w->ww_index] = 0; + if (w->ww_pty >= 0) + (void) close(w->ww_pty); + if (w->ww_socket >= 0) + (void) close(w->ww_socket); + wwfree((char **)w->ww_win, w->ww_w.t); + wwfree((char **)w->ww_buf, w->ww_b.t); + if (w->ww_fmap != 0) + wwfree((char **)w->ww_fmap, w->ww_w.t); + free((char *)(w->ww_nvis + w->ww_w.t)); + if (w->ww_ob != 0) + free(w->ww_ob); + free((char *)w); +} diff --git a/usr.bin/window/wwclreol.c b/usr.bin/window/wwclreol.c new file mode 100644 index 00000000000..53c6a1dd712 --- /dev/null +++ b/usr.bin/window/wwclreol.c @@ -0,0 +1,101 @@ +/* $NetBSD: wwclreol.c,v 1.3 1995/09/28 10:35:15 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclreol.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwclreol.c,v 1.3 1995/09/28 10:35:15 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Clear w to the end of line. + * If cleared is true, then the screen line has already been cleared. + */ +wwclreol1(w, row, col, cleared) +register struct ww *w; +int row, col; +char cleared; +{ + register i; + + /* + * Clear the buffer right off + */ + { + register union ww_char *buf; + + buf = &w->ww_buf[row][col]; + for (i = w->ww_b.r - col; --i >= 0;) + buf++->c_w = ' '; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now fix wwns. + */ + { + register union ww_char *s; + register char *smap, *win; + + i = col; + smap = &wwsmap[row][i]; + s = &wwns[row][i]; + win = &w->ww_win[row][i]; + for (i = w->ww_i.r - i; --i >= 0;) + if (*smap++ == w->ww_index) + s++->c_w = ' ' | *win++ << WWC_MSHIFT; + else + s++, win++; + } + if (!cleared) + wwtouched[row] |= WWU_TOUCHED; +} diff --git a/usr.bin/window/wwclreos.c b/usr.bin/window/wwclreos.c new file mode 100644 index 00000000000..e89c2b6ccff --- /dev/null +++ b/usr.bin/window/wwclreos.c @@ -0,0 +1,61 @@ +/* $NetBSD: wwclreos.c,v 1.3 1995/09/28 10:35:18 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclreos.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwclreos.c,v 1.3 1995/09/28 10:35:18 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwclreos(w, row, col) +register struct ww *w; +{ + register i; + + wwclreol(w, row, col); + for (i = row + 1; i < w->ww_b.b; i++) + wwclreol(w, i, w->ww_b.l); + /* XXX */ + if (!w->ww_noupdate) + wwupdate1(w->ww_i.t, w->ww_i.b); +} diff --git a/usr.bin/window/wwcursor.c b/usr.bin/window/wwcursor.c new file mode 100644 index 00000000000..32d173423da --- /dev/null +++ b/usr.bin/window/wwcursor.c @@ -0,0 +1,98 @@ +/* $NetBSD: wwcursor.c,v 1.3 1995/09/28 10:35:19 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwcursor.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwcursor.c,v 1.3 1995/09/28 10:35:19 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwcursor(w, on) +register struct ww *w; +{ + register char *win; + + if (on) { + if (w->ww_hascursor) + return; + w->ww_hascursor = 1; + } else { + if (!w->ww_hascursor) + return; + w->ww_hascursor = 0; + } + if (wwcursormodes != 0) { + win = &w->ww_win[w->ww_cur.r][w->ww_cur.c]; + *win ^= wwcursormodes; + if (w->ww_cur.r < w->ww_i.t || w->ww_cur.r >= w->ww_i.b + || w->ww_cur.c < w->ww_i.l || w->ww_cur.c >= w->ww_i.r) + return; + if (wwsmap[w->ww_cur.r][w->ww_cur.c] == w->ww_index) { + if (*win == 0) + w->ww_nvis[w->ww_cur.r]++; + else if (*win == wwcursormodes) + w->ww_nvis[w->ww_cur.r]--; + wwns[w->ww_cur.r][w->ww_cur.c].c_m ^= wwcursormodes; + wwtouched[w->ww_cur.r] |= WWU_TOUCHED; + } + } +} + +wwsetcursormodes(new) +register new; +{ + register i; + register struct ww *w; + register old = wwcursormodes; + + new &= wwavailmodes; + if (new == wwcursormodes) + return; + for (i = 0; i < NWW; i++) + if (wwindex[i] != 0 && (w = wwindex[i])->ww_hascursor) { + wwcursor(w, 0); + wwcursormodes = new; + wwcursor(w, 1); + wwcursormodes = old; + } + wwcursormodes = new; +} diff --git a/usr.bin/window/wwdata.c b/usr.bin/window/wwdata.c new file mode 100644 index 00000000000..6406c10c212 --- /dev/null +++ b/usr.bin/window/wwdata.c @@ -0,0 +1,45 @@ +/* $NetBSD: wwdata.c,v 1.3 1995/09/28 10:35:20 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdata.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwdata.c,v 1.3 1995/09/28 10:35:20 tls Exp $"; +#endif +#endif /* not lint */ diff --git a/usr.bin/window/wwdelchar.c b/usr.bin/window/wwdelchar.c new file mode 100644 index 00000000000..dfe74c0727f --- /dev/null +++ b/usr.bin/window/wwdelchar.c @@ -0,0 +1,129 @@ +/* $NetBSD: wwdelchar.c,v 1.3 1995/09/28 10:35:21 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelchar.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwdelchar.c,v 1.3 1995/09/28 10:35:21 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwdelchar(w, row, col) +register struct ww *w; +{ + register i; + int nvis; + + /* + * First, shift the line. + */ + { + register union ww_char *p, *q; + + p = &w->ww_buf[row][col]; + q = p + 1; + for (i = w->ww_b.r - col; --i > 0;) + *p++ = *q++; + p->c_w = ' '; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now find out how much is actually changed, and fix wwns. + */ + { + register union ww_char *buf; + register char *win; + register union ww_char *ns; + register char *smap; + char touched; + + nvis = 0; + smap = &wwsmap[row][col]; + for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++) + ; + if (i >= w->ww_i.r) + return; + col = i; + buf = w->ww_buf[row]; + win = w->ww_win[row]; + ns = wwns[row]; + smap = &wwsmap[row][i]; + touched = wwtouched[row]; + for (; i < w->ww_i.r; i++) { + if (*smap++ != w->ww_index) + continue; + touched |= WWU_TOUCHED; + if (win[i]) + ns[i].c_w = + buf[i].c_w ^ win[i] << WWC_MSHIFT; + else { + nvis++; + ns[i] = buf[i]; + } + } + wwtouched[row] = touched; + } + + /* + * Can/Should we use delete character? + */ + if (tt.tt_delchar != 0 && nvis > (wwncol - col) / 2) { + register union ww_char *p, *q; + + xxdelchar(row, col); + p = &wwos[row][col]; + q = p + 1; + for (i = wwncol - col; --i > 0;) + *p++ = *q++; + p->c_w = ' '; + } +} diff --git a/usr.bin/window/wwdelete.c b/usr.bin/window/wwdelete.c new file mode 100644 index 00000000000..2be15f6ae88 --- /dev/null +++ b/usr.bin/window/wwdelete.c @@ -0,0 +1,145 @@ +/* $NetBSD: wwdelete.c,v 1.3 1995/09/28 10:35:23 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelete.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwdelete.c,v 1.3 1995/09/28 10:35:23 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Pull w free from the cover list. + */ +wwdelete(w) +register struct ww *w; +{ + register i; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + register j; + register char *smap = wwsmap[i]; + register union ww_char *ns = wwns[i]; + register int nchanged = 0; + + for (j = w->ww_i.l; j < w->ww_i.r; j++) + if (smap[j] == w->ww_index) { + smap[j] = WWX_NOBODY; + ns[j].c_w = ' '; + nchanged++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + } + + { + register struct ww *wp; + + for (wp = w->ww_forw; wp != &wwhead; wp = wp->ww_forw) + wp->ww_order--; + } + + if (w->ww_forw != &wwhead) + wwdelete1(w->ww_forw, + w->ww_i.t, w->ww_i.b, w->ww_i.l, w->ww_i.r); + + w->ww_back->ww_forw = w->ww_forw; + w->ww_forw->ww_back = w->ww_back; + w->ww_forw = w->ww_back = 0; +} + +wwdelete1(w, t, b, l, r) +register struct ww *w; +{ + int i; + int tt, bb, ll, rr; + char hasglass; + +again: + hasglass = 0; + tt = MAX(t, w->ww_i.t); + bb = MIN(b, w->ww_i.b); + ll = MAX(l, w->ww_i.l); + rr = MIN(r, w->ww_i.r); + if (tt >= bb || ll >= rr) { + if ((w = w->ww_forw) == &wwhead) + return; + goto again; + } + for (i = tt; i < bb; i++) { + register j; + register char *smap = wwsmap[i]; + register union ww_char *ns = wwns[i]; + register char *win = w->ww_win[i]; + register union ww_char *buf = w->ww_buf[i]; + int nvis = w->ww_nvis[i]; + int nchanged = 0; + + for (j = ll; j < rr; j++) { + if (smap[j] != WWX_NOBODY) + continue; + if (win[j] & WWM_GLS) { + hasglass = 1; + continue; + } + smap[j] = w->ww_index; + ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT; + nchanged++; + if (win[j] == 0) + nvis++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w->ww_nvis[i] = nvis; + } + if ((w = w->ww_forw) == &wwhead) + return; + if (hasglass) + goto again; + if (tt > t) + wwdelete1(w, t, tt, l, r); + if (bb < b) + wwdelete1(w, bb, b, l, r); + if (ll > l) + wwdelete1(w, tt, bb, l, ll); + if (rr < r) + wwdelete1(w, tt, bb, rr, r); +} diff --git a/usr.bin/window/wwdelline.c b/usr.bin/window/wwdelline.c new file mode 100644 index 00000000000..7a1b5c1d1b9 --- /dev/null +++ b/usr.bin/window/wwdelline.c @@ -0,0 +1,94 @@ +/* $NetBSD: wwdelline.c,v 1.3 1995/09/28 10:35:24 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelline.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwdelline.c,v 1.3 1995/09/28 10:35:24 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwdelline(w, row) +register struct ww *w; +int row; +{ + register i; + register union ww_char **cpp, **cqq; + register union ww_char *cp; + int row1, row2; + char deleted; + int visible; + + /* + * Scroll first. + */ + if ((row1 = row) < w->ww_i.t) { + row1 = w->ww_i.t; + } + if ((row2 = w->ww_b.b) > w->ww_i.b) { + row2 = w->ww_i.b; + visible = 0; + } else + visible = 1; + deleted = wwscroll1(w, row1, row2, 1, visible); + + /* + * Fix the buffer. + * But leave clearing the last line for wwclreol(). + */ + cpp = &w->ww_buf[row]; + cqq = cpp + 1; + cp = *cpp; + for (i = w->ww_b.b - row; --i > 0;) + *cpp++ = *cqq++; + *cpp = cp; + + /* + * Now clear the last line. + */ + if (visible) + wwclreol1(w, w->ww_b.b - 1, w->ww_b.l, deleted); + else { + cp += w->ww_b.l; + for (i = w->ww_b.nc; --i >= 0;) + cp++->c_w = ' '; + } +} diff --git a/usr.bin/window/wwdump.c b/usr.bin/window/wwdump.c new file mode 100644 index 00000000000..4cc156e4e3a --- /dev/null +++ b/usr.bin/window/wwdump.c @@ -0,0 +1,121 @@ +/* $NetBSD: wwdump.c,v 1.5 1995/09/29 00:44:09 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdump.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwdump.c,v 1.5 1995/09/29 00:44:09 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include <string.h> + +static char cmap[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +wwdumpwin(w) +register struct ww *w; +{ + register i, j; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + (*tt.tt_move)(i, w->ww_i.l); + for (j = w->ww_i.l; j < w->ww_i.r; j++) + (*tt.tt_putc)(w->ww_win[i][j] & WWM_GLS ? 'G' : ' '); + } +} + +wwdumpnvis(w) +register struct ww *w; +{ + register i; + char buf[20]; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + (*tt.tt_move)(i, w->ww_i.l); + (void) sprintf(buf, "%d", w->ww_nvis[i]); + (*tt.tt_write)(buf, strlen(buf)); + } +} + +wwdumpsmap() +{ + register i, j; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) + (*tt.tt_putc)(cmap[wwsmap[i][j]]); + } +} + +wwdumpns() +{ + register i, j; + + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) { + tt.tt_nmodes = wwns[i][j].c_m & tt.tt_availmodes; + (*tt.tt_putc)(wwns[i][j].c_c); + } + } +} + +wwdumpos() +{ + register i, j; + + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) { + tt.tt_nmodes = wwos[i][j].c_m & tt.tt_availmodes; + (*tt.tt_putc)(wwns[i][j].c_c); + } + } +} diff --git a/usr.bin/window/wwend.c b/usr.bin/window/wwend.c new file mode 100644 index 00000000000..0c6704f408a --- /dev/null +++ b/usr.bin/window/wwend.c @@ -0,0 +1,70 @@ +/* $NetBSD: wwend.c,v 1.3 1995/09/28 10:35:26 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwend.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwend.c,v 1.3 1995/09/28 10:35:26 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/*ARGSUSED*/ +wwend(exit) +{ + if (tt.tt_checkpoint) { + (void) alarm(0); + wwdocheckpoint = 0; + } + xxend(); + (void) wwsettty(0, &wwoldtty); +#ifdef TERMINFO + if (exit) + wwterminfoend(); +#endif +} + +void +wwquit() +{ + wwend(1); + exit(1); +} diff --git a/usr.bin/window/wwenviron.c b/usr.bin/window/wwenviron.c new file mode 100644 index 00000000000..69a168a3308 --- /dev/null +++ b/usr.bin/window/wwenviron.c @@ -0,0 +1,108 @@ +/* $NetBSD: wwenviron.c,v 1.3 1995/09/28 10:35:27 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwenviron.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwenviron.c,v 1.3 1995/09/28 10:35:27 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#if !defined(OLD_TTY) && !defined(TIOCSCTTY) && !defined(TIOCNOTTY) +#include <sys/ioctl.h> +#endif +#include <sys/signal.h> + +/* + * Set up the environment of this process to run in window 'wp'. + */ +wwenviron(wp) +register struct ww *wp; +{ + register i; +#ifndef TIOCSCTTY + int pgrp = getpid(); +#endif + char buf[1024]; + +#ifndef TIOCSCTTY + if ((i = open("/dev/tty", 0)) < 0) + goto bad; + if (ioctl(i, TIOCNOTTY, (char *)0) < 0) + goto bad; + (void) close(i); +#endif + if ((i = wp->ww_socket) < 0) { + if ((i = open(wp->ww_ttyname, 2)) < 0) + goto bad; + if (wwsettty(i, &wwwintty) < 0) + goto bad; + if (wwsetttysize(i, wp->ww_w.nr, wp->ww_w.nc) < 0) + goto bad; + } + (void) dup2(i, 0); + (void) dup2(i, 1); + (void) dup2(i, 2); + (void) close(i); +#ifdef TIOCSCTTY + (void) setsid(); + (void) ioctl(0, TIOCSCTTY, 0); +#else + (void) ioctl(0, TIOCSPGRP, (char *)&pgrp); + (void) setpgrp(pgrp, pgrp); +#endif + /* SIGPIPE is the only one we ignore */ + (void) signal(SIGPIPE, SIG_DFL); + (void) sigsetmask(0); + /* + * Two conditions that make destructive setenv ok: + * 1. setenv() copies the string, + * 2. we've already called tgetent which copies the termcap entry. + */ + (void) sprintf(buf, "%sco#%d:li#%d:%s", + WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap); + (void) setenv("TERMCAP", buf, 1); + (void) sprintf(buf, "%d", wp->ww_id + 1); + (void) setenv("WINDOW_ID", buf, 1); + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} diff --git a/usr.bin/window/wwerror.c b/usr.bin/window/wwerror.c new file mode 100644 index 00000000000..ed33454def7 --- /dev/null +++ b/usr.bin/window/wwerror.c @@ -0,0 +1,75 @@ +/* $NetBSD: wwerror.c,v 1.3 1995/09/28 10:35:29 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwerror.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwerror.c,v 1.3 1995/09/28 10:35:29 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +char * +wwerror() +{ + extern int errno; + char *strerror(); + + switch (wwerrno) { + case WWE_NOERR: + return "No error"; + case WWE_SYS: + return strerror(errno); + case WWE_NOMEM: + return "Out of memory"; + case WWE_TOOMANY: + return "Too many windows"; + case WWE_NOPTY: + return "Out of pseudo-terminals"; + case WWE_SIZE: + return "Bad window size"; + case WWE_BADTERM: + return "Unknown terminal type"; + case WWE_CANTDO: + return "Can't run window on this terminal"; + default: + return "Unknown error"; + } +} diff --git a/usr.bin/window/wwflush.c b/usr.bin/window/wwflush.c new file mode 100644 index 00000000000..a741ac882eb --- /dev/null +++ b/usr.bin/window/wwflush.c @@ -0,0 +1,114 @@ +/* $NetBSD: wwflush.c,v 1.3 1995/09/28 10:35:30 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwflush.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwflush.c,v 1.3 1995/09/28 10:35:30 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include <sys/signal.h> + +wwflush() +{ + register row, col; + + if ((row = wwcursorrow) < 0) + row = 0; + else if (row >= wwnrow) + row = wwnrow - 1; + if ((col = wwcursorcol) < 0) + col = 0; + else if (col >= wwncol) + col = wwncol - 1; + xxmove(row, col); + if (wwdocheckpoint) { + xxflush(0); + wwcheckpoint(); + } else + xxflush(1); +} + +wwcheckpoint() +{ + int s = sigblock(sigmask(SIGALRM) | sigmask(SIGIO)); + + tt.tt_ack = 0; + do { + (*tt.tt_checkpoint)(); +#ifndef OLD_TTY + (void) tcdrain(1); +#endif + (void) alarm(3); + for (wwdocheckpoint = 0; !wwdocheckpoint && tt.tt_ack == 0;) + (void) sigpause(s); + } while (tt.tt_ack == 0); + (void) alarm(0); + wwdocheckpoint = 0; + if (tt.tt_ack < 0) { + wwcopyscreen(wwcs, wwos); + (void) alarm(1); + wwreset(); + wwupdate(); + wwflush(); + } else { + wwcopyscreen(wwos, wwcs); + (void) alarm(3); + } + (void) sigsetmask(s); +} + +wwcopyscreen(s1, s2) + register union ww_char **s1, **s2; +{ + register i; + register s = wwncol * sizeof **s1; + + for (i = wwnrow; --i >= 0;) + bcopy((char *) *s1++, (char *) *s2++, s); +} + +void +wwalarm() +{ + wwdocheckpoint = 1; +} diff --git a/usr.bin/window/wwframe.c b/usr.bin/window/wwframe.c new file mode 100644 index 00000000000..4d502b65a32 --- /dev/null +++ b/usr.bin/window/wwframe.c @@ -0,0 +1,255 @@ +/* $NetBSD: wwframe.c,v 1.3 1995/09/28 10:35:31 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwframe.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwframe.c,v 1.3 1995/09/28 10:35:31 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define frameok(w, r, c) (w1 = wwindex[wwsmap[r][c]], \ + w1->ww_fmap || w1->ww_order > (w)->ww_order) + +wwframe(w, wframe) +register struct ww *w; +struct ww *wframe; +{ + register r, c; + char a1, a2, a3; + char b1, b2, b3; + register char *smap; + register code; + register struct ww *w1; + + if (w->ww_w.t > 0) { + r = w->ww_w.t - 1; + c = w->ww_i.l - 1; + smap = &wwsmap[r + 1][c + 1]; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = c < 0 || frameok(w, r, c); + + for (; c < w->ww_i.r; c++) { + if (c + 1 >= wwncol) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == *smap++; + b3 = frameok(w, r, c + 1); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_L; + if ((a2 || a3) && b3) + code |= WWF_R; + if (code) + wwframec(wframe, r, c, code|WWF_TOP); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_L|WWF_TOP); + } + + if (w->ww_w.b < wwnrow) { + r = w->ww_w.b; + c = w->ww_i.l - 1; + smap = &wwsmap[r - 1][c + 1]; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = c < 0 || frameok(w, r, c); + + for (; c < w->ww_i.r; c++) { + if (c + 1 >= wwncol) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == *smap++; + b3 = frameok(w, r, c + 1); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_L; + if ((a2 || a3) && b3) + code |= WWF_R; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_L); + } + + if (w->ww_w.l > 0) { + r = w->ww_i.t - 1; + c = w->ww_w.l - 1; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = r < 0 || frameok(w, r, c); + + for (; r < w->ww_i.b; r++) { + if (r + 1 >= wwnrow) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r + 1][c + 1]; + b3 = frameok(w, r + 1, c); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_U; + if ((a2 || a3) && b3) + code |= WWF_D; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_U); + } + + if (w->ww_w.r < wwncol) { + r = w->ww_i.t - 1; + c = w->ww_w.r; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = r < 0 || frameok(w, r, c); + + for (; r < w->ww_i.b; r++) { + if (r + 1 >= wwnrow) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r + 1][c - 1]; + b3 = frameok(w, r + 1, c); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_U; + if ((a2 || a3) && b3) + code |= WWF_D; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_U); + } +} + +wwframec(f, r, c, code) +register struct ww *f; +register r, c; +char code; +{ + char oldcode; + register char *smap; + + if (r < f->ww_i.t || r >= f->ww_i.b || c < f->ww_i.l || c >= f->ww_i.r) + return; + + smap = &wwsmap[r][c]; + + { + register struct ww *w; + + w = wwindex[*smap]; + if (w->ww_order > f->ww_order) { + if (w != &wwnobody && w->ww_win[r][c] == 0) + w->ww_nvis[r]--; + *smap = f->ww_index; + } + } + + if (f->ww_fmap != 0) { + register char *fmap; + + fmap = &f->ww_fmap[r][c]; + oldcode = *fmap; + *fmap |= code; + if (code & WWF_TOP) + *fmap &= ~WWF_LABEL; + code = *fmap; + } else + oldcode = 0; + { + register char *win = &f->ww_win[r][c]; + + if (*win == WWM_GLS && *smap == f->ww_index) + f->ww_nvis[r]++; + *win &= ~WWM_GLS; + } + if (oldcode != code && (code & WWF_LABEL) == 0) { + register short frame; + + frame = tt.tt_frame[code & WWF_MASK]; + f->ww_buf[r][c].c_w = frame; + if (wwsmap[r][c] == f->ww_index) { + wwtouched[r] |= WWU_TOUCHED; + wwns[r][c].c_w = frame; + } + } +} diff --git a/usr.bin/window/wwgets.c b/usr.bin/window/wwgets.c new file mode 100644 index 00000000000..c83edd3c17d --- /dev/null +++ b/usr.bin/window/wwgets.c @@ -0,0 +1,116 @@ +/* $NetBSD: wwgets.c,v 1.5 1995/09/29 00:44:10 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwgets.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwgets.c,v 1.5 1995/09/29 00:44:10 cgd Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "char.h" +#include <string.h> + +wwgets(buf, n, w) +char *buf; +int n; +register struct ww *w; +{ + register char *p = buf; + register char c; + char uc = w->ww_unctrl; + static void rub(); + + w->ww_unctrl = 0; + for (;;) { + wwcurtowin(w); + while ((c = wwgetc()) < 0) + wwiomux(); +#ifdef OLD_TTY + if (c == wwoldtty.ww_sgttyb.sg_erase) +#else + if (c == wwoldtty.ww_termios.c_cc[VERASE]) +#endif + { + if (p > buf) + rub(*--p, w); + } else +#ifdef OLD_TTY + if (c == wwoldtty.ww_sgttyb.sg_kill) +#else + if (c == wwoldtty.ww_termios.c_cc[VKILL]) +#endif + { + while (p > buf) + rub(*--p, w); + } else +#ifdef OLD_TTY + if (c == wwoldtty.ww_ltchars.t_werasc) +#else + if (c == wwoldtty.ww_termios.c_cc[VWERASE]) +#endif + { + while (--p >= buf && (*p == ' ' || *p == '\t')) + rub(*p, w); + while (p >= buf && *p != ' ' && *p != '\t') + rub(*p--, w); + p++; + } else if (c == '\r' || c == '\n') { + break; + } else { + if (p >= buf + n - 1) + wwputc(ctrl('g'), w); + else + wwputs(unctrl(*p++ = c), w); + } + } + *p = 0; + w->ww_unctrl = uc; +} + +static void +rub(c, w) +struct ww *w; +{ + register i; + + for (i = strlen(unctrl(c)); --i >= 0;) + (void) wwwrite(w, "\b \b", 3); +} diff --git a/usr.bin/window/wwinit.c b/usr.bin/window/wwinit.c new file mode 100644 index 00000000000..8a7e7489e8d --- /dev/null +++ b/usr.bin/window/wwinit.c @@ -0,0 +1,405 @@ +/* $NetBSD: wwinit.c,v 1.7 1995/09/28 10:35:33 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinit.c 8.2 (Berkeley) 4/28/95"; +#else +static char rcsid[] = "$NetBSD: wwinit.c,v 1.7 1995/09/28 10:35:33 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include <sys/signal.h> +#include <fcntl.h> +#include "char.h" + +wwinit() +{ + register i, j; + char *kp; + int s; + + wwdtablesize = 3; + wwhead.ww_forw = &wwhead; + wwhead.ww_back = &wwhead; + + s = sigblock(sigmask(SIGIO) | sigmask(SIGCHLD) | sigmask(SIGALRM) | + sigmask(SIGHUP) | sigmask(SIGTERM)); + if (signal(SIGIO, wwrint) == BADSIG || + signal(SIGCHLD, wwchild) == BADSIG || + signal(SIGHUP, wwquit) == BADSIG || + signal(SIGTERM, wwquit) == BADSIG || + signal(SIGPIPE, SIG_IGN) == BADSIG) { + wwerrno = WWE_SYS; + return -1; + } + + if (wwgettty(0, &wwoldtty) < 0) + return -1; + wwwintty = wwoldtty; +#ifdef OLD_TTY + wwwintty.ww_sgttyb.sg_flags &= ~XTABS; + wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb; + wwnewtty.ww_sgttyb.sg_erase = -1; + wwnewtty.ww_sgttyb.sg_kill = -1; + wwnewtty.ww_sgttyb.sg_flags |= CBREAK; + wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD); + wwnewtty.ww_tchars.t_intrc = -1; + wwnewtty.ww_tchars.t_quitc = -1; + wwnewtty.ww_tchars.t_startc = -1; + wwnewtty.ww_tchars.t_stopc = -1; + wwnewtty.ww_tchars.t_eofc = -1; + wwnewtty.ww_tchars.t_brkc = -1; + wwnewtty.ww_ltchars.t_suspc = -1; + wwnewtty.ww_ltchars.t_dsuspc = -1; + wwnewtty.ww_ltchars.t_rprntc = -1; + wwnewtty.ww_ltchars.t_flushc = -1; + wwnewtty.ww_ltchars.t_werasc = -1; + wwnewtty.ww_ltchars.t_lnextc = -1; + wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT; + wwnewtty.ww_ldisc = wwoldtty.ww_ldisc; +#else +#ifndef OXTABS +#define OXTABS XTABS +#endif +#ifndef _POSIX_VDISABLE +#define _POSIX_VDISABLE -1 +#endif + wwwintty.ww_termios.c_oflag &= ~OXTABS; + wwnewtty.ww_termios = wwoldtty.ww_termios; + wwnewtty.ww_termios.c_iflag &= + ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL); + wwnewtty.ww_termios.c_oflag = 0; + wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB); + wwnewtty.ww_termios.c_cflag |= CS8; + wwnewtty.ww_termios.c_lflag = 0; + for (i = 0; i < NCCS; i++) + wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE; + wwnewtty.ww_termios.c_cc[VMIN] = 1; + wwnewtty.ww_termios.c_cc[VTIME] = 0; +#endif + wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC; + if (wwsettty(0, &wwnewtty) < 0) + goto bad; + + if ((wwterm = getenv("TERM")) == 0) { + wwerrno = WWE_BADTERM; + goto bad; + } + if (tgetent(wwtermcap, wwterm) != 1) { + wwerrno = WWE_BADTERM; + goto bad; + } +#ifdef OLD_TTY + wwospeed = wwoldtty.ww_sgttyb.sg_ospeed; +#else + wwospeed = cfgetospeed(&wwoldtty.ww_termios); + wwbaud = wwospeed; +#endif + switch (wwospeed) { + default: + case B0: + wwbaud = 0; + break; + case B50: + wwbaud = 50; + break; + case B75: + wwbaud = 75; + break; + case B110: + wwbaud = 110; + break; + case B134: + wwbaud = 134; + break; + case B150: + wwbaud = 150; + break; + case B200: + wwbaud = 200; + break; + case B300: + wwbaud = 300; + break; + case B600: + wwbaud = 600; + break; + case B1200: + wwbaud = 1200; + break; + case B1800: + wwbaud = 1800; + break; + case B2400: + wwbaud = 2400; + break; + case B4800: + wwbaud = 4800; + break; + case B9600: + wwbaud = 9600; + break; +#ifdef B19200 + case B19200: +#else + case EXTA: +#endif + wwbaud = 19200; + break; +#ifdef B38400 + case B38400: +#else + case EXTB: +#endif + wwbaud = 38400; + break; +#ifdef B57600 + case B57600: + wwbaud= 57600; + break; +#endif +#ifdef B115200 + case B115200: + wwbaud = 115200; + break; +#endif + } + + if (xxinit() < 0) + goto bad; + wwnrow = tt.tt_nrow; + wwncol = tt.tt_ncol; + wwavailmodes = tt.tt_availmodes; + wwwrap = tt.tt_wrap; + + if (wwavailmodes & WWM_REV) + wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK; + else if (wwavailmodes & WWM_UL) + wwcursormodes = WWM_UL; + + if ((wwib = malloc((unsigned) 512)) == 0) + goto bad; + wwibe = wwib + 512; + wwibq = wwibp = wwib; + + if ((wwsmap = wwalloc(0, 0, wwnrow, wwncol, sizeof (char))) == 0) + goto bad; + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) + wwsmap[i][j] = WWX_NOBODY; + + wwos = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwos == 0) + goto bad; + /* wwos is cleared in wwstart1() */ + wwns = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwns == 0) + goto bad; + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) + wwns[i][j].c_w = ' '; + if (tt.tt_checkpoint) { + /* wwcs is also cleared in wwstart1() */ + wwcs = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwcs == 0) + goto bad; + } + + wwtouched = malloc((unsigned) wwnrow); + if (wwtouched == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + for (i = 0; i < wwnrow; i++) + wwtouched[i] = 0; + + wwupd = (struct ww_update *) malloc((unsigned) wwnrow * sizeof *wwupd); + if (wwupd == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + + wwindex[WWX_NOBODY] = &wwnobody; + wwnobody.ww_order = NWW; + + kp = wwwintermcap; + if (wwavailmodes & WWM_REV) + wwaddcap1(WWT_REV, &kp); + if (wwavailmodes & WWM_BLK) + wwaddcap1(WWT_BLK, &kp); + if (wwavailmodes & WWM_UL) + wwaddcap1(WWT_UL, &kp); + if (wwavailmodes & WWM_GRP) + wwaddcap1(WWT_GRP, &kp); + if (wwavailmodes & WWM_DIM) + wwaddcap1(WWT_DIM, &kp); + if (wwavailmodes & WWM_USR) + wwaddcap1(WWT_USR, &kp); + if (tt.tt_insline && tt.tt_delline || tt.tt_setscroll) + wwaddcap1(WWT_ALDL, &kp); + if (tt.tt_inschar) + wwaddcap1(WWT_IMEI, &kp); + if (tt.tt_insspace) + wwaddcap1(WWT_IC, &kp); + if (tt.tt_delchar) + wwaddcap1(WWT_DC, &kp); + wwaddcap("kb", &kp); + wwaddcap("ku", &kp); + wwaddcap("kd", &kp); + wwaddcap("kl", &kp); + wwaddcap("kr", &kp); + wwaddcap("kh", &kp); + if ((j = tgetnum("kn")) >= 0) { + char cap[32]; + + (void) sprintf(kp, "kn#%d:", j); + for (; *kp; kp++) + ; + for (i = 1; i <= j; i++) { + (void) sprintf(cap, "k%d", i); + wwaddcap(cap, &kp); + cap[0] = 'l'; + wwaddcap(cap, &kp); + } + } + /* + * It's ok to do this here even if setenv() is destructive + * since tt_init() has already made its own copy of it and + * wwterm now points to the copy. + */ + (void) setenv("TERM", WWT_TERM, 1); +#ifdef TERMINFO + if (wwterminfoinit() < 0) + goto bad; +#endif + + if (tt.tt_checkpoint) + if (signal(SIGALRM, wwalarm) == BADSIG) { + wwerrno = WWE_SYS; + goto bad; + } + /* catch typeahead before ASYNC was set */ + (void) kill(getpid(), SIGIO); + wwstart1(); + (void) sigsetmask(s); + return 0; +bad: + /* + * Don't bother to free storage. We're supposed + * to exit when wwinit fails anyway. + */ + (void) wwsettty(0, &wwoldtty); + (void) signal(SIGIO, SIG_DFL); + (void) sigsetmask(s); + return -1; +} + +wwaddcap(cap, kp) + register char *cap; + register char **kp; +{ + char tbuf[512]; + char *tp = tbuf; + register char *str, *p; + + if ((str = tgetstr(cap, &tp)) != 0) { + while (*(*kp)++ = *cap++) + ; + (*kp)[-1] = '='; + while (*str) { + for (p = unctrl(*str++); *(*kp)++ = *p++;) + ; + (*kp)--; + } + *(*kp)++ = ':'; + **kp = 0; + } +} + +wwaddcap1(cap, kp) + register char *cap; + register char **kp; +{ + while (*(*kp)++ = *cap++) + ; + (*kp)--; +} + +wwstart() +{ + register i; + + (void) wwsettty(0, &wwnewtty); + for (i = 0; i < wwnrow; i++) + wwtouched[i] = WWU_TOUCHED; + wwstart1(); +} + +wwstart1() +{ + register i, j; + + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) { + wwos[i][j].c_w = ' '; + if (tt.tt_checkpoint) + wwcs[i][j].c_w = ' '; + } + xxstart(); + if (tt.tt_checkpoint) + wwdocheckpoint = 1; +} + +/* + * Reset data structures and terminal from an unknown state. + * Restoring wwos has been taken care of elsewhere. + */ +wwreset() +{ + register i; + + xxreset(); + for (i = 0; i < wwnrow; i++) + wwtouched[i] = WWU_TOUCHED; +} diff --git a/usr.bin/window/wwinschar.c b/usr.bin/window/wwinschar.c new file mode 100644 index 00000000000..83710f27c60 --- /dev/null +++ b/usr.bin/window/wwinschar.c @@ -0,0 +1,136 @@ +/* $NetBSD: wwinschar.c,v 1.3 1995/09/28 10:35:35 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinschar.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwinschar.c,v 1.3 1995/09/28 10:35:35 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwinschar(w, row, col, c, m) +register struct ww *w; +char c, m; +{ + register i; + int nvis; + short x = c | m << WWC_MSHIFT; + + /* + * First, shift the line. + */ + { + register union ww_char *p, *q; + + p = &w->ww_buf[row][w->ww_b.r]; + q = p - 1; + for (i = w->ww_b.r - col; --i > 0;) + *--p = *--q; + q->c_w = x; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now find out how much is actually changed, and fix wwns. + */ + { + register union ww_char *buf; + register char *win; + register union ww_char *ns; + register char *smap; + char touched; + + nvis = 0; + smap = &wwsmap[row][col]; + for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++) + ; + if (i >= w->ww_i.r) + return; + col = i; + buf = w->ww_buf[row]; + win = w->ww_win[row]; + ns = wwns[row]; + smap = &wwsmap[row][i]; + touched = wwtouched[row]; + for (; i < w->ww_i.r; i++) { + if (*smap++ != w->ww_index) + continue; + touched |= WWU_TOUCHED; + if (win[i]) + ns[i].c_w = + buf[i].c_w ^ win[i] << WWC_MSHIFT; + else { + nvis++; + ns[i] = buf[i]; + } + } + wwtouched[row] = touched; + } + + /* + * Can/Should we use delete character? + */ + if ((tt.tt_inschar || tt.tt_insspace) && nvis > (wwncol - col) / 2) { + register union ww_char *p, *q; + + if (tt.tt_inschar) + xxinschar(row, col, c, m); + else { + xxinsspace(row, col); + x = ' '; + } + p = &wwos[row][wwncol]; + q = p - 1; + for (i = wwncol - col; --i > 0;) + *--p = *--q; + q->c_w = x; + } +} diff --git a/usr.bin/window/wwinsline.c b/usr.bin/window/wwinsline.c new file mode 100644 index 00000000000..1189d6e4424 --- /dev/null +++ b/usr.bin/window/wwinsline.c @@ -0,0 +1,94 @@ +/* $NetBSD: wwinsline.c,v 1.3 1995/09/28 10:35:36 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinsline.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwinsline.c,v 1.3 1995/09/28 10:35:36 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwinsline(w, row) +register struct ww *w; +int row; +{ + register i; + register union ww_char **cpp, **cqq; + register union ww_char *cp; + int row1, row2; + char deleted; + int visible; + + /* + * Scroll first. + */ + if ((row1 = row) < w->ww_i.t) { + row1 = w->ww_i.t; + visible = 0; + } else + visible = 1; + if ((row2 = w->ww_b.b) > w->ww_i.b) { + row2 = w->ww_i.b; + } + deleted = wwscroll1(w, row1, row2, -1, visible); + + /* + * Fix the buffer. + * But leave clearing the last line for wwclreol(). + */ + cpp = &w->ww_buf[w->ww_b.b]; + cqq = cpp - 1; + cp = *cqq; + for (i = w->ww_b.b - row; --i > 0;) + *--cpp = *--cqq; + *cqq = cp; + + /* + * Now clear the last line. + */ + if (visible) + wwclreol1(w, row, w->ww_b.l, deleted); + else { + cp += w->ww_b.l; + for (i = w->ww_b.nc; --i >= 0;) + cp++->c_w = ' '; + } +} diff --git a/usr.bin/window/wwiomux.c b/usr.bin/window/wwiomux.c new file mode 100644 index 00000000000..6155d5a75b6 --- /dev/null +++ b/usr.bin/window/wwiomux.c @@ -0,0 +1,209 @@ +/* $NetBSD: wwiomux.c,v 1.3 1995/09/28 10:35:37 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwiomux.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwiomux.c,v 1.3 1995/09/28 10:35:37 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <sys/time.h> +#include <sys/types.h> +#if !defined(OLD_TTY) && !defined(TIOCPKT_DATA) +#include <sys/ioctl.h> +#endif +#include <fcntl.h> + +/* + * Multiple window output handler. + * The idea is to copy window outputs to the terminal, via the + * display package. We try to give wwcurwin highest priority. + * The only return conditions are when there is keyboard input + * and when a child process dies, which are serviced by signal + * catchers (wwrint() and wwchild()). + * When there's nothing to do, we sleep in a select(). + * This can be done better with interrupt driven io. But that's + * not supported on ptys, yet. + * The history of this routine is interesting. + */ +wwiomux() +{ + register struct ww *w; + fd_set imask; + register n; + register char *p; + char c; + struct timeval tv; + char noblock = 0; + + for (;;) { + if (wwinterrupt()) { + wwclrintr(); + return; + } + + FD_ZERO(&imask); + n = -1; + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) { + if (w->ww_pty < 0) + continue; + if (w->ww_obq < w->ww_obe) { + if (w->ww_pty > n) + n = w->ww_pty; + FD_SET(w->ww_pty, &imask); + } + if (w->ww_obq > w->ww_obp && !w->ww_stopped) + noblock = 1; + } + + if (!noblock) { + if (wwcurwin != 0) + wwcurtowin(wwcurwin); + wwupdate(); + wwflush(); + (void) setjmp(wwjmpbuf); + wwsetjmp = 1; + if (wwinterrupt()) { + wwsetjmp = 0; + wwclrintr(); + return; + } + /* + * Defensive code. If somebody else (for example, + * wall) clears the ASYNC flag on us, we will block + * forever. So we need a finite timeout and set + * the flag again. Anything more clever will probably + * need even more system calls. (This is a bug + * in the kernel.) + * I don't like this one bit. + */ + (void) fcntl(0, F_SETFL, wwnewtty.ww_fflags); + tv.tv_sec = 30; + tv.tv_usec = 0; + } else { + tv.tv_sec = 0; + tv.tv_usec = 10000; + } + wwnselect++; + n = select(n + 1, &imask, (fd_set *)0, (fd_set *)0, &tv); + wwsetjmp = 0; + noblock = 0; + + if (n < 0) + wwnselecte++; + else if (n == 0) + wwnselectz++; + else + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) { + if (w->ww_pty < 0 || + !FD_ISSET(w->ww_pty, &imask)) + continue; + wwnwread++; + p = w->ww_obq; + if (w->ww_ispty) { + if (p == w->ww_ob) { + w->ww_obp++; + w->ww_obq++; + } else + p--; + c = *p; + } + n = read(w->ww_pty, p, w->ww_obe - p); + if (n < 0) { + wwnwreade++; + (void) close(w->ww_pty); + w->ww_pty = -1; + } else if (n == 0) { + wwnwreadz++; + (void) close(w->ww_pty); + w->ww_pty = -1; + } else if (!w->ww_ispty) { + wwnwreadd++; + wwnwreadc += n; + w->ww_obq += n; + } else if (*p == TIOCPKT_DATA) { + n--; + wwnwreadd++; + wwnwreadc += n; + w->ww_obq += n; + } else { + wwnwreadp++; + if (*p & TIOCPKT_STOP) + w->ww_stopped = 1; + if (*p & TIOCPKT_START) + w->ww_stopped = 0; + if (*p & TIOCPKT_FLUSHWRITE) { + w->ww_stopped = 0; + w->ww_obq = w->ww_obp = + w->ww_ob; + } + } + if (w->ww_ispty) + *p = c; + } + /* + * Try the current window first, if there is output + * then process it and go back to the top to try again. + * This can lead to starvation of the other windows, + * but presumably that what we want. + * Update will eventually happen when output from wwcurwin + * dies down. + */ + if ((w = wwcurwin) != 0 && w->ww_pty >= 0 && + w->ww_obq > w->ww_obp && !w->ww_stopped) { + n = wwwrite(w, w->ww_obp, w->ww_obq - w->ww_obp); + if ((w->ww_obp += n) == w->ww_obq) + w->ww_obq = w->ww_obp = w->ww_ob; + noblock = 1; + continue; + } + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) + if (w->ww_pty >= 0 && w->ww_obq > w->ww_obp && + !w->ww_stopped) { + n = wwwrite(w, w->ww_obp, + w->ww_obq - w->ww_obp); + if ((w->ww_obp += n) == w->ww_obq) + w->ww_obq = w->ww_obp = w->ww_ob; + if (wwinterrupt()) + break; + } + } +} diff --git a/usr.bin/window/wwlabel.c b/usr.bin/window/wwlabel.c new file mode 100644 index 00000000000..41a07357d7b --- /dev/null +++ b/usr.bin/window/wwlabel.c @@ -0,0 +1,102 @@ +/* $NetBSD: wwlabel.c,v 1.3 1995/09/28 10:35:38 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwlabel.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwlabel.c,v 1.3 1995/09/28 10:35:38 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "char.h" + +/* + * Label window w on f, + * at 1 line above w and 'where' columns from it's left edge. + * Gross, but it works. + */ +wwlabel(w, f, where, l, mode) +struct ww *w; +struct ww *f; +char *l; +{ + int row; + register j; + int jj; + register char *win; + register union ww_char *buf; + register union ww_char *ns; + register char *fmap; + register char *smap; + char touched; + char *p; + + if (f->ww_fmap == 0) + return; + + row = w->ww_w.t - 1; + if (row < f->ww_i.t || row >= f->ww_i.b) + return; + win = f->ww_win[row]; + buf = f->ww_buf[row]; + fmap = f->ww_fmap[row]; + ns = wwns[row]; + smap = wwsmap[row]; + touched = wwtouched[row]; + mode <<= WWC_MSHIFT; + + jj = MIN(w->ww_i.r, f->ww_i.r); + j = w->ww_i.l + where; + while (j < jj && *l) + for (p = unctrl(*l++); j < jj && *p; j++, p++) { + /* can't label if not already framed */ + if (win[j] & WWM_GLS) + continue; + if (smap[j] != f->ww_index) + buf[j].c_w = mode | *p; + else { + ns[j].c_w = (buf[j].c_w = mode | *p) + ^ win[j] << WWC_MSHIFT; + touched |= WWU_TOUCHED; + } + fmap[j] |= WWF_LABEL; + } + wwtouched[row] = touched; +} diff --git a/usr.bin/window/wwmisc.c b/usr.bin/window/wwmisc.c new file mode 100644 index 00000000000..cafb0d9d5cc --- /dev/null +++ b/usr.bin/window/wwmisc.c @@ -0,0 +1,73 @@ +/* $NetBSD: wwmisc.c,v 1.3 1995/09/28 10:35:40 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwmisc.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwmisc.c,v 1.3 1995/09/28 10:35:40 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* + * Sufficient but not necessary test for total visibility. + */ +wwvisible(w) +register struct ww *w; +{ + register i; + register nvis = 0; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) + nvis += w->ww_nvis[i]; + if (w->ww_hascursor + && w->ww_cur.r >= w->ww_i.t && w->ww_cur.r < w->ww_i.b + && w->ww_cur.c >= w->ww_i.l && w->ww_cur.c < w->ww_i.r + && wwsmap[w->ww_cur.r][w->ww_cur.c] == w->ww_index) + nvis++; + return nvis == w->ww_i.nr * w->ww_i.nc; +} + +wwbell() +{ + ttputc(ctrl('g')); +} diff --git a/usr.bin/window/wwmove.c b/usr.bin/window/wwmove.c new file mode 100644 index 00000000000..bd8e4f0b02b --- /dev/null +++ b/usr.bin/window/wwmove.c @@ -0,0 +1,104 @@ +/* $NetBSD: wwmove.c,v 1.3 1995/09/28 10:35:41 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwmove.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwmove.c,v 1.3 1995/09/28 10:35:41 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Move a window. Should be unattached. + */ +wwmove(w, row, col) +register struct ww *w; +{ + register dr, dc; + register i; + + dr = row - w->ww_w.t; + dc = col - w->ww_w.l; + + w->ww_w.t += dr; + w->ww_w.b += dr; + w->ww_w.l += dc; + w->ww_w.r += dc; + + w->ww_b.t += dr; + w->ww_b.b += dr; + w->ww_b.l += dc; + w->ww_b.r += dc; + + w->ww_i.t = MAX(w->ww_w.t, 0); + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.l = MAX(w->ww_w.l, 0); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + + w->ww_cur.r += dr; + w->ww_cur.c += dc; + + w->ww_win -= dr; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_win[i] -= dc; + if (w->ww_fmap != 0) { + w->ww_fmap -= dr; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_fmap[i] -= dc; + } + w->ww_nvis -= dr; + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + register j = w->ww_i.l; + register char *win = &w->ww_win[i][j]; + register char *smap = &wwsmap[i][j]; + int nvis = 0; + + for (; j < w->ww_i.r; j++, win++, smap++) + if (*win == 0 && *smap == w->ww_index) + nvis++; + w->ww_nvis[i] = nvis; + } + w->ww_buf -= dr; + for (i = w->ww_b.t; i < w->ww_b.b; i++) + w->ww_buf[i] -= dc; +} diff --git a/usr.bin/window/wwopen.c b/usr.bin/window/wwopen.c new file mode 100644 index 00000000000..59ed3c130ea --- /dev/null +++ b/usr.bin/window/wwopen.c @@ -0,0 +1,196 @@ +/* $NetBSD: wwopen.c,v 1.4 1995/09/28 10:35:42 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwopen.c 8.2 (Berkeley) 4/28/95"; +#else +static char rcsid[] = "$NetBSD: wwopen.c,v 1.4 1995/09/28 10:35:42 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <sys/types.h> +#include <sys/socket.h> +#include <fcntl.h> + +struct ww * +wwopen(flags, nrow, ncol, row, col, nline) +{ + register struct ww *w; + register i, j; + char m; + short nvis; + + w = (struct ww *)calloc(sizeof (struct ww), 1); + if (w == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_pty = -1; + w->ww_socket = -1; + + for (i = 0; i < NWW && wwindex[i] != 0; i++) + ; + if (i >= NWW) { + wwerrno = WWE_TOOMANY; + goto bad; + } + w->ww_index = i; + + if (nline < nrow) + nline = nrow; + + w->ww_w.t = row; + w->ww_w.b = row + nrow; + w->ww_w.l = col; + w->ww_w.r = col + ncol; + w->ww_w.nr = nrow; + w->ww_w.nc = ncol; + + w->ww_b.t = row; + w->ww_b.b = row + nline; + w->ww_b.l = col; + w->ww_b.r = col + ncol; + w->ww_b.nr = nline; + w->ww_b.nc = ncol; + + w->ww_i.t = MAX(w->ww_w.t, 0); + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.l = MAX(w->ww_w.l, 0); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + + if (flags & WWO_PTY) { + if (wwgetpty(w) < 0) + goto bad; + w->ww_ispty = 1; + } else if (flags & WWO_SOCKET) { + int d[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, d) < 0) { + wwerrno = WWE_SYS; + goto bad; + } + (void) fcntl(d[0], F_SETFD, 1); + (void) fcntl(d[1], F_SETFD, 1); + w->ww_pty = d[0]; + w->ww_socket = d[1]; + } + if (flags & (WWO_PTY|WWO_SOCKET)) { + if ((w->ww_ob = malloc(512)) == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_obe = w->ww_ob + 512; + w->ww_obp = w->ww_obq = w->ww_ob; + if (w->ww_pty >= wwdtablesize) + wwdtablesize = w->ww_pty + 1; + } + + w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l, + w->ww_w.nr, w->ww_w.nc, sizeof (char)); + if (w->ww_win == 0) + goto bad; + m = 0; + if (flags & WWO_GLASS) + m |= WWM_GLS; + if (flags & WWO_REVERSE) + if (wwavailmodes & WWM_REV) + m |= WWM_REV; + else + flags &= ~WWO_REVERSE; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_win[i][j] = m; + + if (flags & WWO_FRAME) { + w->ww_fmap = wwalloc(w->ww_w.t, w->ww_w.l, + w->ww_w.nr, w->ww_w.nc, sizeof (char)); + if (w->ww_fmap == 0) + goto bad; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_fmap[i][j] = 0; + } + + w->ww_buf = (union ww_char **) + wwalloc(w->ww_b.t, w->ww_b.l, + w->ww_b.nr, w->ww_b.nc, sizeof (union ww_char)); + if (w->ww_buf == 0) + goto bad; + for (i = w->ww_b.t; i < w->ww_b.b; i++) + for (j = w->ww_b.l; j < w->ww_b.r; j++) + w->ww_buf[i][j].c_w = ' '; + + w->ww_nvis = (short *)malloc((unsigned) w->ww_w.nr * sizeof (short)); + if (w->ww_nvis == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_nvis -= w->ww_w.t; + nvis = m ? 0 : w->ww_w.nc; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_nvis[i] = nvis; + + w->ww_state = WWS_INITIAL; + w->ww_oflags = flags; + return wwindex[w->ww_index] = w; +bad: + if (w != 0) { + if (w->ww_win != 0) + wwfree(w->ww_win, w->ww_w.t); + if (w->ww_fmap != 0) + wwfree(w->ww_fmap, w->ww_w.t); + if (w->ww_buf != 0) + wwfree((char **)w->ww_buf, w->ww_b.t); + if (w->ww_nvis != 0) + free((char *)(w->ww_nvis + w->ww_w.t)); + if (w->ww_ob != 0) + free(w->ww_ob); + if (w->ww_pty >= 0) + (void) close(w->ww_pty); + if (w->ww_socket >= 0) + (void) close(w->ww_socket); + free((char *)w); + } + return 0; +} diff --git a/usr.bin/window/wwprintf.c b/usr.bin/window/wwprintf.c new file mode 100644 index 00000000000..f4c19638ea9 --- /dev/null +++ b/usr.bin/window/wwprintf.c @@ -0,0 +1,63 @@ +/* $NetBSD: wwprintf.c,v 1.3 1995/09/28 10:35:44 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwprintf.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwprintf.c,v 1.3 1995/09/28 10:35:44 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <varargs.h> + +/*VARARGS2*/ +wwprintf(w, fmt, va_alist) +struct ww *w; +char *fmt; +va_dcl +{ + char buf[1024]; + va_list ap; + + va_start(ap); + /* buffer can overflow */ + (void) wwwrite(w, buf, vsprintf(buf, fmt, ap)); + va_end(ap); +} diff --git a/usr.bin/window/wwpty.c b/usr.bin/window/wwpty.c new file mode 100644 index 00000000000..918de2f9f27 --- /dev/null +++ b/usr.bin/window/wwpty.c @@ -0,0 +1,93 @@ +/* $NetBSD: wwpty.c,v 1.3 1995/09/28 10:35:45 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwpty.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwpty.c,v 1.3 1995/09/28 10:35:45 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <fcntl.h> +#if !defined(OLD_TTY) && !defined(TIOCPKT) +#include <sys/ioctl.h> +#endif + +wwgetpty(w) +register struct ww *w; +{ + register char c, *p; + int tty; + int on = 1; +#define PTY "/dev/XtyXX" +#define _PT 5 +#define _PQRS 8 +#define _0_9 9 + + (void) strcpy(w->ww_ttyname, PTY); + for (c = 'p'; c <= 'u'; c++) { + w->ww_ttyname[_PT] = 'p'; + w->ww_ttyname[_PQRS] = c; + w->ww_ttyname[_0_9] = '0'; + if (access(w->ww_ttyname, 0) < 0) + break; + for (p = "0123456789abcdef"; *p; p++) { + w->ww_ttyname[_PT] = 'p'; + w->ww_ttyname[_0_9] = *p; + if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0) + continue; + w->ww_ttyname[_PT] = 't'; + if ((tty = open(w->ww_ttyname, 2)) < 0) { + (void) close(w->ww_pty); + continue; + } + (void) close(tty); + if (ioctl(w->ww_pty, TIOCPKT, (char *)&on) < 0) { + (void) close(w->ww_pty); + continue; + } + (void) fcntl(w->ww_pty, F_SETFD, 1); + return 0; + } + } + w->ww_pty = -1; + wwerrno = WWE_NOPTY; + return -1; +} diff --git a/usr.bin/window/wwputc.c b/usr.bin/window/wwputc.c new file mode 100644 index 00000000000..f910128a4fc --- /dev/null +++ b/usr.bin/window/wwputc.c @@ -0,0 +1,54 @@ +/* $NetBSD: wwputc.c,v 1.3 1995/09/28 10:35:47 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwputc.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwputc.c,v 1.3 1995/09/28 10:35:47 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwputc(c, w) +char c; +struct ww *w; +{ + (void) wwwrite(w, &c, sizeof c); +} diff --git a/usr.bin/window/wwputs.c b/usr.bin/window/wwputs.c new file mode 100644 index 00000000000..1e4d45d8227 --- /dev/null +++ b/usr.bin/window/wwputs.c @@ -0,0 +1,58 @@ +/* $NetBSD: wwputs.c,v 1.3 1995/09/28 10:35:48 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwputs.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwputs.c,v 1.3 1995/09/28 10:35:48 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwputs(s, w) +register char *s; +struct ww *w; +{ + register char *p = s; + + while (*p++) + ; + (void) wwwrite(w, s, p - s - 1); +} diff --git a/usr.bin/window/wwredraw.c b/usr.bin/window/wwredraw.c new file mode 100644 index 00000000000..517ffdcf272 --- /dev/null +++ b/usr.bin/window/wwredraw.c @@ -0,0 +1,62 @@ +/* $NetBSD: wwredraw.c,v 1.3 1995/09/28 10:35:49 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwredraw.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwredraw.c,v 1.3 1995/09/28 10:35:49 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwredraw() +{ + register i, j; + register union ww_char *os; + + xxclear(); + for (i = 0; i < wwnrow; i++) { + wwtouched[i] = WWU_TOUCHED; + os = wwos[i]; + for (j = wwncol; --j >= 0;) + (os++)->c_w = ' '; + } +} diff --git a/usr.bin/window/wwredrawwin.c b/usr.bin/window/wwredrawwin.c new file mode 100644 index 00000000000..82f8088dd51 --- /dev/null +++ b/usr.bin/window/wwredrawwin.c @@ -0,0 +1,79 @@ +/* $NetBSD: wwredrawwin.c,v 1.3 1995/09/28 10:35:50 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwredrawwin.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwredrawwin.c,v 1.3 1995/09/28 10:35:50 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwredrawwin1(w, row1, row2, offset) +register struct ww *w; +int row1, row2, offset; +{ + int row; + register col; + register char *smap; + register union ww_char *buf; + register char *win; + register union ww_char *ns; + int x; + int nchanged; + + for (row = row1; row < row2; row++) { + col = w->ww_i.l; + ns = wwns[row]; + smap = &wwsmap[row][col]; + buf = w->ww_buf[row + offset]; + win = w->ww_win[row]; + nchanged = 0; + for (; col < w->ww_i.r; col++) + if (*smap++ == w->ww_index && + ns[col].c_w != + (x = buf[col].c_w ^ win[col] << WWC_MSHIFT)) { + nchanged++; + ns[col].c_w = x; + } + if (nchanged > 0) + wwtouched[row] |= WWU_TOUCHED; + } +} diff --git a/usr.bin/window/wwrint.c b/usr.bin/window/wwrint.c new file mode 100644 index 00000000000..10b70561dd1 --- /dev/null +++ b/usr.bin/window/wwrint.c @@ -0,0 +1,97 @@ +/* $NetBSD: wwrint.c,v 1.3 1995/09/28 10:35:52 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwrint.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwrint.c,v 1.3 1995/09/28 10:35:52 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#if defined(OLD_TTY) || defined(VMIN_BUG) +#include <fcntl.h> +#endif + +/* + * Tty input interrupt handler. + * (1) Read input into buffer (wwib*). + * (2) Set the interrupt flag if anything is read. + * Currently, the last is used to get out of the blocking + * select() in wwiomux(). + * To avoid race conditions, we only modify wwibq in here, except + * when the buffer is empty; and everywhere else, we only change wwibp. + * It should be completely safe. + */ +void +wwrint() +{ + register n; + + if (wwibp == wwibq) + wwibp = wwibq = wwib; + wwnread++; +#if defined(OLD_TTY) || defined(VMIN_BUG) + /* we have set c_cc[VMIN] to 0 */ + (void) fcntl(0, F_SETFL, O_NONBLOCK|wwnewtty.ww_fflags); +#endif + n = read(0, wwibq, wwibe - wwibq); +#if defined(OLD_TTY) || defined(VMIN_BUG) + (void) fcntl(0, F_SETFL, wwnewtty.ww_fflags); +#endif + if (n > 0) { + if (tt.tt_rint) + n = (*tt.tt_rint)(wwibq, n); + if (n > 0) { + wwibq += n; + wwnreadc += n; + /* + * Hasten or delay the next checkpoint, + * as the case may be. + */ + if (tt.tt_checkpoint && !wwdocheckpoint) + (void) alarm(1); + wwsetintr(); + } + } else if (n == 0) + wwnreadz++; + else + wwnreade++; +} diff --git a/usr.bin/window/wwscroll.c b/usr.bin/window/wwscroll.c new file mode 100644 index 00000000000..07d8d2e2802 --- /dev/null +++ b/usr.bin/window/wwscroll.c @@ -0,0 +1,240 @@ +/* $NetBSD: wwscroll.c,v 1.3 1995/09/28 10:35:53 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwscroll.c,v 1.3 1995/09/28 10:35:53 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwscroll(w, n) +register struct ww *w; +int n; +{ + register dir; + register top; + + if (n == 0) + return; + dir = n < 0 ? -1 : 1; + top = w->ww_b.t - n; + if (top > w->ww_w.t) + top = w->ww_w.t; + else if (top + w->ww_b.nr < w->ww_w.b) + top = w->ww_w.b - w->ww_b.nr; + n = abs(top - w->ww_b.t); + if (n < w->ww_i.nr) { + while (--n >= 0) { + (void) wwscroll1(w, w->ww_i.t, w->ww_i.b, dir, 0); + w->ww_buf += dir; + w->ww_b.t -= dir; + w->ww_b.b -= dir; + } + } else { + w->ww_buf -= top - w->ww_b.t; + w->ww_b.t = top; + w->ww_b.b = top + w->ww_b.nr; + wwredrawwin(w); + } +} + +/* + * Scroll one line, between 'row1' and 'row2', in direction 'dir'. + * Don't adjust ww_scroll. + * And don't redraw 'leaveit' lines. + */ +wwscroll1(w, row1, row2, dir, leaveit) +register struct ww *w; +int row1, row2, dir; +int leaveit; +{ + register i; + int row1x, row2x; + int nvis; + int nvismax; + int scrolled = 0; + + /* + * See how many lines on the screen are affected. + * And calculate row1x, row2x, and left at the same time. + */ + for (i = row1; i < row2 && w->ww_nvis[i] == 0; i++) + ; + if (i >= row2) /* can't do any fancy stuff */ + goto out; + row1x = i; + for (i = row2 - 1; i >= row1 && w->ww_nvis[i] == 0; i--) + ; + if (i <= row1x) + goto out; /* just one line is easy */ + row2x = i + 1; + + /* + * See how much of this window is visible. + */ + nvismax = wwncol * (row2x - row1x); + nvis = 0; + for (i = row1x; i < row2x; i++) + nvis += w->ww_nvis[i]; + + /* + * If it's a good idea to scroll and the terminal can, then do it. + */ + if (nvis < nvismax / 2) + goto no_scroll; /* not worth it */ + if ((dir > 0 ? tt.tt_scroll_down == 0 : tt.tt_scroll_up == 0) || + (tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1) && + tt.tt_setscroll == 0) + if (tt.tt_delline == 0 || tt.tt_insline == 0) + goto no_scroll; + xxscroll(dir, row1x, row2x); + scrolled = 1; + /* + * Fix up the old screen. + */ + { + register union ww_char *tmp; + register union ww_char **cpp, **cqq; + + if (dir > 0) { + cpp = &wwos[row1x]; + cqq = cpp + 1; + tmp = *cpp; + for (i = row2x - row1x; --i > 0;) + *cpp++ = *cqq++; + *cpp = tmp; + } else { + cpp = &wwos[row2x]; + cqq = cpp - 1; + tmp = *cqq; + for (i = row2x - row1x; --i > 0;) + *--cpp = *--cqq; + *cqq = tmp; + } + for (i = wwncol; --i >= 0;) + tmp++->c_w = ' '; + } + +no_scroll: + /* + * Fix the new screen. + */ + if (nvis == nvismax) { + /* + * Can shift whole lines. + */ + if (dir > 0) { + { + register union ww_char *tmp; + register union ww_char **cpp, **cqq; + + cpp = &wwns[row1x]; + cqq = cpp + 1; + tmp = *cpp; + for (i = row2x - row1x; --i > 0;) + *cpp++ = *cqq++; + *cpp = tmp; + } + if (scrolled) { + register char *p, *q; + + p = &wwtouched[row1x]; + q = p + 1; + for (i = row2x - row1x; --i > 0;) + *p++ = *q++; + *p |= WWU_TOUCHED; + } else { + register char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } + wwredrawwin1(w, row1, row1x, dir); + wwredrawwin1(w, row2x - 1, row2 - leaveit, dir); + } else { + { + register union ww_char *tmp; + register union ww_char **cpp, **cqq; + + cpp = &wwns[row2x]; + cqq = cpp - 1; + tmp = *cqq; + for (i = row2x - row1x; --i > 0;) + *--cpp = *--cqq; + *cqq = tmp; + } + if (scrolled) { + register char *p, *q; + + p = &wwtouched[row2x]; + q = p - 1; + for (i = row2x - row1x; --i > 0;) + *--p = *--q; + *q |= WWU_TOUCHED; + } else { + register char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } + wwredrawwin1(w, row1 + leaveit, row1x + 1, dir); + wwredrawwin1(w, row2x, row2, dir); + } + } else { + if (scrolled) { + register char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } +out: + if (dir > 0) + wwredrawwin1(w, row1, row2 - leaveit, dir); + else + wwredrawwin1(w, row1 + leaveit, row2, dir); + } + return scrolled; +} diff --git a/usr.bin/window/wwsize.c b/usr.bin/window/wwsize.c new file mode 100644 index 00000000000..2ed40d49472 --- /dev/null +++ b/usr.bin/window/wwsize.c @@ -0,0 +1,197 @@ +/* $NetBSD: wwsize.c,v 1.3 1995/09/28 10:35:54 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwsize.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwsize.c,v 1.3 1995/09/28 10:35:54 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Resize a window. Should be unattached. + */ +wwsize(w, nrow, ncol) +register struct ww *w; +{ + register i, j; + int nline; + union ww_char **buf = 0; + char **win = 0; + short *nvis = 0; + char **fmap = 0; + char m; + + /* + * First allocate new buffers. + */ + win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char)); + if (win == 0) + goto bad; + if (w->ww_fmap != 0) { + fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char)); + if (fmap == 0) + goto bad; + } + if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) { + nline = MAX(w->ww_b.nr, nrow); + buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l, + nline, ncol, sizeof (union ww_char)); + if (buf == 0) + goto bad; + } + nvis = (short *)malloc((unsigned) nrow * sizeof (short)); + if (nvis == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + nvis -= w->ww_w.t; + /* + * Copy text buffer. + */ + if (buf != 0) { + int b, r; + + b = w->ww_b.t + nline; + r = w->ww_b.l + ncol; + if (ncol < w->ww_b.nc) + for (i = w->ww_b.t; i < w->ww_b.b; i++) + for (j = w->ww_b.l; j < r; j++) + buf[i][j] = w->ww_buf[i][j]; + else + for (i = w->ww_b.t; i < w->ww_b.b; i++) { + for (j = w->ww_b.l; j < w->ww_b.r; j++) + buf[i][j] = w->ww_buf[i][j]; + for (; j < r; j++) + buf[i][j].c_w = ' '; + } + for (; i < b; i++) + for (j = w->ww_b.l; j < r; j++) + buf[i][j].c_w = ' '; + } + /* + * Now free the old stuff. + */ + wwfree((char **)w->ww_win, w->ww_w.t); + w->ww_win = win; + if (buf != 0) { + wwfree((char **)w->ww_buf, w->ww_b.t); + w->ww_buf = buf; + } + if (w->ww_fmap != 0) { + wwfree((char **)w->ww_fmap, w->ww_w.t); + w->ww_fmap = fmap; + } + free((char *)(w->ww_nvis + w->ww_w.t)); + w->ww_nvis = nvis; + /* + * Set new sizes. + */ + /* window */ + w->ww_w.b = w->ww_w.t + nrow; + w->ww_w.r = w->ww_w.l + ncol; + w->ww_w.nr = nrow; + w->ww_w.nc = ncol; + /* text buffer */ + if (buf != 0) { + w->ww_b.b = w->ww_b.t + nline; + w->ww_b.r = w->ww_b.l + ncol; + w->ww_b.nr = nline; + w->ww_b.nc = ncol; + } + /* scroll */ + if ((i = w->ww_b.b - w->ww_w.b) < 0 || + (i = w->ww_cur.r - w->ww_w.b + 1) > 0) { + w->ww_buf += i; + w->ww_b.t -= i; + w->ww_b.b -= i; + w->ww_cur.r -= i; + } + /* interior */ + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + /* + * Initialize new buffers. + */ + /* window */ + m = 0; + if (w->ww_oflags & WWO_GLASS) + m |= WWM_GLS; + if (w->ww_oflags & WWO_REVERSE) + m |= WWM_REV; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_win[i][j] = m; + /* frame map */ + if (fmap != 0) + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_fmap[i][j] = 0; + /* visibility */ + j = m ? 0 : w->ww_w.nc; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_nvis[i] = j; + /* + * Put cursor back. + */ + if (w->ww_hascursor) { + w->ww_hascursor = 0; + wwcursor(w, 1); + } + /* + * Fool with pty. + */ + if (w->ww_ispty && w->ww_pty >= 0) + (void) wwsetttysize(w->ww_pty, nrow, ncol); + return 0; +bad: + if (win != 0) + wwfree(win, w->ww_w.t); + if (fmap != 0) + wwfree(fmap, w->ww_w.t); + if (buf != 0) + wwfree((char **)buf, w->ww_b.t); + if (nvis != 0) + free((char *)(nvis + w->ww_w.t)); + return -1; +} diff --git a/usr.bin/window/wwspawn.c b/usr.bin/window/wwspawn.c new file mode 100644 index 00000000000..300a4c4da10 --- /dev/null +++ b/usr.bin/window/wwspawn.c @@ -0,0 +1,91 @@ +/* $NetBSD: wwspawn.c,v 1.3 1995/09/28 10:35:55 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwspawn.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwspawn.c,v 1.3 1995/09/28 10:35:55 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <sys/signal.h> + +/* + * There is a dead lock with vfork and closing of pseudo-ports. + * So we have to be sneaky about error reporting. + */ +wwspawn(wp, file, argv) +register struct ww *wp; +char *file; +char **argv; +{ + int pid; + int ret; + char erred = 0; + int s; + + s = sigblock(sigmask(SIGCHLD)); + switch (pid = vfork()) { + case -1: + wwerrno = WWE_SYS; + ret = -1; + break; + case 0: + if (wwenviron(wp) >= 0) + execvp(file, argv); + erred = 1; + _exit(1); + default: + if (erred) { + wwerrno = WWE_SYS; + ret = -1; + } else { + wp->ww_pid = pid; + wp->ww_state = WWS_HASPROC; + ret = pid; + } + } + (void) sigsetmask(s); + if (wp->ww_socket >= 0) { + (void) close(wp->ww_socket); + wp->ww_socket = -1; + } + return ret; +} diff --git a/usr.bin/window/wwsuspend.c b/usr.bin/window/wwsuspend.c new file mode 100644 index 00000000000..356d19c2351 --- /dev/null +++ b/usr.bin/window/wwsuspend.c @@ -0,0 +1,62 @@ +/* $NetBSD: wwsuspend.c,v 1.3 1995/09/28 10:35:56 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwsuspend.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwsuspend.c,v 1.3 1995/09/28 10:35:56 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include <sys/signal.h> + +wwsuspend() +{ + sig_t oldsig; + + oldsig = signal(SIGTSTP, SIG_IGN); + wwend(0); + (void) signal(SIGTSTP, SIG_DFL); + (void) kill(0, SIGTSTP); + (void) signal(SIGTSTP, SIG_IGN); + wwstart(); + (void) signal(SIGTSTP, oldsig); +} diff --git a/usr.bin/window/wwterminfo.c b/usr.bin/window/wwterminfo.c new file mode 100644 index 00000000000..8039b1ede40 --- /dev/null +++ b/usr.bin/window/wwterminfo.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1982, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)wwterminfo.c 8.1 (Berkeley) 6/6/93"; +#endif /* not lint */ + +#ifdef TERMINFO + +#include "ww.h" +#include <stdio.h> +#include <paths.h> +#include "local.h" + +/* + * Terminfo support + * + * Written by Brian Buhrow + * + * Subsequently modified by Edward Wang + */ + +/* + * Initialize the working terminfo directory + */ +wwterminfoinit() +{ + FILE *fp; + char buf[2048]; + + /* make the directory */ + (void) sprintf(wwterminfopath, "%swwinXXXXXX", _PATH_TMP); + mktemp(wwterminfopath); + if (mkdir(wwterminfopath, 0755) < 0 || + chmod(wwterminfopath, 00755) < 0) { + wwerrno = WWE_SYS; + return -1; + } + (void) setenv("TERMINFO", wwterminfopath, 1); + /* make a termcap entry and turn it into terminfo */ + (void) sprintf(buf, "%s/cap", wwterminfopath); + if ((fp = fopen(buf, "w")) == NULL) { + wwerrno = WWE_SYS; + return -1; + } + (void) fprintf(fp, "%sco#%d:li#%d:%s\n", + WWT_TERMCAP, wwncol, wwnrow, wwwintermcap); + (void) fclose(fp); + (void) sprintf(buf, + "cd %s; %s cap >info 2>/dev/null; %s info >/dev/null 2>&1", + wwterminfopath, _PATH_CAPTOINFO, _PATH_TIC); + (void) system(buf); + return 0; +} + +/* + * Delete the working terminfo directory at shutdown + */ +wwterminfoend() +{ + + switch (vfork()) { + case -1: + /* can't really do (or say) anything about errors */ + return -1; + case 0: + execl(_PATH_RM, _PATH_RM, "-rf", wwterminfopath, 0); + return -1; + default: + return 0; + } +} + +#endif /* TERMINFO */ diff --git a/usr.bin/window/wwtty.c b/usr.bin/window/wwtty.c new file mode 100644 index 00000000000..347862608ef --- /dev/null +++ b/usr.bin/window/wwtty.c @@ -0,0 +1,186 @@ +/* $NetBSD: wwtty.c,v 1.3 1995/09/28 10:35:58 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwtty.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwtty.c,v 1.3 1995/09/28 10:35:58 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include <sys/types.h> +#include <fcntl.h> +#if !defined(OLD_TTY) && !defined(TIOCGWINSZ) +#include <sys/ioctl.h> +#endif + +wwgettty(d, t) +register struct ww_tty *t; +{ +#ifdef OLD_TTY + if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0) + goto bad; + if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0) + goto bad; + if (ioctl(d, TIOCGLTC, (char *)&t->ww_ltchars) < 0) + goto bad; + if (ioctl(d, TIOCLGET, (char *)&t->ww_lmode) < 0) + goto bad; + if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0) + goto bad; +#else + if (tcgetattr(d, &t->ww_termios) < 0) + goto bad; +#endif + if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0) + goto bad; + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} + +/* + * Set the modes of tty 'd' to 't' + * 'o' is the current modes. We set the line discipline only if + * it changes, to avoid unnecessary flushing of typeahead. + */ +wwsettty(d, t) +register struct ww_tty *t; +{ +#ifdef OLD_TTY + int i; + + /* XXX, for buggy tty drivers that don't wait for output to drain */ + while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0) + usleep(100000); + if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0) + goto bad; + if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0) + goto bad; + if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0) + goto bad; + if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0) + goto bad; + if (ioctl(d, TIOCGETD, (char *)&i) < 0) + goto bad; + if (t->ww_ldisc != i && + ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0) + goto bad; +#else +#ifdef sun + /* XXX, for buggy tty drivers that don't wait for output to drain */ + (void) tcdrain(d); +#endif + if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0) + goto bad; +#endif + if (fcntl(d, F_SETFL, t->ww_fflags) < 0) + goto bad; + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} + +/* + * The ttysize and stop-start routines must also work + * on the control side of pseudoterminals. + */ + +wwgetttysize(d, r, c) + int *r, *c; +{ + struct winsize winsize; + + if (ioctl(d, TIOCGWINSZ, (char *)&winsize) < 0) { + wwerrno = WWE_SYS; + return -1; + } + if (winsize.ws_row != 0) + *r = winsize.ws_row; + if (winsize.ws_col != 0) + *c = winsize.ws_col; + return 0; +} + +wwsetttysize(d, r, c) +{ + struct winsize winsize; + + winsize.ws_row = r; + winsize.ws_col = c; + winsize.ws_xpixel = winsize.ws_ypixel = 0; + if (ioctl(d, TIOCSWINSZ, (char *)&winsize) < 0) { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} + +wwstoptty(d) +{ +#if !defined(OLD_TTY) && defined(TCOOFF) + /* not guaranteed to work on the pty side */ + if (tcflow(d, TCOOFF) < 0) +#else + if (ioctl(d, TIOCSTOP, (char *)0) < 0) +#endif + { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} + +wwstarttty(d) +{ +#if !defined(OLD_TTY) && defined(TCOON) + /* not guaranteed to work on the pty side */ + if (tcflow(d, TCOON) < 0) +#else + if (ioctl(d, TIOCSTART, (char *)0) < 0) +#endif + { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} diff --git a/usr.bin/window/wwunframe.c b/usr.bin/window/wwunframe.c new file mode 100644 index 00000000000..535790fdebf --- /dev/null +++ b/usr.bin/window/wwunframe.c @@ -0,0 +1,82 @@ +/* $NetBSD: wwunframe.c,v 1.3 1995/09/28 10:35:59 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwunframe.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwunframe.c,v 1.3 1995/09/28 10:35:59 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" + +wwunframe(w) +register struct ww *w; +{ + int i; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + register j; + register char *win = w->ww_win[i]; + register char *fmap = w->ww_fmap ? w->ww_fmap[i] : 0; + register char *smap = wwsmap[i]; + register union ww_char *ns = wwns[i]; + int nchanged = 0; + + for (j = w->ww_i.l; j < w->ww_i.r; j++) { + if (win[j] & WWM_GLS) + continue; + win[j] |= WWM_GLS; + if (fmap != 0) + fmap[j] = 0; + if (smap[j] == w->ww_index) { + smap[j] = WWX_NOBODY; + ns[j].c_w = ' '; + nchanged++; + } + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w->ww_nvis[i] = 0; + } + + if (w->ww_forw != &wwhead) + wwdelete1(w->ww_forw, + w->ww_i.t, w->ww_i.b, w->ww_i.l, w->ww_i.r); +} diff --git a/usr.bin/window/wwupdate.c b/usr.bin/window/wwupdate.c new file mode 100644 index 00000000000..834da7ba4bc --- /dev/null +++ b/usr.bin/window/wwupdate.c @@ -0,0 +1,277 @@ +/* $NetBSD: wwupdate.c,v 1.3 1995/09/28 10:36:00 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwupdate.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwupdate.c,v 1.3 1995/09/28 10:36:00 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +wwupdate1(top, bot) +{ + int i; + register j; + char *touched; + struct ww_update *upd; + char check_clreos = 0; + int scan_top, scan_bot; + + wwnupdate++; + { + register char *t1 = wwtouched + top, *t2 = wwtouched + bot; + register n; + + while (!*t1++) + if (t1 == t2) + return; + while (!*--t2) + ; + scan_top = top = t1 - wwtouched - 1; + scan_bot = bot = t2 - wwtouched + 1; + if (scan_bot - scan_top > 1 && + (tt.tt_clreos != 0 || tt.tt_clear != 0)) { + int st = tt.tt_clreos != 0 ? scan_top : 0; + + /* + * t1 is one past the first touched row, + * t2 is on the last touched row. + */ + for (t1--, n = 1; t1 < t2;) + if (*t1++) + n++; + /* + * If we can't clreos then we try for clearing + * the whole screen. + */ + if (check_clreos = n * 10 > (wwnrow - st) * 9) { + scan_top = st; + scan_bot = wwnrow; + } + } + } + if (tt.tt_clreol == 0 && !check_clreos) + goto simple; + for (i = scan_top, touched = &wwtouched[i], upd = &wwupd[i]; + i < scan_bot; + i++, touched++, upd++) { + register gain = 0; + register best_gain = 0; + register best_col; + register union ww_char *ns, *os; + + if (wwinterrupt()) + return; + if (!check_clreos && !*touched) + continue; + wwnupdscan++; + j = wwncol; + ns = &wwns[i][j]; + os = &wwos[i][j]; + while (--j >= 0) { + /* + * The cost of clearing is: + * ncol - nblank + X + * The cost of straight update is, more or less: + * ncol - nsame + * We clear if nblank - nsame > X + * X is the clreol overhead. + * So we make gain = nblank - nsame. + */ + if ((--ns)->c_w == (--os)->c_w) + gain--; + else + best_gain--; + if (ns->c_w == ' ') + gain++; + if (gain > best_gain) { + best_col = j; + best_gain = gain; + } + } + upd->best_gain = best_gain; + upd->best_col = best_col; + upd->gain = gain; + } + if (check_clreos) { + register struct ww_update *u; + register gain = 0; + register best_gain = 0; + int best_row; + register simple_gain = 0; + char didit = 0; + + /* + * gain is the advantage of clearing all the lines. + * best_gain is the advantage of clearing to eos + * at best_row and u->best_col. + * simple_gain is the advantage of using only clreol. + * We use g > best_gain because u->best_col can be + * undefined when u->best_gain is 0 so we can't use it. + */ + for (j = scan_bot - 1, u = wwupd + j; j >= top; j--, u--) { + register g = gain + u->best_gain; + + if (g > best_gain) { + best_gain = g; + best_row = j; + } + gain += u->gain; + if (tt.tt_clreol != 0 && u->best_gain > 4) + simple_gain += u->best_gain - 4; + } + if (tt.tt_clreos == 0) { + if (gain > simple_gain && gain > 4) { + xxclear(); + i = top = scan_top; + bot = scan_bot; + j = 0; + didit = 1; + } + } else + if (best_gain > simple_gain && best_gain > 4) { + i = best_row; + xxclreos(i, j = wwupd[i].best_col); + bot = scan_bot; + didit = 1; + } + if (didit) { + wwnupdclreos++; + wwnupdclreosline += wwnrow - i; + u = wwupd + i; + while (i < scan_bot) { + register union ww_char *os = &wwos[i][j]; + + for (j = wwncol - j; --j >= 0;) + os++->c_w = ' '; + wwtouched[i++] |= WWU_TOUCHED; + u++->best_gain = 0; + j = 0; + } + } else + wwnupdclreosmiss++; + } +simple: + for (i = top, touched = &wwtouched[i], upd = &wwupd[i]; i < bot; + i++, touched++, upd++) { + register union ww_char *os, *ns; + char didit; + + if (!*touched) + continue; + *touched = 0; + wwnupdline++; + didit = 0; + if (tt.tt_clreol != 0 && upd->best_gain > 4) { + wwnupdclreol++; + xxclreol(i, j = upd->best_col); + for (os = &wwos[i][j], j = wwncol - j; --j >= 0;) + os++->c_w = ' '; + didit = 1; + } + ns = wwns[i]; + os = wwos[i]; + for (j = 0; j < wwncol;) { + register char *p, *q; + char m; + int c; + register n; + char buf[512]; /* > wwncol */ + union ww_char lastc; + + for (; j++ < wwncol && ns++->c_w == os++->c_w;) + ; + if (j > wwncol) + break; + p = buf; + m = ns[-1].c_m; + c = j - 1; + os[-1] = ns[-1]; + *p++ = ns[-1].c_c; + n = 5; + q = p; + while (j < wwncol && ns->c_m == m) { + *p++ = ns->c_c; + if (ns->c_w == os->c_w) { + if (--n <= 0) + break; + os++; + ns++; + } else { + n = 5; + q = p; + lastc = *os; + *os++ = *ns++; + } + j++; + } + n = q - buf; + if (!wwwrap || i != wwnrow - 1 || c + n != wwncol) + xxwrite(i, c, buf, n, m); + else if (tt.tt_inschar || tt.tt_insspace) { + if (n > 1) { + q[-2] = q[-1]; + n--; + } else + c--; + xxwrite(i, c, buf, n, m); + c += n - 1; + if (tt.tt_inschar) + xxinschar(i, c, ns[-2].c_c, + ns[-2].c_m); + else { + xxinsspace(i, c); + xxwrite(i, c, &ns[-2].c_c, 1, + ns[-2].c_m); + } + } else { + if (--n) + xxwrite(i, c, buf, n, m); + os[-1] = lastc; + *touched = WWU_TOUCHED; + } + didit = 1; + } + if (!didit) + wwnupdmiss++; + } +} diff --git a/usr.bin/window/wwwrite.c b/usr.bin/window/wwwrite.c new file mode 100644 index 00000000000..bb45e281e5f --- /dev/null +++ b/usr.bin/window/wwwrite.c @@ -0,0 +1,304 @@ +/* $NetBSD: wwwrite.c,v 1.3 1995/09/28 10:36:01 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwwrite.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: wwwrite.c,v 1.3 1995/09/28 10:36:01 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +#define UPDATE() \ + if (!w->ww_noupdate && w->ww_cur.r >= 0 && w->ww_cur.r < wwnrow && \ + wwtouched[w->ww_cur.r]) \ + wwupdate1(w->ww_cur.r, w->ww_cur.r + 1) + +/* + * To support control character expansion, we save the old + * p and q values in r and s, and point p at the beginning + * of the expanded string, and q at some safe place beyond it + * (p + 10). At strategic points in the loops, we check + * for (r && !*p) and restore the saved values back into + * p and q. Essentially, we implement a stack of depth 2, + * to avoid recursion, which might be a better idea. + */ +wwwrite(w, p, n) +register struct ww *w; +register char *p; +int n; +{ + char hascursor; + char *savep = p; + char *q = p + n; + char *r = 0; + char *s; + +#ifdef lint + s = 0; /* define it before possible use */ +#endif + if (hascursor = w->ww_hascursor) + wwcursor(w, 0); + while (p < q && !w->ww_stopped && (!wwinterrupt() || w->ww_nointr)) { + if (r && !*p) { + p = r; + q = s; + r = 0; + continue; + } + if (w->ww_wstate == 0 && + (isprt(*p) || w->ww_unctrl && isunctrl(*p))) { + register i; + register union ww_char *bp; + int col, col1; + + if (w->ww_insert) { /* this is very slow */ + if (*p == '\t') { + p++; + w->ww_cur.c += 8 - + (w->ww_cur.c - w->ww_w.l & 7); + goto chklf; + } + if (!isprt(*p)) { + r = p + 1; + s = q; + p = unctrl(*p); + q = p + 10; + } + wwinschar(w, w->ww_cur.r, w->ww_cur.c, + *p++, w->ww_modes); + goto right; + } + + bp = &w->ww_buf[w->ww_cur.r][w->ww_cur.c]; + i = w->ww_cur.c; + while (i < w->ww_w.r && p < q) + if (!*p && r) { + p = r; + q = s; + r = 0; + } else if (*p == '\t') { + register tmp = 8 - (i - w->ww_w.l & 7); + p++; + i += tmp; + bp += tmp; + } else if (isprt(*p)) { + bp++->c_w = *p++ + | w->ww_modes << WWC_MSHIFT; + i++; + } else if (w->ww_unctrl && isunctrl(*p)) { + r = p + 1; + s = q; + p = unctrl(*p); + q = p + 10; + } else + break; + col = MAX(w->ww_cur.c, w->ww_i.l); + col1 = MIN(i, w->ww_i.r); + w->ww_cur.c = i; + if (w->ww_cur.r >= w->ww_i.t + && w->ww_cur.r < w->ww_i.b) { + register union ww_char *ns = wwns[w->ww_cur.r]; + register char *smap = &wwsmap[w->ww_cur.r][col]; + register char *win = w->ww_win[w->ww_cur.r]; + int nchanged = 0; + + bp = w->ww_buf[w->ww_cur.r]; + for (i = col; i < col1; i++) + if (*smap++ == w->ww_index) { + nchanged++; + ns[i].c_w = bp[i].c_w + ^ win[i] << WWC_MSHIFT; + } + if (nchanged > 0) + wwtouched[w->ww_cur.r] |= WWU_TOUCHED; + } + chklf: + if (w->ww_cur.c >= w->ww_w.r) + goto crlf; + } else switch (w->ww_wstate) { + case 0: + switch (*p++) { + case '\n': + if (w->ww_mapnl) + crlf: + w->ww_cur.c = w->ww_w.l; + lf: + UPDATE(); + if (++w->ww_cur.r >= w->ww_w.b) { + w->ww_cur.r = w->ww_w.b - 1; + if (w->ww_w.b < w->ww_b.b) { + (void) wwscroll1(w, w->ww_i.t, + w->ww_i.b, 1, 0); + w->ww_buf++; + w->ww_b.t--; + w->ww_b.b--; + } else + wwdelline(w, w->ww_b.t); + } + break; + case '\b': + if (--w->ww_cur.c < w->ww_w.l) { + w->ww_cur.c = w->ww_w.r - 1; + goto up; + } + break; + case '\r': + w->ww_cur.c = w->ww_w.l; + break; + case ctrl('g'): + ttputc(ctrl('g')); + break; + case ctrl('['): + w->ww_wstate = 1; + break; + } + break; + case 1: + w->ww_wstate = 0; + switch (*p++) { + case '@': + w->ww_insert = 1; + break; + case 'A': + up: + UPDATE(); + if (--w->ww_cur.r < w->ww_w.t) { + w->ww_cur.r = w->ww_w.t; + if (w->ww_w.t > w->ww_b.t) { + (void) wwscroll1(w, w->ww_i.t, + w->ww_i.b, -1, 0); + w->ww_buf--; + w->ww_b.t++; + w->ww_b.b++; + } else + wwinsline(w, w->ww_b.t); + } + break; + case 'B': + goto lf; + case 'C': + right: + w->ww_cur.c++; + goto chklf; + case 'E': + w->ww_buf -= w->ww_w.t - w->ww_b.t; + w->ww_b.t = w->ww_w.t; + w->ww_b.b = w->ww_b.t + w->ww_b.nr; + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + wwclreos(w, w->ww_w.t, w->ww_w.l); + break; + case 'H': + UPDATE(); + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + break; + case 'J': + wwclreos(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'K': + wwclreol(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'L': + UPDATE(); + wwinsline(w, w->ww_cur.r); + break; + case 'M': + wwdelline(w, w->ww_cur.r); + break; + case 'N': + wwdelchar(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'O': + w->ww_insert = 0; + break; + case 'P': + wwinschar(w, w->ww_cur.r, w->ww_cur.c, ' ', 0); + break; + case 'X': + wwupdate(); + break; + case 'Y': + UPDATE(); + w->ww_wstate = 2; + break; + case 'Z': + wwupdate(); + xxflush(0); + break; + case 's': + w->ww_wstate = 4; + break; + case 'r': + w->ww_wstate = 5; + break; + } + break; + case 2: + w->ww_cur.r = w->ww_w.t + + (unsigned)(*p++ - ' ') % w->ww_w.nr; + w->ww_wstate = 3; + break; + case 3: + w->ww_cur.c = w->ww_w.l + + (unsigned)(*p++ - ' ') % w->ww_w.nc; + w->ww_wstate = 0; + break; + case 4: + w->ww_modes |= *p++ & wwavailmodes; + w->ww_wstate = 0; + break; + case 5: + w->ww_modes &= ~*p++; + w->ww_wstate = 0; + break; + } + } + if (hascursor) + wwcursor(w, 1); + wwnwwr++; + wwnwwra += n; + n = p - savep; + wwnwwrc += n; + return n; +} diff --git a/usr.bin/window/xx.c b/usr.bin/window/xx.c new file mode 100644 index 00000000000..83d7355be0a --- /dev/null +++ b/usr.bin/window/xx.c @@ -0,0 +1,258 @@ +/* $NetBSD: xx.c,v 1.3 1995/09/28 10:36:03 tls Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)xx.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: xx.c,v 1.3 1995/09/28 10:36:03 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "xx.h" +#include "tt.h" + +xxinit() +{ + if (ttinit() < 0) + return -1; + xxbufsize = tt.tt_nrow * tt.tt_ncol * 2; + /* ccinit may choose to change xxbufsize */ + if (tt.tt_ntoken > 0 && ccinit() < 0) + return -1; + xxbuf = malloc((unsigned) xxbufsize * sizeof *xxbuf); + if (xxbuf == 0) { + wwerrno = WWE_NOMEM; + return -1; + } + xxbufp = xxbuf; + xxbufe = xxbuf + xxbufsize; + return 0; +} + +xxstart() +{ + (*tt.tt_start)(); + if (tt.tt_ntoken > 0) + ccstart(); + xxreset1(); /* might be a restart */ +} + +xxreset() +{ + if (tt.tt_ntoken > 0) + ccreset(); + xxreset1(); + (*tt.tt_reset)(); +} + +xxreset1() +{ + register struct xx *xp, *xq; + + for (xp = xx_head; xp != 0; xp = xq) { + xq = xp->link; + xxfree(xp); + } + xx_tail = xx_head = 0; + xxbufp = xxbuf; +} + +xxend() +{ + if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1) + /* tt.tt_setscroll is known to be defined */ + (*tt.tt_setscroll)(0, tt.tt_nrow - 1); + if (tt.tt_modes) + (*tt.tt_setmodes)(0); + if (tt.tt_scroll_down) + (*tt.tt_scroll_down)(1); + (*tt.tt_move)(tt.tt_nrow - 1, 0); + if (tt.tt_ntoken > 0) + ccend(); + (*tt.tt_end)(); + ttflush(); +} + +struct xx * +xxalloc() +{ + register struct xx *xp; + + if (xxbufp > xxbufe) + abort(); + if ((xp = xx_freelist) == 0) + /* XXX can't deal with failure */ + xp = (struct xx *) malloc((unsigned) sizeof *xp); + else + xx_freelist = xp->link; + if (xx_head == 0) + xx_head = xp; + else + xx_tail->link = xp; + xx_tail = xp; + xp->link = 0; + return xp; +} + +xxfree(xp) + register struct xx *xp; +{ + xp->link = xx_freelist; + xx_freelist = xp; +} + +xxmove(row, col) +{ + register struct xx *xp = xx_tail; + + if (xp == 0 || xp->cmd != xc_move) { + xp = xxalloc(); + xp->cmd = xc_move; + } + xp->arg0 = row; + xp->arg1 = col; +} + +xxscroll(dir, top, bot) +{ + register struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_scroll && + xp->arg1 == top && xp->arg2 == bot && + (xp->arg0 < 0 && dir < 0 || xp->arg0 > 0 && dir > 0)) { + xp->arg0 += dir; + return; + } + xp = xxalloc(); + xp->cmd = xc_scroll; + xp->arg0 = dir; + xp->arg1 = top; + xp->arg2 = bot; +} + +xxinschar(row, col, c, m) +{ + register struct xx *xp; + + xp = xxalloc(); + xp->cmd = xc_inschar; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = c; + xp->arg3 = m; +} + +xxinsspace(row, col) +{ + register struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_insspace && xp->arg0 == row && + col >= xp->arg1 && col <= xp->arg1 + xp->arg2) { + xp->arg2++; + return; + } + xp = xxalloc(); + xp->cmd = xc_insspace; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = 1; +} + +xxdelchar(row, col) +{ + register struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_delchar && + xp->arg0 == row && xp->arg1 == col) { + xp->arg2++; + return; + } + xp = xxalloc(); + xp->cmd = xc_delchar; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = 1; +} + +xxclear() +{ + register struct xx *xp; + + xxreset1(); + xp = xxalloc(); + xp->cmd = xc_clear; +} + +xxclreos(row, col) +{ + register struct xx *xp = xxalloc(); + + xp->cmd = xc_clreos; + xp->arg0 = row; + xp->arg1 = col; +} + +xxclreol(row, col) +{ + register struct xx *xp = xxalloc(); + + xp->cmd = xc_clreol; + xp->arg0 = row; + xp->arg1 = col; +} + +xxwrite(row, col, p, n, m) + char *p; +{ + register struct xx *xp; + + if (xxbufp + n + 1 > xxbufe) + xxflush(0); + xp = xxalloc(); + xp->cmd = xc_write; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = n; + xp->arg3 = m; + xp->buf = xxbufp; + bcopy(p, xxbufp, n); + xxbufp += n; + *xxbufp++ = char_sep; +} diff --git a/usr.bin/window/xx.h b/usr.bin/window/xx.h new file mode 100644 index 00000000000..62c1945025b --- /dev/null +++ b/usr.bin/window/xx.h @@ -0,0 +1,60 @@ +/* $NetBSD: xx.h,v 1.3 1995/09/28 10:36:04 tls Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)xx.h 8.1 (Berkeley) 6/6/93 + */ + +struct xx { + enum { xc_move, xc_scroll, xc_inschar, xc_insspace, xc_delchar, + xc_clear, xc_clreos, xc_clreol, xc_write } cmd; + int arg0; + int arg1; + int arg2; + int arg3; + char *buf; + struct xx *link; +}; + +struct xx *xxalloc(); + +struct xx *xx_head, *xx_tail; +struct xx *xx_freelist; + +char *xxbuf, *xxbufp, *xxbufe; +int xxbufsize; + +#define char_sep '\0' diff --git a/usr.bin/window/xxflush.c b/usr.bin/window/xxflush.c new file mode 100644 index 00000000000..c18ec6afd2a --- /dev/null +++ b/usr.bin/window/xxflush.c @@ -0,0 +1,202 @@ +/* $NetBSD: xxflush.c,v 1.3 1995/09/28 10:36:05 tls Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)xxflush.c 8.1 (Berkeley) 6/6/93"; +#else +static char rcsid[] = "$NetBSD: xxflush.c,v 1.3 1995/09/28 10:36:05 tls Exp $"; +#endif +#endif /* not lint */ + +#include "ww.h" +#include "xx.h" +#include "tt.h" + +xxflush(intr) + register intr; +{ + register struct xx *xp, *xq; + + for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) { + switch (xp->cmd) { + case xc_move: + if (xp->link == 0) + (*tt.tt_move)(xp->arg0, xp->arg1); + break; + case xc_scroll: + xxflush_scroll(xp); + break; + case xc_inschar: + (*tt.tt_move)(xp->arg0, xp->arg1); + tt.tt_nmodes = xp->arg3; + (*tt.tt_inschar)(xp->arg2); + break; + case xc_insspace: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_insspace)(xp->arg2); + break; + case xc_delchar: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_delchar)(xp->arg2); + break; + case xc_clear: + (*tt.tt_clear)(); + break; + case xc_clreos: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_clreos)(); + break; + case xc_clreol: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_clreol)(); + break; + case xc_write: + (*tt.tt_move)(xp->arg0, xp->arg1); + tt.tt_nmodes = xp->arg3; + (*tt.tt_write)(xp->buf, xp->arg2); + break; + } + xq = xp->link; + xxfree(xp); + } + if ((xx_head = xp) == 0) { + xx_tail = 0; + xxbufp = xxbuf; + } + ttflush(); +} + +xxflush_scroll(xp) + register struct xx *xp; +{ + register struct xx *xq; + + top: + if (xp->arg0 == 0) + return; + /* + * We handle retain (da and db) by putting the burden on scrolling up, + * which is the less common operation. It must ensure that + * text is not pushed below the screen, so scrolling down doesn't + * have to worry about it. + * + * Try scrolling region (or scrolling the whole screen) first. + * Can we assume "sr" doesn't push text below the screen + * so we don't have to worry about retain below? + * What about scrolling down with a newline? It probably does + * push text above (with da). Scrolling up would then have + * to take care of that. + * It's easy to be fool proof, but that slows things down. + * The current solution is to disallow tt_scroll_up if da or db is true + * but cs (scrolling region) is not. Again, we sacrifice scrolling + * up in favor of scrolling down. The idea is having scrolling regions + * probably means we can scroll (even the whole screen) with impunity. + * This lets us work efficiently on simple terminals (use newline + * on the bottom to scroll), on any terminal without retain, and + * on vt100 style scrolling regions (I think). + */ + if (xp->arg0 > 0) { + if ((xq = xp->link) != 0 && xq->cmd == xc_scroll && + xp->arg2 == xq->arg2 && xq->arg0 < 0) { + if (xp->arg1 < xq->arg1) { + if (xp->arg2 - xp->arg0 <= xq->arg1) { + xq->arg0 = xp->arg0; + xq->arg1 = xp->arg1; + xq->arg2 = xp->arg2; + return; + } + xp->arg2 = xq->arg1 + xp->arg0; + xq->arg0 += xp->arg0; + xq->arg1 = xp->arg2; + if (xq->arg0 > 0) + xq->arg1 -= xq->arg0; + goto top; + } else { + if (xp->arg1 - xq->arg0 >= xp->arg2) + return; + xq->arg2 = xp->arg1 - xq->arg0; + xp->arg0 += xq->arg0; + xp->arg1 = xq->arg2; + if (xp->arg0 < 0) + xp->arg1 += xp->arg0; + goto top; + } + } + if (xp->arg0 > xp->arg2 - xp->arg1) + xp->arg0 = xp->arg2 - xp->arg1; + if (tt.tt_scroll_down) { + if (tt.tt_scroll_top != xp->arg1 || + tt.tt_scroll_bot != xp->arg2 - 1) { + if (tt.tt_setscroll == 0) + goto down; + (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1); + } + tt.tt_scroll_down(xp->arg0); + } else { + down: + (*tt.tt_move)(xp->arg1, 0); + (*tt.tt_delline)(xp->arg0); + if (xp->arg2 < tt.tt_nrow) { + (*tt.tt_move)(xp->arg2 - xp->arg0, 0); + (*tt.tt_insline)(xp->arg0); + } + } + } else { + xp->arg0 = - xp->arg0; + if (xp->arg0 > xp->arg2 - xp->arg1) + xp->arg0 = xp->arg2 - xp->arg1; + if (tt.tt_scroll_up) { + if (tt.tt_scroll_top != xp->arg1 || + tt.tt_scroll_bot != xp->arg2 - 1) { + if (tt.tt_setscroll == 0) + goto up; + (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1); + } + tt.tt_scroll_up(xp->arg0); + } else { + up: + if (tt.tt_retain || xp->arg2 != tt.tt_nrow) { + (*tt.tt_move)(xp->arg2 - xp->arg0, 0); + (*tt.tt_delline)(xp->arg0); + } + (*tt.tt_move)(xp->arg1, 0); + (*tt.tt_insline)(xp->arg0); + } + } +} |