]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/hashmap.c
ncurses 5.6 - patch 20071201
[ncurses.git] / ncurses / tty / hashmap.c
index ba53786a53499af351fd72c28f5e69ef7dd49743..9b60df62d5cfbd1941f38c933cd4da544c35e65e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2006,2007 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            *
@@ -70,7 +70,7 @@ AUTHOR
 #include <curses.priv.h>
 #include <term.h>              /* for back_color_erase */
 
-MODULE_ID("$Id: hashmap.c,v 1.46 2002/09/07 18:13:15 tom Exp $")
+MODULE_ID("$Id: hashmap.c,v 1.56 2007/10/13 18:47:25 Miroslav.Lichvar Exp $")
 
 #ifdef HASHDEBUG
 
@@ -81,7 +81,8 @@ MODULE_ID("$Id: hashmap.c,v 1.46 2002/09/07 18:13:15 tom Exp $")
 # define screen_lines MAXLINES
 # define TEXTWIDTH     1
 int oldnums[MAXLINES], reallines[MAXLINES];
-static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
+static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH];
+static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH];
 # define OLDNUM(n)     oldnums[n]
 # define OLDTEXT(n)    oldtext[n]
 # define NEWTEXT(m)    newtext[m]
@@ -89,7 +90,7 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
 
 #else /* !HASHDEBUG */
 
-# define OLDNUM(n)     _nc_oldnums[n]
+# define OLDNUM(n)     SP->_oldnum_list[n]
 # define OLDTEXT(n)    curscr->_line[n].text
 # define NEWTEXT(m)    newscr->_line[m].text
 # define TEXTWIDTH     (curscr->_maxx+1)
@@ -108,7 +109,9 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH];
 #define HASH_VAL(ch) (ch)
 #endif
 
-static inline unsigned long
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+static NCURSES_INLINE unsigned long
 hash(NCURSES_CH_T * text)
 {
     int i;
@@ -128,8 +131,8 @@ update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to)
     int cost = 0;
     int i;
 
-    for (i = TEXTWIDTH; i > 0; i--)
-       if (!(CharEq(*from++, *to++)))
+    for (i = TEXTWIDTH; i > 0; i--, from++, to++)
+       if (!(CharEq(*from, *to)))
            cost++;
 
     return cost;
@@ -140,13 +143,13 @@ update_cost_from_blank(NCURSES_CH_T * to)
 {
     int cost = 0;
     int i;
-    NCURSES_CH_T blank = NewChar2(BLANK_TEXT, BLANK_ATTR);
+    NCURSES_CH_T blank = blankchar;
 
     if (back_color_erase)
-       AddAttr(blank, (AttrOf(stdscr->_nc_bkgd) & A_COLOR));
+       SetPair(blank, GetPair(stdscr->_nc_bkgd));
 
-    for (i = TEXTWIDTH; i > 0; i--)
-       if (!(CharEq(blank, *to++)))
+    for (i = TEXTWIDTH; i > 0; i--, to++)
+       if (!(CharEq(blank, *to)))
            cost++;
 
     return cost;
@@ -156,7 +159,7 @@ update_cost_from_blank(NCURSES_CH_T * to)
  * Returns true when moving line 'from' to line 'to' seems to be cost
  * effective. 'blank' indicates whether the line 'to' would become blank.
  */
-static inline bool
+static NCURSES_INLINE bool
 cost_effective(const int from, const int to, const bool blank)
 {
     int new_from;
@@ -444,11 +447,14 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
     char line[BUFSIZ], *st;
     int n;
 
-    SP = typeCalloc(SCREEN, 1);
+    if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR)
+       return EXIT_FAILURE;
+    (void) _nc_alloc_screen();
+
     for (n = 0; n < screen_lines; n++) {
        reallines[n] = n;
        oldnums[n] = _NEWINDEX;
-       oldtext[n][0] = newtext[n][0] = '.';
+       CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.';
     }
 
     if (isatty(fileno(stdin)))
@@ -460,7 +466,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
     for (;;) {
        /* grab a test command */
        if (fgets(line, sizeof(line), stdin) == (char *) NULL)
-           exit(EXIT_SUCCESS);
+           break;
 
        switch (line[0]) {
        case '#':               /* comment */
@@ -482,22 +488,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 
        case 'n':               /* use following letters as text of new lines */
            for (n = 0; n < screen_lines; n++)
-               newtext[n][0] = '.';
+               CharOf(newtext[n][0]) = '.';
            for (n = 0; n < screen_lines; n++)
                if (line[n + 1] == '\n')
                    break;
                else
-                   newtext[n][0] = line[n + 1];
+                   CharOf(newtext[n][0]) = line[n + 1];
            break;
 
        case 'o':               /* use following letters as text of old lines */
            for (n = 0; n < screen_lines; n++)
-               oldtext[n][0] = '.';
+               CharOf(oldtext[n][0]) = '.';
            for (n = 0; n < screen_lines; n++)
                if (line[n + 1] == '\n')
                    break;
                else
-                   oldtext[n][0] = line[n + 1];
+                   CharOf(oldtext[n][0]) = line[n + 1];
            break;
 
        case 'd':               /* dump state of test arrays */
@@ -506,12 +512,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 #endif
            (void) fputs("Old lines: [", stdout);
            for (n = 0; n < screen_lines; n++)
-               putchar(oldtext[n][0]);
+               putchar(CharOf(oldtext[n][0]));
            putchar(']');
            putchar('\n');
            (void) fputs("New lines: [", stdout);
            for (n = 0; n < screen_lines; n++)
-               putchar(newtext[n][0]);
+               putchar(CharOf(newtext[n][0]));
            putchar(']');
            putchar('\n');
            break;
@@ -525,12 +531,17 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
            _nc_scroll_optimize();
            (void) fputs("Done.\n", stderr);
            break;
+       default:
        case '?':
            usage();
            break;
        }
     }
+#if NO_LEAKS
+    _nc_free_and_exit(EXIT_SUCCESS);
+#else
     return EXIT_SUCCESS;
+#endif
 }
 
 #endif /* HASHDEBUG */