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";
40 "$FreeBSD: src/usr.bin/window/lcmd1.c,v 1.2.6.2 2001/05/17 09:45:00 obrien Exp $";
44 #include <string.h> /* System string definitions. */
45 #include "mystring.h" /* Local string definitions. */
50 struct lcmd_arg arg_window[] = {
51 { "row", 1, ARG_NUM },
52 { "column", 1, ARG_NUM },
53 { "nrows", 2, ARG_NUM },
54 { "ncols", 2, ARG_NUM },
55 { "nlines", 2, ARG_NUM },
56 { "label", 1, ARG_STR },
57 { "pty", 1, ARG_ANY },
58 { "frame", 1, ARG_ANY },
59 { "mapnl", 1, ARG_ANY },
60 { "keepopen", 1, ARG_ANY },
61 { "smooth", 1, ARG_ANY },
62 { "shell", 1, ARG_STR|ARG_LIST },
68 register struct value *a;
71 int col, row, ncol, nrow, id, nline;
73 char haspty, hasframe, mapnl, keepopen, smooth;
75 char *argv[sizeof default_shell / sizeof *default_shell];
78 if ((id = findid()) < 0)
80 row = a->v_type == V_ERR ? 1 : a->v_num;
82 col = a->v_type == V_ERR ? 0 : a->v_num;
84 nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num;
86 ncol = a->v_type == V_ERR ? wwncol - col : a->v_num;
88 nline = a->v_type == V_ERR ? default_nline : a->v_num;
90 label = a->v_type == V_ERR ? 0 : a->v_str;
91 if ((haspty = vtobool(++a, 1, -1)) < 0)
93 if ((hasframe = vtobool(++a, 1, -1)) < 0)
95 if ((mapnl = vtobool(++a, !haspty, -1)) < 0)
97 if ((keepopen = vtobool(++a, 0, -1)) < 0)
99 if ((smooth = vtobool(++a, default_smooth, -1)) < 0)
101 if ((++a)->v_type != V_ERR) {
102 for (pp = argv; a->v_type != V_ERR &&
103 pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++)
107 if (*sh = rindex(shf, '/'))
113 shf = default_shellfile;
115 if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
116 hasframe, shf, sh)) == 0)
119 w->ww_keepopen = keepopen;
120 w->ww_noupdate = !smooth;
125 struct lcmd_arg arg_def_nline[] = {
126 { "nlines", 1, ARG_NUM },
131 register struct value *v, *a;
133 v->v_num = default_nline;
135 if (a->v_type != V_ERR)
136 default_nline = a->v_num;
139 struct lcmd_arg arg_smooth[] = {
140 { "window", 1, ARG_NUM },
141 { "flag", 1, ARG_ANY },
146 register struct value *v, *a;
152 if ((w = vtowin(a++, selwin)) == 0)
154 v->v_num = !w->ww_noupdate;
155 w->ww_noupdate = !vtobool(a, v->v_num, v->v_num);
158 struct lcmd_arg arg_def_smooth[] = {
159 { "flag", 1, ARG_ANY },
164 register struct value *v, *a;
167 v->v_num = default_smooth;
168 default_smooth = vtobool(a, v->v_num, v->v_num);
171 struct lcmd_arg arg_select[] = {
172 { "window", 1, ARG_NUM },
177 register struct value *v, *a;
182 v->v_num = selwin ? selwin->ww_id + 1 : -1;
183 if (a->v_type == V_ERR)
185 if ((w = vtowin(a, (struct ww *)0)) == 0)
190 struct lcmd_arg arg_debug[] = {
191 { "flag", 1, ARG_ANY },
196 register struct value *v, *a;
200 debug = vtobool(a, debug, debug);
203 struct lcmd_arg arg_escape[] = {
204 { "escapec", 1, ARG_STR },
209 register struct value *v, *a;
215 if ((v->v_str = str_cpy(buf)) == 0) {
216 error("Out of memory.");
220 if (a->v_type != V_ERR)
224 struct lcmd_arg arg_label[] = {
225 { "window", 1, ARG_NUM },
226 { "label", 1, ARG_STR },
233 register struct value *a;
237 if ((w = vtowin(a, selwin)) == 0)
239 if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
240 error("Out of memory.");
244 struct lcmd_arg arg_foreground[] = {
245 { "window", 1, ARG_NUM },
246 { "flag", 1, ARG_ANY },
251 register struct value *v, *a;
256 if ((w = vtowin(a, selwin)) == 0)
260 flag = vtobool(++a, v->v_num, v->v_num);
261 if (flag == v->v_num)
268 struct lcmd_arg arg_terse[] = {
269 { "flag", 1, ARG_ANY },
274 register struct value *v, *a;
278 setterse(vtobool(a, terse, terse));
281 struct lcmd_arg arg_source[] = {
282 { "filename", 1, ARG_STR },
287 register struct value *v, *a;
290 if (a->v_type != V_ERR && dosource(a->v_str) < 0) {
291 error("Can't open %s.", a->v_str);
297 struct lcmd_arg arg_write[] = {
298 { "window", 1, ARG_NUM },
299 { "", 0, ARG_ANY|ARG_LIST },
306 register struct value *a;
311 if ((w = vtowin(a++, selwin)) == 0)
313 while (a->v_type != V_ERR) {
314 if (a->v_type == V_NUM) {
315 (void) sprintf(buf, "%d", a->v_num);
316 (void) write(w->ww_pty, buf, strlen(buf));
318 (void) write(w->ww_pty, a->v_str, strlen(a->v_str));
319 if ((++a)->v_type != V_ERR)
320 (void) write(w->ww_pty, " ", 1);
324 struct lcmd_arg arg_close[] = {
325 { "window", 1, ARG_ANY|ARG_LIST },
332 register struct value *a;
336 if (a->v_type == V_STR && str_match(a->v_str, "all", 3))
337 closewin((struct ww *)0);
339 for (; a->v_type != V_ERR; a++)
340 if ((w = vtowin(a, (struct ww *)0)) != 0)
344 struct lcmd_arg arg_cursormodes[] = {
345 { "modes", 1, ARG_NUM },
350 register struct value *v, *a;
354 v->v_num = wwcursormodes;
355 if (a->v_type != V_ERR)
356 wwsetcursormodes(a->v_num);
359 struct lcmd_arg arg_unset[] = {
360 { "variable", 1, ARG_ANY },
365 register struct value *v, *a;
373 if ((a->v_str = str_itoa(a->v_num)) == 0) {
374 error("Out of memory.");
381 v->v_num = var_unset(a->v_str);
386 register struct value *v;
393 error("No window specified.");
396 error("%s: No such window.", v->v_str);
399 if (v->v_num < 1 || v->v_num > NWINDOW
400 || (w = window[v->v_num - 1]) == 0) {
401 error("%d: No such window.", v->v_num);
408 register struct value *v;
413 return v->v_num != 0;
415 if (str_match(v->v_str, "true", 1)
416 || str_match(v->v_str, "on", 2)
417 || str_match(v->v_str, "yes", 1))
419 else if (str_match(v->v_str, "false", 1)
420 || str_match(v->v_str, "off", 2)
421 || str_match(v->v_str, "no", 1))
424 error("%s: Illegal boolean value.", v->v_str);