]> git.saurik.com Git - apple/shell_cmds.git/blob - window/cmd2.c
shell_cmds-17.1.tar.gz
[apple/shell_cmds.git] / window / cmd2.c
1 /* $NetBSD: cmd2.c,v 1.4 1997/11/21 08:35:47 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
25 *
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
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93";
43 #else
44 __RCSID("$NetBSD: cmd2.c,v 1.4 1997/11/21 08:35:47 lukem Exp $");
45 #endif
46 #endif /* not lint */
47
48 #include "defs.h"
49
50 char *help_shortcmd[] = {
51 "# Select window # and return to conversation mode",
52 "%# Select window # but stay in command mode",
53 "escape Return to conversation mode without changing window",
54 "^^ Return to conversation mode and change to previous window",
55 "c# Close window #",
56 "w Open a new window",
57 "m# Move window #",
58 "M# Move window # to its previous position",
59 "s# Change the size of window #",
60 "S# Change window # to its previous size",
61 "^Y Scroll up one line",
62 "^E Scroll down one line",
63 "^U Scroll up half a window",
64 "^D Scroll down half a window",
65 "^B Scroll up a full window",
66 "^F Scroll down a full window",
67 "h Move cursor left",
68 "j Move cursor down",
69 "k Move cursor up",
70 "l Move cursor right",
71 "y Yank",
72 "p Put",
73 "^S Stop output in current window",
74 "^Q Restart output in current window",
75 "^L Redraw screen",
76 "^Z Suspend",
77 "q Quit",
78 ": Enter a long command",
79 0
80 };
81
82 char *help_longcmd[] = {
83 ":alias name string ... Make `name' an alias for `string ...'",
84 ":alias Show all aliases",
85 ":close # ... Close windows",
86 ":close all Close all windows",
87 ":cursor modes Set the cursor modes",
88 ":echo # string ... Print `string ...' in window #",
89 ":escape c Set escape character to `c'",
90 ":foreground # flag Make # a foreground window, if `flag' is true",
91 ":label # string Set label of window # to `string'",
92 ":list List all open windows",
93 ":default_nline lines Set default window buffer size to `lines'",
94 ":default_shell string ...",
95 " Set default shell to `string ...'",
96 ":default_smooth flag Set default smooth scroll flag",
97 ":select # Select window #",
98 ":smooth # flag Set window # to smooth scroll mode",
99 ":source filename Execute commands in `filename'",
100 ":terse flag Set terse mode",
101 ":unalias name Undefine `name' as an alias",
102 ":unset variable Deallocate `variable'",
103 ":variable List all variables",
104 ":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
105 " Open a window at `row', `col' of size `nrow', `ncol',",
106 " with `nline' lines in the buffer, and `label'",
107 ":write # string ... Write `string ...' to window # as input",
108 0
109 };
110
111 int help_print __P((struct ww *, char *, char **));
112
113 void
114 c_help()
115 {
116 struct ww *w;
117
118 if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
119 error("Can't open help window: %s.", wwerror());
120 return;
121 }
122 wwprintf(w, "The escape character is %c.\n", escapec);
123 wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
124 if (help_print(w, "Short commands", help_shortcmd) >= 0)
125 (void) help_print(w, "Long commands", help_longcmd);
126 closeiwin(w);
127 }
128
129 int
130 help_print(w, name, list)
131 struct ww *w;
132 char *name;
133 char **list;
134 {
135 wwprintf(w, "%s:\n\n", name);
136 while (*list)
137 switch (more(w, 0)) {
138 case 0:
139 wwputs(*list++, w);
140 wwputc('\n', w);
141 break;
142 case 1:
143 wwprintf(w, "%s: (continued)\n\n", name);
144 break;
145 case 2:
146 return -1;
147 }
148 return more(w, 1) == 2 ? -1 : 0;
149 }
150
151 void
152 c_quit()
153 {
154 char oldterse = terse;
155
156 setterse(0);
157 wwputs("Really quit [yn]? ", cmdwin);
158 wwcurtowin(cmdwin);
159 while (wwpeekc() < 0)
160 wwiomux();
161 if (wwgetc() == 'y') {
162 wwputs("Yes", cmdwin);
163 quit++;
164 } else
165 wwputc('\n', cmdwin);
166 setterse(!quit && oldterse);
167 }