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

Annotation of src/usr.bin/talk/display.c, Revision 1.4

1.3       deraadt     1: /*     $OpenBSD: display.c,v 1.2 1996/06/26 05:40:21 deraadt Exp $     */
1.1       deraadt     2: /*     $NetBSD: display.c,v 1.3 1994/12/09 02:14:13 jtc Exp $  */
                      3:
                      4: /*
                      5:  * Copyright (c) 1983, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)display.c  8.1 (Berkeley) 6/6/93";
                     40: #endif
1.3       deraadt    41: static char rcsid[] = "$OpenBSD: display.c,v 1.2 1996/06/26 05:40:21 deraadt Exp $";
1.1       deraadt    42: #endif /* not lint */
                     43:
                     44: /*
                     45:  * The window 'manager', initializes curses and handles the actual
                     46:  * displaying of text
                     47:  */
                     48: #include "talk.h"
1.3       deraadt    49: #include <ctype.h>
1.1       deraadt    50:
                     51: xwin_t my_win;
                     52: xwin_t his_win;
                     53: WINDOW *line_win;
                     54:
                     55: int    curses_initialized = 0;
                     56:
                     57: /*
                     58:  * max HAS to be a function, it is called with
                     59:  * a argument of the form --foo at least once.
                     60:  */
                     61: max(a,b)
                     62:        int a, b;
                     63: {
                     64:
                     65:        return (a > b ? a : b);
                     66: }
                     67:
                     68: /*
                     69:  * Display some text on somebody's window, processing some control
                     70:  * characters while we are at it.
                     71:  */
                     72: display(win, text, size)
                     73:        register xwin_t *win;
                     74:        register char *text;
                     75:        int size;
                     76: {
                     77:        register int i;
                     78:        char cch;
                     79:
                     80:        for (i = 0; i < size; i++) {
1.4     ! deraadt    81:                if (*text == '\n' || *text == '\r') {
1.1       deraadt    82:                        xscroll(win, 0);
                     83:                        text++;
                     84:                        continue;
                     85:                }
                     86:                /* erase character */
                     87:                if (*text == win->cerase) {
                     88:                        wmove(win->x_win, win->x_line, max(--win->x_col, 0));
                     89:                        getyx(win->x_win, win->x_line, win->x_col);
                     90:                        waddch(win->x_win, ' ');
                     91:                        wmove(win->x_win, win->x_line, win->x_col);
                     92:                        getyx(win->x_win, win->x_line, win->x_col);
                     93:                        text++;
                     94:                        continue;
                     95:                }
                     96:                /*
                     97:                 * On word erase search backwards until we find
                     98:                 * the beginning of a word or the beginning of
                     99:                 * the line.
                    100:                 */
                    101:                if (*text == win->werase) {
                    102:                        int endcol, xcol, i, c;
                    103:
                    104:                        endcol = win->x_col;
                    105:                        xcol = endcol - 1;
                    106:                        while (xcol >= 0) {
                    107:                                c = readwin(win->x_win, win->x_line, xcol);
                    108:                                if (c != ' ')
                    109:                                        break;
                    110:                                xcol--;
                    111:                        }
                    112:                        while (xcol >= 0) {
                    113:                                c = readwin(win->x_win, win->x_line, xcol);
                    114:                                if (c == ' ')
                    115:                                        break;
                    116:                                xcol--;
                    117:                        }
                    118:                        wmove(win->x_win, win->x_line, xcol + 1);
                    119:                        for (i = xcol + 1; i < endcol; i++)
                    120:                                waddch(win->x_win, ' ');
                    121:                        wmove(win->x_win, win->x_line, xcol + 1);
                    122:                        getyx(win->x_win, win->x_line, win->x_col);
                    123:                        text++;
                    124:                        continue;
                    125:                }
                    126:                /* line kill */
                    127:                if (*text == win->kill) {
                    128:                        wmove(win->x_win, win->x_line, 0);
                    129:                        wclrtoeol(win->x_win);
                    130:                        getyx(win->x_win, win->x_line, win->x_col);
                    131:                        text++;
                    132:                        continue;
                    133:                }
                    134:                if (*text == '\f') {
                    135:                        if (win == &my_win)
                    136:                                wrefresh(curscr);
                    137:                        text++;
                    138:                        continue;
                    139:                }
                    140:                if (win->x_col == COLS-1) {
                    141:                        /* check for wraparound */
                    142:                        xscroll(win, 0);
                    143:                }
1.3       deraadt   144:                if (!isprint(*text) && *text != '\t') {
1.1       deraadt   145:                        waddch(win->x_win, '^');
                    146:                        getyx(win->x_win, win->x_line, win->x_col);
                    147:                        if (win->x_col == COLS-1) /* check for wraparound */
                    148:                                xscroll(win, 0);
                    149:                        cch = (*text & 63) + 64;
                    150:                        waddch(win->x_win, cch);
                    151:                } else
                    152:                        waddch(win->x_win, *text);
                    153:                getyx(win->x_win, win->x_line, win->x_col);
                    154:                text++;
                    155:        }
                    156:        wrefresh(win->x_win);
                    157: }
                    158:
                    159: /*
                    160:  * Read the character at the indicated position in win
                    161:  */
                    162: readwin(win, line, col)
                    163:        WINDOW *win;
                    164: {
                    165:        int oldline, oldcol;
                    166:        register int c;
                    167:
                    168:        getyx(win, oldline, oldcol);
                    169:        wmove(win, line, col);
                    170:        c = winch(win);
                    171:        wmove(win, oldline, oldcol);
                    172:        return (c);
                    173: }
                    174:
                    175: /*
                    176:  * Scroll a window, blanking out the line following the current line
                    177:  * so that the current position is obvious
                    178:  */
                    179: xscroll(win, flag)
                    180:        register xwin_t *win;
                    181:        int flag;
                    182: {
                    183:
                    184:        if (flag == -1) {
                    185:                wmove(win->x_win, 0, 0);
                    186:                win->x_line = 0;
                    187:                win->x_col = 0;
                    188:                return;
                    189:        }
                    190:        win->x_line = (win->x_line + 1) % win->x_nlines;
                    191:        win->x_col = 0;
                    192:        wmove(win->x_win, win->x_line, win->x_col);
                    193:        wclrtoeol(win->x_win);
                    194:        wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
                    195:        wclrtoeol(win->x_win);
                    196:        wmove(win->x_win, win->x_line, win->x_col);
                    197: }