. use library function to parse memory string
[minix3.git] / lib / curses / update.c
blob968ca9836da7051e5be3737b5a0c53f8b2206702
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(lineno)
116 register int lineno;
118 register int *dstp;
119 register int *srcp;
120 register int dstc;
121 register int srcc;
122 int x;
123 int endx;
125 x = twin->_minchng[lineno];
126 endx = twin->_maxchng[lineno];
127 dstp = curscr->_line[lineno] + x;
128 srcp = twin->_line[lineno] + x;
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++;
138 } else {
139 *dstp++ = *srcp++;
140 x++;
142 } /* for */
143 twin->_minchng[lineno] = _NO_CHANGE;
144 twin->_maxchng[lineno] = _NO_CHANGE;
145 } /* transformline */
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 /****************************************************************/
153 void doupdate()
155 int i;
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);
169 curscr->_curx = twin->_curx;
170 curscr->_cury = twin->_cury;
171 gotoxy(curscr->_cury, curscr->_curx);
172 fflush(stdout);
173 } /* doupdate */