]> git.saurik.com Git - apple/shell_cmds.git/blob - window/ww.h
shell_cmds-17.1.tar.gz
[apple/shell_cmds.git] / window / ww.h
1 /* $NetBSD: ww.h,v 1.12 1998/07/26 15:28:20 mycroft Exp $ */
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 #ifndef __WW_H__
42 #define __WW_H__
43
44 #include <sys/types.h>
45 #ifdef OLD_TTY
46 #include <sgtty.h>
47 #else
48 #include <termios.h>
49 #endif
50 #include <setjmp.h>
51
52 #if __STDC__
53 #include <stdarg.h>
54 #else
55 #include <varargs.h>
56 #endif
57 #include <stdio.h>
58
59 #ifndef EXTERN
60 #define EXTERN extern
61 #endif
62
63 #define NWW 30 /* maximum number of windows */
64
65 /* Macros to clear/set/test flags. */
66 #define SET(t, f) (t) |= (f)
67 #define CLR(t, f) (t) &= ~(f)
68 #define ISSET(t, f) ((t) & (f))
69
70 /* a rectangle */
71 struct ww_dim {
72 int nr; /* number of rows */
73 int nc; /* number of columns */
74 int t, b; /* top, bottom */
75 int l, r; /* left, right */
76 };
77
78 /* a coordinate */
79 struct ww_pos {
80 int r; /* row */
81 int c; /* column */
82 };
83
84 /* the window structure */
85 struct ww {
86 int ww_flags;
87
88 /* general flags and states */
89 int ww_state; /* state of window */
90 #define WWS_INITIAL 0 /* just opened */
91 #define WWS_HASPROC 1 /* has process on pty */
92 #define WWS_DEAD 3 /* child died */
93 #define ww_oflags ww_flags
94 #define WWO_REVERSE 0x0001 /* make it all reverse video */
95 #define WWO_GLASS 0x0002 /* make it all glass */
96 #define WWO_FRAME 0x0004 /* this is a frame window */
97 #define WWO_ALLFLAGS 0x0007
98
99 /* information for overlap */
100 struct ww *ww_forw; /* doubly linked list, for overlapping info */
101 struct ww *ww_back;
102 unsigned char ww_index; /* the window index, for wwindex[] */
103 #define WWX_NOBODY NWW
104 int ww_order; /* the overlapping order */
105
106 /* sizes and positions */
107 struct ww_dim ww_w; /* window size and pos */
108 struct ww_dim ww_b; /* buffer size and pos */
109 struct ww_dim ww_i; /* the part inside the screen */
110 struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
111
112 /* arrays */
113 char **ww_win; /* the window */
114 union ww_char **ww_buf; /* the buffer */
115 char **ww_fmap; /* map for frame and box windows */
116 short *ww_nvis; /* how many ww_buf chars are visible per row */
117
118 /* information for wwwrite() and company */
119 int ww_wstate; /* state for outputting characters */
120 char ww_modes; /* current display modes */
121 #define ww_wflags ww_flags
122 #define WWW_INSERT 0x0008 /* insert mode */
123 #define WWW_MAPNL 0x0010 /* map \n to \r\n */
124 #define WWW_NOUPDATE 0x0020 /* don't do updates in wwwrite() */
125 #define WWW_UNCTRL 0x0040 /* expand control characters */
126 #define WWW_NOINTR 0x0080 /* wwwrite() not interruptable */
127 #define WWW_HASCURSOR 0x0100 /* has fake cursor */
128
129 /* things for the window process and io */
130 int ww_type;
131 #define WWT_PTY 0 /* pty */
132 #define WWT_SOCKET 1 /* socket pair */
133 #define WWT_INTERNAL 2
134 #define ww_pflags ww_flags
135 #define WWP_STOPPED 0x0200 /* output stopped */
136 int ww_pty; /* file descriptor of pty or socket pair */
137 int ww_socket; /* other end of socket pair */
138 int ww_pid; /* pid of process, if WWS_HASPROC true */
139 char ww_ttyname[11]; /* "/dev/ttyp?" */
140 char *ww_ob; /* output buffer */
141 char *ww_obe; /* end of ww_ob */
142 char *ww_obp; /* current read position in ww_ob */
143 char *ww_obq; /* current write position in ww_ob */
144
145 /* things for the user, they really don't belong here */
146 int ww_id; /* the user window id */
147 #define ww_uflags ww_flags
148 #define WWU_CENTER 0x0400 /* center the label */
149 #define WWU_HASFRAME 0x0800 /* frame it */
150 #define WWU_KEEPOPEN 0x1000 /* keep it open after the process dies */
151 #define WWU_ALLFLAGS 0x1c00
152 char *ww_label; /* the user supplied label */
153 struct ww_dim ww_alt; /* alternate position and size */
154 };
155
156 /* state of a tty */
157 struct ww_tty {
158 #ifdef OLD_TTY
159 struct sgttyb ww_sgttyb;
160 struct tchars ww_tchars;
161 struct ltchars ww_ltchars;
162 int ww_lmode;
163 int ww_ldisc;
164 #else
165 struct termios ww_termios;
166 #endif
167 };
168
169 union ww_char {
170 short c_w; /* as a word */
171 struct {
172 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
173 char C_c; /* the character part */
174 char C_m; /* the mode part */
175 #endif
176 #if BYTE_ORDER == BIG_ENDIAN
177 char C_m; /* the mode part */
178 char C_c; /* the character part */
179 #endif
180 } c_un;
181 };
182 #define c_c c_un.C_c
183 #define c_m c_un.C_m
184
185 /* for display update */
186 struct ww_update {
187 int best_gain;
188 int best_col;
189 int gain;
190 };
191
192 /* parts of ww_char */
193 #define WWC_CMASK 0x00ff
194 #define WWC_MMASK 0xff00
195 #define WWC_MSHIFT 8
196
197 /* c_m bits */
198 #define WWM_REV 0x01 /* reverse video */
199 #define WWM_BLK 0x02 /* blinking */
200 #define WWM_UL 0x04 /* underlined */
201 #define WWM_GRP 0x08 /* graphics */
202 #define WWM_DIM 0x10 /* half intensity */
203 #define WWM_USR 0x20 /* user specified mode */
204 #define WWM_GLS 0x40 /* window only, glass, i.e., transparent */
205
206 /* flags for ww_fmap */
207 #define WWF_U 0x01
208 #define WWF_R 0x02
209 #define WWF_D 0x04
210 #define WWF_L 0x08
211 #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
212 #define WWF_LABEL 0x40
213 #define WWF_TOP 0x80
214
215 /* error codes */
216 #define WWE_NOERR 0
217 #define WWE_SYS 1 /* system error */
218 #define WWE_NOMEM 2 /* out of memory */
219 #define WWE_TOOMANY 3 /* too many windows */
220 #define WWE_NOPTY 4 /* no more ptys */
221 #define WWE_SIZE 5 /* bad window size */
222 #define WWE_BADTERM 6 /* bad terminal type */
223 #define WWE_CANTDO 7 /* dumb terminal */
224
225 /* wwtouched[] bits, there used to be more than one */
226 #define WWU_TOUCHED 0x01 /* touched */
227
228 /* the window structures */
229 EXTERN struct ww wwhead;
230 EXTERN struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
231 EXTERN struct ww wwnobody;
232
233 /* tty things */
234 EXTERN struct ww_tty wwoldtty; /* the old (saved) terminal settings */
235 EXTERN struct ww_tty wwnewtty; /* the new (current) terminal settings */
236 EXTERN struct ww_tty wwwintty; /* the terminal settings for windows */
237 EXTERN char *wwterm; /* the terminal name */
238 EXTERN char wwtermcap[1024]; /* place for the termcap */
239
240 /* generally useful variables */
241 EXTERN int wwnrow, wwncol; /* the screen size */
242 EXTERN char wwavailmodes; /* actually supported modes */
243 EXTERN char wwcursormodes; /* the modes for the fake cursor */
244 EXTERN char wwwrap; /* terminal has auto wrap around */
245 EXTERN int wwdtablesize; /* result of getdtablesize() call */
246 EXTERN unsigned char **wwsmap; /* the screen map */
247 EXTERN union ww_char **wwos; /* the old (current) screen */
248 EXTERN union ww_char **wwns; /* the new (desired) screen */
249 EXTERN union ww_char **wwcs; /* the checkpointed screen */
250 EXTERN char *wwtouched; /* wwns changed flags */
251 EXTERN struct ww_update *wwupd; /* for display update */
252 EXTERN int wwospeed; /* output baud rate, copied from wwoldtty */
253 EXTERN int wwbaud; /* wwospeed converted into actual number */
254 EXTERN int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
255 EXTERN int wwerrno; /* error number */
256
257 /* statistics */
258 EXTERN int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
259 EXTERN int wwnwwr, wwnwwra, wwnwwrc;
260 EXTERN int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
261 EXTERN int wwnupdate, wwnupdline, wwnupdmiss;
262 EXTERN int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
263 EXTERN int wwnread, wwnreade, wwnreadz;
264 EXTERN int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec;
265 EXTERN int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
266 EXTERN int wwnselect, wwnselecte, wwnselectz;
267
268 /* quicky macros */
269 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
270 #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
271 #define wwunbox(w) wwunframe(w)
272 #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
273 #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
274 #define wwupdate() wwupdate1(0, wwnrow);
275
276 /* things for handling input */
277 EXTERN struct ww *wwcurwin; /* window to copy input into */
278 EXTERN char *wwib; /* input (keyboard) buffer */
279 EXTERN char *wwibe; /* wwib + sizeof buffer */
280 EXTERN char *wwibp; /* current read position in buffer */
281 EXTERN char *wwibq; /* current write position in buffer */
282 #define wwmaskc(c) ((c) & 0x7f)
283 #define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1)
284 #define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1)
285 #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1)
286
287 /* things for short circuiting wwiomux() */
288 EXTERN char wwintr; /* interrupting */
289 EXTERN char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */
290 EXTERN jmp_buf wwjmpbuf; /* jmpbuf for above */
291 #define wwinterrupt() wwintr
292 #define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
293 while (0)
294 #define wwclrintr() (wwintr = 0)
295
296 /* checkpointing */
297 EXTERN int wwdocheckpoint;
298
299 /* the window virtual terminal */
300 #define WWT_TERM "window-v2"
301 #define WWT_TERMCAP "WW|window-v2|window program version 2:\
302 :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
303 :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
304 :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
305 #define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:"
306 #define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
307 #define WWT_UL "ue=\\ErD:us=\\EsD:"
308 #define WWT_GRP "ae=\\ErH:as=\\EsH:"
309 #define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
310 #define WWT_USR "XE=\\Er`:XS=\\Es`:"
311 #define WWT_ALDL "al=\\EL:dl=\\EM:"
312 #define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
313 #define WWT_IC "ic=\\EP:"
314 #define WWT_DC "dc=\\EN:"
315 EXTERN char wwwintermcap[1024]; /* terminal-specific but window-independent
316 part of the window termcap */
317 #ifdef TERMINFO
318 /* where to put the temporary terminfo directory */
319 EXTERN char wwterminfopath[1024];
320 #endif
321
322 struct ww *wwopen __P((int, int, int, int, int, int, int));
323 void wwadd __P((struct ww *, struct ww *));
324 void wwaddcap __P((char *, char **));
325 void wwaddcap1 __P((char *, char **));
326 void wwalarm __P((int));
327 char **wwalloc __P((int, int, int, int, int));
328 void wwbell __P((void));
329 void wwbox __P((struct ww *, int, int, int, int));
330 void wwcheckpoint __P((void));
331 void wwchild __P((int));
332 void wwclose __P((struct ww *));
333 void wwclreol1 __P((struct ww *, int, int, char));
334 void wwclreos __P((struct ww *, int, int));
335 void wwcopyscreen __P((union ww_char **s1, union ww_char **s2));
336 void wwcursor __P((struct ww *, int));
337 void wwdelchar __P((struct ww *, int, int));
338 void wwdelete __P((struct ww *));
339 void wwdelete1 __P((struct ww *, int, int, int, int));
340 void wwdelline __P((struct ww *, int));
341 void wwdumpns __P((void));
342 void wwdumpnvis __P((struct ww *));
343 void wwdumpos __P((void));
344 void wwdumpsmap __P((void));
345 void wwdumpwin __P((struct ww *));
346 void wwend __P((int));
347 int wwenviron __P((struct ww *));
348 const char *
349 wwerror __P((void));
350 void wwflush __P((void));
351 void wwframe __P((struct ww *, struct ww *));
352 void wwframec __P((struct ww *, int, int, char));
353 void wwfree __P((char **, int));
354 int wwgetpty __P((struct ww *));
355 int wwgettty __P((int, struct ww_tty *));
356 int wwgetttysize __P((int, int *, int *));
357 void wwgets __P((char *, int, struct ww *));
358 int wwinit __P((void));
359 void wwinschar __P((struct ww *, int, int, char, char));
360 void wwinsline __P((struct ww *, int));
361 void wwiomux __P((void));
362 void wwlabel __P((struct ww *, struct ww *, int, char *, int));
363 void wwmove __P((struct ww *, int, int));
364 void wwprintf __P((struct ww *, const char *, ...));
365 void wwputc __P((char, struct ww *));
366 void wwputs __P((char *, struct ww *));
367 void wwredraw __P((void));
368 void wwredrawwin1 __P((struct ww *,int, int, int));
369 void wwquit __P((int));
370 void wwreset __P((void));
371 void wwrint __P((void));
372 void wwscroll __P((struct ww *, int));
373 int wwscroll1 __P((struct ww *, int, int, int, int));
374 void wwsetcursormodes __P((int));
375 int wwsettty __P((int, struct ww_tty *));
376 int wwsetttysize __P((int, int, int));
377 int wwsize __P((struct ww *, int, int));
378 int wwspawn __P((struct ww *, char *, char **));
379 void wwstart __P((void));
380 void wwstart1 __P((void));
381 int wwstarttty __P((int));
382 int wwstoptty __P((int));
383 void wwsuspend __P((void));
384 void wwunframe __P((struct ww *));
385 void wwupdate1 __P((int, int));
386 int wwvisible __P((struct ww *));
387 void wwvprintf __P((struct ww *, const char *, va_list));
388 int wwwrite __P((struct ww *, char *, int));
389 #ifdef TERMINFO
390 int wwterminfoinit __P((void));
391 int wwterminfoend __P((void));
392 #endif
393
394 #undef MIN
395 #undef MAX
396 #define MIN(x, y) ((x) > (y) ? (y) : (x))
397 #define MAX(x, y) ((x) > (y) ? (x) : (y))
398
399 #endif __WW_H__