Annotation of 43BSDReno/usr.bin/window/cmd.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * 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 are permitted provided
                      9:  * that: (1) source distributions retain this entire copyright notice and
                     10:  * comment, and (2) distributions including binaries display the following
                     11:  * acknowledgement:  ``This product includes software developed by the
                     12:  * University of California, Berkeley and its contributors'' in the
                     13:  * documentation or other materials provided with the distribution and in
                     14:  * all advertising materials mentioning features or use of this software.
                     15:  * Neither the name of the University nor the names of its contributors may
                     16:  * be used to endorse or promote products derived from this software without
                     17:  * specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: static char sccsid[] = "@(#)cmd.c      3.40 (Berkeley) 6/6/90";
                     25: #endif /* not lint */
                     26: 
                     27: #include "defs.h"
                     28: #include "char.h"
                     29: 
                     30: docmd()
                     31: {
                     32:        register char c;
                     33:        register struct ww *w;
                     34:        char out = 0;
                     35: 
                     36:        while (!out && !quit) {
                     37:                if ((c = wwgetc()) < 0) {
                     38:                        if (terse)
                     39:                                wwsetcursor(0, 0);
                     40:                        else {
                     41:                                wwputs("Command: ", cmdwin);
                     42:                                wwcurtowin(cmdwin);
                     43:                        }
                     44:                        do
                     45:                                wwiomux();
                     46:                        while ((c = wwgetc()) < 0);
                     47:                }
                     48:                if (!terse)
                     49:                        wwputc('\n', cmdwin);
                     50:                switch (c) {
                     51:                default:
                     52:                        if (c != escapec)
                     53:                                break;
                     54:                case 'h': case 'j': case 'k': case 'l':
                     55:                case ctrl('y'):
                     56:                case ctrl('e'):
                     57:                case ctrl('u'):
                     58:                case ctrl('d'):
                     59:                case ctrl('b'):
                     60:                case ctrl('f'):
                     61:                case ctrl('s'):
                     62:                case ctrl('q'):
                     63:                case ctrl('['):
                     64:                        if (selwin == 0) {
                     65:                                error("No window.");
                     66:                                continue;
                     67:                        }
                     68:                }
                     69:                switch (c) {
                     70:                case '1': case '2': case '3': case '4': case '5':
                     71:                case '6': case '7': case '8': case '9':
                     72:                        if ((w = window[c - '1']) == 0) {
                     73:                                error("%c: No such window.", c);
                     74:                                break;
                     75:                        }
                     76:                        setselwin(w);
                     77:                        if (checkproc(selwin) >= 0)
                     78:                                 out = 1;
                     79:                        break;
                     80:                case '%':
                     81:                        if ((w = getwin()) != 0)
                     82:                                setselwin(w);
                     83:                        break;
                     84:                case ctrl('^'):
                     85:                        if (lastselwin != 0) {
                     86:                                setselwin(lastselwin);
                     87:                                if (checkproc(selwin) >= 0)
                     88:                                        out = 1;
                     89:                        } else
                     90:                                error("No previous window.");
                     91:                        break;
                     92:                case 'c':
                     93:                        if ((w = getwin()) != 0)
                     94:                                closewin(w);
                     95:                        break;
                     96:                case 'w':
                     97:                        c_window();
                     98:                        break;
                     99:                case 'm':
                    100:                        if ((w = getwin()) != 0)
                    101:                                c_move(w);
                    102:                        break;
                    103:                case 'M':
                    104:                        if ((w = getwin()) != 0)
                    105:                                movewin(w, w->ww_alt.t, w->ww_alt.l);
                    106:                        break;
                    107:                case 's':
                    108:                        if ((w = getwin()) != 0)
                    109:                                c_size(w);
                    110:                        break;
                    111:                case 'S':
                    112:                        if ((w = getwin()) != 0)
                    113:                                sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                    114:                        break;
                    115:                case ':':
                    116:                        c_colon();
                    117:                        break;
                    118:                case 'h':
                    119:                        (void) wwwrite(selwin, "\b", 1);
                    120:                        break;
                    121:                case 'j':
                    122:                        (void) wwwrite(selwin, "\n", 1);
                    123:                        break;
                    124:                case 'k':
                    125:                        (void) wwwrite(selwin, "\033A", 2);
                    126:                        break;
                    127:                case 'l':
                    128:                        (void) wwwrite(selwin, "\033C", 2);
                    129:                        break;
                    130:                case ctrl('e'):
                    131:                        wwscroll(selwin, 1);
                    132:                        break;
                    133:                case ctrl('y'):
                    134:                        wwscroll(selwin, -1);
                    135:                        break;
                    136:                case ctrl('d'):
                    137:                        wwscroll(selwin, selwin->ww_w.nr / 2);
                    138:                        break;
                    139:                case ctrl('u'):
                    140:                        wwscroll(selwin, - selwin->ww_w.nr / 2);
                    141:                        break;
                    142:                case ctrl('f'):
                    143:                        wwscroll(selwin, selwin->ww_w.nr);
                    144:                        break;
                    145:                case ctrl('b'):
                    146:                        wwscroll(selwin, - selwin->ww_w.nr);
                    147:                        break;
                    148:                case ctrl('s'):
                    149:                        stopwin(selwin);
                    150:                        break;
                    151:                case ctrl('q'):
                    152:                        startwin(selwin);
                    153:                        break;
                    154:                case ctrl('l'):
                    155:                        wwredraw();
                    156:                        break;
                    157:                case '?':
                    158:                        c_help();
                    159:                        break;
                    160:                case ctrl('['):
                    161:                        if (checkproc(selwin) >= 0)
                    162:                                out = 1;
                    163:                        break;
                    164:                case ctrl('z'):
                    165:                        wwsuspend();
                    166:                        break;
                    167:                case 'q':
                    168:                        c_quit();
                    169:                        break;
                    170:                /* debugging stuff */
                    171:                case '&':
                    172:                        if (debug) {
                    173:                                c_debug();
                    174:                                break;
                    175:                        }
                    176:                default:
                    177:                        if (c == escapec) {
                    178:                                if (checkproc(selwin) >= 0) {
                    179:                                        (void) write(selwin->ww_pty,
                    180:                                                &escapec, 1);
                    181:                                        out = 1;
                    182:                                }
                    183:                        } else {
                    184:                                if (!terse)
                    185:                                        wwbell();
                    186:                                error("Type ? for help.");
                    187:                        }
                    188:                }
                    189:        }
                    190:        if (!quit)
                    191:                setcmd(0);
                    192: }
                    193: 
                    194: struct ww *
                    195: getwin()
                    196: {
                    197:        register int c;
                    198:        struct ww *w = 0;
                    199: 
                    200:        if (!terse)
                    201:                wwputs("Which window? ", cmdwin);
                    202:        wwcurtowin(cmdwin);
                    203:        while ((c = wwgetc()) < 0)
                    204:                wwiomux();
                    205:        if (debug && c == 'c')
                    206:                w = cmdwin;
                    207:        else if (debug && c == 'f')
                    208:                w = framewin;
                    209:        else if (debug && c == 'b')
                    210:                w = boxwin;
                    211:        else if (c >= '1' && c < NWINDOW + '1')
                    212:                w = window[c - '1'];
                    213:        else if (c == '+')
                    214:                w = selwin;
                    215:        else if (c == '-')
                    216:                w = lastselwin;
                    217:        if (w == 0)
                    218:                wwbell();
                    219:        if (!terse)
                    220:                wwputc('\n', cmdwin);
                    221:        return w;
                    222: }
                    223: 
                    224: checkproc(w)
                    225: struct ww *w;
                    226: {
                    227:        if (w->ww_state != WWS_HASPROC) {
                    228:                error("No process in window.");
                    229:                return -1;
                    230:        }
                    231:        return 0;
                    232: }
                    233: 
                    234: setcmd(new)
                    235: char new;
                    236: {
                    237:        if (new && !incmd) {
                    238:                if (!terse)
                    239:                        wwadd(cmdwin, &wwhead);
                    240:                if (selwin != 0)
                    241:                        wwcursor(selwin, 1);
                    242:                wwcurwin = 0;
                    243:        } else if (!new && incmd) {
                    244:                if (!terse) {
                    245:                        wwdelete(cmdwin);
                    246:                        reframe();
                    247:                }
                    248:                if (selwin != 0)
                    249:                        wwcursor(selwin, 0);
                    250:                wwcurwin = selwin;
                    251:        }
                    252:        incmd = new;
                    253: }
                    254: 
                    255: setterse(new)
                    256: char new;
                    257: {
                    258:        if (incmd)
                    259:                if (new && !terse) {
                    260:                        wwdelete(cmdwin);
                    261:                        reframe();
                    262:                } else if (!new && terse)
                    263:                        wwadd(cmdwin, &wwhead);
                    264:        terse = new;
                    265: }
                    266: 
                    267: /*
                    268:  * Set the current window.
                    269:  */
                    270: setselwin(w)
                    271: struct ww *w;
                    272: {
                    273:        if (selwin == w)
                    274:                return;
                    275:        if (selwin != 0)
                    276:                lastselwin = selwin;
                    277:        if ((selwin = w) != 0)
                    278:                front(selwin, 1);
                    279: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.