Don't fiddle with the modes with the -R flag...
[unix-history] / usr / src / usr.bin / window / win.c
CommitLineData
b6b63f20 1#ifndef lint
b1189050 2static char *sccsid = "@(#)win.c 3.3 84/03/03";
b6b63f20
EW
3#endif
4
5#include "defs.h"
6
7/*
8 * Routines for opening and closing windows
9 */
10
11/*
12 * Open a user window.
13 */
14struct ww *
15openwin(id, row, col, nrow, ncol, nline, label)
16char *label;
17{
18 register struct ww *w;
19
20 if (id < 0 && (id = findid()) < 0)
21 return 0;
22 if (row + nrow <= 0 || row > wwnrow - 1
23 || col + ncol <= 0 || col > wwncol - 1) {
24 error("Illegal window position.");
25 return 0;
26 }
27 if ((w = wwopen(WWO_PTY, nrow, ncol, row, col, nline)) == 0) {
28 error("%s.", wwerror());
29 return 0;
30 }
31 w->ww_id = id;
32 window[id] = w;
33 w->ww_hasframe = 1;
34 w->ww_altpos.r = 1;
35 w->ww_altpos.c = 0;
36 if (label != 0 && setlabel(w, label) < 0)
37 error("No memory for label.");
38 wwcursor(w, 1);
39 wwadd(w, framewin);
40 selwin = w;
41 reframe();
42 wwupdate();
43 wwflush();
44 if (wwspawn(w, shell, shellname, (char *)0) < 0) {
45 c_close(w);
46 error("%s: %s.", shell, wwerror());
47 return 0;
48 }
49 return w;
50}
51
52findid()
53{
54 register i;
55
56 for (i = 0; i < NWINDOW && window[i] != 0; i++)
57 ;
58 if (i >= NWINDOW) {
59 error("Too many windows.");
60 return -1;
61 }
62 return i;
63}
64
65/*
66 * Close a user window.
67 */
68closewin(w)
69register struct ww *w;
70{
71 if (w == selwin)
72 selwin = 0;
73 if (w == lastselwin)
74 lastselwin = 0;
75 if (w->ww_id >= 0 && w->ww_id < NWINDOW)
76 window[w->ww_id] = 0;
77 if (w->ww_label)
78 str_free(w->ww_label);
79 wwdelete(w);
80 wwclose(w);
81}
82
83/*
84 * Open an information (display) window.
85 */
86struct ww *
87openiwin(nrow, label)
88char *label;
89{
90 register struct ww *w;
91
92 if ((w = wwopen(0, nrow, wwncol, 2, 0, 0)) == 0)
93 return 0;
94 w->ww_mapnl = 1;
95 w->ww_hasframe = 1;
b1189050 96 w->ww_nointr = 1;
b6b63f20
EW
97 w->ww_id = -1;
98 w->ww_center = 1;
99 (void) setlabel(w, label);
100 wwadd(w, framewin);
101 reframe();
b1189050 102 wwupdate();
b6b63f20
EW
103 return w;
104}
105
106/*
107 * Close an information window.
108 */
109closeiwin(w)
110struct ww *w;
111{
112 closewin(w);
113 reframe();
114}
115
116waitnl(w)
117struct ww *w;
118{
119 (void) waitnl1(w, "[Type any key to continue]");
120}
121
b1189050 122more(w, always)
b6b63f20 123register struct ww *w;
b1189050 124char always;
b6b63f20
EW
125{
126 int c;
127
b1189050 128 if (!always && w->ww_cur.r < w->ww_w.b - 2)
b6b63f20
EW
129 return 0;
130 c = waitnl1(w, "[Type escape to abort, any other key to continue]");
b1189050 131 wwputs("\033E", w);
b6b63f20
EW
132 return c == CTRL([) ? 2 : 1;
133}
134
135waitnl1(w, prompt)
136register struct ww *w;
137char *prompt;
138{
139 front(w, 0);
b1189050 140 wwprintf(w, "\033Y%c%c\033p%s\033q ",
b6b63f20
EW
141 w->ww_w.nr - 1 + ' ', ' ', prompt); /* print on last line */
142 wwcurtowin(w);
8fa6d94c
EW
143 while (wwpeekc() < 0)
144 wwiomux();
145 return wwgetc();
b6b63f20 146}