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