date and time created 81/01/26 17:03:10 by arnold
authorKen Arnold <arnold@ucbvax.Berkeley.EDU>
Tue, 27 Jan 1981 09:03:10 +0000 (01:03 -0800)
committerKen Arnold <arnold@ucbvax.Berkeley.EDU>
Tue, 27 Jan 1981 09:03:10 +0000 (01:03 -0800)
SCCS-vsn: lib/libcurses/refresh.c 1.1

usr/src/lib/libcurses/refresh.c [new file with mode: 0644]

diff --git a/usr/src/lib/libcurses/refresh.c b/usr/src/lib/libcurses/refresh.c
new file mode 100644 (file)
index 0000000..8c33525
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * make the current screen look like "win" over the area coverd by
+ * win.
+ *
+ * %G% (Berkeley) @(#)refresh.c        1.1
+ */
+
+# include      "curses.ext"
+
+# ifndef DEBUG
+static short   ly, lx;
+# else
+short          ly, lx;
+# endif
+
+WINDOW *_win = NULL;
+
+wrefresh(win)
+reg WINDOW     *win;
+{
+       reg short       wy;
+
+       /*
+        * make sure were in visual state
+        */
+       if (_endwin) {
+               _puts(VS);
+               _puts(TI);
+               _endwin = FALSE;
+       }
+       if (win->_clear || curscr->_clear) {
+               if ((win->_flags & _FULLWIN) || curscr->_clear) {
+                       _puts(CL);
+                       curscr->_curx = curscr->_cury = 0;
+                       curscr->_clear = FALSE;
+                       werase(curscr);
+                       touchwin(win);
+               }
+               win->_clear = FALSE;
+       }
+       if (!CA) {
+               if (win->_curx != 0)
+                       putchar('\n');
+               werase(curscr);
+       }
+# ifdef DEBUG
+       fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n");
+# endif
+       ly = curscr->_cury;
+       lx = curscr->_curx;
+       wy = 0;
+       _win = win;
+       for (wy = 0; wy < win->_maxy; wy++) {
+# ifdef DEBUG
+               fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], win->_lastch[wy]);
+# endif
+               if (win->_firstch[wy] != _NOCHANGE)
+                       if (makech(win, wy) == ERR)
+                               return ERR;
+                       else
+                               win->_firstch[wy] = _NOCHANGE;
+       }
+       if (win->_leave) {
+               curscr->_cury = ly;
+               curscr->_curx = lx;
+               ly -= win->_begy;
+               lx -= win->_begx;
+               if (ly >= 0 && ly < win->_maxy && lx >= 0 && lx < win->_maxx) {
+                       win->_cury = ly;
+                       win->_curx = lx;
+               }
+               else
+                       win->_cury = win->_curx = 0;
+       }
+       else {
+               mvcur(ly, lx, win->_cury + win->_begy, win->_curx + win->_begx);
+               curscr->_cury = win->_cury + win->_begy;
+               curscr->_curx = win->_curx + win->_begx;
+       }
+       _win = NULL;
+       fflush(stdout);
+       return OK;
+}
+
+/*
+ * make a change on the screen
+ */
+# ifndef DEBUG
+static
+# endif
+makech(win, wy)
+reg WINDOW     *win;
+short          wy;
+{
+       reg char        *nsp, *csp, *ce;
+       reg short       wx, lch, y;
+       reg int         nlsp, clsp;     /* last space in lines          */
+
+       wx = win->_firstch[wy];
+       y = wy + win->_begy;
+       lch = win->_lastch[wy];
+       csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
+       nsp = &win->_y[wy][wx];
+       if (CE) {
+               for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
+                       if (ce <= win->_y[wy])
+                               break;
+               nlsp = ce - win->_y[wy];
+       }
+       ce = CE;
+       while (wx <= lch) {
+               if (*nsp != *csp) {
+                       mvcur(ly, lx, y, wx + win->_begx);
+# ifdef DEBUG
+                       fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx);
+# endif        
+                       ly = y;
+                       lx = wx + win->_begx;
+                       while (*nsp != *csp && wx <= lch) {
+                               if (ce && wx >= nlsp && *nsp == ' ') {
+                                       /*
+                                        * check for clear to end-of-line
+                                        */
+                                       ce = &curscr->_y[ly][COLS - 1];
+                                       while (*ce == ' ')
+                                               if (ce-- <= csp)
+                                                       break;
+                                       clsp = ce - curscr->_y[ly] - win->_begx;
+# ifdef DEBUG
+                                       fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp);
+# endif
+                                       if (clsp - nlsp >= strlen(CE)
+                                           && clsp < win->_maxx) {
+# ifdef DEBUG
+                                               fprintf(outf, "MAKECH: using CE\n");
+# endif
+                                               _puts(CE);
+                                               lx = wx + win->_begx;
+                                               while (wx++ <= clsp)
+                                                       *csp++ = ' ';
+                                               goto ret;
+                                       }
+                                       ce = NULL;
+                               }
+                               /*
+                                * enter/exit standout mode as appropriate
+                                */
+                               if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) {
+                                       if (*nsp & _STANDOUT) {
+                                               _puts(SO);
+                                               curscr->_flags |= _STANDOUT;
+                                       }
+                                       else {
+                                               _puts(SE);
+                                               curscr->_flags &= ~_STANDOUT;
+                                       }
+                               }
+                               wx++;
+                               if (wx >= win->_maxx && wy == win->_maxy)
+                                               if (win->_scroll) {
+                                                   if ((win->_flags&(_ENDLINE|_STANDOUT)) == (_ENDLINE|_STANDOUT))
+                                                       if (!MS) {
+                                                               _puts(SE);
+                                                               win->_flags &= ~_STANDOUT;
+                                                       }
+                                                   putchar((*csp = *nsp) & 0177);
+                                                   scroll(win);
+                                                   if (win->_flags&_FULLWIN)
+                                                       scroll(curscr);
+                                                   ly = win->_begy+win->_cury;
+                                                   lx = win->_begx+win->_curx;
+                                                   return OK;
+                                               }
+                                               else if (win->_flags&_SCROLLWIN) {
+                                                   lx = --wx;
+                                                   return ERR;
+                                               }
+                               putchar((*csp++ = *nsp) & 0177);
+                               if (UC && (*nsp & _STANDOUT)) {
+                                       putchar('\b');
+                                       _puts(UC);
+                               }
+                               nsp++;
+                       }
+# ifdef DEBUG
+                       fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx);
+# endif        
+                       if (lx == wx + win->_begx)      /* if no change */
+                               break;
+                       lx = wx + win->_begx;
+               }
+               else if (wx < lch)
+                       while (*nsp == *csp) {
+                               nsp++, csp++;
+                               ++wx;
+                       }
+               else
+                       break;
+# ifdef DEBUG
+               fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
+# endif        
+       }
+ret:
+       if ((win->_flags & _STANDOUT) && !MS) {
+               _puts(SE);
+               win->_flags &= ~_STANDOUT;
+       }
+       return OK;
+}