]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/hardscroll.c
ncurses 5.0
[ncurses.git] / ncurses / tty / hardscroll.c
similarity index 89%
rename from ncurses/hardscroll.c
rename to ncurses/tty/hardscroll.c
index f37008e76073f6b571e2c376ba5fa69cbdb8d0ac..b80d08aa5467764cf5fe0a6d0dd30e7a243d0d10 100644 (file)
@@ -146,19 +146,32 @@ AUTHOR
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: hardscroll.c,v 1.29 1998/02/11 12:13:57 tom Exp $")
+MODULE_ID("$Id: hardscroll.c,v 1.33 1999/02/27 20:01:29 tom Exp $")
 
 #if defined(SCROLLDEBUG) || defined(HASHDEBUG)
+
+# undef screen_lines
+# define screen_lines MAXLINES
 int oldnums[MAXLINES];
-#define OLDNUM(n)      oldnums[n]
-#undef T
-#define T(x)           (void) printf x ; (void) putchar('\n');
-#else
-#include <curses.h>
-#define OLDNUM(n)      newscr->_line[n].oldindex
-#ifndef _NEWINDEX
-#define _NEWINDEX      -1
-#endif /* _NEWINDEX */
+# define OLDNUM(n)     oldnums[n]
+# define _tracef       printf
+# undef TR
+# define TR(n, a)      if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
+
+#else /* no debug */
+
+/* OLDNUM(n) indicates which line will be shifted to the position n.
+   if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from
+   somewhere. */
+# if USE_HASHMAP
+int *_nc_oldnums = 0;
+static int oldnums_allocated = 0;
+#  define oldnums       _nc_oldnums
+#  define OLDNUM(n)    oldnums[n]
+# else /* !USE_HASHMAP */
+#  define OLDNUM(n)    newscr->_line[n].oldindex
+# endif /* !USE_HASHMAP */
+
 #endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */
 
 
@@ -170,6 +183,22 @@ void _nc_scroll_optimize(void)
 
     TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins"));
 
+#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
+#if USE_HASHMAP
+    /* get enough storage */
+    if (oldnums_allocated < screen_lines)
+    {
+       int *new_oldnums = typeRealloc(int, screen_lines, oldnums);
+       if (!new_oldnums)
+           return;
+       oldnums = new_oldnums;
+       oldnums_allocated = screen_lines;
+    }
+    /* calculate the indices */
+    _nc_hash_map();
+#endif
+#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
+
 #ifdef TRACE
     if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE))
        _nc_linedump();
@@ -182,10 +211,10 @@ void _nc_scroll_optimize(void)
            i++;
        if (i >= screen_lines)
            break;
-           
+
        shift = OLDNUM(i) - i; /* shift > 0 */
        start = i;
-       
+
        i++;
        while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift)
            i++;
@@ -208,10 +237,10 @@ void _nc_scroll_optimize(void)
            i--;
        if (i < 0)
            break;
-           
+
        shift = OLDNUM(i) - i; /* shift < 0 */
        end = i;
-       
+
        i--;
        while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift)
            i--;
@@ -228,7 +257,7 @@ void _nc_scroll_optimize(void)
     }
 }
 
-#if defined(TRACE) || defined(SCROLLDEBUG)
+#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
 void _nc_linedump(void)
 /* dump the state of the real and virtual oldnum fields */
 {
@@ -239,7 +268,7 @@ void _nc_linedump(void)
     size_t     want = (screen_lines + 1) * 4;
 
     if (have < want)
-       buf = malloc(have = want);
+       buf = typeMalloc(char, have = want);
 
     (void) strcpy(buf, "virt");
     for (n = 0; n < screen_lines; n++)