add -a flag
[unix-history] / usr / src / usr.bin / talk / display.c
CommitLineData
d0aeaf5a
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
f9ac90b4
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
b36fc510
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
d0aeaf5a
DF
16 */
17
963ce42e 18#ifndef lint
b36fc510 19static char sccsid[] = "@(#)display.c 5.3 (Berkeley) %G%";
f9ac90b4 20#endif /* not lint */
a07b5a38 21
963ce42e
MK
22/*
23 * The window 'manager', initializes curses and handles the actual
a07b5a38
MK
24 * displaying of text
25 */
a07b5a38
MK
26#include "talk.h"
27
963ce42e
MK
28xwin_t my_win;
29xwin_t his_win;
30WINDOW *line_win;
a07b5a38 31
963ce42e 32int curses_initialized = 0;
a07b5a38 33
963ce42e
MK
34/*
35 * max HAS to be a function, it is called with
36 * a argument of the form --foo at least once.
37 */
a07b5a38 38max(a,b)
963ce42e 39 int a, b;
a07b5a38 40{
963ce42e
MK
41
42 return (a > b ? a : b);
a07b5a38
MK
43}
44
45/*
46 * Display some text on somebody's window, processing some control
47 * characters while we are at it.
48 */
a07b5a38 49display(win, text, size)
963ce42e
MK
50 register xwin_t *win;
51 register char *text;
52 int size;
a07b5a38 53{
963ce42e
MK
54 register int i;
55 char cch;
56
57 for (i = 0; i < size; i++) {
58 if (*text == '\n') {
59 xscroll(win, 0);
60 text++;
61 continue;
62 }
63 /* erase character */
64 if (*text == win->cerase) {
65 wmove(win->x_win, win->x_line, max(--win->x_col, 0));
66 getyx(win->x_win, win->x_line, win->x_col);
67 waddch(win->x_win, ' ');
68 wmove(win->x_win, win->x_line, win->x_col);
69 getyx(win->x_win, win->x_line, win->x_col);
70 text++;
71 continue;
72 }
73 /*
74 * On word erase search backwards until we find
75 * the beginning of a word or the beginning of
76 * the line.
77 */
78 if (*text == win->werase) {
79 int endcol, xcol, i, c;
80
81 endcol = win->x_col;
82 xcol = endcol - 1;
83 while (xcol >= 0) {
84 c = readwin(win->x_win, win->x_line, xcol);
85 if (c != ' ')
86 break;
87 xcol--;
88 }
89 while (xcol >= 0) {
90 c = readwin(win->x_win, win->x_line, xcol);
91 if (c == ' ')
92 break;
93 xcol--;
94 }
95 wmove(win->x_win, win->x_line, xcol + 1);
96 for (i = xcol + 1; i < endcol; i++)
97 waddch(win->x_win, ' ');
98 wmove(win->x_win, win->x_line, xcol + 1);
99 getyx(win->x_win, win->x_line, win->x_col);
100 continue;
101 }
102 /* line kill */
103 if (*text == win->kill) {
104 wmove(win->x_win, win->x_line, 0);
105 wclrtoeol(win->x_win);
106 getyx(win->x_win, win->x_line, win->x_col);
107 text++;
108 continue;
109 }
110 if (*text == '\f') {
111 if (win == &my_win)
112 wrefresh(curscr);
113 text++;
114 continue;
115 }
116 if (win->x_col == COLS-1) {
117 /* check for wraparound */
118 xscroll(win, 0);
119 }
120 if (*text < ' ' && *text != '\t') {
121 waddch(win->x_win, '^');
122 getyx(win->x_win, win->x_line, win->x_col);
123 if (win->x_col == COLS-1) /* check for wraparound */
124 xscroll(win, 0);
125 cch = (*text & 63) + 64;
126 waddch(win->x_win, cch);
127 } else
128 waddch(win->x_win, *text);
129 getyx(win->x_win, win->x_line, win->x_col);
130 text++;
a07b5a38 131 }
963ce42e 132 wrefresh(win->x_win);
a07b5a38
MK
133}
134
135/*
963ce42e
MK
136 * Read the character at the indicated position in win
137 */
a07b5a38 138readwin(win, line, col)
963ce42e 139 WINDOW *win;
a07b5a38 140{
963ce42e
MK
141 int oldline, oldcol;
142 register int c;
143
144 getyx(win, oldline, oldcol);
145 wmove(win, line, col);
146 c = winch(win);
147 wmove(win, oldline, oldcol);
148 return (c);
a07b5a38
MK
149}
150
151/*
963ce42e
MK
152 * Scroll a window, blanking out the line following the current line
153 * so that the current position is obvious
154 */
a07b5a38 155xscroll(win, flag)
963ce42e
MK
156 register xwin_t *win;
157 int flag;
a07b5a38 158{
963ce42e
MK
159
160 if (flag == -1) {
161 wmove(win->x_win, 0, 0);
162 win->x_line = 0;
163 win->x_col = 0;
164 return;
165 }
166 win->x_line = (win->x_line + 1) % win->x_nlines;
a07b5a38 167 win->x_col = 0;
963ce42e
MK
168 wmove(win->x_win, win->x_line, win->x_col);
169 wclrtoeol(win->x_win);
170 wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
171 wclrtoeol(win->x_win);
172 wmove(win->x_win, win->x_line, win->x_col);
a07b5a38 173}