Commit | Line | Data |
---|---|---|
bd002416 | 1 | #ifndef lint |
2422abab | 2 | static char sccsid[] = "@(#)lcmd1.c 3.31 %G%"; |
bd002416 EW |
3 | #endif |
4 | ||
60de5df9 EW |
5 | /* |
6 | * Copyright (c) 1983 Regents of the University of California, | |
7 | * All rights reserved. Redistribution permitted subject to | |
8 | * the terms of the Berkeley Software License Agreement. | |
9 | */ | |
10 | ||
bd002416 | 11 | #include "defs.h" |
1c0ca238 EW |
12 | #include "string.h" |
13 | #include "value.h" | |
14 | #include "lcmd.h" | |
bb4a0c0b | 15 | #include "var.h" |
1c0ca238 EW |
16 | |
17 | struct lcmd_arg arg_window[] = { | |
855d0f8f EW |
18 | { "row", 1, ARG_NUM }, |
19 | { "column", 1, ARG_NUM }, | |
20 | { "nrows", 2, ARG_NUM }, | |
21 | { "ncols", 2, ARG_NUM }, | |
1c0ca238 EW |
22 | { "nlines", 2, ARG_NUM }, |
23 | { "label", 1, ARG_STR }, | |
7ecf4dca EW |
24 | { "pty", 1, ARG_ANY }, |
25 | { "frame", 1, ARG_ANY }, | |
74bac1db | 26 | { "mapnl", 1, ARG_ANY }, |
2422abab EW |
27 | { "keepopen", 1, ARG_ANY }, |
28 | { "smooth", 1, ARG_ANY }, | |
4cbd8755 | 29 | { "shell", 1, ARG_STR|ARG_LIST }, |
4222244b | 30 | 0 |
1c0ca238 EW |
31 | }; |
32 | ||
4222244b | 33 | l_window(v, a) |
855d0f8f EW |
34 | struct value *v; |
35 | register struct value *a; | |
bd002416 | 36 | { |
855d0f8f | 37 | struct ww *w; |
4cbe417d | 38 | int col, row, ncol, nrow, id, nline; |
1c0ca238 | 39 | char *label; |
2422abab | 40 | char haspty, hasframe, mapnl, keepopen, smooth; |
7ecf4dca EW |
41 | char *shf, **sh; |
42 | char *argv[sizeof shell / sizeof *shell]; | |
855d0f8f | 43 | register char **pp; |
bd002416 | 44 | |
03e75950 | 45 | if ((id = findid()) < 0) |
bd002416 | 46 | return; |
855d0f8f EW |
47 | row = a->v_type == V_ERR ? 1 : a->v_num; |
48 | a++; | |
49 | col = a->v_type == V_ERR ? 0 : a->v_num; | |
50 | a++; | |
51 | nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num; | |
52 | a++; | |
53 | ncol = a->v_type == V_ERR ? wwncol - col : a->v_num; | |
54 | a++; | |
55 | nline = a->v_type == V_ERR ? nbufline : a->v_num; | |
56 | a++; | |
57 | label = a->v_type == V_ERR ? 0 : a->v_str; | |
58 | if ((haspty = vtobool(++a, 1, -1)) < 0) | |
59 | return; | |
60 | if ((hasframe = vtobool(++a, 1, -1)) < 0) | |
61 | return; | |
62 | if ((mapnl = vtobool(++a, !haspty, -1)) < 0) | |
63 | return; | |
2422abab EW |
64 | if ((keepopen = vtobool(++a, 0, -1)) < 0) |
65 | return; | |
66 | if ((smooth = vtobool(++a, 1, -1)) < 0) | |
67 | return; | |
855d0f8f EW |
68 | if ((++a)->v_type != V_ERR) { |
69 | for (pp = argv; a->v_type != V_ERR && | |
4cbd8755 | 70 | pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++) |
855d0f8f | 71 | *pp = a->v_str; |
855d0f8f EW |
72 | *pp = 0; |
73 | shf = *(sh = argv); | |
74 | if (*sh = rindex(shf, '/')) | |
75 | (*sh)++; | |
76 | else | |
77 | *sh = shf; | |
7ecf4dca EW |
78 | } else { |
79 | sh = shell; | |
80 | shf = shellfile; | |
81 | } | |
74bac1db EW |
82 | if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty, |
83 | hasframe, shf, sh)) == 0) | |
84 | return; | |
85 | w->ww_mapnl = mapnl; | |
2422abab EW |
86 | w->ww_keepopen = keepopen; |
87 | w->ww_noupdate = !smooth; | |
1c0ca238 | 88 | v->v_type = V_NUM; |
7a57b3e2 | 89 | v->v_num = id + 1; |
4cbe417d EW |
90 | } |
91 | ||
1f12ea41 | 92 | struct lcmd_arg arg_nline[] = { |
1c0ca238 | 93 | { "nlines", 1, ARG_NUM }, |
4222244b | 94 | 0 |
1c0ca238 EW |
95 | }; |
96 | ||
1f12ea41 | 97 | l_nline(v, a) |
4222244b | 98 | register struct value *v, *a; |
4cbe417d | 99 | { |
1c0ca238 EW |
100 | v->v_num = nbufline; |
101 | v->v_type = V_NUM; | |
4222244b EW |
102 | if (a->v_type != V_ERR) |
103 | nbufline = a->v_num; | |
bd002416 EW |
104 | } |
105 | ||
2422abab EW |
106 | struct lcmd_arg arg_smooth[] = { |
107 | { "window", 1, ARG_NUM }, | |
108 | { "flag", 1, ARG_ANY }, | |
109 | 0 | |
110 | }; | |
111 | ||
112 | l_smooth(v, a) | |
113 | register struct value *v, *a; | |
114 | { | |
115 | struct ww *w; | |
116 | ||
117 | v->v_type = V_NUM; | |
118 | v->v_num = 0; | |
119 | if ((w = vtowin(a++, selwin)) == 0) | |
120 | return; | |
121 | v->v_num = !w->ww_noupdate; | |
122 | w->ww_noupdate = !vtobool(a, v->v_num, v->v_num); | |
123 | } | |
124 | ||
1c0ca238 EW |
125 | struct lcmd_arg arg_select[] = { |
126 | { "window", 1, ARG_NUM }, | |
4222244b | 127 | 0 |
1c0ca238 EW |
128 | }; |
129 | ||
4222244b EW |
130 | l_select(v, a) |
131 | register struct value *v, *a; | |
bd002416 EW |
132 | { |
133 | struct ww *w; | |
134 | ||
1c0ca238 | 135 | v->v_type = V_NUM; |
7a57b3e2 | 136 | v->v_num = selwin ? selwin->ww_id + 1 : -1; |
4222244b | 137 | if (a->v_type == V_ERR) |
bd002416 | 138 | return; |
ba5c0855 | 139 | if ((w = vtowin(a, (struct ww *)0)) == 0) |
1c0ca238 | 140 | return; |
bd002416 EW |
141 | setselwin(w); |
142 | } | |
143 | ||
b0640643 EW |
144 | struct lcmd_arg arg_debug[] = { |
145 | { "flag", 1, ARG_ANY }, | |
1f12ea41 | 146 | 0 |
b0640643 EW |
147 | }; |
148 | ||
4222244b EW |
149 | l_debug(v, a) |
150 | register struct value *v, *a; | |
b0640643 EW |
151 | { |
152 | v->v_type = V_NUM; | |
153 | v->v_num = debug; | |
96cdc840 | 154 | debug = vtobool(a, debug, debug); |
b0640643 EW |
155 | } |
156 | ||
1c0ca238 | 157 | struct lcmd_arg arg_escape[] = { |
4222244b EW |
158 | { "escapec", 1, ARG_STR }, |
159 | 0 | |
1c0ca238 EW |
160 | }; |
161 | ||
4222244b EW |
162 | l_escape(v, a) |
163 | register struct value *v, *a; | |
bd002416 | 164 | { |
0e64e422 EW |
165 | char buf[2]; |
166 | ||
167 | buf[0] = escapec; | |
168 | buf[1] = 0; | |
169 | if ((v->v_str = str_cpy(buf)) == 0) { | |
1c0ca238 EW |
170 | error("Out of memory."); |
171 | return; | |
172 | } | |
173 | v->v_type = V_STR; | |
4222244b EW |
174 | if (a->v_type != V_ERR) |
175 | setescape(a->v_str); | |
bd002416 EW |
176 | } |
177 | ||
1c0ca238 EW |
178 | struct lcmd_arg arg_label[] = { |
179 | { "window", 1, ARG_NUM }, | |
180 | { "label", 1, ARG_STR }, | |
4222244b | 181 | 0 |
1c0ca238 EW |
182 | }; |
183 | ||
184 | /*ARGSUSED*/ | |
4222244b | 185 | l_label(v, a) |
c654e7d4 EW |
186 | struct value *v; |
187 | register struct value *a; | |
bd002416 EW |
188 | { |
189 | struct ww *w; | |
190 | ||
ba5c0855 | 191 | if ((w = vtowin(a, selwin)) == 0) |
bd002416 | 192 | return; |
4222244b | 193 | if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0) |
bd002416 EW |
194 | error("Out of memory."); |
195 | reframe(); | |
196 | } | |
197 | ||
e1dba5dd EW |
198 | struct lcmd_arg arg_foreground[] = { |
199 | { "window", 1, ARG_NUM }, | |
200 | { "flag", 1, ARG_ANY }, | |
201 | 0 | |
202 | }; | |
203 | ||
204 | l_foreground(v, a) | |
205 | register struct value *v, *a; | |
206 | { | |
207 | struct ww *w; | |
208 | char flag; | |
209 | ||
ba5c0855 | 210 | if ((w = vtowin(a, selwin)) == 0) |
e1dba5dd EW |
211 | return; |
212 | v->v_type = V_NUM; | |
213 | v->v_num = isfg(w); | |
ba5c0855 | 214 | flag = vtobool(++a, v->v_num, v->v_num); |
e1dba5dd EW |
215 | if (flag == v->v_num) |
216 | return; | |
217 | deletewin(w); | |
d7c2cbb0 | 218 | addwin(w, flag); |
e1dba5dd EW |
219 | reframe(); |
220 | } | |
221 | ||
1c0ca238 | 222 | struct lcmd_arg arg_terse[] = { |
37661cbd | 223 | { "flag", 1, ARG_ANY }, |
4222244b | 224 | 0 |
1c0ca238 EW |
225 | }; |
226 | ||
4222244b EW |
227 | l_terse(v, a) |
228 | register struct value *v, *a; | |
bd002416 | 229 | { |
1c0ca238 EW |
230 | v->v_type = V_NUM; |
231 | v->v_num = terse; | |
ba5c0855 | 232 | setterse(vtobool(a, terse, terse)); |
bd002416 EW |
233 | } |
234 | ||
1c0ca238 EW |
235 | struct lcmd_arg arg_source[] = { |
236 | { "filename", 1, ARG_STR }, | |
4222244b | 237 | 0 |
1c0ca238 EW |
238 | }; |
239 | ||
4222244b EW |
240 | l_source(v, a) |
241 | register struct value *v, *a; | |
bd002416 | 242 | { |
4222244b EW |
243 | v->v_type = V_NUM; |
244 | if (a->v_type != V_ERR && dosource(a->v_str) < 0) { | |
245 | error("Can't open %s.", a->v_str); | |
1c0ca238 EW |
246 | v->v_num = -1; |
247 | } else | |
248 | v->v_num = 0; | |
bd002416 EW |
249 | } |
250 | ||
855d0f8f EW |
251 | struct lcmd_arg arg_write[] = { |
252 | { "window", 1, ARG_NUM }, | |
253 | { "", 0, ARG_ANY|ARG_LIST }, | |
254 | 0 | |
255 | }; | |
256 | ||
1c0ca238 | 257 | /*ARGSUSED*/ |
4222244b | 258 | l_write(v, a) |
c654e7d4 EW |
259 | struct value *v; |
260 | register struct value *a; | |
bd002416 | 261 | { |
1f12ea41 | 262 | char buf[20]; |
bd002416 EW |
263 | struct ww *w; |
264 | ||
ba5c0855 | 265 | if ((w = vtowin(a++, selwin)) == 0) |
bd002416 | 266 | return; |
1f12ea41 EW |
267 | while (a->v_type != V_ERR) { |
268 | if (a->v_type == V_NUM) { | |
269 | (void) sprintf(buf, "%d", a->v_num); | |
270 | (void) write(w->ww_pty, buf, strlen(buf)); | |
271 | } else | |
272 | (void) write(w->ww_pty, a->v_str, strlen(a->v_str)); | |
273 | if ((++a)->v_type != V_ERR) | |
274 | (void) write(w->ww_pty, " ", 1); | |
275 | } | |
bd002416 EW |
276 | } |
277 | ||
855d0f8f EW |
278 | struct lcmd_arg arg_close[] = { |
279 | { "window", 1, ARG_ANY|ARG_LIST }, | |
280 | 0 | |
281 | }; | |
282 | ||
1c0ca238 | 283 | /*ARGSUSED*/ |
4222244b | 284 | l_close(v, a) |
c654e7d4 EW |
285 | struct value *v; |
286 | register struct value *a; | |
8aee01cc | 287 | { |
1c0ca238 | 288 | struct ww *w; |
8aee01cc | 289 | |
ba5c0855 | 290 | if (a->v_type == V_STR && str_match(a->v_str, "all", 3)) |
2422abab | 291 | closewin((struct ww *)0); |
1f12ea41 EW |
292 | else |
293 | for (; a->v_type != V_ERR; a++) | |
ba5c0855 | 294 | if ((w = vtowin(a, (struct ww *)0)) != 0) |
2422abab | 295 | closewin(w); |
8aee01cc EW |
296 | } |
297 | ||
7a57b3e2 EW |
298 | struct lcmd_arg arg_cursormodes[] = { |
299 | { "modes", 1, ARG_NUM }, | |
4222244b | 300 | 0 |
7a57b3e2 EW |
301 | }; |
302 | ||
4222244b EW |
303 | l_cursormodes(v, a) |
304 | register struct value *v, *a; | |
7a57b3e2 | 305 | { |
7a57b3e2 EW |
306 | |
307 | v->v_type = V_NUM; | |
308 | v->v_num = wwcursormodes; | |
4222244b EW |
309 | if (a->v_type != V_ERR) |
310 | wwsetcursormodes(a->v_num); | |
7a57b3e2 EW |
311 | } |
312 | ||
b65b69eb EW |
313 | struct lcmd_arg arg_unset[] = { |
314 | { "variable", 1, ARG_ANY }, | |
4222244b | 315 | 0 |
b65b69eb EW |
316 | }; |
317 | ||
4222244b EW |
318 | l_unset(v, a) |
319 | register struct value *v, *a; | |
b65b69eb | 320 | { |
b65b69eb | 321 | v->v_type = V_NUM; |
4222244b | 322 | switch (a->v_type) { |
b65b69eb EW |
323 | case V_ERR: |
324 | v->v_num = -1; | |
325 | return; | |
326 | case V_NUM: | |
4222244b | 327 | if ((a->v_str = str_itoa(a->v_num)) == 0) { |
b65b69eb EW |
328 | error("Out of memory."); |
329 | v->v_num = -1; | |
330 | return; | |
331 | } | |
4222244b | 332 | a->v_type = V_STR; |
b65b69eb EW |
333 | break; |
334 | } | |
4222244b | 335 | v->v_num = var_unset(a->v_str); |
b65b69eb EW |
336 | } |
337 | ||
bd002416 | 338 | struct ww * |
ba5c0855 | 339 | vtowin(v, w) |
1c0ca238 | 340 | register struct value *v; |
ba5c0855 | 341 | struct ww *w; |
bd002416 | 342 | { |
1c0ca238 EW |
343 | switch (v->v_type) { |
344 | case V_ERR: | |
ba5c0855 EW |
345 | if (w != 0) |
346 | return w; | |
1f12ea41 | 347 | error("No window specified."); |
1c0ca238 EW |
348 | return 0; |
349 | case V_STR: | |
1f12ea41 | 350 | error("%s: No such window.", v->v_str); |
1c0ca238 EW |
351 | return 0; |
352 | } | |
353 | if (v->v_num < 1 || v->v_num > NWINDOW | |
354 | || (w = window[v->v_num - 1]) == 0) { | |
355 | error("%d: No such window.", v->v_num); | |
bd002416 EW |
356 | return 0; |
357 | } | |
358 | return w; | |
359 | } | |
1c0ca238 EW |
360 | |
361 | vtobool(v, def, err) | |
362 | register struct value *v; | |
363 | char def, err; | |
364 | { | |
365 | switch (v->v_type) { | |
366 | case V_NUM: | |
367 | return v->v_num != 0; | |
368 | case V_STR: | |
369 | if (str_match(v->v_str, "true", 1) | |
370 | || str_match(v->v_str, "on", 2) | |
371 | || str_match(v->v_str, "yes", 1)) | |
372 | return 1; | |
373 | else if (str_match(v->v_str, "false", 1) | |
374 | || str_match(v->v_str, "off", 2) | |
375 | || str_match(v->v_str, "no", 1)) | |
376 | return 0; | |
377 | else { | |
378 | error("%s: Illegal boolean value.", v->v_str); | |
379 | return err; | |
380 | } | |
381 | /*NOTREACHED*/ | |
382 | case V_ERR: | |
383 | return def; | |
384 | } | |
385 | /*NOTREACHED*/ | |
386 | } |