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