Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[fw/sdcc] / src / SDCChasht.c
index cc467afd7f928a19b799849e75d82e67c1feb816..dd6322d451c632b5a70231f1ed0f57b6f979e628 100644 (file)
@@ -62,7 +62,7 @@ newHashTable (int size)
   if (!(htab->table = Safe_alloc ((size + 1) * sizeof (hashtItem *))))
     {
       fprintf (stderr, "out of virtual memory %s %d\n",
-              __FILE__, (size + 1) * sizeof (hashtItem *));
+              __FILE__, (size + 1) * (int) sizeof (hashtItem *));
       exit (1);
     }
   htab->minKey = htab->size = size;
@@ -513,6 +513,14 @@ hTabItemWithKey (hTab * htab, int key)
   return htip->item;
 }
 
+/*-----------------------------------------------------------------*/
+/* hTabMaxKey - return the maxKey of item in the hashTable         */
+/*-----------------------------------------------------------------*/
+int hTabMaxKey (hTab *htab)
+{
+    return (htab ? htab->maxKey : 0);
+}      
+
 /*-----------------------------------------------------------------*/
 /*hTabAddItemIfNotP - adds an item with nothing found with key     */
 /*-----------------------------------------------------------------*/
@@ -553,11 +561,21 @@ _hash (const char *sz)
 void 
 shash_add (hTab ** h, const char *szKey, const char *szValue)
 {
+  char *val;
   int key = _hash (szKey);
-  /* First, delete any that currently exist */
-  hTabDeleteByKey (h, key, szKey, _compare);
+
+  /* Find value of the item */
+  val = (char *)hTabFindByKey(*h, key, szKey, _compare);
+  /* Delete any that currently exist */
+  hTabDeleteByKey(h, key, szKey, _compare);
+  /* Deallocate old value in not NULL */
+  if (val != NULL)
+    Safe_free(val);
+  /* Duplicate new value if not NULL */
+  if (szValue != NULL)
+    szValue = Safe_strdup(szValue);
   /* Now add in ours */
-  hTabAddItemLong (h, key, Safe_strdup (szKey), Safe_strdup (szValue));
+  hTabAddItemLong (h, key, Safe_strdup (szKey), (void *)szValue);
 }
 
 const char *