added error messages for zero length files.
[unix-history] / usr / src / usr.bin / window / ww.h
CommitLineData
bb05dfb5 1/*
86697c44 2 * @(#)ww.h 3.15 83/09/15
bb05dfb5 3 */
0edb449f 4
4711df8b 5#include <stdio.h>
0edb449f 6#include <sgtty.h>
bb05dfb5
EW
7
8#define NWW 30
0edb449f 9
c417b691 10struct ww_dim {
bb05dfb5
EW
11 int nr; /* number of rows */
12 int nc; /* number of columns */
13 int t, b; /* top, bottom */
14 int l, r; /* left, right */
15};
16
17struct ww_pos {
18 int r; /* row */
19 int c; /* column */
c417b691
EW
20};
21
0edb449f 22struct ww {
bb05dfb5
EW
23 struct ww *ww_forw; /* doubly linked list, for overlapping info */
24 struct ww *ww_back;
2b44d852 25 char ww_state; /* state of window creation */
2b44d852 26 char ww_wstate; /* state for printing charcters */
7d77e730
EW
27 char ww_modes; /* current printing modes */
28 char ww_insert :1; /* insert mode, for printing */
29 char ww_mapnl :1; /* map \n to \r\n */
30 char ww_haspty :1; /* has pty */
73218728 31 char ww_hascursor :1; /* has fake cursor */
c04e1ce2 32 char ww_hasframe :1; /* frame it */
bb05dfb5
EW
33 char ww_index; /* the index, for wwindex[] */
34 char ww_order; /* the overlapping order */
f2a77fe1
EW
35
36 /* sizes and positions */
37 struct ww_dim ww_w; /* window size and pos */
38 struct ww_dim ww_b; /* buffer size and pos */
19f9784c 39 struct ww_dim ww_i; /* the part inside the screen */
bb05dfb5 40 struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
f2a77fe1
EW
41
42 /* arrays */
bb05dfb5
EW
43 char **ww_win; /* the window */
44 union ww_char **ww_buf; /* the buffer */
45 char **ww_cov; /* the covered-by array */
2357b64e 46 char **ww_fmap; /* map for frame and box windows */
bb05dfb5 47 short *ww_nvis; /* how many ww_buf chars are visible per row */
f2a77fe1 48
bb05dfb5
EW
49 int ww_pty; /* file descriptor of pty */
50 int ww_tty; /* . . . tty */
51 int ww_pid; /* pid of process, if WWS_HASPROC true */
0896e17e 52 char ww_ttyname[11]; /* "/dev/ttyp?" */
bb05dfb5 53 /* below are things for the user */
bb05dfb5
EW
54 char ww_center :1; /* center the label */
55 int ww_id; /* the user id */
56 char *ww_label; /* the user supplied label */
4711df8b
EW
57};
58
59struct ww_tty {
0edb449f
EW
60 struct sgttyb ww_sgttyb;
61 struct tchars ww_tchars;
62 struct ltchars ww_ltchars;
63 int ww_lmode;
64 int ww_ldisc;
65 int ww_pgrp;
0edb449f
EW
66};
67
0896e17e
EW
68union ww_char {
69 short c_w; /* as a word */
70 struct {
71 char C_c; /* the character part */
72 char C_m; /* the mode part */
73 } c_un;
74};
75#define c_c c_un.C_c
76#define c_m c_un.C_m
77
78 /* parts of ww_char */
79#define WWC_CMASK 0x00ff
80#define WWC_MMASK 0xff00
81#define WWC_MSHIFT 8
82
83 /* c_m bits */
84#define WWM_REV 0x01 /* reverse video */
85#define WWM_BLK 0x02 /* blinking */
86#define WWM_UL 0x04 /* underlined */
87#define WWM_GLS 0x10 /* window only, glass, i.e. transparent */
88#define WWM_COV 0x20 /* window only, covered */
89
90 /* ww_state values */
91#define WWS_INITIAL 0 /* just opened */
92#define WWS_HASPROC 1 /* forked, in parent */
93#define WWS_INCHILD 2 /* forked, in child */
94#define WWS_DEAD 3 /* child died */
95
2357b64e 96 /* flags for ww_fmap */
0896e17e
EW
97#define WWF_U 0x01
98#define WWF_R 0x02
99#define WWF_D 0x04
100#define WWF_L 0x08
101#define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
102#define WWF_LABEL 0x40
103#define WWF_TOP 0x80
104
2357b64e
EW
105 /* flags to wwopen() */
106#define WWO_PTY 0x01 /* want pty */
107#define WWO_REVERSE 0x02 /* make it all reverse video */
108#define WWO_GLASS 0x04 /* make it all glass */
109#define WWO_FRAME 0x08 /* this is a frame window */
110
0896e17e
EW
111 /* special ww_index value */
112#define WWX_NOBODY NWW
113
03e75950
EW
114#define WWE_NOERR 0
115#define WWE_SYS 1 /* system error */
116#define WWE_NOMEM 2 /* out of memory */
117#define WWE_TOOMANY 3 /* too many windows */
118#define WWE_NOPTY 4 /* no more ptys */
119#define WWE_SIZE 5 /* bad window size */
120#define WWE_BADTERM 6 /* bad terminal type */
121#define WWE_CANTDO 7 /* dumb terminal */
122
bb05dfb5 123struct ww wwhead;
0896e17e 124struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
bb05dfb5 125struct ww wwnobody;
2b44d852 126
0896e17e
EW
127struct ww_tty wwoldtty; /* the old (saved) terminal settings */
128struct ww_tty wwnewtty; /* the new (current) terminal settings */
129struct ww_tty wwwintty; /* the terminal settings for windows */
130char *wwterm; /* the terminal name */
131char wwtermcap[1024]; /* place for the termcap */
132char wwkeys[512]; /* termcap fields for the function keys */
bb05dfb5 133
bb05dfb5 134int wwnrow, wwncol; /* the screen size */
7d77e730 135char wwavailmodes; /* actually supported modes */
73218728 136char wwcursormodes; /* the modes for the fake cursor */
5e785082 137char wwwrap; /* terminal has auto wrap around */
0896e17e 138int wwdtablesize; /* result of getdtablesize() call */
bb05dfb5 139char **wwsmap; /* the screen map */
0896e17e
EW
140union ww_char **wwos; /* the old (current) screen */
141union ww_char **wwns; /* the new (desired) screen */
861cd1ed 142char *wwtouched; /* wwns changed flags */
0896e17e
EW
143int wwbaudmap[]; /* maps stty() baud rate code into number */
144int wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
145int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
03e75950 146int wwerrno; /* error number */
0edb449f 147
bb05dfb5 148 /* statistics */
861cd1ed
EW
149int wwnwrite, wwnwritec;
150int wwnupdate, wwntouched, wwnmiss;
0edb449f 151
0896e17e 152 /* quicky macros */
bb05dfb5 153#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
f2a77fe1 154#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
bb05dfb5 155#define wwbell() putchar(CTRL(g))
2357b64e 156#define wwunbox(w) wwunframe(w)
f2a77fe1 157#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
86697c44 158#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
2b44d852 159
7d77e730
EW
160 /* the window virtual terminal */
161#define WWT_TERM "TERM=window"
a598c465 162#define WWT_TERMCAP "WW|window|window package:\
7d77e730 163 :cr=^M:nl=^J:bl=^G:\
a598c465
EW
164 :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%+ %+ :\
165 :da:db:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:im=\\E@:mi:\
7d77e730
EW
166 :nd=\\EC:ta=^I:pt:up=\\EA:"
167#define WWT_REV "se=\\Eq:so=\\Ep:"
168#define WWT_UL "ue=\\Es:us=\\Er:"
169
0896e17e 170 /* our functions */
2b44d852
EW
171struct ww *wwopen();
172struct ww *wwfind();
173int wwchild();
bb05dfb5 174int wwsuspend();
27fd1bda 175char *unctrl();
bb05dfb5 176char **wwalloc();
03e75950 177char *wwerror();
bb05dfb5 178
0896e17e 179 /* c library functions */
bb05dfb5
EW
180char *malloc();
181char *calloc();
182char *getenv();
183char *tgetstr();
184char *rindex();
185char *strcpy();
186char *strcat();
187
188#undef MIN
189#undef MAX
190#define MIN(x, y) ((x) > (y) ? (y) : (x))
191#define MAX(x, y) ((x) > (y) ? (x) : (y))
192
193#undef CTRL
194#define CTRL(c) ('c'&0x1f)
195#define DEL 0x7f
196#define ISCTRL(c) ((c) < ' ' || (c) >= DEL)