Annotation of src/usr.bin/window/ww.h, Revision 1.3
1.3 ! niklas 1: /* $NetBSD: ww.h,v 1.8 1996/02/08 21:48:51 mycroft Exp $ */
1.1 deraadt 2:
3: /*
4: * Copyright (c) 1983, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Edward Wang at The University of California, Berkeley.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
38: * @(#)ww.h 8.1 (Berkeley) 6/6/93
39: */
40:
41: #ifdef OLD_TTY
42: #include <sgtty.h>
43: #else
44: #include <termios.h>
45: #endif
46: #include <setjmp.h>
47: #include <machine/endian.h>
48:
49: #define NWW 30 /* maximum number of windows */
50:
1.3 ! niklas 51: /* Macros to clear/set/test flags. */
! 52: #define SET(t, f) (t) |= (f)
! 53: #define CLR(t, f) (t) &= ~(f)
! 54: #define ISSET(t, f) ((t) & (f))
! 55:
1.1 deraadt 56: /* a rectangle */
57: struct ww_dim {
58: int nr; /* number of rows */
59: int nc; /* number of columns */
60: int t, b; /* top, bottom */
61: int l, r; /* left, right */
62: };
63:
64: /* a coordinate */
65: struct ww_pos {
66: int r; /* row */
67: int c; /* column */
68: };
69:
70: /* the window structure */
71: struct ww {
1.3 ! niklas 72: int ww_flags;
! 73:
1.1 deraadt 74: /* general flags and states */
1.3 ! niklas 75: int ww_state; /* state of window */
! 76: #define WWS_INITIAL 0 /* just opened */
! 77: #define WWS_HASPROC 1 /* has process on pty */
! 78: #define WWS_DEAD 3 /* child died */
! 79: #define ww_oflags ww_flags
! 80: #define WWO_REVERSE 0x0001 /* make it all reverse video */
! 81: #define WWO_GLASS 0x0002 /* make it all glass */
! 82: #define WWO_FRAME 0x0004 /* this is a frame window */
! 83: #define WWO_ALLFLAGS 0x0007
1.1 deraadt 84:
85: /* information for overlap */
86: struct ww *ww_forw; /* doubly linked list, for overlapping info */
87: struct ww *ww_back;
1.3 ! niklas 88: unsigned char ww_index; /* the window index, for wwindex[] */
! 89: #define WWX_NOBODY NWW
! 90: int ww_order; /* the overlapping order */
1.1 deraadt 91:
92: /* sizes and positions */
93: struct ww_dim ww_w; /* window size and pos */
94: struct ww_dim ww_b; /* buffer size and pos */
95: struct ww_dim ww_i; /* the part inside the screen */
96: struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
97:
98: /* arrays */
99: char **ww_win; /* the window */
100: union ww_char **ww_buf; /* the buffer */
101: char **ww_fmap; /* map for frame and box windows */
102: short *ww_nvis; /* how many ww_buf chars are visible per row */
103:
104: /* information for wwwrite() and company */
1.3 ! niklas 105: int ww_wstate; /* state for outputting characters */
1.1 deraadt 106: char ww_modes; /* current display modes */
1.3 ! niklas 107: #define ww_wflags ww_flags
! 108: #define WWW_INSERT 0x0008 /* insert mode */
! 109: #define WWW_MAPNL 0x0010 /* map \n to \r\n */
! 110: #define WWW_NOUPDATE 0x0020 /* don't do updates in wwwrite() */
! 111: #define WWW_UNCTRL 0x0040 /* expand control characters */
! 112: #define WWW_NOINTR 0x0080 /* wwwrite() not interruptable */
! 113: #define WWW_HASCURSOR 0x0100 /* has fake cursor */
1.1 deraadt 114:
115: /* things for the window process and io */
1.3 ! niklas 116: int ww_type;
! 117: #define WWT_PTY 0 /* pty */
! 118: #define WWT_SOCKET 1 /* socket pair */
! 119: #define WWT_INTERNAL 2
! 120: #define ww_pflags ww_flags
! 121: #define WWP_STOPPED 0x0200 /* output stopped */
1.1 deraadt 122: int ww_pty; /* file descriptor of pty or socket pair */
123: int ww_socket; /* other end of socket pair */
124: int ww_pid; /* pid of process, if WWS_HASPROC true */
125: char ww_ttyname[11]; /* "/dev/ttyp?" */
126: char *ww_ob; /* output buffer */
127: char *ww_obe; /* end of ww_ob */
128: char *ww_obp; /* current read position in ww_ob */
129: char *ww_obq; /* current write position in ww_ob */
130:
131: /* things for the user, they really don't belong here */
1.3 ! niklas 132: int ww_id; /* the user window id */
! 133: #define ww_uflags ww_flags
! 134: #define WWU_CENTER 0x0400 /* center the label */
! 135: #define WWU_HASFRAME 0x0800 /* frame it */
! 136: #define WWU_KEEPOPEN 0x1000 /* keep it open after the process dies */
! 137: #define WWU_ALLFLAGS 0x1c00
1.1 deraadt 138: char *ww_label; /* the user supplied label */
139: struct ww_dim ww_alt; /* alternate position and size */
140: };
141:
142: /* state of a tty */
143: struct ww_tty {
144: #ifdef OLD_TTY
145: struct sgttyb ww_sgttyb;
146: struct tchars ww_tchars;
147: struct ltchars ww_ltchars;
148: int ww_lmode;
149: int ww_ldisc;
150: #else
151: struct termios ww_termios;
152: #endif
153: };
154:
155: union ww_char {
156: short c_w; /* as a word */
157: struct {
158: #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
159: char C_c; /* the character part */
160: char C_m; /* the mode part */
161: #endif
162: #if BYTE_ORDER == BIG_ENDIAN
163: char C_m; /* the mode part */
164: char C_c; /* the character part */
165: #endif
166: } c_un;
167: };
168: #define c_c c_un.C_c
169: #define c_m c_un.C_m
170:
171: /* for display update */
172: struct ww_update {
173: int best_gain;
174: int best_col;
175: int gain;
176: };
177:
178: /* parts of ww_char */
179: #define WWC_CMASK 0x00ff
180: #define WWC_MMASK 0xff00
181: #define WWC_MSHIFT 8
182:
183: /* c_m bits */
184: #define WWM_REV 0x01 /* reverse video */
185: #define WWM_BLK 0x02 /* blinking */
186: #define WWM_UL 0x04 /* underlined */
187: #define WWM_GRP 0x08 /* graphics */
188: #define WWM_DIM 0x10 /* half intensity */
189: #define WWM_USR 0x20 /* user specified mode */
190: #define WWM_GLS 0x40 /* window only, glass, i.e., transparent */
191:
192: /* flags for ww_fmap */
193: #define WWF_U 0x01
194: #define WWF_R 0x02
195: #define WWF_D 0x04
196: #define WWF_L 0x08
197: #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
198: #define WWF_LABEL 0x40
199: #define WWF_TOP 0x80
1.2 deraadt 200:
1.1 deraadt 201: /* error codes */
202: #define WWE_NOERR 0
203: #define WWE_SYS 1 /* system error */
204: #define WWE_NOMEM 2 /* out of memory */
205: #define WWE_TOOMANY 3 /* too many windows */
206: #define WWE_NOPTY 4 /* no more ptys */
207: #define WWE_SIZE 5 /* bad window size */
208: #define WWE_BADTERM 6 /* bad terminal type */
209: #define WWE_CANTDO 7 /* dumb terminal */
210:
211: /* wwtouched[] bits, there used to be more than one */
212: #define WWU_TOUCHED 0x01 /* touched */
213:
214: /* the window structures */
215: struct ww wwhead;
216: struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
217: struct ww wwnobody;
218:
219: /* tty things */
220: struct ww_tty wwoldtty; /* the old (saved) terminal settings */
221: struct ww_tty wwnewtty; /* the new (current) terminal settings */
222: struct ww_tty wwwintty; /* the terminal settings for windows */
223: char *wwterm; /* the terminal name */
224: char wwtermcap[1024]; /* place for the termcap */
225:
226: /* generally useful variables */
227: int wwnrow, wwncol; /* the screen size */
228: char wwavailmodes; /* actually supported modes */
229: char wwcursormodes; /* the modes for the fake cursor */
230: char wwwrap; /* terminal has auto wrap around */
231: int wwdtablesize; /* result of getdtablesize() call */
1.3 ! niklas 232: unsigned char **wwsmap; /* the screen map */
1.1 deraadt 233: union ww_char **wwos; /* the old (current) screen */
234: union ww_char **wwns; /* the new (desired) screen */
235: union ww_char **wwcs; /* the checkpointed screen */
236: char *wwtouched; /* wwns changed flags */
237: struct ww_update *wwupd; /* for display update */
238: int wwospeed; /* output baud rate, copied from wwoldtty */
239: int wwbaud; /* wwospeed converted into actual number */
240: int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
241: int wwerrno; /* error number */
242:
243: /* statistics */
244: int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
245: int wwnwwr, wwnwwra, wwnwwrc;
246: int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
247: int wwnupdate, wwnupdline, wwnupdmiss;
248: int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
249: int wwnread, wwnreade, wwnreadz;
250: int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec;
251: int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
252: int wwnselect, wwnselecte, wwnselectz;
253:
254: /* quicky macros */
255: #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
256: #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
257: #define wwunbox(w) wwunframe(w)
258: #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
259: #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
260: #define wwupdate() wwupdate1(0, wwnrow);
261:
262: /* things for handling input */
263: void wwrint(); /* interrupt handler */
264: struct ww *wwcurwin; /* window to copy input into */
265: char *wwib; /* input (keyboard) buffer */
266: char *wwibe; /* wwib + sizeof buffer */
267: char *wwibp; /* current read position in buffer */
268: char *wwibq; /* current write position in buffer */
269: #define wwmaskc(c) ((c) & 0x7f)
270: #define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1)
271: #define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1)
272: #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1)
273:
274: /* things for short circuiting wwiomux() */
275: char wwintr; /* interrupting */
276: char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */
277: jmp_buf wwjmpbuf; /* jmpbuf for above */
278: #define wwinterrupt() wwintr
279: #define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
280: while (0)
281: #define wwclrintr() (wwintr = 0)
282:
283: /* checkpointing */
284: int wwdocheckpoint;
285:
286: /* the window virtual terminal */
287: #define WWT_TERM "window-v2"
288: #define WWT_TERMCAP "WW|window-v2|window program version 2:\
289: :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
290: :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
291: :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
292: #define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:"
293: #define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
294: #define WWT_UL "ue=\\ErD:us=\\EsD:"
295: #define WWT_GRP "ae=\\ErH:as=\\EsH:"
296: #define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
297: #define WWT_USR "XE=\\Er`:XS=\\Es`:"
298: #define WWT_ALDL "al=\\EL:dl=\\EM:"
299: #define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
300: #define WWT_IC "ic=\\EP:"
301: #define WWT_DC "dc=\\EN:"
302: char wwwintermcap[1024]; /* terminal-specific but window-independent
303: part of the window termcap */
304: #ifdef TERMINFO
305: /* where to put the temporary terminfo directory */
306: char wwterminfopath[1024];
307: #endif
308:
309: /* our functions */
310: struct ww *wwopen();
311: void wwchild();
312: void wwalarm();
313: void wwquit();
314: char **wwalloc();
315: char *wwerror();
316:
317: /* c library functions */
318: char *malloc();
319: char *calloc();
320: char *getenv();
321: char *tgetstr();
322: char *rindex();
323: char *strcpy();
324: char *strcat();
325:
326: #undef MIN
327: #undef MAX
328: #define MIN(x, y) ((x) > (y) ? (y) : (x))
329: #define MAX(x, y) ((x) > (y) ? (x) : (y))