Annotation of 42BSD/ucb/talk/display.c, revision 1.1

1.1     ! root        1: /* $Header: display.c 1.2 83/04/23 02:09:33 moore Exp $ */
        !             2: 
        !             3: /* The window 'manager', initializes curses and handles the actual
        !             4:  * displaying of text
        !             5:  */
        !             6: 
        !             7: #include "talk.h"
        !             8: 
        !             9: xwin_t my_win;
        !            10: xwin_t his_win;
        !            11: WINDOW *line_win;
        !            12: 
        !            13: int curses_initialized = 0;
        !            14: 
        !            15:     /* max HAS to be a function, it is called with
        !            16:      * a argument of the form --foo at least once.
        !            17:      */
        !            18: 
        !            19: max(a,b)
        !            20: int a, b;
        !            21: {
        !            22:     if (a > b) {
        !            23:        return(a);
        !            24:     } else {
        !            25:        return(b);
        !            26:     }
        !            27: }
        !            28: 
        !            29: /*
        !            30:  * Display some text on somebody's window, processing some control
        !            31:  * characters while we are at it.
        !            32:  */
        !            33: 
        !            34: display(win, text, size)
        !            35: register xwin_t *win;
        !            36: register char *text;
        !            37: int size;
        !            38: {
        !            39:     register int i;
        !            40:     char cch;
        !            41: 
        !            42:     for (i = 0; i < size; i++) {
        !            43: 
        !            44:        if (*text == '\n') {
        !            45:            xscroll(win, 0);
        !            46:            text++;
        !            47:            continue;
        !            48:        }
        !            49: 
        !            50:            /* erase character */
        !            51: 
        !            52:        if (*text == win->cerase) {
        !            53:            wmove(win->x_win, win->x_line, max(--win->x_col, 0));
        !            54:            getyx(win->x_win, win->x_line, win->x_col);
        !            55:            waddch(win->x_win, ' ');
        !            56:            wmove(win->x_win, win->x_line, win->x_col);
        !            57:            getyx(win->x_win, win->x_line, win->x_col);
        !            58:            text++;
        !            59:            continue;
        !            60:        }
        !            61:        /*
        !            62:         * On word erase search backwards until we find
        !            63:         * the beginning of a word or the beginning of
        !            64:         * the line.
        !            65:         */
        !            66:        if (*text == win->werase) {
        !            67:            int endcol, xcol, i, c;
        !            68: 
        !            69:            endcol = win->x_col;
        !            70:            xcol = endcol - 1;
        !            71:            while (xcol >= 0) {
        !            72:                c = readwin(win->x_win, win->x_line, xcol);
        !            73:                if (c != ' ')
        !            74:                        break;
        !            75:                xcol--;
        !            76:            }
        !            77:            while (xcol >= 0) {
        !            78:                c = readwin(win->x_win, win->x_line, xcol);
        !            79:                if (c == ' ')
        !            80:                        break;
        !            81:                xcol--;
        !            82:            }
        !            83:            wmove(win->x_win, win->x_line, xcol + 1);
        !            84:            for (i = xcol + 1; i < endcol; i++)
        !            85:                waddch(win->x_win, ' ');
        !            86:            wmove(win->x_win, win->x_line, xcol + 1);
        !            87:            getyx(win->x_win, win->x_line, win->x_col);
        !            88:            continue;
        !            89:        }
        !            90:            /* line kill */
        !            91:        if (*text == win->kill) {
        !            92:            wmove(win->x_win, win->x_line, 0);
        !            93:            wclrtoeol(win->x_win);
        !            94:            getyx(win->x_win, win->x_line, win->x_col);
        !            95:            text++;
        !            96:            continue;
        !            97:        }
        !            98:        if (*text == '\f') {
        !            99:            if (win == &my_win)
        !           100:                wrefresh(curscr);
        !           101:            text++;
        !           102:            continue;
        !           103:        }
        !           104: 
        !           105:        if (win->x_col == COLS-1) {
        !           106:                /* check for wraparound */
        !           107:            xscroll(win, 0);
        !           108:        }
        !           109: 
        !           110:        if (*text < ' ' && *text != '\t') {
        !           111:            waddch(win->x_win, '^');
        !           112:            getyx(win->x_win, win->x_line, win->x_col);
        !           113: 
        !           114:            if (win->x_col == COLS-1) {
        !           115:                    /* check for wraparound */
        !           116:                xscroll(win, 0);
        !           117:            }
        !           118: 
        !           119:            cch = (*text & 63) + 64;
        !           120:            waddch(win->x_win, cch);
        !           121:        } else {
        !           122:            waddch(win->x_win, *text);
        !           123:        }
        !           124: 
        !           125:        getyx(win->x_win, win->x_line, win->x_col);
        !           126:        text++;
        !           127: 
        !           128:     }
        !           129: wrefresh(win->x_win);
        !           130: }
        !           131: 
        !           132: /*
        !           133: * Read the character at the indicated position in win
        !           134: */
        !           135: readwin(win, line, col)
        !           136: WINDOW *win;
        !           137: {
        !           138: int oldline, oldcol;
        !           139: register int c;
        !           140: 
        !           141: getyx(win, oldline, oldcol);
        !           142: wmove(win, line, col);
        !           143: c = winch(win);
        !           144: wmove(win, oldline, oldcol);
        !           145: return(c);
        !           146: }
        !           147: 
        !           148: /*
        !           149: * Scroll a window, blanking out the line following the current line
        !           150: * so that the current position is obvious
        !           151: */
        !           152: 
        !           153: xscroll(win, flag)
        !           154: register xwin_t *win;
        !           155: int flag;
        !           156: {
        !           157:     if (flag == -1) {
        !           158:        wmove(win->x_win, 0, 0);
        !           159:        win->x_line = 0;
        !           160:        win->x_col = 0;
        !           161:        return;
        !           162:     }
        !           163:     win->x_line = (win->x_line + 1) % win->x_nlines;
        !           164:     win->x_col = 0;
        !           165:     wmove(win->x_win, win->x_line, win->x_col);
        !           166:     wclrtoeol(win->x_win);
        !           167:     wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
        !           168:     wclrtoeol(win->x_win);
        !           169:     wmove(win->x_win, win->x_line, win->x_col);
        !           170: }

unix.superglobalmegacorp.com

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