2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)lcmd1.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
43 #include <string.h> /* System string definitions. */
44 #include "mystring.h" /* Local string definitions. */
49 struct lcmd_arg arg_window[] = {
50 { "row", 1, ARG_NUM },
51 { "column", 1, ARG_NUM },
52 { "nrows", 2, ARG_NUM },
53 { "ncols", 2, ARG_NUM },
54 { "nlines", 2, ARG_NUM },
55 { "label", 1, ARG_STR },
56 { "pty", 1, ARG_ANY },
57 { "frame", 1, ARG_ANY },
58 { "mapnl", 1, ARG_ANY },
59 { "keepopen", 1, ARG_ANY },
60 { "smooth", 1, ARG_ANY },
61 { "shell", 1, ARG_STR|ARG_LIST },
67 register struct value *a;
70 int col, row, ncol, nrow, id, nline;
72 char haspty, hasframe, mapnl, keepopen, smooth;
74 char *argv[sizeof default_shell / sizeof *default_shell];
77 if ((id = findid()) < 0)
79 row = a->v_type == V_ERR ? 1 : a->v_num;
81 col = a->v_type == V_ERR ? 0 : a->v_num;
83 nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num;
85 ncol = a->v_type == V_ERR ? wwncol - col : a->v_num;
87 nline = a->v_type == V_ERR ? default_nline : a->v_num;
89 label = a->v_type == V_ERR ? 0 : a->v_str;
90 if ((haspty = vtobool(++a, 1, -1)) < 0)
92 if ((hasframe = vtobool(++a, 1, -1)) < 0)
94 if ((mapnl = vtobool(++a, !haspty, -1)) < 0)
96 if ((keepopen = vtobool(++a, 0, -1)) < 0)
98 if ((smooth = vtobool(++a, default_smooth, -1)) < 0)
100 if ((++a)->v_type != V_ERR) {
101 for (pp = argv; a->v_type != V_ERR &&
102 pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++)
106 if (*sh = rindex(shf, '/'))
112 shf = default_shellfile;
114 if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
115 hasframe, shf, sh)) == 0)
118 w->ww_keepopen = keepopen;
119 w->ww_noupdate = !smooth;
124 struct lcmd_arg arg_def_nline[] = {
125 { "nlines", 1, ARG_NUM },
130 register struct value *v, *a;
132 v->v_num = default_nline;
134 if (a->v_type != V_ERR)
135 default_nline = a->v_num;
138 struct lcmd_arg arg_smooth[] = {
139 { "window", 1, ARG_NUM },
140 { "flag", 1, ARG_ANY },
145 register struct value *v, *a;
151 if ((w = vtowin(a++, selwin)) == 0)
153 v->v_num = !w->ww_noupdate;
154 w->ww_noupdate = !vtobool(a, v->v_num, v->v_num);
157 struct lcmd_arg arg_def_smooth[] = {
158 { "flag", 1, ARG_ANY },
163 register struct value *v, *a;
166 v->v_num = default_smooth;
167 default_smooth = vtobool(a, v->v_num, v->v_num);
170 struct lcmd_arg arg_select[] = {
171 { "window", 1, ARG_NUM },
176 register struct value *v, *a;
181 v->v_num = selwin ? selwin->ww_id + 1 : -1;
182 if (a->v_type == V_ERR)
184 if ((w = vtowin(a, (struct ww *)0)) == 0)
189 struct lcmd_arg arg_debug[] = {
190 { "flag", 1, ARG_ANY },
195 register struct value *v, *a;
199 debug = vtobool(a, debug, debug);
202 struct lcmd_arg arg_escape[] = {
203 { "escapec", 1, ARG_STR },
208 register struct value *v, *a;
214 if ((v->v_str = str_cpy(buf)) == 0) {
215 error("Out of memory.");
219 if (a->v_type != V_ERR)
223 struct lcmd_arg arg_label[] = {
224 { "window", 1, ARG_NUM },
225 { "label", 1, ARG_STR },
232 register struct value *a;
236 if ((w = vtowin(a, selwin)) == 0)
238 if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
239 error("Out of memory.");
243 struct lcmd_arg arg_foreground[] = {
244 { "window", 1, ARG_NUM },
245 { "flag", 1, ARG_ANY },
250 register struct value *v, *a;
255 if ((w = vtowin(a, selwin)) == 0)
259 flag = vtobool(++a, v->v_num, v->v_num);
260 if (flag == v->v_num)
267 struct lcmd_arg arg_terse[] = {
268 { "flag", 1, ARG_ANY },
273 register struct value *v, *a;
277 setterse(vtobool(a, terse, terse));
280 struct lcmd_arg arg_source[] = {
281 { "filename", 1, ARG_STR },
286 register struct value *v, *a;
289 if (a->v_type != V_ERR && dosource(a->v_str) < 0) {
290 error("Can't open %s.", a->v_str);
296 struct lcmd_arg arg_write[] = {
297 { "window", 1, ARG_NUM },
298 { "", 0, ARG_ANY|ARG_LIST },
305 register struct value *a;
310 if ((w = vtowin(a++, selwin)) == 0)
312 while (a->v_type != V_ERR) {
313 if (a->v_type == V_NUM) {
314 (void) sprintf(buf, "%d", a->v_num);
315 (void) write(w->ww_pty, buf, strlen(buf));
317 (void) write(w->ww_pty, a->v_str, strlen(a->v_str));
318 if ((++a)->v_type != V_ERR)
319 (void) write(w->ww_pty, " ", 1);
323 struct lcmd_arg arg_close[] = {
324 { "window", 1, ARG_ANY|ARG_LIST },
331 register struct value *a;
335 if (a->v_type == V_STR && str_match(a->v_str, "all", 3))
336 closewin((struct ww *)0);
338 for (; a->v_type != V_ERR; a++)
339 if ((w = vtowin(a, (struct ww *)0)) != 0)
343 struct lcmd_arg arg_cursormodes[] = {
344 { "modes", 1, ARG_NUM },
349 register struct value *v, *a;
353 v->v_num = wwcursormodes;
354 if (a->v_type != V_ERR)
355 wwsetcursormodes(a->v_num);
358 struct lcmd_arg arg_unset[] = {
359 { "variable", 1, ARG_ANY },
364 register struct value *v, *a;
372 if ((a->v_str = str_itoa(a->v_num)) == 0) {
373 error("Out of memory.");
380 v->v_num = var_unset(a->v_str);
385 register struct value *v;
392 error("No window specified.");
395 error("%s: No such window.", v->v_str);
398 if (v->v_num < 1 || v->v_num > NWINDOW
399 || (w = window[v->v_num - 1]) == 0) {
400 error("%d: No such window.", v->v_num);
407 register struct value *v;
412 return v->v_num != 0;
414 if (str_match(v->v_str, "true", 1)
415 || str_match(v->v_str, "on", 2)
416 || str_match(v->v_str, "yes", 1))
418 else if (str_match(v->v_str, "false", 1)
419 || str_match(v->v_str, "off", 2)
420 || str_match(v->v_str, "no", 1))
423 error("%s: Illegal boolean value.", v->v_str);