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

1.5     ! millert     1: /*     $OpenBSD: cmd5.c,v 1.4 2001/11/19 19:02:18 mpech Exp $  */
1.1       deraadt     2: /*     $NetBSD: cmd5.c,v 1.3 1995/09/28 10:34:09 tls Exp $     */
                      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.
1.5     ! millert    19:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
                     36: #ifndef lint
                     37: #if 0
                     38: static char sccsid[] = "@(#)cmd5.c     8.1 (Berkeley) 6/6/93";
                     39: #else
1.5     ! millert    40: static char rcsid[] = "$OpenBSD: cmd5.c,v 1.4 2001/11/19 19:02:18 mpech Exp $";
1.1       deraadt    41: #endif
                     42: #endif /* not lint */
                     43:
                     44: #include "defs.h"
                     45:
                     46: /*
                     47:  * Window movement.
                     48:  */
                     49:
                     50: c_move(w)
1.4       mpech      51: struct ww *w;
1.1       deraadt    52: {
                     53:        int col, row;
                     54:        int mincol, minrow;
                     55:        int maxcol, maxrow;
                     56:        int curcol, currow;
                     57:
                     58:        if (!terse)
                     59:                wwputs("New window position: ", cmdwin);
                     60:        col = w->ww_w.l;
                     61:        row = w->ww_w.t;
                     62:        wwadd(boxwin, framewin->ww_back);
                     63:        for (;;) {
                     64:                wwbox(boxwin, row - 1, col - 1, w->ww_w.nr + 2, w->ww_w.nc + 2);
                     65:                getminmax(row, w->ww_w.nr, 1, wwnrow,
                     66:                        &currow, &minrow, &maxrow);
                     67:                getminmax(col, w->ww_w.nc, 0, wwncol,
                     68:                        &curcol, &mincol, &maxcol);
                     69:                wwsetcursor(currow, curcol);
                     70:                while (wwpeekc() < 0)
                     71:                        wwiomux();
                     72:                switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) {
                     73:                case 3:
                     74:                        wwunbox(boxwin);
                     75:                        wwdelete(boxwin);
                     76:                        return;
                     77:                case 2:
                     78:                        wwunbox(boxwin);
                     79:                        break;
                     80:                case 1:
                     81:                        wwunbox(boxwin);
                     82:                case 0:
                     83:                        continue;
                     84:                }
                     85:                break;
                     86:        }
                     87:        wwdelete(boxwin);
                     88:        if (!terse)
                     89:                wwputc('\n', cmdwin);
                     90:        wwcurtowin(cmdwin);
                     91:        movewin(w, row, col);
                     92: }
                     93:
                     94: movewin(w, row, col)
1.4       mpech      95: struct ww *w;
1.1       deraadt    96: {
                     97:        struct ww *back = w->ww_back;
                     98:
                     99:        w->ww_alt.t = w->ww_w.t;
                    100:        w->ww_alt.l = w->ww_w.l;
                    101:        wwdelete(w);
                    102:        wwmove(w, row, col);
                    103:        wwadd(w, back);
                    104:        reframe();
                    105: }
                    106:
                    107: /*
                    108:  * Weird stufff, don't ask.
                    109:  */
                    110: getminmax(x, n, a, b, curx, minx, maxx)
1.4       mpech     111: int x, n, a, b;
1.1       deraadt   112: int *curx, *minx, *maxx;
                    113: {
                    114:        if (x < 0)
                    115:                *curx = x + n - 1;
                    116:        else
                    117:                *curx = x;
                    118:
                    119:        if (x <= a)
                    120:                *minx = 1 - n;
                    121:        else if (x <= b - n)
                    122:                *minx = a;
                    123:        else
                    124:                *minx = b - n;
                    125:
                    126:        if (x >= b - n)
                    127:                *maxx = b - 1;
                    128:        else if (x >= a)
                    129:                *maxx = b - n;
                    130:        else
                    131:                *maxx = a;
                    132: }