]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/tty_update.c
ncurses 5.7 - patch 20100619
[ncurses.git] / ncurses / tty / tty_update.c
index 7e99b358eb4e93d796d68fda3d678029b1b7791e..dd6c3b670597c3cafd95860d7b32fd30de05636d 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -82,7 +82,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: tty_update.c,v 1.255 2009/05/10 00:53:14 tom Exp $")
+MODULE_ID("$Id: tty_update.c,v 1.263 2010/05/01 20:44:34 tom Exp $")
 
 /*
  * This define controls the line-breakout optimization.  Every once in a
@@ -192,12 +192,15 @@ position_check(NCURSES_SP_DCLx int expected_y, int expected_x, char *legend)
 static NCURSES_INLINE void
 GoTo(NCURSES_SP_DCLx int const row, int const col)
 {
-    TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
-                   row, col, SP_PARM->_cursrow, SP_PARM->_curscol));
+    TR(TRACE_MOVE, ("GoTo(%p, %d, %d) from (%d, %d)",
+                   (void *) SP_PARM, row, col, SP_PARM->_cursrow, SP_PARM->_curscol));
 
     position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "GoTo");
 
-    mvcur(SP_PARM->_cursrow, SP_PARM->_curscol, row, col);
+    TINFO_MVCUR(NCURSES_SP_ARGx
+               SP_PARM->_cursrow,
+               SP_PARM->_curscol,
+               row, col);
     position_check(SP_PARM, SP_PARM->_cursrow, SP_PARM->_curscol, "GoTo2");
 }
 
@@ -558,7 +561,8 @@ EmitRange(NCURSES_SP_DCLx const NCURSES_CH_T * ntext, int num)
                && runcount > SP_PARM->_ech_cost + SP_PARM->_cup_ch_cost
                && can_clear_with(NCURSES_SP_ARGx CHREF(ntext0))) {
                UpdateAttrs(SP_PARM, ntext0);
-               NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx TPARM_1(erase_chars, runcount));
+               NCURSES_SP_NAME(putp) (NCURSES_SP_ARGx
+                                      TPARM_1(erase_chars, runcount));
 
                /*
                 * If this is the last part of the given interval,
@@ -624,7 +628,10 @@ PutRange(NCURSES_SP_DCLx
     int i, j, same;
 
     TR(TRACE_CHARPUT, ("PutRange(%p, %p, %p, %d, %d, %d)",
-                      SP_PARM, otext, ntext, row, first, last));
+                      (void *) SP_PARM,
+                      (const void *) otext,
+                      (const void *) ntext,
+                      row, first, last));
 
     if (otext != ntext
        && (last - first + 1) > SP_PARM->_inline_cost) {
@@ -658,7 +665,7 @@ PutRange(NCURSES_SP_DCLx
                if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
 
 NCURSES_EXPORT(int)
-NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
+TINFO_DOUPDATE(NCURSES_SP_DCL0)
 {
     int i;
     int nonempty;
@@ -666,10 +673,29 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
     struct tms before, after;
 #endif /* USE_TRACE_TIMES */
 
-    T((T_CALLED("doupdate()")));
+    T((T_CALLED("_nc_tinfo:doupdate(%p)"), (void *) SP_PARM));
+
+#if !USE_REENTRANT
+    /*
+     * It is "legal" but unlikely that an application could assign a new
+     * value to one of the standard windows.  Check for that possibility
+     * and try to recover.
+     *
+     * We do not allow applications to assign new values in the reentrant
+     * model.
+     */
+#define SyncScreens(internal,exported) \
+       if (internal == 0) internal = exported; \
+       if (internal != exported) exported = internal
+
+    SyncScreens(CurScreen(SP_PARM), curscr);
+    SyncScreens(NewScreen(SP_PARM), newscr);
+    SyncScreens(StdScreen(SP_PARM), stdscr);
+#endif
 
     if (CurScreen(SP_PARM) == 0
-       || NewScreen(SP_PARM) == 0)
+       || NewScreen(SP_PARM) == 0
+       || StdScreen(SP_PARM) == 0)
        returnCode(ERR);
 
 #ifdef TRACE
@@ -787,9 +813,8 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
                    /* find end of span, if it's onscreen */
                    for (m = i; m < screen_lines(SP_PARM); m++) {
                        for (; n < screen_columns(SP_PARM); n++) {
-                           attr_t testattr
-                           = AttrOf(NewScreen(SP_PARM)->_line[m].text[n]);
-
+                           attr_t testattr =
+                           AttrOf(NewScreen(SP_PARM)->_line[m].text[n]);
                            if ((testattr & SP_PARM->_xmc_triggers) == rattr) {
                                end_onscreen = TRUE;
                                TR(TRACE_ATTRS,
@@ -851,8 +876,7 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
                    /* turn off new attributes over span */
                    for (p = i; p < screen_lines(SP_PARM); p++) {
                        for (; q < screen_columns(SP_PARM); q++) {
-                           attr_t testattr =
-                           AttrOf(NewScreen(SP_PARM)->_line[p].text[q]);
+                           attr_t testattr = AttrOf(newscr->_line[p].text[q]);
                            if ((testattr & SP_PARM->_xmc_triggers) == rattr)
                                goto foundend;
                            RemAttr(NewScreen(SP_PARM)->_line[p].text[q], turnon);
@@ -902,7 +926,7 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
        nonempty = min(screen_lines(SP_PARM), NewScreen(SP_PARM)->_maxy + 1);
 
        if (SP_PARM->_scrolling) {
-           _nc_scroll_optimize();
+           NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_ARG);
        }
 
        nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
@@ -919,8 +943,8 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
            }
 
            /*
-            * newscr.line[i].firstchar is normally set
-            * by wnoutrefresh.  curscr.line[i].firstchar
+            * newscr->line[i].firstchar is normally set
+            * by wnoutrefresh.  curscr->line[i].firstchar
             * is normally set by _nc_scroll_window in the
             * vertical-movement optimization code,
             */
@@ -984,11 +1008,11 @@ NCURSES_SP_NAME(doupdate) (NCURSES_SP_DCL0)
     returnCode(OK);
 }
 
-#if NCURSES_SP_FUNCS
+#if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)
 NCURSES_EXPORT(int)
 doupdate(void)
 {
-    return NCURSES_SP_NAME(doupdate) (CURRENT_SCREEN);
+    return TINFO_DOUPDATE(CURRENT_SCREEN);
 }
 #endif
 
@@ -1003,14 +1027,14 @@ doupdate(void)
  *     in the wbkgd() call.  Assume 'stdscr' for this case.
  */
 #define BCE_ATTRS (A_NORMAL|A_COLOR)
-#define BCE_BKGD(win) (((win) == CurScreen(SP_PARM) ? StdScreen(SP_PARM) : (win))->_nc_bkgd)
+#define BCE_BKGD(sp,win) (((win) == CurScreen(sp) ? StdScreen(sp) : (win))->_nc_bkgd)
 
 static NCURSES_INLINE NCURSES_CH_T
 ClrBlank(NCURSES_SP_DCLx WINDOW *win)
 {
     NCURSES_CH_T blank = blankchar;
     if (back_color_erase)
-       AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
+       AddAttr(blank, (AttrOf(BCE_BKGD(SP_PARM, win)) & BCE_ATTRS));
     return blank;
 }
 
@@ -1054,24 +1078,24 @@ ClrToEOL(NCURSES_SP_DCLx NCURSES_CH_T blank, bool needclear)
 {
     int j;
 
-    if (CurScreen(SP_PARM) != 0
-       && SP_PARM->_cursrow >= 0) {
-       for (j = SP_PARM->_curscol; j < screen_columns(SP_PARM); j++) {
-           if (j >= 0) {
-               NCURSES_CH_T *cp =
-               &(CurScreen(SP_PARM)->_line[SP_PARM->_cursrow].text[j]);
-
-               if (!CharEq(*cp, blank)) {
-                   *cp = blank;
-                   needclear = TRUE;
+    if (SP_PARM != 0) {
+       if (CurScreen(SP_PARM) != 0
+           && SP_PARM->_cursrow >= 0) {
+           for (j = SP_PARM->_curscol; j < screen_columns(SP_PARM); j++) {
+               if (j >= 0) {
+                   NCURSES_CH_T *cp =
+                   &(CurScreen(SP_PARM)->_line[SP_PARM->_cursrow].text[j]);
+
+                   if (!CharEq(*cp, blank)) {
+                       *cp = blank;
+                       needclear = TRUE;
+                   }
                }
            }
        }
-    } else {
-       needclear = TRUE;
     }
 
-    if (needclear) {
+    if (needclear && (SP_PARM != 0)) {
        UpdateAttrs(SP_PARM, blank);
        TPUTS_TRACE("clr_eol");
        if (clr_eol && SP_PARM->_el_cost <= (screen_columns(SP_PARM) - SP_PARM->_curscol)) {
@@ -1172,7 +1196,7 @@ ClrBottom(NCURSES_SP_DCLx int total)
 #define xmc_turn_on(sp,a,b) ((((a)^(b)) & ~(a) & (sp)->_xmc_triggers) != 0)
 #endif
 
-#define xmc_new(sp,r,c) NewScreen(SP_PARM)->_line[r].text[c]
+#define xmc_new(sp,r,c) NewScreen(sp)->_line[r].text[c]
 #define xmc_turn_off(sp,a,b) xmc_turn_on(sp,b,a)
 #endif /* USE_XMC_SUPPORT */
 
@@ -1180,7 +1204,7 @@ ClrBottom(NCURSES_SP_DCLx int total)
 **     TransformLine(lineno)
 **
 **     Transform the given line in curscr to the one in newscr, using
-**     Insert/Delete Character if _nc_idcok && has_ic().
+**     Insert/Delete Character if idcok && has_ic().
 **
 **             firstChar = position of first different character in line
 **             oLastChar = position of last different character in old line
@@ -1203,7 +1227,7 @@ TransformLine(NCURSES_SP_DCLx int const lineno)
     int n;
     bool attrchanged = FALSE;
 
-    TR(TRACE_UPDATE, (T_CALLED("TransformLine(%p, %d)"), SP_PARM, lineno));
+    TR(TRACE_UPDATE, (T_CALLED("TransformLine(%p, %d)"), (void *) SP_PARM, lineno));
 
     /* copy new hash value to old one */
     if (SP_PARM->oldhash && SP_PARM->newhash)
@@ -1252,8 +1276,8 @@ TransformLine(NCURSES_SP_DCLx int const lineno)
     if (attrchanged) {         /* we may have to disregard the whole line */
        GoTo(NCURSES_SP_ARGx lineno, firstChar);
        ClrToEOL(NCURSES_SP_ARGx
-                ClrBlank(NCURSES_SP_ARGx CurScreen(SP_PARM)),
-                FALSE);
+                ClrBlank(NCURSES_SP_ARGx
+                         CurScreen(SP_PARM)), FALSE);
        PutRange(NCURSES_SP_ARGx
                 oldLine, newLine, lineno, 0,
                 screen_columns(SP_PARM) - 1);
@@ -1413,7 +1437,8 @@ TransformLine(NCURSES_SP_DCLx int const lineno)
            ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
        } else if ((nLastChar != oLastChar)
                   && (!CharEq(newLine[nLastChar], oldLine[oLastChar])
-                      || !(_nc_idcok && has_ic()))) {
+                      || !(SP_PARM->_nc_sp_idcok
+                           && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG)))) {
            GoTo(NCURSES_SP_ARGx lineno, firstChar);
            if ((oLastChar - nLastChar) > SP_PARM->_el_cost) {
                if (PutRange(NCURSES_SP_ARGx
@@ -1557,7 +1582,6 @@ ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
        } else if (clr_eos) {
            SP_PARM->_cursrow = SP_PARM->_curscol = -1;
            GoTo(NCURSES_SP_ARGx 0, 0);
-
            UpdateAttrs(SP_PARM, blank);
            TPUTS_TRACE("clr_eos");
            NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
@@ -1566,7 +1590,6 @@ ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
                                    NCURSES_SP_NAME(_nc_outch));
        } else if (clr_eol) {
            SP_PARM->_cursrow = SP_PARM->_curscol = -1;
-
            UpdateAttrs(SP_PARM, blank);
            for (i = 0; i < screen_lines(SP_PARM); i++) {
                GoTo(NCURSES_SP_ARGx i, 0);
@@ -1603,7 +1626,9 @@ ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
 static void
 InsStr(NCURSES_SP_DCLx NCURSES_CH_T * line, int count)
 {
-    TR(TRACE_UPDATE, ("InsStr(%p, %p,%d) called", SP_PARM, line, count));
+    TR(TRACE_UPDATE, ("InsStr(%p, %p,%d) called",
+                     (void *) SP_PARM,
+                     (void *) line, count));
 
     /* Prefer parm_ich as it has the smallest cost - no need to shift
      * the whole line on each character. */
@@ -1662,7 +1687,7 @@ DelChar(NCURSES_SP_DCLx int count)
     int n;
 
     TR(TRACE_UPDATE, ("DelChar(%p, %d) called, position = (%ld,%ld)",
-                     SP_PARM, count,
+                     (void *) SP_PARM, count,
                      (long) NewScreen(SP_PARM)->_cury,
                      (long) NewScreen(SP_PARM)->_curx));
 
@@ -1914,12 +1939,18 @@ NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
                              int maxy)
 /* scroll region from top to bot by n lines */
 {
-    NCURSES_CH_T blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
+    NCURSES_CH_T blank;
     int i;
     bool cursor_saved = FALSE;
     int res;
 
-    TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy));
+    TR(TRACE_MOVE, ("_nc_scrolln(%p, %d, %d, %d, %d)",
+                   (void *) SP_PARM, n, top, bot, maxy));
+
+    if (!IsValidScreen(SP_PARM))
+       return (ERR);
+
+    blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
 
 #if USE_XMC_SUPPORT
     /*
@@ -1963,7 +1994,7 @@ NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
            SP_PARM->_cursrow = SP_PARM->_curscol = -1;
        }
 
-       if (res == ERR && _nc_idlok)
+       if (res == ERR && SP_PARM->_nc_sp_idlok)
            res = scroll_idl(NCURSES_SP_ARGx n, top, bot - n + 1, blank);
 
        /*
@@ -2014,7 +2045,7 @@ NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
            SP_PARM->_cursrow = SP_PARM->_curscol = -1;
        }
 
-       if (res == ERR && _nc_idlok)
+       if (res == ERR && SP_PARM->_nc_sp_idlok)
            res = scroll_idl(NCURSES_SP_ARGx -n, bot + n + 1, top, blank);
 
        /*
@@ -2060,7 +2091,7 @@ NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_DCL0)
 
     /* reset color pairs and definitions */
     if (SP_PARM->_coloron || SP_PARM->_color_defs)
-       _nc_reset_colors();
+       NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
 
     /* restore user-defined colors, if any */
     if (SP_PARM->_color_defs < 0) {
@@ -2132,20 +2163,23 @@ NCURSES_SP_NAME(_nc_screen_wrap) (NCURSES_SP_DCL0)
        static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
        SP_PARM->_default_color = TRUE;
        NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
-                                      -1, 0,
+                                      -1,
+                                      0,
                                       FALSE,
                                       NCURSES_SP_NAME(_nc_outch));
        SP_PARM->_default_color = FALSE;
 
-       mvcur(SP_PARM->_cursrow,
-             SP_PARM->_curscol,
-             screen_lines(SP_PARM) - 1, 0);
+       TINFO_MVCUR(NCURSES_SP_ARGx
+                   SP_PARM->_cursrow,
+                   SP_PARM->_curscol,
+                   screen_lines(SP_PARM) - 1,
+                   0);
 
        ClrToEOL(NCURSES_SP_ARGx blank, TRUE);
     }
 #endif
     if (SP_PARM->_color_defs) {
-       _nc_reset_colors();
+       NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
     }
 }