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
36 * @(#)lcmd1.c 8.1 (Berkeley) 6/6/93
37 * $FreeBSD: src/usr.bin/window/lcmd1.c,v 1.2.6.2 2001/05/17 09:45:00 obrien Exp $
38 * $DragonFly: src/usr.bin/window/lcmd1.c,v 1.4 2005/04/15 17:55:29 drhodus Exp $
42 #include <string.h> /* System string definitions. */
43 #include "mystring.h" /* Local string definitions. */
48 struct lcmd_arg arg_window
[] = {
49 { "row", 1, ARG_NUM
},
50 { "column", 1, ARG_NUM
},
51 { "nrows", 2, ARG_NUM
},
52 { "ncols", 2, ARG_NUM
},
53 { "nlines", 2, ARG_NUM
},
54 { "label", 1, ARG_STR
},
55 { "pty", 1, ARG_ANY
},
56 { "frame", 1, ARG_ANY
},
57 { "mapnl", 1, ARG_ANY
},
58 { "keepopen", 1, ARG_ANY
},
59 { "smooth", 1, ARG_ANY
},
60 { "shell", 1, ARG_STR
|ARG_LIST
},
69 int col
, row
, ncol
, nrow
, id
, nline
;
71 char haspty
, hasframe
, mapnl
, keepopen
, smooth
;
73 char *argv
[sizeof default_shell
/ sizeof *default_shell
];
76 if ((id
= findid()) < 0)
78 row
= a
->v_type
== V_ERR
? 1 : a
->v_num
;
80 col
= a
->v_type
== V_ERR
? 0 : a
->v_num
;
82 nrow
= a
->v_type
== V_ERR
? wwnrow
- row
: a
->v_num
;
84 ncol
= a
->v_type
== V_ERR
? wwncol
- col
: a
->v_num
;
86 nline
= a
->v_type
== V_ERR
? default_nline
: a
->v_num
;
88 label
= a
->v_type
== V_ERR
? 0 : a
->v_str
;
89 if ((haspty
= vtobool(++a
, 1, -1)) < 0)
91 if ((hasframe
= vtobool(++a
, 1, -1)) < 0)
93 if ((mapnl
= vtobool(++a
, !haspty
, -1)) < 0)
95 if ((keepopen
= vtobool(++a
, 0, -1)) < 0)
97 if ((smooth
= vtobool(++a
, default_smooth
, -1)) < 0)
99 if ((++a
)->v_type
!= V_ERR
) {
100 for (pp
= argv
; a
->v_type
!= V_ERR
&&
101 pp
< &argv
[sizeof argv
/sizeof *argv
-1]; pp
++, a
++)
105 if (*sh
= strrchr(shf
, '/'))
111 shf
= default_shellfile
;
113 if ((w
= openwin(id
, row
, col
, nrow
, ncol
, nline
, label
, haspty
,
114 hasframe
, shf
, sh
)) == 0)
117 w
->ww_keepopen
= keepopen
;
118 w
->ww_noupdate
= !smooth
;
123 struct lcmd_arg arg_def_nline
[] = {
124 { "nlines", 1, ARG_NUM
},
131 v
->v_num
= default_nline
;
133 if (a
->v_type
!= V_ERR
)
134 default_nline
= a
->v_num
;
137 struct lcmd_arg arg_smooth
[] = {
138 { "window", 1, ARG_NUM
},
139 { "flag", 1, ARG_ANY
},
150 if ((w
= vtowin(a
++, selwin
)) == 0)
152 v
->v_num
= !w
->ww_noupdate
;
153 w
->ww_noupdate
= !vtobool(a
, v
->v_num
, v
->v_num
);
156 struct lcmd_arg arg_def_smooth
[] = {
157 { "flag", 1, ARG_ANY
},
165 v
->v_num
= default_smooth
;
166 default_smooth
= vtobool(a
, v
->v_num
, v
->v_num
);
169 struct lcmd_arg arg_select
[] = {
170 { "window", 1, ARG_NUM
},
180 v
->v_num
= selwin
? selwin
->ww_id
+ 1 : -1;
181 if (a
->v_type
== V_ERR
)
183 if ((w
= vtowin(a
, (struct ww
*)0)) == 0)
188 struct lcmd_arg arg_debug
[] = {
189 { "flag", 1, ARG_ANY
},
198 debug
= vtobool(a
, debug
, debug
);
201 struct lcmd_arg arg_escape
[] = {
202 { "escapec", 1, ARG_STR
},
213 if ((v
->v_str
= str_cpy(buf
)) == 0) {
214 error("Out of memory.");
218 if (a
->v_type
!= V_ERR
)
222 struct lcmd_arg arg_label
[] = {
223 { "window", 1, ARG_NUM
},
224 { "label", 1, ARG_STR
},
235 if ((w
= vtowin(a
, selwin
)) == 0)
237 if ((++a
)->v_type
!= V_ERR
&& setlabel(w
, a
->v_str
) < 0)
238 error("Out of memory.");
242 struct lcmd_arg arg_foreground
[] = {
243 { "window", 1, ARG_NUM
},
244 { "flag", 1, ARG_ANY
},
254 if ((w
= vtowin(a
, selwin
)) == 0)
258 flag
= vtobool(++a
, v
->v_num
, v
->v_num
);
259 if (flag
== v
->v_num
)
266 struct lcmd_arg arg_terse
[] = {
267 { "flag", 1, ARG_ANY
},
276 setterse(vtobool(a
, terse
, terse
));
279 struct lcmd_arg arg_source
[] = {
280 { "filename", 1, ARG_STR
},
288 if (a
->v_type
!= V_ERR
&& dosource(a
->v_str
) < 0) {
289 error("Can't open %s.", a
->v_str
);
295 struct lcmd_arg arg_write
[] = {
296 { "window", 1, ARG_NUM
},
297 { "", 0, ARG_ANY
|ARG_LIST
},
309 if ((w
= vtowin(a
++, selwin
)) == 0)
311 while (a
->v_type
!= V_ERR
) {
312 if (a
->v_type
== V_NUM
) {
313 (void) sprintf(buf
, "%d", a
->v_num
);
314 (void) write(w
->ww_pty
, buf
, strlen(buf
));
316 (void) write(w
->ww_pty
, a
->v_str
, strlen(a
->v_str
));
317 if ((++a
)->v_type
!= V_ERR
)
318 (void) write(w
->ww_pty
, " ", 1);
322 struct lcmd_arg arg_close
[] = {
323 { "window", 1, ARG_ANY
|ARG_LIST
},
334 if (a
->v_type
== V_STR
&& str_match(a
->v_str
, "all", 3))
335 closewin((struct ww
*)0);
337 for (; a
->v_type
!= V_ERR
; a
++)
338 if ((w
= vtowin(a
, (struct ww
*)0)) != 0)
342 struct lcmd_arg arg_cursormodes
[] = {
343 { "modes", 1, ARG_NUM
},
352 v
->v_num
= wwcursormodes
;
353 if (a
->v_type
!= V_ERR
)
354 wwsetcursormodes(a
->v_num
);
357 struct lcmd_arg arg_unset
[] = {
358 { "variable", 1, ARG_ANY
},
371 if ((a
->v_str
= str_itoa(a
->v_num
)) == 0) {
372 error("Out of memory.");
379 v
->v_num
= var_unset(a
->v_str
);
391 error("No window specified.");
394 error("%s: No such window.", v
->v_str
);
397 if (v
->v_num
< 1 || v
->v_num
> NWINDOW
398 || (w
= window
[v
->v_num
- 1]) == 0) {
399 error("%d: No such window.", v
->v_num
);
411 return v
->v_num
!= 0;
413 if (str_match(v
->v_str
, "true", 1)
414 || str_match(v
->v_str
, "on", 2)
415 || str_match(v
->v_str
, "yes", 1))
417 else if (str_match(v
->v_str
, "false", 1)
418 || str_match(v
->v_str
, "off", 2)
419 || str_match(v
->v_str
, "no", 1))
422 error("%s: Illegal boolean value.", v
->v_str
);