panic() cleanup.
[minix.git] / lib / libcurses / update.c
blob44632608555b27d4d31d0150ac0a054a938d947d
1 #include <curses.h>
2 #include "curspriv.h"
3 #include <termcap.h>
5 static WINDOW *twin; /* used by many routines */
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 /****************************************************************/
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 ));
19 static void gotoxy(row, col)
20 int row, col;
22 poscur(row, col);
23 _cursvar.cursrow = row;
24 _cursvar.curscol = col;
27 /* Update attributes */
28 static void newattr(ch)
29 int ch;
31 extern char *me, *as, *ae, *mb, *md, *mr, *so, *us;
32 static int lastattr = 0;
34 if (lastattr != (ch &= ATR_MSK)) {
35 lastattr = ch;
37 tputs(me, 1, outc);
38 if (ae) tputs(ae, 1, outc);
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);
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?
55 /* Output char with attribute */
56 static void Putchar(ch)
57 int ch;
59 if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS)) {
60 newattr(ch);
61 putchar(ch);
65 /****************************************************************/
66 /* Clrupdate(scr) updates the screen by clearing it and then */
67 /* Redraw it in it's entirety. */
68 /****************************************************************/
70 static void clrupdate(scr)
71 WINDOW *scr;
73 register int *src;
74 register int *dst;
75 register int i;
76 register int j;
77 WINDOW *w;
79 w = curscr;
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++;
101 } else {
102 src++;
103 j++;
105 } /* for */
106 } /* for */
107 fflush(stdout);
108 } /* clrupdate */
110 /****************************************************************/
111 /* Transformline() updates the given physical line to look */
112 /* Like the corresponding line in _cursvar.tmpwin. */
113 /****************************************************************/
115 static void transformline(register int lineno)
117 register int *dstp;
118 register int *srcp;
119 int x;
120 int endx;
122 x = twin->_minchng[lineno];
123 endx = twin->_maxchng[lineno];
124 dstp = curscr->_line[lineno] + x;
125 srcp = twin->_line[lineno] + x;
127 while (x <= endx) {
128 if (*dstp != *srcp) {
129 gotoxy(lineno, x);
130 while (x <= endx && (*dstp != *srcp)) {
131 Putchar(*srcp);
132 *dstp++ = *srcp++;
133 x++;
135 } else {
136 *dstp++ = *srcp++;
137 x++;
139 } /* for */
140 twin->_minchng[lineno] = _NO_CHANGE;
141 twin->_maxchng[lineno] = _NO_CHANGE;
142 } /* transformline */
144 /****************************************************************/
145 /* Doupdate() updates the physical screen to look like _curs- */
146 /* Var.tmpwin if curscr is not 'Clear-marked'. Otherwise it */
147 /* Updates the screen to look like curscr. */
148 /****************************************************************/
150 void doupdate()
152 int i;
154 twin = _cursvar.tmpwin;
155 if (curscr->_clear)
156 clrupdate(curscr);
157 else {
158 if (twin->_clear)
159 clrupdate(twin);
160 else {
161 for (i = 0; i < LINES; i++)
162 if (twin->_minchng[i] != _NO_CHANGE)
163 transformline(i);
166 curscr->_curx = twin->_curx;
167 curscr->_cury = twin->_cury;
168 gotoxy(curscr->_cury, curscr->_curx);
169 fflush(stdout);
170 } /* doupdate */