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

Annotation of src/usr.bin/window/cmd1.c, Revision 1.1.1.1

1.1       deraadt     1: /*     $NetBSD: cmd1.c,v 1.3 1995/09/28 10:34:03 tls Exp $     */
                      2:
                      3: /*
                      4:  * Copyright (c) 1983, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Edward Wang at The University of California, Berkeley.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  */
                     38:
                     39: #ifndef lint
                     40: #if 0
                     41: static char sccsid[] = "@(#)cmd1.c     8.1 (Berkeley) 6/6/93";
                     42: #else
                     43: static char rcsid[] = "$NetBSD: cmd1.c,v 1.3 1995/09/28 10:34:03 tls Exp $";
                     44: #endif
                     45: #endif /* not lint */
                     46:
                     47: #include "defs.h"
                     48: #include "char.h"
                     49:
                     50: c_window()
                     51: {
                     52:        int col, row, xcol, xrow;
                     53:        int id;
                     54:
                     55:        if ((id = findid()) < 0)
                     56:                return;
                     57:        if (!terse)
                     58:                wwputs("New window (upper left corner): ", cmdwin);
                     59:        col = 0;
                     60:        row = 1;
                     61:        wwadd(boxwin, framewin->ww_back);
                     62:        for (;;) {
                     63:                wwbox(boxwin, row - 1, col - 1, 3, 3);
                     64:                wwsetcursor(row, col);
                     65:                while (wwpeekc() < 0)
                     66:                        wwiomux();
                     67:                switch (getpos(&row, &col, row > 1, 0,
                     68:                        wwnrow - 1, wwncol - 1)) {
                     69:                case 3:
                     70:                        wwunbox(boxwin);
                     71:                        wwdelete(boxwin);
                     72:                        return;
                     73:                case 2:
                     74:                        wwunbox(boxwin);
                     75:                        break;
                     76:                case 1:
                     77:                        wwunbox(boxwin);
                     78:                case 0:
                     79:                        continue;
                     80:                }
                     81:                break;
                     82:        }
                     83:        if (!terse)
                     84:                wwputs("\nNew window (lower right corner): ", cmdwin);
                     85:        xcol = col;
                     86:        xrow = row;
                     87:        for (;;) {
                     88:                wwbox(boxwin, row - 1, col - 1,
                     89:                        xrow - row + 3, xcol - col + 3);
                     90:                wwsetcursor(xrow, xcol);
                     91:                while (wwpeekc() < 0)
                     92:                        wwiomux();
                     93:                switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
                     94:                {
                     95:                case 3:
                     96:                        wwunbox(boxwin);
                     97:                        wwdelete(boxwin);
                     98:                        return;
                     99:                case 2:
                    100:                        wwunbox(boxwin);
                    101:                        break;
                    102:                case 1:
                    103:                        wwunbox(boxwin);
                    104:                case 0:
                    105:                        continue;
                    106:                }
                    107:                break;
                    108:        }
                    109:        wwdelete(boxwin);
                    110:        if (!terse)
                    111:                wwputc('\n', cmdwin);
                    112:        wwcurtowin(cmdwin);
                    113:        (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline,
                    114:                (char *) 0, 1, 1, default_shellfile, default_shell);
                    115: }
                    116:
                    117: getpos(row, col, minrow, mincol, maxrow, maxcol)
                    118: register int *row, *col;
                    119: int minrow, mincol;
                    120: int maxrow, maxcol;
                    121: {
                    122:        static int scount;
                    123:        int count;
                    124:        char c;
                    125:        int oldrow = *row, oldcol = *col;
                    126:
                    127:        while ((c = wwgetc()) >= 0) {
                    128:                switch (c) {
                    129:                case '0': case '1': case '2': case '3': case '4':
                    130:                case '5': case '6': case '7': case '8': case '9':
                    131:                        scount = scount * 10 + c - '0';
                    132:                        continue;
                    133:                }
                    134:                count = scount ? scount : 1;
                    135:                scount = 0;
                    136:                switch (c) {
                    137:                case 'h':
                    138:                        if ((*col -= count) < mincol)
                    139:                                *col = mincol;
                    140:                        break;
                    141:                case 'H':
                    142:                        *col = mincol;
                    143:                        break;
                    144:                case 'l':
                    145:                        if ((*col += count) > maxcol)
                    146:                                *col = maxcol;
                    147:                        break;
                    148:                case 'L':
                    149:                        *col = maxcol;
                    150:                        break;
                    151:                case 'j':
                    152:                        if ((*row += count) > maxrow)
                    153:                                *row = maxrow;
                    154:                        break;
                    155:                case 'J':
                    156:                        *row = maxrow;
                    157:                        break;
                    158:                case 'k':
                    159:                        if ((*row -= count) < minrow)
                    160:                                *row = minrow;
                    161:                        break;
                    162:                case 'K':
                    163:                        *row = minrow;
                    164:                        break;
                    165:                case ctrl('['):
                    166:                        if (!terse)
                    167:                                wwputs("\nCancelled.  ", cmdwin);
                    168:                        return 3;
                    169:                case '\r':
                    170:                        return 2;
                    171:                default:
                    172:                        if (!terse)
                    173:                                wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
                    174:                        wwbell();
                    175:                }
                    176:        }
                    177:        return oldrow != *row || oldcol != *col;
                    178: }