front() must reframe() when called from setselwin()
[unix-history] / usr / src / usr.bin / window / lcmd1.c
CommitLineData
bd002416 1#ifndef lint
7c0483b9 2static char *sccsid = "@(#)lcmd1.c 3.9 83/11/30";
bd002416
EW
3#endif
4
5#include "defs.h"
1c0ca238
EW
6#include "string.h"
7#include "value.h"
8#include "lcmd.h"
9
10struct lcmd_arg arg_window[] = {
11 { "row", 1, ARG_NUM },
12 { "column", 1, ARG_NUM },
13 { "nrows", 2, ARG_NUM },
14 { "ncols", 2, ARG_NUM },
15 { "nlines", 2, ARG_NUM },
16 { "label", 1, ARG_STR },
17 { 0, 0, 0 }
18};
19
20l_window(v)
21register struct value *v;
bd002416 22{
1c0ca238 23 register struct lcmd_arg *a = arg_window;
4cbe417d 24 int col, row, ncol, nrow, id, nline;
1c0ca238 25 char *label;
bd002416 26
03e75950 27 if ((id = findid()) < 0)
bd002416 28 return;
1c0ca238
EW
29 row = a->arg_vtype == V_ERR ? 1 : a->arg_num;
30 col = (++a)->arg_vtype == V_ERR ? 0 : a->arg_num;
31 nrow = (++a)->arg_vtype == V_ERR ? wwnrow - row : a->arg_num;
32 ncol = (++a)->arg_vtype == V_ERR ? wwncol - col : a->arg_num;
33 nline = (++a)->arg_vtype == V_ERR ? nbufline : a->arg_num;
34 label = (++a)->arg_vtype == V_ERR ? 0 : a->arg_str;
35 if (openwin(id, row, col, nrow, ncol, nline, label) == 0)
36 return;
37 v->v_type = V_NUM;
38 v->v_num = id;
4cbe417d
EW
39}
40
1c0ca238
EW
41struct lcmd_arg arg_buffer[] = {
42 { "nlines", 1, ARG_NUM },
43 { 0, 0, 0 }
44};
45
46l_buffer(v)
47struct value *v;
4cbe417d 48{
1c0ca238
EW
49 v->v_num = nbufline;
50 v->v_type = V_NUM;
51 if (arg_buffer[0].arg_vtype != V_ERR)
52 nbufline = arg_buffer[0].arg_num;
bd002416
EW
53}
54
1c0ca238
EW
55struct lcmd_arg arg_select[] = {
56 { "window", 1, ARG_NUM },
57 { 0, 0, 0 }
58};
59
60l_select(v)
61struct value *v;
bd002416
EW
62{
63 struct ww *w;
64
1c0ca238
EW
65 v->v_type = V_NUM;
66 v->v_num = selwin ? selwin->ww_id : -1;
67 if (arg_select[0].arg_vtype == V_ERR)
bd002416 68 return;
37661cbd 69 if ((w = vtowin(&arg_select[0].arg_val)) == 0)
1c0ca238 70 return;
bd002416
EW
71 setselwin(w);
72}
73
1c0ca238
EW
74struct lcmd_arg arg_escape[] = {
75 { "escapec", 1, ARG_NUM },
76 { 0, 0, 0 }
77};
78
79l_escape(v)
80struct value *v;
bd002416 81{
1c0ca238
EW
82 if ((v->v_str = str_cpy(unctrl(escapec))) == 0) {
83 error("Out of memory.");
84 return;
85 }
86 v->v_type = V_STR;
87 if (arg_escape[0].arg_type != V_ERR)
88 setescape(arg_escape[0].arg_str);
bd002416
EW
89}
90
1c0ca238
EW
91struct lcmd_arg arg_label[] = {
92 { "window", 1, ARG_NUM },
93 { "label", 1, ARG_STR },
94 { 0, 0, 0 }
95};
96
97/*ARGSUSED*/
98l_label(v)
99struct value *v;
bd002416
EW
100{
101 struct ww *w;
1c0ca238 102 register struct lcmd_arg *a = arg_label;
bd002416 103
1c0ca238 104 if ((w = vtowin(&a->arg_val)) == 0)
bd002416 105 return;
1c0ca238 106 if ((++a)->arg_vtype != V_ERR && setlabel(w, a->arg_str) < 0)
bd002416
EW
107 error("Out of memory.");
108 reframe();
109}
110
1c0ca238 111struct lcmd_arg arg_terse[] = {
37661cbd 112 { "flag", 1, ARG_ANY },
1c0ca238
EW
113 { 0, 0, 0 }
114};
115
116l_terse(v)
117struct value *v;
bd002416 118{
1c0ca238
EW
119 v->v_type = V_NUM;
120 v->v_num = terse;
121 terse = vtobool(&arg_terse[0].arg_val, 1, terse);
122 if (!terse && v->v_num)
bd002416 123 wwadd(cmdwin, &wwhead);
37661cbd
EW
124 else if (!v->v_num && terse)
125 wwdelete(cmdwin);
bd002416
EW
126 reframe();
127}
128
1c0ca238
EW
129struct lcmd_arg arg_source[] = {
130 { "filename", 1, ARG_STR },
131 { 0, 0, 0 }
132};
133
134/*ARGSUSED*/
135l_source(v)
136struct value *v;
bd002416 137{
1c0ca238
EW
138 if (arg_source[0].arg_vtype != V_ERR
139 && dosource(arg_source[0].arg_str) < 0) {
140 error("Can't open %s.", arg_source[0].arg_str);
141 v->v_num = -1;
142 } else
143 v->v_num = 0;
144 v->v_type = V_NUM;
bd002416
EW
145}
146
1c0ca238
EW
147struct lcmd_arg arg_write[] = {
148 { "window", 1, ARG_NUM },
149 { "string", 1, ARG_STR },
150 { 0, 0, 0 }
151};
152
153/*ARGSUSED*/
154l_write(v)
155struct value *v;
bd002416 156{
1c0ca238 157 register struct lcmd_arg *a = arg_write;
bd002416
EW
158 struct ww *w;
159
1c0ca238 160 if ((w = vtowin(&a->arg_val)) == 0)
bd002416 161 return;
1c0ca238
EW
162 a++;
163 (void) write(w->ww_pty, a->arg_str, strlen(a->arg_str));
bd002416
EW
164}
165
1c0ca238
EW
166struct lcmd_arg arg_close[] = {
167 { "window", 1, ARG_NUM },
168 { 0, 0, 0 }
169};
170
171/*ARGSUSED*/
172l_close(v)
173struct value *v;
8aee01cc 174{
1c0ca238 175 register struct lcmd_arg *a = arg_close;
1c0ca238 176 struct ww *w;
8aee01cc 177
7c0483b9 178 if (a->arg_vtype == V_ERR)
a4c3bba5 179 c_close((struct ww *)0);
7c0483b9
EW
180 else if ((w = vtowin(&a->arg_val)) != 0)
181 c_close(w);
8aee01cc
EW
182}
183
bd002416 184struct ww *
1c0ca238
EW
185vtowin(v)
186register struct value *v;
bd002416 187{
bd002416
EW
188 struct ww *w;
189
1c0ca238
EW
190 switch (v->v_type) {
191 case V_ERR:
192 error("Window identifier required.");
193 return 0;
194 case V_STR:
195 error("Number required for window identifier.");
196 return 0;
197 }
198 if (v->v_num < 1 || v->v_num > NWINDOW
199 || (w = window[v->v_num - 1]) == 0) {
200 error("%d: No such window.", v->v_num);
bd002416
EW
201 return 0;
202 }
203 return w;
204}
1c0ca238
EW
205
206vtobool(v, def, err)
207register struct value *v;
208char def, err;
209{
210 switch (v->v_type) {
211 case V_NUM:
212 return v->v_num != 0;
213 case V_STR:
214 if (str_match(v->v_str, "true", 1)
215 || str_match(v->v_str, "on", 2)
216 || str_match(v->v_str, "yes", 1))
217 return 1;
218 else if (str_match(v->v_str, "false", 1)
219 || str_match(v->v_str, "off", 2)
220 || str_match(v->v_str, "no", 1))
221 return 0;
222 else {
223 error("%s: Illegal boolean value.", v->v_str);
224 return err;
225 }
226 /*NOTREACHED*/
227 case V_ERR:
228 return def;
229 }
230 /*NOTREACHED*/
231}