[BACK]Return to cmd2.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / window

Annotation of src/usr.bin/window/cmd2.c, Revision 1.4

1.4     ! mpech       1: /*     $OpenBSD: cmd2.c,v 1.3 1997/02/25 00:03:56 downsj Exp $ */
1.1       deraadt     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. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the University of
                     22:  *     California, Berkeley and its contributors.
                     23:  * 4. Neither the name of the University nor the names of its contributors
                     24:  *    may be used to endorse or promote products derived from this software
                     25:  *    without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     28:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     29:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     30:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     31:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     32:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     33:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     34:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     35:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     36:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     37:  * SUCH DAMAGE.
                     38:  */
                     39:
                     40: #ifndef lint
                     41: #if 0
                     42: static char sccsid[] = "@(#)cmd2.c     8.1 (Berkeley) 6/6/93";
                     43: #else
1.4     ! mpech      44: static char rcsid[] = "$OpenBSD: cmd2.c,v 1.3 1997/02/25 00:03:56 downsj Exp $";
1.1       deraadt    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: char *help_longcmd[] = {
                     82:        ":alias name string ...  Make `name' an alias for `string ...'",
                     83:        ":alias                  Show all aliases",
                     84:        ":close # ...            Close windows",
                     85:        ":close all              Close all windows",
                     86:        ":cursor modes           Set the cursor modes",
                     87:        ":echo # string ...      Print `string ...' in window #",
                     88:        ":escape c               Set escape character to `c'",
                     89:        ":foreground # flag      Make # a foreground window, if `flag' is true",
                     90:        ":label # string         Set label of window # to `string'",
                     91:        ":list                   List all open windows",
                     92:        ":default_nline lines    Set default window buffer size to `lines'",
                     93:        ":default_shell string ...",
                     94:        "                        Set default shell to `string ...'",
                     95:        ":default_smooth flag    Set default smooth scroll flag",
                     96:        ":select #               Select window #",
                     97:        ":smooth # flag          Set window # to smooth scroll mode",
                     98:        ":source filename        Execute commands in `filename'",
                     99:        ":terse flag             Set terse mode",
                    100:        ":unalias name           Undefine `name' as an alias",
                    101:        ":unset variable         Deallocate `variable'",
                    102:        ":variable               List all variables",
                    103:        ":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]",
                    104:        "                        Open a window at `row', `col' of size `nrow', `ncol',",
                    105:        "                        with `nline' lines in the buffer, and `label'",
                    106:        ":write # string ...     Write `string ...' to window # as input",
                    107:        0
                    108: };
                    109:
                    110: c_help()
                    111: {
1.4     ! mpech     112:        struct ww *w;
1.1       deraadt   113:
                    114:        if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
                    115:                error("Can't open help window: %s.", wwerror());
                    116:                return;
                    117:        }
                    118:        wwprintf(w, "The escape character is %c.\n", escapec);
                    119:        wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
                    120:        if (help_print(w, "Short commands", help_shortcmd) >= 0)
                    121:                (void) help_print(w, "Long commands", help_longcmd);
                    122:        closeiwin(w);
                    123: }
                    124:
                    125: help_print(w, name, list)
1.4     ! mpech     126: struct ww *w;
1.1       deraadt   127: char *name;
1.4     ! mpech     128: char **list;
1.1       deraadt   129: {
                    130:        wwprintf(w, "%s:\n\n", name);
                    131:        while (*list)
                    132:                switch (more(w, 0)) {
                    133:                case 0:
                    134:                        wwputs(*list++, w);
                    135:                        wwputc('\n', w);
                    136:                        break;
                    137:                case 1:
                    138:                        wwprintf(w, "%s: (continued)\n\n", name);
                    139:                        break;
                    140:                case 2:
                    141:                        return -1;
                    142:                }
                    143:        return more(w, 1) == 2 ? -1 : 0;
                    144: }
                    145:
                    146: c_quit()
                    147: {
                    148:        char oldterse = terse;
                    149:
                    150:        setterse(0);
                    151:        wwputs("Really quit [yn]? ", cmdwin);
                    152:        wwcurtowin(cmdwin);
                    153:        while (wwpeekc() < 0)
                    154:                wwiomux();
                    155:        if (wwgetc() == 'y') {
                    156:                wwputs("Yes", cmdwin);
                    157:                quit++;
                    158:        } else
                    159:                wwputc('\n', cmdwin);
                    160:        setterse(!quit && oldterse);
                    161: }