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

Annotation of src/usr.bin/window/cmd.c, Revision 1.6

1.6     ! mpech       1: /*     $OpenBSD: cmd.c,v 1.5 2000/04/15 05:22:14 millert Exp $ */
1.2       niklas      2: /*     $NetBSD: cmd.c,v 1.4 1996/02/08 20:44:57 mycroft Exp $  */
1.1       deraadt     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[] = "@(#)cmd.c      8.1 (Berkeley) 6/6/93";
                     43: #else
1.6     ! mpech      44: static char rcsid[] = "$OpenBSD: cmd.c,v 1.5 2000/04/15 05:22:14 millert Exp $";
1.1       deraadt    45: #endif
                     46: #endif /* not lint */
                     47:
                     48: #include "defs.h"
                     49: #include "char.h"
                     50:
                     51: docmd()
                     52: {
1.6     ! mpech      53:        int c;
        !            54:        struct ww *w;
1.1       deraadt    55:        char out = 0;
                     56:
                     57:        while (!out && !quit) {
                     58:                if ((c = wwgetc()) < 0) {
                     59:                        if (terse)
                     60:                                wwsetcursor(0, 0);
                     61:                        else {
                     62:                                wwputs("Command: ", cmdwin);
                     63:                                wwcurtowin(cmdwin);
                     64:                        }
                     65:                        do
                     66:                                wwiomux();
                     67:                        while ((c = wwgetc()) < 0);
                     68:                }
                     69:                if (!terse)
                     70:                        wwputc('\n', cmdwin);
                     71:                switch (c) {
                     72:                default:
                     73:                        if (c != escapec)
                     74:                                break;
                     75:                case 'h': case 'j': case 'k': case 'l':
                     76:                case 'y': case 'p':
                     77:                case ctrl('y'):
                     78:                case ctrl('e'):
                     79:                case ctrl('u'):
                     80:                case ctrl('d'):
                     81:                case ctrl('b'):
                     82:                case ctrl('f'):
                     83:                case ctrl('s'):
                     84:                case ctrl('q'):
                     85:                case ctrl('['):
                     86:                        if (selwin == 0) {
                     87:                                error("No window.");
                     88:                                continue;
                     89:                        }
                     90:                }
                     91:                switch (c) {
                     92:                case '1': case '2': case '3': case '4': case '5':
                     93:                case '6': case '7': case '8': case '9':
                     94:                        if ((w = window[c - '1']) == 0) {
                     95:                                error("%c: No such window.", c);
                     96:                                break;
                     97:                        }
                     98:                        setselwin(w);
                     99:                        if (checkproc(selwin) >= 0)
                    100:                                 out = 1;
                    101:                        break;
                    102:                case '%':
1.5       millert   103:                        if ((w = getwindow()) != 0)
1.1       deraadt   104:                                setselwin(w);
                    105:                        break;
                    106:                case ctrl('^'):
                    107:                        if (lastselwin != 0) {
                    108:                                setselwin(lastselwin);
                    109:                                if (checkproc(selwin) >= 0)
                    110:                                        out = 1;
                    111:                        } else
                    112:                                error("No previous window.");
                    113:                        break;
                    114:                case 'c':
1.5       millert   115:                        if ((w = getwindow()) != 0)
1.1       deraadt   116:                                closewin(w);
                    117:                        break;
                    118:                case 'w':
                    119:                        c_window();
                    120:                        break;
                    121:                case 'm':
1.5       millert   122:                        if ((w = getwindow()) != 0)
1.1       deraadt   123:                                c_move(w);
                    124:                        break;
                    125:                case 'M':
1.5       millert   126:                        if ((w = getwindow()) != 0)
1.1       deraadt   127:                                movewin(w, w->ww_alt.t, w->ww_alt.l);
                    128:                        break;
                    129:                case 's':
1.5       millert   130:                        if ((w = getwindow()) != 0)
1.1       deraadt   131:                                c_size(w);
                    132:                        break;
                    133:                case 'S':
1.5       millert   134:                        if ((w = getwindow()) != 0)
1.1       deraadt   135:                                sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                    136:                        break;
                    137:                case 'y':
                    138:                        c_yank();
                    139:                        break;
                    140:                case 'p':
                    141:                        c_put();
                    142:                        break;
                    143:                case ':':
                    144:                        c_colon();
                    145:                        break;
                    146:                case 'h':
                    147:                        (void) wwwrite(selwin, "\b", 1);
                    148:                        break;
                    149:                case 'j':
                    150:                        (void) wwwrite(selwin, "\n", 1);
                    151:                        break;
                    152:                case 'k':
                    153:                        (void) wwwrite(selwin, "\033A", 2);
                    154:                        break;
                    155:                case 'l':
                    156:                        (void) wwwrite(selwin, "\033C", 2);
                    157:                        break;
                    158:                case ctrl('e'):
                    159:                        wwscroll(selwin, 1);
                    160:                        break;
                    161:                case ctrl('y'):
                    162:                        wwscroll(selwin, -1);
                    163:                        break;
                    164:                case ctrl('d'):
                    165:                        wwscroll(selwin, selwin->ww_w.nr / 2);
                    166:                        break;
                    167:                case ctrl('u'):
                    168:                        wwscroll(selwin, - selwin->ww_w.nr / 2);
                    169:                        break;
                    170:                case ctrl('f'):
                    171:                        wwscroll(selwin, selwin->ww_w.nr);
                    172:                        break;
                    173:                case ctrl('b'):
                    174:                        wwscroll(selwin, - selwin->ww_w.nr);
                    175:                        break;
                    176:                case ctrl('s'):
                    177:                        stopwin(selwin);
                    178:                        break;
                    179:                case ctrl('q'):
                    180:                        startwin(selwin);
                    181:                        break;
                    182:                case ctrl('l'):
                    183:                        wwredraw();
                    184:                        break;
                    185:                case '?':
                    186:                        c_help();
                    187:                        break;
                    188:                case ctrl('['):
                    189:                        if (checkproc(selwin) >= 0)
                    190:                                out = 1;
                    191:                        break;
                    192:                case ctrl('z'):
                    193:                        wwsuspend();
                    194:                        break;
                    195:                case 'q':
                    196:                        c_quit();
                    197:                        break;
                    198:                /* debugging stuff */
                    199:                case '&':
                    200:                        if (debug) {
                    201:                                c_debug();
                    202:                                break;
                    203:                        }
                    204:                default:
                    205:                        if (c == escapec) {
                    206:                                if (checkproc(selwin) >= 0) {
                    207:                                        (void) write(selwin->ww_pty,
                    208:                                                &escapec, 1);
                    209:                                        out = 1;
                    210:                                }
                    211:                        } else {
                    212:                                if (!terse)
                    213:                                        wwbell();
                    214:                                error("Type ? for help.");
                    215:                        }
                    216:                }
                    217:        }
                    218:        if (!quit)
                    219:                setcmd(0);
                    220: }
                    221:
                    222: struct ww *
1.5       millert   223: getwindow()
1.1       deraadt   224: {
1.6     ! mpech     225:        int c;
1.1       deraadt   226:        struct ww *w = 0;
                    227:
                    228:        if (!terse)
                    229:                wwputs("Which window? ", cmdwin);
                    230:        wwcurtowin(cmdwin);
                    231:        while ((c = wwgetc()) < 0)
                    232:                wwiomux();
                    233:        if (debug && c == 'c')
                    234:                w = cmdwin;
                    235:        else if (debug && c == 'f')
                    236:                w = framewin;
                    237:        else if (debug && c == 'b')
                    238:                w = boxwin;
                    239:        else if (c >= '1' && c < NWINDOW + '1')
                    240:                w = window[c - '1'];
                    241:        else if (c == '+')
                    242:                w = selwin;
                    243:        else if (c == '-')
                    244:                w = lastselwin;
                    245:        if (w == 0)
                    246:                wwbell();
                    247:        if (!terse)
                    248:                wwputc('\n', cmdwin);
                    249:        return w;
                    250: }
                    251:
                    252: checkproc(w)
                    253: struct ww *w;
                    254: {
                    255:        if (w->ww_state != WWS_HASPROC) {
                    256:                error("No process in window.");
                    257:                return -1;
                    258:        }
                    259:        return 0;
                    260: }
                    261:
                    262: setcmd(new)
                    263: char new;
                    264: {
                    265:        if (new && !incmd) {
                    266:                if (!terse)
                    267:                        wwadd(cmdwin, &wwhead);
                    268:                if (selwin != 0)
                    269:                        wwcursor(selwin, 1);
                    270:                wwcurwin = 0;
                    271:        } else if (!new && incmd) {
                    272:                if (!terse) {
                    273:                        wwdelete(cmdwin);
                    274:                        reframe();
                    275:                }
                    276:                if (selwin != 0)
                    277:                        wwcursor(selwin, 0);
                    278:                wwcurwin = selwin;
                    279:        }
                    280:        incmd = new;
                    281: }
                    282:
                    283: setterse(new)
                    284: char new;
                    285: {
                    286:        if (incmd)
                    287:                if (new && !terse) {
                    288:                        wwdelete(cmdwin);
                    289:                        reframe();
                    290:                } else if (!new && terse)
                    291:                        wwadd(cmdwin, &wwhead);
                    292:        terse = new;
                    293: }
                    294:
                    295: /*
                    296:  * Set the current window.
                    297:  */
                    298: setselwin(w)
                    299: struct ww *w;
                    300: {
                    301:        if (selwin == w)
                    302:                return;
                    303:        if (selwin != 0)
                    304:                lastselwin = selwin;
                    305:        if ((selwin = w) != 0)
                    306:                front(selwin, 1);
                    307: }