]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/hashmap.c
ncurses 5.9 - patch 20130525
[ncurses.git] / ncurses / tty / hashmap.c
index 05c379199c217f4aa513b1f8d4f1aef5ccc7ff95..4a723865a4fdb0d425c3d67efd7bbe0050621865 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2007,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -69,7 +69,11 @@ AUTHOR
 
 #include <curses.priv.h>
 
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: hashmap.c,v 1.57 2009/04/18 19:03:50 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: hashmap.c,v 1.63 2011/10/22 16:34:50 tom Exp $")
 
 #ifdef HASHDEBUG
 
 
 #ifdef HASHDEBUG
 
@@ -90,10 +94,10 @@ static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH];
 #else /* !HASHDEBUG */
 
 # define OLDNUM(sp,n)  (sp)->_oldnum_list[n]
 #else /* !HASHDEBUG */
 
 # define OLDNUM(sp,n)  (sp)->_oldnum_list[n]
-# define OLDTEXT(sp,n) (sp)->_curscr->_line[n].text
-# define NEWTEXT(sp,m) (sp)->_newscr->_line[m].text
-# define TEXTWIDTH(sp) ((sp)->_curscr->_maxx+1)
-# define PENDING(sp,n)  ((sp)->_newscr->_line[n].firstchar != _NOCHANGE)
+# define OLDTEXT(sp,n) CurScreen(sp)->_line[n].text
+# define NEWTEXT(sp,m) NewScreen(sp)->_line[m].text
+# define TEXTWIDTH(sp) (CurScreen(sp)->_maxx + 1)
+# define PENDING(sp,n)  (NewScreen(sp)->_line[n].firstchar != _NOCHANGE)
 
 #endif /* !HASHDEBUG */
 
 
 #endif /* !HASHDEBUG */
 
@@ -118,7 +122,7 @@ hash(SCREEN *sp, NCURSES_CH_T * text)
     unsigned long result = 0;
     for (i = TEXTWIDTH(sp); i > 0; i--) {
        ch = *text++;
     unsigned long result = 0;
     for (i = TEXTWIDTH(sp); i > 0; i--) {
        ch = *text++;
-       result += (result << 5) + HASH_VAL(ch);
+       result += (result << 5) + (unsigned long) HASH_VAL(ch);
     }
     return result;
 }
     }
     return result;
 }
@@ -159,7 +163,7 @@ update_cost_from_blank(SCREEN *sp, NCURSES_CH_T * to)
  * effective. 'blank' indicates whether the line 'to' would become blank.
  */
 static NCURSES_INLINE bool
  * effective. 'blank' indicates whether the line 'to' would become blank.
  */
 static NCURSES_INLINE bool
-cost_effective(SCREEN *sp, const int from, const int to, const bool blank)
+cost_effective(SCREEN *sp, const int from, const int to, const int blank)
 {
     int new_from;
 
 {
     int new_from;
 
@@ -278,7 +282,8 @@ NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_DCL0)
     if (screen_lines(SP_PARM) > lines_alloc(SP_PARM)) {
        if (hashtab(SP_PARM))
            free(hashtab(SP_PARM));
     if (screen_lines(SP_PARM) > lines_alloc(SP_PARM)) {
        if (hashtab(SP_PARM))
            free(hashtab(SP_PARM));
-       hashtab(SP_PARM) = typeMalloc(HASHMAP, (screen_lines(SP_PARM) + 1) * 2);
+       hashtab(SP_PARM) = typeMalloc(HASHMAP,
+                                     ((size_t) screen_lines(SP_PARM) + 1) * 2);
        if (!hashtab(SP_PARM)) {
            if (oldhash(SP_PARM)) {
                FreeAndNull(oldhash(SP_PARM));
        if (!hashtab(SP_PARM)) {
            if (oldhash(SP_PARM)) {
                FreeAndNull(oldhash(SP_PARM));
@@ -299,10 +304,10 @@ NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_DCL0)
        /* re-hash all */
        if (oldhash(SP_PARM) == 0)
            oldhash(SP_PARM) = typeCalloc(unsigned long,
        /* re-hash all */
        if (oldhash(SP_PARM) == 0)
            oldhash(SP_PARM) = typeCalloc(unsigned long,
-                                           (unsigned) screen_lines(SP_PARM));
+                                           (size_t) screen_lines(SP_PARM));
        if (newhash(SP_PARM) == 0)
            newhash(SP_PARM) = typeCalloc(unsigned long,
        if (newhash(SP_PARM) == 0)
            newhash(SP_PARM) = typeCalloc(unsigned long,
-                                           (unsigned) screen_lines(SP_PARM));
+                                           (size_t) screen_lines(SP_PARM));
        if (!oldhash(SP_PARM) || !newhash(SP_PARM))
            return;             /* malloc failure */
        for (i = 0; i < screen_lines(SP_PARM); i++) {
        if (!oldhash(SP_PARM) || !newhash(SP_PARM))
            return;             /* malloc failure */
        for (i = 0; i < screen_lines(SP_PARM); i++) {
@@ -324,7 +329,8 @@ NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_DCL0)
      * Set up and count line-hash values.
      */
     memset(hashtab(SP_PARM), '\0',
      * Set up and count line-hash values.
      */
     memset(hashtab(SP_PARM), '\0',
-          sizeof(*(hashtab(SP_PARM))) * (screen_lines(SP_PARM) + 1) * 2);
+          sizeof(*(hashtab(SP_PARM)))
+          * ((size_t) screen_lines(SP_PARM) + 1) * 2);
     for (i = 0; i < screen_lines(SP_PARM); i++) {
        unsigned long hashval = oldhash(SP_PARM)[i];
 
     for (i = 0; i < screen_lines(SP_PARM); i++) {
        unsigned long hashval = oldhash(SP_PARM)[i];
 
@@ -429,7 +435,7 @@ NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_DCLx int n, int top, int bot)
     if (!oldhash(SP_PARM))
        return;
 
     if (!oldhash(SP_PARM))
        return;
 
-    size = sizeof(*(oldhash(SP_PARM))) * (bot - top + 1 - abs(n));
+    size = sizeof(*(oldhash(SP_PARM))) * (size_t) (bot - top + 1 - abs(n));
     if (n > 0) {
        memmove(oldhash(SP_PARM) + top, oldhash(SP_PARM) + top + n, size);
        for (i = bot; i > bot - n; i--)
     if (n > 0) {
        memmove(oldhash(SP_PARM) + top, oldhash(SP_PARM) + top + n, size);
        for (i = bot; i > bot - n; i--)