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

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

1.1       deraadt     1: /*     $NetBSD: cmd5.c,v 1.3 1995/09/28 10:34:09 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[] = "@(#)cmd5.c     8.1 (Berkeley) 6/6/93";
                     42: #else
                     43: static char rcsid[] = "$NetBSD: cmd5.c,v 1.3 1995/09/28 10:34:09 tls Exp $";
                     44: #endif
                     45: #endif /* not lint */
                     46:
                     47: #include "defs.h"
                     48:
                     49: /*
                     50:  * Window movement.
                     51:  */
                     52:
                     53: c_move(w)
                     54: register struct ww *w;
                     55: {
                     56:        int col, row;
                     57:        int mincol, minrow;
                     58:        int maxcol, maxrow;
                     59:        int curcol, currow;
                     60:
                     61:        if (!terse)
                     62:                wwputs("New window position: ", cmdwin);
                     63:        col = w->ww_w.l;
                     64:        row = w->ww_w.t;
                     65:        wwadd(boxwin, framewin->ww_back);
                     66:        for (;;) {
                     67:                wwbox(boxwin, row - 1, col - 1, w->ww_w.nr + 2, w->ww_w.nc + 2);
                     68:                getminmax(row, w->ww_w.nr, 1, wwnrow,
                     69:                        &currow, &minrow, &maxrow);
                     70:                getminmax(col, w->ww_w.nc, 0, wwncol,
                     71:                        &curcol, &mincol, &maxcol);
                     72:                wwsetcursor(currow, curcol);
                     73:                while (wwpeekc() < 0)
                     74:                        wwiomux();
                     75:                switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) {
                     76:                case 3:
                     77:                        wwunbox(boxwin);
                     78:                        wwdelete(boxwin);
                     79:                        return;
                     80:                case 2:
                     81:                        wwunbox(boxwin);
                     82:                        break;
                     83:                case 1:
                     84:                        wwunbox(boxwin);
                     85:                case 0:
                     86:                        continue;
                     87:                }
                     88:                break;
                     89:        }
                     90:        wwdelete(boxwin);
                     91:        if (!terse)
                     92:                wwputc('\n', cmdwin);
                     93:        wwcurtowin(cmdwin);
                     94:        movewin(w, row, col);
                     95: }
                     96:
                     97: movewin(w, row, col)
                     98: register struct ww *w;
                     99: {
                    100:        struct ww *back = w->ww_back;
                    101:
                    102:        w->ww_alt.t = w->ww_w.t;
                    103:        w->ww_alt.l = w->ww_w.l;
                    104:        wwdelete(w);
                    105:        wwmove(w, row, col);
                    106:        wwadd(w, back);
                    107:        reframe();
                    108: }
                    109:
                    110: /*
                    111:  * Weird stufff, don't ask.
                    112:  */
                    113: getminmax(x, n, a, b, curx, minx, maxx)
                    114: register x, n, a, b;
                    115: int *curx, *minx, *maxx;
                    116: {
                    117:        if (x < 0)
                    118:                *curx = x + n - 1;
                    119:        else
                    120:                *curx = x;
                    121:
                    122:        if (x <= a)
                    123:                *minx = 1 - n;
                    124:        else if (x <= b - n)
                    125:                *minx = a;
                    126:        else
                    127:                *minx = b - n;
                    128:
                    129:        if (x >= b - n)
                    130:                *maxx = b - 1;
                    131:        else if (x >= a)
                    132:                *maxx = b - n;
                    133:        else
                    134:                *maxx = a;
                    135: }