|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: *
17: * @(#)ww.h 3.49 (Berkeley) 6/29/88
18: */
19:
20: #include <sgtty.h>
21: #include <setjmp.h>
22:
23: #define NWW 30 /* maximum number of windows */
24:
25: /* a rectangle */
26: struct ww_dim {
27: int nr; /* number of rows */
28: int nc; /* number of columns */
29: int t, b; /* top, bottom */
30: int l, r; /* left, right */
31: };
32:
33: /* a coordinate */
34: struct ww_pos {
35: int r; /* row */
36: int c; /* column */
37: };
38:
39: /* the window structure */
40: struct ww {
41: /* general flags and states */
42: char ww_state; /* state of window */
43: char ww_oflags; /* wwopen flags */
44:
45: /* information for overlap */
46: struct ww *ww_forw; /* doubly linked list, for overlapping info */
47: struct ww *ww_back;
48: char ww_index; /* the window index, for wwindex[] */
49: char ww_order; /* the overlapping order */
50:
51: /* sizes and positions */
52: struct ww_dim ww_w; /* window size and pos */
53: struct ww_dim ww_b; /* buffer size and pos */
54: struct ww_dim ww_i; /* the part inside the screen */
55: struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
56:
57: /* arrays */
58: char **ww_win; /* the window */
59: union ww_char **ww_buf; /* the buffer */
60: char **ww_fmap; /* map for frame and box windows */
61: short *ww_nvis; /* how many ww_buf chars are visible per row */
62:
63: /* information for wwwrite() and company */
64: char ww_wstate; /* state for outputting characters */
65: char ww_modes; /* current display modes */
66: char ww_insert; /* insert mode */
67: char ww_mapnl; /* map \n to \r\n */
68: char ww_noupdate; /* don't do updates in wwwrite() */
69: char ww_unctrl; /* expand control characters */
70: char ww_nointr; /* wwwrite() not interruptable */
71: char ww_hascursor; /* has fake cursor */
72:
73: /* things for the window process and io */
74: char ww_ispty; /* ww_pty is really a pty, not socket pair */
75: char ww_stopped; /* output stopped */
76: int ww_pty; /* file descriptor of pty or socket pair */
77: int ww_socket; /* other end of socket pair */
78: int ww_pid; /* pid of process, if WWS_HASPROC true */
79: char ww_ttyname[11]; /* "/dev/ttyp?" */
80: char *ww_ob; /* output buffer */
81: char *ww_obe; /* end of ww_ob */
82: char *ww_obp; /* current read position in ww_ob */
83: char *ww_obq; /* current write position in ww_ob */
84:
85: /* things for the user, they really don't belong here */
86: char ww_id; /* the user window id */
87: char ww_center; /* center the label */
88: char ww_hasframe; /* frame it */
89: char ww_keepopen; /* keep it open after the process dies */
90: char *ww_label; /* the user supplied label */
91: struct ww_dim ww_alt; /* alternate position and size */
92: };
93:
94: /* state of a tty */
95: struct ww_tty {
96: struct sgttyb ww_sgttyb;
97: struct tchars ww_tchars;
98: struct ltchars ww_ltchars;
99: int ww_lmode;
100: int ww_ldisc;
101: int ww_fflags;
102: };
103:
104: union ww_char {
105: short c_w; /* as a word */
106: struct {
107: #if defined(vax) || defined(MIPSEL)
108: char C_c; /* the character part */
109: char C_m; /* the mode part */
110: #else
111: char C_m; /* the mode part */
112: char C_c; /* the character part */
113: #endif
114: } c_un;
115: };
116: #define c_c c_un.C_c
117: #define c_m c_un.C_m
118:
119: /* parts of ww_char */
120: #define WWC_CMASK 0x00ff
121: #define WWC_MMASK 0xff00
122: #define WWC_MSHIFT 8
123:
124: /* c_m bits */
125: #define WWM_REV 0x01 /* reverse video */
126: #define WWM_BLK 0x02 /* blinking */
127: #define WWM_UL 0x04 /* underlined */
128: #define WWM_GRP 0x08 /* graphics */
129: #define WWM_DIM 0x10 /* half intensity */
130: #define WWM_USR 0x20 /* user specified mode */
131: #define WWM_GLS 0x40 /* window only, glass, i.e., transparent */
132:
133: /* ww_state values */
134: #define WWS_INITIAL 0 /* just opened */
135: #define WWS_HASPROC 1 /* has process on pty */
136: #define WWS_DEAD 3 /* child died */
137:
138: /* flags for ww_fmap */
139: #define WWF_U 0x01
140: #define WWF_R 0x02
141: #define WWF_D 0x04
142: #define WWF_L 0x08
143: #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
144: #define WWF_LABEL 0x40
145: #define WWF_TOP 0x80
146:
147: /* flags to wwopen() */
148: #define WWO_PTY 0x01 /* want pty */
149: #define WWO_SOCKET 0x02 /* want socket pair */
150: #define WWO_REVERSE 0x04 /* make it all reverse video */
151: #define WWO_GLASS 0x08 /* make it all glass */
152: #define WWO_FRAME 0x10 /* this is a frame window */
153:
154: /* special ww_index value */
155: #define WWX_NOBODY NWW
156:
157: /* error codes */
158: #define WWE_NOERR 0
159: #define WWE_SYS 1 /* system error */
160: #define WWE_NOMEM 2 /* out of memory */
161: #define WWE_TOOMANY 3 /* too many windows */
162: #define WWE_NOPTY 4 /* no more ptys */
163: #define WWE_SIZE 5 /* bad window size */
164: #define WWE_BADTERM 6 /* bad terminal type */
165: #define WWE_CANTDO 7 /* dumb terminal */
166:
167: /* wwtouched[] bits */
168: #define WWU_TOUCHED 0x01 /* touched */
169: #define WWU_MAJOR 0x02 /* major change */
170:
171: /* the window structures */
172: struct ww wwhead;
173: struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
174: struct ww wwnobody;
175:
176: /* tty things */
177: struct ww_tty wwoldtty; /* the old (saved) terminal settings */
178: struct ww_tty wwnewtty; /* the new (current) terminal settings */
179: struct ww_tty wwwintty; /* the terminal settings for windows */
180: char *wwterm; /* the terminal name */
181: char wwtermcap[1024]; /* place for the termcap */
182:
183: /* generally useful variables */
184: int wwnrow, wwncol; /* the screen size */
185: char wwavailmodes; /* actually supported modes */
186: char wwcursormodes; /* the modes for the fake cursor */
187: char wwwrap; /* terminal has auto wrap around */
188: int wwdtablesize; /* result of getdtablesize() call */
189: char **wwsmap; /* the screen map */
190: union ww_char **wwos; /* the old (current) screen */
191: union ww_char **wwns; /* the new (desired) screen */
192: char *wwtouched; /* wwns changed flags */
193: extern int wwbaudmap[]; /* maps stty() baud rate code into number */
194: int wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
195: int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
196: int wwerrno; /* error number */
197:
198: /* statistics */
199: int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
200: int wwnwwr, wwnwwra, wwnwwrc;
201: int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
202: int wwnread, wwnreade, wwnreadz, wwnreadc;
203: int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
204: int wwnselect, wwnselecte, wwnselectz;
205:
206: /* quicky macros */
207: #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
208: #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
209: #define wwunbox(w) wwunframe(w)
210: #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
211: #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
212: #define wwupdate() wwupdate1(0, wwnrow);
213:
214: /* things for handling input */
215: int wwrint(); /* interrupt handler */
216: struct ww *wwcurwin; /* window to copy input into */
217: char *wwib; /* input (keyboard) buffer */
218: char *wwibe; /* wwib + sizeof buffer */
219: char *wwibp; /* current read position in buffer */
220: char *wwibq; /* current write position in buffer */
221: #define wwgetc() (wwibp < wwibq ? *wwibp++ & 0x7f : -1)
222: #define wwpeekc() (wwibp < wwibq ? *wwibp & 0x7f : -1)
223: #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1)
224:
225: /* things for short circuiting wwiomux() */
226: char wwintr; /* interrupting */
227: char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */
228: jmp_buf wwjmpbuf; /* jmpbuf for above */
229: #define wwinterrupt() wwintr
230: #define wwsetintr() (wwintr = 1, wwsetjmp ? longjmp(wwjmpbuf, 1) : 0)
231: #define wwclrintr() (wwintr = 0)
232:
233: /* the window virtual terminal */
234: #define WWT_TERM "window-v2"
235: #define WWT_TERMCAP "WW|window-v2|window program version 2:\
236: :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
237: :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
238: :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
239: #define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:"
240: #define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
241: #define WWT_UL "ue=\\ErD:us=\\EsD:"
242: #define WWT_GRP "ae=\\ErH:as=\\EsH:"
243: #define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
244: #define WWT_USR "XE=\\Er`:XS=\\Es`:"
245: #define WWT_ALDL "al=\\EL:dl=\\EM:"
246: #define WWT_IMEI "im=\\E@:ei=\\EO:mi:"
247: #define WWT_DC "dc=\\EN:"
248: char wwwintermcap[1024]; /* terminal-specific but window-independent
249: part of the window termcap */
250:
251: /* our functions */
252: struct ww *wwopen();
253: int wwchild();
254: int wwsuspend();
255: char **wwalloc();
256: char *wwerror();
257:
258: /* c library functions */
259: char *malloc();
260: char *calloc();
261: char *getenv();
262: char *tgetstr();
263: char *rindex();
264: char *strcpy();
265: char *strcat();
266:
267: #undef MIN
268: #undef MAX
269: #define MIN(x, y) ((x) > (y) ? (y) : (x))
270: #define MAX(x, y) ((x) > (y) ? (x) : (y))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.