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