1 /*	$OpenBSD: cmd2.c,v 1.5 2003/06/03 02:56:23 millert Exp $	*/
2 /*	$NetBSD: cmd2.c,v 1.3 1995/09/28 10:34:05 tls Exp $	*/
3 
4 /*
5  * Copyright (c) 1983, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Edward Wang at The University of California, Berkeley.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)cmd2.c	8.1 (Berkeley) 6/6/93";
39 #else
40 static char rcsid[] = "$OpenBSD: cmd2.c,v 1.5 2003/06/03 02:56:23 millert Exp $";
41 #endif
42 #endif /* not lint */
43 
44 #include "defs.h"
45 
46 char *help_shortcmd[] = {
47 	"#       Select window # and return to conversation mode",
48 	"%#      Select window # but stay in command mode",
49 	"escape  Return to conversation mode without changing window",
50 	"^^      Return to conversation mode and change to previous window",
51 	"c#      Close window #",
52 	"w       Open a new window",
53 	"m#      Move window #",
54 	"M#      Move window # to its previous position",
55 	"s#      Change the size of window #",
56 	"S#      Change window # to its previous size",
57 	"^Y      Scroll up one line",
58 	"^E      Scroll down one line",
59 	"^U      Scroll up half a window",
60 	"^D      Scroll down half a window",
61 	"^B      Scroll up a full window",
62 	"^F      Scroll down a full window",
63 	"h       Move cursor left",
64 	"j       Move cursor down",
65 	"k       Move cursor up",
66 	"l       Move cursor right",
67 	"y       Yank",
68 	"p       Put",
69 	"^S      Stop output in current window",
70 	"^Q      Restart output in current window",
71 	"^L      Redraw screen",
72 	"^Z      Suspend",
73 	"q       Quit",
74 	":       Enter a long command",
75 	0
76 };
77 char *help_longcmd[] = {
78 	":alias name string ...  Make `name' an alias for `string ...'",
79 	":alias                  Show all aliases",
80 	":close # ...            Close windows",
81 	":close all              Close all windows",
82 	":cursor modes           Set the cursor modes",
83 	":echo # string ...      Print `string ...' in window #",
84 	":escape c               Set escape character to `c'",
85 	":foreground # flag      Make # a foreground window, if `flag' is true",
86 	":label # string         Set label of window # to `string'",
87 	":list                   List all open windows",
88 	":default_nline lines    Set default window buffer size to `lines'",
89 	":default_shell string ...",
90 	"                        Set default shell to `string ...'",
91 	":default_smooth flag    Set default smooth scroll flag",
92 	":select #               Select window #",
93 	":smooth # flag          Set window # to smooth scroll mode",
94 	":source filename        Execute commands in `filename'",
95 	":terse flag             Set terse mode",
96 	":unalias name           Undefine `name' as an alias",
97 	":unset variable         Deallocate `variable'",
98 	":variable               List all variables",
99 	":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
100 	"                        Open a window at `row', `col' of size `nrow', `ncol',",
101 	"                        with `nline' lines in the buffer, and `label'",
102 	":write # string ...     Write `string ...' to window # as input",
103 	0
104 };
105 
c_help()106 c_help()
107 {
108 	struct ww *w;
109 
110 	if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
111 		error("Can't open help window: %s.", wwerror());
112 		return;
113 	}
114 	wwprintf(w, "The escape character is %c.\n", escapec);
115 	wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
116 	if (help_print(w, "Short commands", help_shortcmd) >= 0)
117 		(void) help_print(w, "Long commands", help_longcmd);
118 	closeiwin(w);
119 }
120 
121 help_print(w, name, list)
122 struct ww *w;
123 char *name;
124 char **list;
125 {
126 	wwprintf(w, "%s:\n\n", name);
127 	while (*list)
128 		switch (more(w, 0)) {
129 		case 0:
130 			wwputs(*list++, w);
131 			wwputc('\n', w);
132 			break;
133 		case 1:
134 			wwprintf(w, "%s: (continued)\n\n", name);
135 			break;
136 		case 2:
137 			return -1;
138 		}
139 	return more(w, 1) == 2 ? -1 : 0;
140 }
141 
c_quit()142 c_quit()
143 {
144 	char oldterse = terse;
145 
146 	setterse(0);
147 	wwputs("Really quit [yn]? ", cmdwin);
148 	wwcurtowin(cmdwin);
149 	while (wwpeekc() < 0)
150 		wwiomux();
151 	if (wwgetc() == 'y') {
152 		wwputs("Yes", cmdwin);
153 		quit++;
154 	} else
155 		wwputc('\n', cmdwin);
156 	setterse(!quit && oldterse);
157 }
158