[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.4

1.4     ! downsj      1: /*     $OpenBSD$       */
1.2       niklas      2: /*     $NetBSD: cmd1.c,v 1.4 1996/02/08 20:44:59 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[] = "@(#)cmd1.c     8.1 (Berkeley) 6/6/93";
                     43: #else
1.4     ! downsj     44: static char rcsid[] = "$OpenBSD$";
1.1       deraadt    45: #endif
                     46: #endif /* not lint */
                     47:
                     48: #include "defs.h"
                     49: #include "char.h"
                     50:
                     51: c_window()
                     52: {
                     53:        int col, row, xcol, xrow;
                     54:        int id;
                     55:
                     56:        if ((id = findid()) < 0)
                     57:                return;
                     58:        if (!terse)
                     59:                wwputs("New window (upper left corner): ", cmdwin);
                     60:        col = 0;
                     61:        row = 1;
                     62:        wwadd(boxwin, framewin->ww_back);
                     63:        for (;;) {
                     64:                wwbox(boxwin, row - 1, col - 1, 3, 3);
                     65:                wwsetcursor(row, col);
                     66:                while (wwpeekc() < 0)
                     67:                        wwiomux();
                     68:                switch (getpos(&row, &col, row > 1, 0,
                     69:                        wwnrow - 1, wwncol - 1)) {
                     70:                case 3:
                     71:                        wwunbox(boxwin);
                     72:                        wwdelete(boxwin);
                     73:                        return;
                     74:                case 2:
                     75:                        wwunbox(boxwin);
                     76:                        break;
                     77:                case 1:
                     78:                        wwunbox(boxwin);
                     79:                case 0:
                     80:                        continue;
                     81:                }
                     82:                break;
                     83:        }
                     84:        if (!terse)
                     85:                wwputs("\nNew window (lower right corner): ", cmdwin);
                     86:        xcol = col;
                     87:        xrow = row;
                     88:        for (;;) {
                     89:                wwbox(boxwin, row - 1, col - 1,
                     90:                        xrow - row + 3, xcol - col + 3);
                     91:                wwsetcursor(xrow, xcol);
                     92:                while (wwpeekc() < 0)
                     93:                        wwiomux();
                     94:                switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
                     95:                {
                     96:                case 3:
                     97:                        wwunbox(boxwin);
                     98:                        wwdelete(boxwin);
                     99:                        return;
                    100:                case 2:
                    101:                        wwunbox(boxwin);
                    102:                        break;
                    103:                case 1:
                    104:                        wwunbox(boxwin);
                    105:                case 0:
                    106:                        continue;
                    107:                }
                    108:                break;
                    109:        }
                    110:        wwdelete(boxwin);
                    111:        if (!terse)
                    112:                wwputc('\n', cmdwin);
                    113:        wwcurtowin(cmdwin);
                    114:        (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline,
1.2       niklas    115:            (char *) 0, WWT_PTY, WWU_HASFRAME, default_shellfile,
                    116:            default_shell);
1.1       deraadt   117: }
                    118:
                    119: getpos(row, col, minrow, mincol, maxrow, maxcol)
                    120: register int *row, *col;
                    121: int minrow, mincol;
                    122: int maxrow, maxcol;
                    123: {
                    124:        static int scount;
                    125:        int count;
1.2       niklas    126:        int c;
1.1       deraadt   127:        int oldrow = *row, oldcol = *col;
                    128:
                    129:        while ((c = wwgetc()) >= 0) {
                    130:                switch (c) {
                    131:                case '0': case '1': case '2': case '3': case '4':
                    132:                case '5': case '6': case '7': case '8': case '9':
                    133:                        scount = scount * 10 + c - '0';
                    134:                        continue;
                    135:                }
                    136:                count = scount ? scount : 1;
                    137:                scount = 0;
                    138:                switch (c) {
                    139:                case 'h':
                    140:                        if ((*col -= count) < mincol)
                    141:                                *col = mincol;
                    142:                        break;
                    143:                case 'H':
                    144:                        *col = mincol;
                    145:                        break;
                    146:                case 'l':
                    147:                        if ((*col += count) > maxcol)
                    148:                                *col = maxcol;
                    149:                        break;
                    150:                case 'L':
                    151:                        *col = maxcol;
                    152:                        break;
                    153:                case 'j':
                    154:                        if ((*row += count) > maxrow)
                    155:                                *row = maxrow;
                    156:                        break;
                    157:                case 'J':
                    158:                        *row = maxrow;
                    159:                        break;
                    160:                case 'k':
                    161:                        if ((*row -= count) < minrow)
                    162:                                *row = minrow;
                    163:                        break;
                    164:                case 'K':
                    165:                        *row = minrow;
                    166:                        break;
                    167:                case ctrl('['):
                    168:                        if (!terse)
                    169:                                wwputs("\nCancelled.  ", cmdwin);
                    170:                        return 3;
                    171:                case '\r':
                    172:                        return 2;
                    173:                default:
                    174:                        if (!terse)
                    175:                                wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
                    176:                        wwbell();
                    177:                }
                    178:        }
                    179:        return oldrow != *row || oldcol != *col;
                    180: }