Annotation of researchv9/X11/src/X.V11R1/clients/xterm/cursor.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     $Source: /u1/X11/clients/xterm/RCS/cursor.c,v $
        !             3:  *     $Header: cursor.c,v 1.6 87/09/11 08:17:27 toddb Exp $
        !             4:  */
        !             5: 
        !             6: #ifndef lint
        !             7: static char *rcsid_cursor_c = "$Header: cursor.c,v 1.6 87/09/11 08:17:27 toddb Exp $";
        !             8: #endif lint
        !             9: 
        !            10: #include <X11/copyright.h>
        !            11: 
        !            12: /*
        !            13:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !            14:  *
        !            15:  *                         All Rights Reserved
        !            16:  *
        !            17:  * Permission to use, copy, modify, and distribute this software and its
        !            18:  * documentation for any purpose and without fee is hereby granted,
        !            19:  * provided that the above copyright notice appear in all copies and that
        !            20:  * both that copyright notice and this permission notice appear in
        !            21:  * supporting documentation, and that the name of Digital Equipment
        !            22:  * Corporation not be used in advertising or publicity pertaining to
        !            23:  * distribution of the software without specific, written prior permission.
        !            24:  *
        !            25:  *
        !            26:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            27:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            28:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            29:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            30:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            31:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            32:  * SOFTWARE.
        !            33:  */
        !            34: 
        !            35: /* cursor.c */
        !            36: 
        !            37: 
        !            38: #ifndef lint
        !            39: static char rcs_id[] = "$Header: cursor.c,v 1.6 87/09/11 08:17:27 toddb Exp $";
        !            40: #endif lint
        !            41: 
        !            42: #include <X11/Xlib.h>
        !            43: #include <stdio.h>
        !            44: #include <sys/ioctl.h>
        !            45: #include "ptyx.h"
        !            46: 
        !            47: extern void bcopy();
        !            48: 
        !            49: /*
        !            50:  * Moves the cursor to the specified position, checking for bounds.
        !            51:  * (this includes scrolling regions)
        !            52:  * The origin is considered to be 0, 0 for this procedure.
        !            53:  */
        !            54: CursorSet(screen, row, col, flags)
        !            55: register TScreen       *screen;
        !            56: register int   row, col;
        !            57: unsigned       flags;
        !            58: {
        !            59:        register int maxr;
        !            60: 
        !            61:        col = (col < 0 ? 0 : col);
        !            62:        screen->cur_col = (col <= screen->max_col ? col : screen->max_col);
        !            63:        maxr = screen->max_row;
        !            64:        if (flags & ORIGIN) {
        !            65:                row += screen->top_marg;
        !            66:                maxr = screen->bot_marg;
        !            67:        }
        !            68:        row = (row < 0 ? 0 : row);
        !            69:        screen->cur_row = (row <= maxr ? row : maxr);
        !            70:        screen->do_wrap = 0;
        !            71: }
        !            72: 
        !            73: /*
        !            74:  * moves the cursor left n, no wrap around
        !            75:  */
        !            76: CursorBack(screen, n)
        !            77: register TScreen       *screen;
        !            78: int            n;
        !            79: {
        !            80:        register int i, j, k, rev;
        !            81:        extern Terminal term;
        !            82: 
        !            83:        if((rev = (term.flags & (REVERSEWRAP | WRAPAROUND)) ==
        !            84:         (REVERSEWRAP | WRAPAROUND)) && screen->do_wrap)
        !            85:                n--;
        !            86:        if ((screen->cur_col -= n) < 0) {
        !            87:                if(rev) {
        !            88:                        if((i = (j = screen->max_col + 1) * screen->cur_row +
        !            89:                         screen->cur_col) < 0) {
        !            90:                                k = j * (screen->max_row + 1);
        !            91:                                i += ((-i) / k + 1) * k;
        !            92:                        }
        !            93:                        screen->cur_row = i / j;
        !            94:                        screen->cur_col = i % j;
        !            95:                } else
        !            96:                        screen->cur_col = 0;
        !            97:        }
        !            98:        screen->do_wrap = 0;
        !            99: }
        !           100: 
        !           101: /*
        !           102:  * moves the cursor forward n, no wraparound
        !           103:  */
        !           104: CursorForward(screen, n)
        !           105: register TScreen       *screen;
        !           106: int            n;
        !           107: {
        !           108:        screen->cur_col += n;
        !           109:        if (screen->cur_col > screen->max_col)
        !           110:                screen->cur_col = screen->max_col;
        !           111:        screen->do_wrap = 0;
        !           112: }
        !           113: 
        !           114: /* 
        !           115:  * moves the cursor down n, no scrolling.
        !           116:  * Won't pass bottom margin or bottom of screen.
        !           117:  */
        !           118: CursorDown(screen, n)
        !           119: register TScreen       *screen;
        !           120: int            n;
        !           121: {
        !           122:        register int max;
        !           123: 
        !           124:        max = (screen->cur_row > screen->bot_marg ?
        !           125:                screen->max_row : screen->bot_marg);
        !           126: 
        !           127:        screen->cur_row += n;
        !           128:        if (screen->cur_row > max)
        !           129:                screen->cur_row = max;
        !           130:        screen->do_wrap = 0;
        !           131: }
        !           132: 
        !           133: /* 
        !           134:  * moves the cursor up n, no linestarving.
        !           135:  * Won't pass top margin or top of screen.
        !           136:  */
        !           137: CursorUp(screen, n)
        !           138: register TScreen       *screen;
        !           139: int            n;
        !           140: {
        !           141:        register int min;
        !           142: 
        !           143:        min = (screen->cur_row < screen->top_marg ?
        !           144:                0 : screen->top_marg);
        !           145: 
        !           146:        screen->cur_row -= n;
        !           147:        if (screen->cur_row < min)
        !           148:                screen->cur_row = min;
        !           149:        screen->do_wrap = 0;
        !           150: }
        !           151: 
        !           152: /* 
        !           153:  * Moves cursor down amount lines, scrolls if necessary.
        !           154:  * Won't leave scrolling region. No carriage return.
        !           155:  */
        !           156: Index(screen, amount)
        !           157: register TScreen       *screen;
        !           158: register int   amount;
        !           159: {
        !           160:        register int j;
        !           161: 
        !           162:        /* 
        !           163:         * indexing when below scrolling region is cursor down.
        !           164:         * if cursor high enough, no scrolling necessary.
        !           165:         */
        !           166:        if (screen->cur_row > screen->bot_marg
        !           167:         || screen->cur_row + amount <= screen->bot_marg) {
        !           168:                CursorDown(screen, amount);
        !           169:                return;
        !           170:        }
        !           171: 
        !           172:        CursorDown(screen, j = screen->bot_marg - screen->cur_row);
        !           173:        Scroll(screen, amount - j);
        !           174: }
        !           175: 
        !           176: /*
        !           177:  * Moves cursor up amount lines, reverse scrolls if necessary.
        !           178:  * Won't leave scrolling region. No carriage return.
        !           179:  */
        !           180: RevIndex(screen, amount)
        !           181: register TScreen       *screen;
        !           182: register int   amount;
        !           183: {
        !           184:        /*
        !           185:         * reverse indexing when above scrolling region is cursor up.
        !           186:         * if cursor low enough, no reverse indexing needed
        !           187:         */
        !           188:        if (screen->cur_row < screen->top_marg
        !           189:         || screen->cur_row-amount >= screen->top_marg) {
        !           190:                CursorUp(screen, amount);
        !           191:                return;
        !           192:        }
        !           193: 
        !           194:        RevScroll(screen, amount - (screen->cur_row - screen->top_marg));
        !           195:        CursorUp(screen, screen->cur_row - screen->top_marg);
        !           196: }
        !           197: 
        !           198: /*
        !           199:  * Moves Cursor To First Column In Line
        !           200:  */
        !           201: CarriageReturn(screen)
        !           202: register TScreen *screen;
        !           203: {
        !           204:        screen->cur_col = 0;
        !           205:        screen->do_wrap = 0;
        !           206: }
        !           207: 
        !           208: /*
        !           209:  * Save Cursor and Attributes
        !           210:  */
        !           211: CursorSave(term, sc)
        !           212: register Terminal *term;
        !           213: register SavedCursor *sc;
        !           214: {
        !           215:        register TScreen *screen = &term->screen;
        !           216: 
        !           217:        sc->row = screen->cur_row;
        !           218:        sc->col = screen->cur_col;
        !           219:        sc->flags = term->flags;
        !           220:        sc->curgl = screen->curgl;
        !           221:        sc->curgr = screen->curgr;
        !           222:        bcopy(screen->gsets, sc->gsets, sizeof(screen->gsets));
        !           223: }
        !           224: 
        !           225: /*
        !           226:  * Restore Cursor and Attributes
        !           227:  */
        !           228: CursorRestore(term, sc)
        !           229: register Terminal *term;
        !           230: register SavedCursor *sc;
        !           231: {
        !           232:        register TScreen *screen = &term->screen;
        !           233: 
        !           234:        bcopy(sc->gsets, screen->gsets, sizeof(screen->gsets));
        !           235:        screen->curgl = sc->curgl;
        !           236:        screen->curgr = sc->curgr;
        !           237:        term->flags &= ~(BOLD|INVERSE|UNDERLINE);
        !           238:        term->flags |= sc->flags & (BOLD|INVERSE|UNDERLINE);
        !           239:        CursorSet(screen, sc->row, sc->col, term->flags);
        !           240: }

unix.superglobalmegacorp.com

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