1 | #include <curses.h>
|
---|
2 | #include "curspriv.h"
|
---|
3 | #include <termcap.h>
|
---|
4 |
|
---|
5 | static WINDOW *twin; /* used by many routines */
|
---|
6 |
|
---|
7 | /****************************************************************/
|
---|
8 | /* Gotoxy() moves the physical cursor to the desired address on */
|
---|
9 | /* The screen. We don't optimize here - on a PC, it takes more */
|
---|
10 | /* Time to optimize than to do things directly. */
|
---|
11 | /****************************************************************/
|
---|
12 |
|
---|
13 | _PROTOTYPE(static void gotoxy, (int row, int col ));
|
---|
14 | _PROTOTYPE(static void newattr, (int ch ));
|
---|
15 | _PROTOTYPE(static void Putchar, (int ch ));
|
---|
16 | _PROTOTYPE(static void clrupdate, (WINDOW *scr ));
|
---|
17 | _PROTOTYPE(static void transformline, (int lineno ));
|
---|
18 |
|
---|
19 | static void gotoxy(row, col)
|
---|
20 | int row, col;
|
---|
21 | {
|
---|
22 | poscur(row, col);
|
---|
23 | _cursvar.cursrow = row;
|
---|
24 | _cursvar.curscol = col;
|
---|
25 | }
|
---|
26 |
|
---|
27 | /* Update attributes */
|
---|
28 | static void newattr(ch)
|
---|
29 | int ch;
|
---|
30 | {
|
---|
31 | extern char *me, *as, *ae, *mb, *md, *mr, *so, *us;
|
---|
32 | static int lastattr = 0;
|
---|
33 |
|
---|
34 | if (lastattr != (ch &= ATR_MSK)) {
|
---|
35 | lastattr = ch;
|
---|
36 |
|
---|
37 | tputs(me, 1, outc);
|
---|
38 | if (ae) tputs(ae, 1, outc);
|
---|
39 |
|
---|
40 | if (ch & A_ALTCHARSET)
|
---|
41 | if (as) tputs(as, 1, outc);
|
---|
42 | if (ch & A_BLINK) tputs(mb, 1, outc);
|
---|
43 | if (ch & A_BOLD) tputs(md, 1, outc);
|
---|
44 | if (ch & A_REVERSE) tputs(mr, 1, outc);
|
---|
45 | if (ch & A_STANDOUT) tputs(so, 1, outc);
|
---|
46 | if (ch & A_UNDERLINE) tputs(us, 1, outc);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | /* Putchar() writes a character, with attributes, to the physical
|
---|
51 | screen, but avoids writing to the lower right screen position.
|
---|
52 | Should it care about am?
|
---|
53 | */
|
---|
54 |
|
---|
55 | /* Output char with attribute */
|
---|
56 | static void Putchar(ch)
|
---|
57 | int ch;
|
---|
58 | {
|
---|
59 | if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS)) {
|
---|
60 | newattr(ch);
|
---|
61 | putchar(ch);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | /****************************************************************/
|
---|
66 | /* Clrupdate(scr) updates the screen by clearing it and then */
|
---|
67 | /* Redraw it in it's entirety. */
|
---|
68 | /****************************************************************/
|
---|
69 |
|
---|
70 | static void clrupdate(scr)
|
---|
71 | WINDOW *scr;
|
---|
72 | {
|
---|
73 | register int *src;
|
---|
74 | register int *dst;
|
---|
75 | register int i;
|
---|
76 | register int j;
|
---|
77 | WINDOW *w;
|
---|
78 |
|
---|
79 | w = curscr;
|
---|
80 |
|
---|
81 | if (scr != w) { /* copy scr to curscr */
|
---|
82 | for (i = 0; i < LINES; i++) {
|
---|
83 | src = scr->_line[i];
|
---|
84 | dst = w->_line[i];
|
---|
85 | for (j = 0; j < COLS; j++) *dst++ = *src++;
|
---|
86 | } /* for */
|
---|
87 | } /* if */
|
---|
88 | newattr(scr->_attrs);
|
---|
89 | clrscr();
|
---|
90 | scr->_clear = FALSE;
|
---|
91 | for (i = 0; i < LINES; i++) { /* update physical screen */
|
---|
92 | src = w->_line[i];
|
---|
93 | j = 0;
|
---|
94 | while (j < COLS) {
|
---|
95 | if (*src != (' ' | ATR_NRM)) {
|
---|
96 | gotoxy(i, j);
|
---|
97 | while (j < COLS && (*src != (' ' | ATR_NRM))) {
|
---|
98 | Putchar(*src++);
|
---|
99 | j++;
|
---|
100 | }
|
---|
101 | } else {
|
---|
102 | src++;
|
---|
103 | j++;
|
---|
104 | }
|
---|
105 | } /* for */
|
---|
106 | } /* for */
|
---|
107 | fflush(stdout);
|
---|
108 | } /* clrupdate */
|
---|
109 |
|
---|
110 | /****************************************************************/
|
---|
111 | /* Transformline() updates the given physical line to look */
|
---|
112 | /* Like the corresponding line in _cursvar.tmpwin. */
|
---|
113 | /****************************************************************/
|
---|
114 |
|
---|
115 | static void transformline(lineno)
|
---|
116 | register int lineno;
|
---|
117 | {
|
---|
118 | register int *dstp;
|
---|
119 | register int *srcp;
|
---|
120 | register int dstc;
|
---|
121 | register int srcc;
|
---|
122 | int x;
|
---|
123 | int endx;
|
---|
124 |
|
---|
125 | x = twin->_minchng[lineno];
|
---|
126 | endx = twin->_maxchng[lineno];
|
---|
127 | dstp = curscr->_line[lineno] + x;
|
---|
128 | srcp = twin->_line[lineno] + x;
|
---|
129 |
|
---|
130 | while (x <= endx) {
|
---|
131 | if ((*dstp != *srcp) || (dstc != srcc)) {
|
---|
132 | gotoxy(lineno, x);
|
---|
133 | while (x <= endx && ((*dstp != *srcp) || (dstc != srcc))) {
|
---|
134 | Putchar(*srcp);
|
---|
135 | *dstp++ = *srcp++;
|
---|
136 | x++;
|
---|
137 | }
|
---|
138 | } else {
|
---|
139 | *dstp++ = *srcp++;
|
---|
140 | x++;
|
---|
141 | }
|
---|
142 | } /* for */
|
---|
143 | twin->_minchng[lineno] = _NO_CHANGE;
|
---|
144 | twin->_maxchng[lineno] = _NO_CHANGE;
|
---|
145 | } /* transformline */
|
---|
146 |
|
---|
147 | /****************************************************************/
|
---|
148 | /* Doupdate() updates the physical screen to look like _curs- */
|
---|
149 | /* Var.tmpwin if curscr is not 'Clear-marked'. Otherwise it */
|
---|
150 | /* Updates the screen to look like curscr. */
|
---|
151 | /****************************************************************/
|
---|
152 |
|
---|
153 | void doupdate()
|
---|
154 | {
|
---|
155 | int i;
|
---|
156 |
|
---|
157 | twin = _cursvar.tmpwin;
|
---|
158 | if (curscr->_clear)
|
---|
159 | clrupdate(curscr);
|
---|
160 | else {
|
---|
161 | if (twin->_clear)
|
---|
162 | clrupdate(twin);
|
---|
163 | else {
|
---|
164 | for (i = 0; i < LINES; i++)
|
---|
165 | if (twin->_minchng[i] != _NO_CHANGE)
|
---|
166 | transformline(i);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | curscr->_curx = twin->_curx;
|
---|
170 | curscr->_cury = twin->_cury;
|
---|
171 | gotoxy(curscr->_cury, curscr->_curx);
|
---|
172 | fflush(stdout);
|
---|
173 | } /* doupdate */
|
---|