1 /* $NetBSD: ww.h,v 1.18 2009/04/14 08:50:06 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)ww.h 8.1 (Berkeley) 6/6/93
40 #include <sys/types.h>
55 #define NWW 30 /* maximum number of windows */
57 /* Macros to clear/set/test flags. */
58 #define SET(t, f) (t) |= (f)
59 #define CLR(t, f) (t) &= ~(f)
60 #define ISSET(t, f) ((t) & (f))
64 int nr; /* number of rows */
65 int nc; /* number of columns */
66 int t, b; /* top, bottom */
67 int l, r; /* left, right */
76 /* the window structure */
80 /* general flags and states */
81 int ww_state; /* state of window */
82 #define WWS_INITIAL 0 /* just opened */
83 #define WWS_HASPROC 1 /* has process on pty */
84 #define WWS_DEAD 3 /* child died */
85 #define ww_oflags ww_flags
86 #define WWO_REVERSE 0x0001 /* make it all reverse video */
87 #define WWO_GLASS 0x0002 /* make it all glass */
88 #define WWO_FRAME 0x0004 /* this is a frame window */
89 #define WWO_ALLFLAGS 0x0007
91 /* information for overlap */
92 struct ww *ww_forw; /* doubly linked list, for overlapping info */
94 unsigned char ww_index; /* the window index, for wwindex[] */
95 #define WWX_NOBODY NWW
96 int ww_order; /* the overlapping order */
98 /* sizes and positions */
99 struct ww_dim ww_w; /* window size and pos */
100 struct ww_dim ww_b; /* buffer size and pos */
101 struct ww_dim ww_i; /* the part inside the screen */
102 struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
105 char **ww_win; /* the window */
106 union ww_char **ww_buf; /* the buffer */
107 char **ww_fmap; /* map for frame and box windows */
108 short *ww_nvis; /* how many ww_buf chars are visible per row */
110 /* information for wwwrite() and company */
111 int ww_wstate; /* state for outputting characters */
112 char ww_modes; /* current display modes */
113 #define ww_wflags ww_flags
114 #define WWW_INSERT 0x0008 /* insert mode */
115 #define WWW_MAPNL 0x0010 /* map \n to \r\n */
116 #define WWW_NOUPDATE 0x0020 /* don't do updates in wwwrite() */
117 #define WWW_UNCTRL 0x0040 /* expand control characters */
118 #define WWW_NOINTR 0x0080 /* wwwrite() not interruptable */
119 #define WWW_HASCURSOR 0x0100 /* has fake cursor */
121 /* things for the window process and io */
123 #define WWT_PTY 0 /* pty */
124 #define WWT_SOCKET 1 /* socket pair */
125 #define WWT_INTERNAL 2
126 #define ww_pflags ww_flags
127 #define WWP_STOPPED 0x0200 /* output stopped */
128 int ww_pty; /* file descriptor of pty or socket pair */
129 int ww_socket; /* other end of socket pair */
130 int ww_pid; /* pid of process, if WWS_HASPROC true */
131 char ww_ttyname[11]; /* "/dev/ttyp?" */
132 char *ww_ob; /* output buffer */
133 char *ww_obe; /* end of ww_ob */
134 char *ww_obp; /* current read position in ww_ob */
135 char *ww_obq; /* current write position in ww_ob */
137 /* things for the user, they really don't belong here */
138 int ww_id; /* the user window id */
139 #define ww_uflags ww_flags
140 #define WWU_CENTER 0x0400 /* center the label */
141 #define WWU_HASFRAME 0x0800 /* frame it */
142 #define WWU_KEEPOPEN 0x1000 /* keep it open after the process dies */
143 #define WWU_ALLFLAGS 0x1c00
144 char *ww_label; /* the user supplied label */
145 struct ww_dim ww_alt; /* alternate position and size */
151 struct sgttyb ww_sgttyb;
152 struct tchars ww_tchars;
153 struct ltchars ww_ltchars;
157 struct termios ww_termios;
162 short c_w; /* as a word */
164 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
165 char C_c; /* the character part */
166 char C_m; /* the mode part */
168 #if BYTE_ORDER == BIG_ENDIAN
169 char C_m; /* the mode part */
170 char C_c; /* the character part */
177 /* for display update */
184 /* parts of ww_char */
185 #define WWC_CMASK 0x00ff
186 #define WWC_MMASK 0xff00
190 #define WWM_REV 0x01 /* reverse video */
191 #define WWM_BLK 0x02 /* blinking */
192 #define WWM_UL 0x04 /* underlined */
193 #define WWM_GRP 0x08 /* graphics */
194 #define WWM_DIM 0x10 /* half intensity */
195 #define WWM_USR 0x20 /* user specified mode */
196 #define WWM_GLS 0x40 /* window only, glass, i.e., transparent */
198 /* flags for ww_fmap */
203 #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
204 #define WWF_LABEL 0x40
209 #define WWE_SYS 1 /* system error */
210 #define WWE_NOMEM 2 /* out of memory */
211 #define WWE_TOOMANY 3 /* too many windows */
212 #define WWE_NOPTY 4 /* no more ptys */
213 #define WWE_SIZE 5 /* bad window size */
214 #define WWE_BADTERM 6 /* bad terminal type */
215 #define WWE_CANTDO 7 /* dumb terminal */
217 /* wwtouched[] bits, there used to be more than one */
218 #define WWU_TOUCHED 0x01 /* touched */
220 /* the window structures */
221 EXTERN struct ww wwhead;
222 EXTERN struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
223 EXTERN struct ww wwnobody;
226 EXTERN struct ww_tty wwoldtty; /* the old (saved) terminal settings */
227 EXTERN struct ww_tty wwnewtty; /* the new (current) terminal settings */
228 EXTERN struct ww_tty wwwintty; /* the terminal settings for windows */
229 EXTERN char *wwterm; /* the terminal name */
230 EXTERN char wwtermcap[1024]; /* place for the termcap */
232 /* generally useful variables */
233 EXTERN int wwnrow, wwncol; /* the screen size */
234 EXTERN char wwavailmodes; /* actually supported modes */
235 EXTERN char wwcursormodes; /* the modes for the fake cursor */
236 EXTERN char wwwrap; /* terminal has auto wrap around */
237 EXTERN int wwdtablesize; /* result of getdtablesize() call */
238 EXTERN unsigned char **wwsmap; /* the screen map */
239 EXTERN union ww_char **wwos; /* the old (current) screen */
240 EXTERN union ww_char **wwns; /* the new (desired) screen */
241 EXTERN union ww_char **wwcs; /* the checkpointed screen */
242 EXTERN char *wwtouched; /* wwns changed flags */
243 EXTERN struct ww_update *wwupd; /* for display update */
244 EXTERN int wwospeed; /* output baud rate, copied from wwoldtty */
245 EXTERN int wwbaud; /* wwospeed converted into actual number */
246 EXTERN int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
247 EXTERN int wwerrno; /* error number */
250 EXTERN int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
251 EXTERN int wwnwwr, wwnwwra, wwnwwrc;
252 EXTERN int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
253 EXTERN int wwnupdate, wwnupdline, wwnupdmiss;
254 EXTERN int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
255 EXTERN int wwnread, wwnreade, wwnreadz;
256 EXTERN int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec;
257 EXTERN int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
258 EXTERN int wwnselect, wwnselecte, wwnselectz;
261 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
262 #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
263 #define wwunbox(w) wwunframe(w)
264 #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
265 #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
266 #define wwupdate() wwupdate1(0, wwnrow);
268 /* things for handling input */
269 EXTERN struct ww *wwcurwin; /* window to copy input into */
270 EXTERN char *wwib; /* input (keyboard) buffer */
271 EXTERN char *wwibe; /* wwib + sizeof buffer */
272 EXTERN char *wwibp; /* current read position in buffer */
273 EXTERN char *wwibq; /* current write position in buffer */
274 #define wwmaskc(c) ((c) & 0x7f)
275 #define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1)
276 #define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1)
277 #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1)
279 /* things for short circuiting wwiomux() */
280 EXTERN char wwintr; /* interrupting */
281 EXTERN char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */
282 EXTERN jmp_buf wwjmpbuf; /* jmpbuf for above */
283 #define wwinterrupt() wwintr
284 #define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
286 #define wwclrintr() (wwintr = 0)
289 EXTERN int wwdocheckpoint;
291 /* the window virtual terminal */
292 #define WWT_TERM "window-v2"
293 #define WWT_TERMCAP "WW|window-v2|window program version 2:\
294 :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
295 :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
296 :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
297 #define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:"
298 #define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
299 #define WWT_UL "ue=\\ErD:us=\\EsD:"
300 #define WWT_GRP "ae=\\ErH:as=\\EsH:"
301 #define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
302 #define WWT_USR "XE=\\Er`:XS=\\Es`:"
303 #define WWT_ALDL "al=\\EL:dl=\\EM:"
304 #define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
305 #define WWT_IC "ic=\\EP:"
306 #define WWT_DC "dc=\\EN:"
307 EXTERN char wwwintermcap[1024]; /* terminal-specific but window-independent
308 part of the window termcap */
310 /* where to put the temporary terminfo directory */
311 EXTERN char wwterminfopath[1024];
314 struct ww *wwopen(int, int, int, int, int, int, int);
315 void wwadd(struct ww *, struct ww *);
316 void wwaddcap(const char *, char **);
317 void wwaddcap1(const char *, char **);
319 char **wwalloc(int, int, int, int, int);
321 void wwbox(struct ww *, int, int, int, int);
322 void wwcheckpoint(void);
324 void wwclose(struct ww *);
325 void wwclreol1(struct ww *, int, int, char);
326 void wwclreos(struct ww *, int, int);
327 void wwcopyscreen(union ww_char **s1, union ww_char **s2);
328 void wwcursor(struct ww *, int);
329 void wwdelchar(struct ww *, int, int);
330 void wwdelete(struct ww *);
331 void wwdelete1(struct ww *, int, int, int, int);
332 void wwdelline(struct ww *, int);
334 void wwdumpnvis(struct ww *);
336 void wwdumpsmap(void);
337 void wwdumpwin(struct ww *);
339 int wwenviron(struct ww *);
343 void wwframe(struct ww *, struct ww *);
344 void wwframec(struct ww *, int, int, char);
345 void wwfree(char **, int);
346 int wwgetpty(struct ww *);
347 int wwgettty(int, struct ww_tty *);
348 int wwgetttysize(int, int *, int *);
349 void wwgets(char *, int, struct ww *);
351 void wwinschar(struct ww *, int, int, char, char);
352 void wwinsline(struct ww *, int);
354 void wwlabel(struct ww *, struct ww *, int, char *, int);
355 void wwmove(struct ww *, int, int);
356 void wwprintf(struct ww *, const char *, ...) __printflike(2, 3);
357 void wwputc(char, struct ww *);
358 void wwputs(const char *, struct ww *);
360 void wwredrawwin1(struct ww *,int, int, int);
364 void wwscroll(struct ww *, int);
365 int wwscroll1(struct ww *, int, int, int, int);
366 void wwsetcursormodes(int);
367 int wwsettty(int, struct ww_tty *);
368 int wwsetttysize(int, int, int);
369 int wwsize(struct ww *, int, int);
370 int wwspawn(struct ww *, char *, char **);
375 void wwsuspend(void);
376 void wwunframe(struct ww *);
377 void wwupdate1(int, int);
378 int wwvisible(struct ww *);
379 void wwvprintf(struct ww *, const char *, va_list) __printflike(2, 0);
380 int wwwrite(struct ww *, const char *, int);
382 int wwterminfoinit(void);
383 int wwterminfoend(void);
388 #define MIN(x, y) ((x) > (y) ? (y) : (x))
389 #define MAX(x, y) ((x) > (y) ? (x) : (y))
391 #endif /* __WW_H__ */