]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/lcmd1.c
1 /* $NetBSD: lcmd1.c,v 1.7 1997/11/21 08:36:03 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)lcmd1.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: lcmd1.c,v 1.7 1997/11/21 08:36:03 lukem Exp $");
51 #include "window_string.h"
55 char vtobool
__P((struct value
*, char, char));
57 struct lcmd_arg arg_window
[] = {
58 { "row", 1, ARG_NUM
},
59 { "column", 1, ARG_NUM
},
60 { "nrows", 2, ARG_NUM
},
61 { "ncols", 2, ARG_NUM
},
62 { "nlines", 2, ARG_NUM
},
63 { "label", 1, ARG_STR
},
64 { "pty", 1, ARG_ANY
},
65 { "frame", 1, ARG_ANY
},
66 { "mapnl", 1, ARG_ANY
},
67 { "keepopen", 1, ARG_ANY
},
68 { "smooth", 1, ARG_ANY
},
69 { "shell", 1, ARG_STR
|ARG_LIST
},
79 int col
, row
, ncol
, nrow
, id
, nline
;
81 int haspty
, hasframe
, mapnl
, keepopen
, smooth
;
83 char *argv
[sizeof default_shell
/ sizeof *default_shell
];
86 if ((id
= findid()) < 0)
88 row
= a
->v_type
== V_ERR
? 1 : a
->v_num
;
90 col
= a
->v_type
== V_ERR
? 0 : a
->v_num
;
92 nrow
= a
->v_type
== V_ERR
? wwnrow
- row
: a
->v_num
;
94 ncol
= a
->v_type
== V_ERR
? wwncol
- col
: a
->v_num
;
96 nline
= a
->v_type
== V_ERR
? default_nline
: a
->v_num
;
98 label
= a
->v_type
== V_ERR
? 0 : a
->v_str
;
99 if ((haspty
= vtobool(++a
, 1, -1)) < 0)
101 if ((hasframe
= vtobool(++a
, 1, -1)) < 0)
103 if ((mapnl
= vtobool(++a
, !haspty
, -1)) < 0)
105 if ((keepopen
= vtobool(++a
, 0, -1)) < 0)
107 if ((smooth
= vtobool(++a
, default_smooth
, -1)) < 0)
109 if ((++a
)->v_type
!= V_ERR
) {
110 for (pp
= argv
; a
->v_type
!= V_ERR
&&
111 pp
< &argv
[sizeof argv
/sizeof *argv
-1]; pp
++, a
++)
115 if ((*sh
= strrchr(shf
, '/')))
121 shf
= default_shellfile
;
123 if ((w
= openwin(id
, row
, col
, nrow
, ncol
, nline
, label
,
124 haspty
? WWT_PTY
: WWT_SOCKET
, hasframe
? WWU_HASFRAME
: 0, shf
,
128 SET(w
->ww_wflags
, WWW_MAPNL
);
130 CLR(w
->ww_wflags
, WWW_MAPNL
);
132 SET(w
->ww_uflags
, WWU_KEEPOPEN
);
134 CLR(w
->ww_uflags
, WWU_KEEPOPEN
);
136 SET(w
->ww_wflags
, WWW_NOUPDATE
);
138 CLR(w
->ww_wflags
, WWW_NOUPDATE
);
143 struct lcmd_arg arg_def_nline
[] = {
144 { "nlines", 1, ARG_NUM
},
152 v
->v_num
= default_nline
;
154 if (a
->v_type
!= V_ERR
)
155 default_nline
= a
->v_num
;
158 struct lcmd_arg arg_smooth
[] = {
159 { "window", 1, ARG_NUM
},
160 { "flag", 1, ARG_ANY
},
172 if ((w
= vtowin(a
++, selwin
)) == 0)
174 v
->v_num
= ISSET(w
->ww_wflags
, WWW_NOUPDATE
) == 0;
175 if (!vtobool(a
, v
->v_num
, v
->v_num
))
176 SET(w
->ww_wflags
, WWW_NOUPDATE
);
178 CLR(w
->ww_wflags
, WWW_NOUPDATE
);
181 struct lcmd_arg arg_def_smooth
[] = {
182 { "flag", 1, ARG_ANY
},
191 v
->v_num
= default_smooth
;
192 default_smooth
= vtobool(a
, v
->v_num
, v
->v_num
);
195 struct lcmd_arg arg_select
[] = {
196 { "window", 1, ARG_NUM
},
207 v
->v_num
= selwin
? selwin
->ww_id
+ 1 : -1;
208 if (a
->v_type
== V_ERR
)
210 if ((w
= vtowin(a
, (struct ww
*)0)) == 0)
215 struct lcmd_arg arg_debug
[] = {
216 { "flag", 1, ARG_ANY
},
226 debug
= vtobool(a
, debug
, debug
);
229 struct lcmd_arg arg_escape
[] = {
230 { "escapec", 1, ARG_STR
},
242 if ((v
->v_str
= str_cpy(buf
)) == 0) {
243 error("Out of memory.");
247 if (a
->v_type
!= V_ERR
)
251 struct lcmd_arg arg_label
[] = {
252 { "window", 1, ARG_NUM
},
253 { "label", 1, ARG_STR
},
264 if ((w
= vtowin(a
, selwin
)) == 0)
266 if ((++a
)->v_type
!= V_ERR
&& setlabel(w
, a
->v_str
) < 0)
267 error("Out of memory.");
271 struct lcmd_arg arg_foreground
[] = {
272 { "window", 1, ARG_NUM
},
273 { "flag", 1, ARG_ANY
},
284 if ((w
= vtowin(a
, selwin
)) == 0)
288 flag
= vtobool(++a
, v
->v_num
, v
->v_num
);
289 if (flag
== v
->v_num
)
296 struct lcmd_arg arg_terse
[] = {
297 { "flag", 1, ARG_ANY
},
307 setterse(vtobool(a
, terse
, terse
));
310 struct lcmd_arg arg_source
[] = {
311 { "filename", 1, ARG_STR
},
320 if (a
->v_type
!= V_ERR
&& dosource(a
->v_str
) < 0) {
321 error("Can't open %s.", a
->v_str
);
327 struct lcmd_arg arg_write
[] = {
328 { "window", 1, ARG_NUM
},
329 { "", 0, ARG_ANY
|ARG_LIST
},
341 if ((w
= vtowin(a
++, selwin
)) == 0)
343 while (a
->v_type
!= V_ERR
) {
344 if (a
->v_type
== V_NUM
) {
345 (void) sprintf(buf
, "%d", a
->v_num
);
346 (void) write(w
->ww_pty
, buf
, strlen(buf
));
348 (void) write(w
->ww_pty
, a
->v_str
, strlen(a
->v_str
));
349 if ((++a
)->v_type
!= V_ERR
)
350 (void) write(w
->ww_pty
, " ", 1);
354 struct lcmd_arg arg_close
[] = {
355 { "window", 1, ARG_ANY
|ARG_LIST
},
366 if (a
->v_type
== V_STR
&& str_match(a
->v_str
, "all", 3))
367 closewin((struct ww
*)0);
369 for (; a
->v_type
!= V_ERR
; a
++)
370 if ((w
= vtowin(a
, (struct ww
*)0)) != 0)
374 struct lcmd_arg arg_cursormodes
[] = {
375 { "modes", 1, ARG_NUM
},
385 v
->v_num
= wwcursormodes
;
386 if (a
->v_type
!= V_ERR
)
387 wwsetcursormodes(a
->v_num
);
390 struct lcmd_arg arg_unset
[] = {
391 { "variable", 1, ARG_ANY
},
405 if ((a
->v_str
= str_itoa(a
->v_num
)) == 0) {
406 error("Out of memory.");
413 v
->v_num
= var_unset(a
->v_str
);
425 error("No window specified.");
428 error("%s: No such window.", v
->v_str
);
431 if (v
->v_num
< 1 || v
->v_num
> NWINDOW
432 || (w
= window
[v
->v_num
- 1]) == 0) {
433 error("%d: No such window.", v
->v_num
);
446 return v
->v_num
!= 0;
448 if (str_match(v
->v_str
, "true", 1)
449 || str_match(v
->v_str
, "on", 2)
450 || str_match(v
->v_str
, "yes", 1))
452 else if (str_match(v
->v_str
, "false", 1)
453 || str_match(v
->v_str
, "off", 2)
454 || str_match(v
->v_str
, "no", 1))
457 error("%s: Illegal boolean value.", v
->v_str
);