Applied initial patches for wx2.8 compatibility
[ctsim.git] / libctsupport / hashtable.cpp
index df2a047adb1874669cc1a7025182e67eafbd04de..c7848ef838bf2ff5d6437983674faee77d4a2bd6 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: hashtable.cpp,v 1.3 2001/01/28 19:10:18 kevin Exp $
+**  $Id$
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -35,7 +35,7 @@ KeywordCodeEntry::KeywordCodeEntry (const char* const pszKeyword, int iCode)
 {
    int nLength = strlen (pszKeyword);
    char* pszCopy = new char [ nLength + 1];
-   for (int i = 0; i < nLength; i++) 
+   for (int i = 0; i < nLength; i++)
      pszCopy[i] = tolower (pszKeyword[i]);
    pszCopy[nLength] = 0;
 
@@ -50,7 +50,7 @@ KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const
 {
     int nLength = strlen (pszCompare);
     char* pszCopy = new char [ nLength + 1];
-    for (int i = 0; i < nLength; i++) 
+    for (int i = 0; i < nLength; i++)
       pszCopy[i] = tolower (pszCompare[i]);
     pszCopy[nLength] = 0;
 
@@ -67,48 +67,48 @@ KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const
 // inittable (table)
 //    clear symbol table
 
-void 
+void
 KeywordCodeHashTable::initTable ()
 {
-       int i;
+        int i;
 
-       for (i = 0; i < HASHSIZE; i++)
-           m_hashTable[i] = NULL;
+        for (i = 0; i < HASHSIZE; i++)
+            m_hashTable[i] = NULL;
 }
 
 // freetable (table)
-//     free all memory allocated to table, then clear table
+//      free all memory allocated to table, then clear table
 
-void 
+void
 KeywordCodeHashTable::freeTable ()
 {
-       int i;
-       KeywordCodeEntry *p, *np;
-
-       for (i = 0; i < HASHSIZE; i++) {
-           np = m_hashTable [i];
-           while (np != NULL) {
-                   p = np->getNext();
-                   delete np;
-                   np = p;
+        int i;
+        KeywordCodeEntry *p, *np;
+
+        for (i = 0; i < HASHSIZE; i++) {
+            np = m_hashTable [i];
+            while (np != NULL) {
+                    p = np->getNext();
+                    delete np;
+                    np = p;
       }
-       }
-       initTable ();
+        }
+        initTable ();
 }
 
 
-// form hash value of string s 
-int 
+// form hash value of string s
+int
 KeywordCodeHashTable::hash (const char* s)
 {
-       int hashval = 0;
+        int hashval = 0;
 
   while (*s != EOS) {
-           hashval += tolower(*s);
+            hashval += tolower(*s);
       s++;
   }
 
-       return (hashval % HASHSIZE);
+        return (hashval % HASHSIZE);
 }
 
 
@@ -118,10 +118,10 @@ KeywordCodeHashTable::lookup (const char* const pszLookup)
 {
     KeywordCodeEntry *found = NULL;
     for (KeywordCodeEntry* np = m_hashTable[ hash( pszLookup ) ]; np != NULL; np = np->getNext())
-           if (np->matchesKeyword (pszLookup)) {
-             found = np;               // found it 
-             break;
-       }
+            if (np->matchesKeyword (pszLookup)) {
+              found = np;               // found it
+              break;
+        }
 
   return (found);
 }
@@ -131,11 +131,11 @@ KeywordCodeHashTable::installKeywordCode (const char* const pszKeyword, int iCod
 {
     KeywordCodeEntry *np = lookup (pszKeyword);
 
-    if (np == NULL) {      // not found 
-           np = new KeywordCodeEntry (pszKeyword, iCode);
-           int hashval = hash (np->getKeyword());
-       np->setNext (m_hashTable[ hashval ]);
-           m_hashTable[hashval] = np;
-    } else                                     // already defined
-           np->setCode (iCode);
+    if (np == NULL) {       // not found
+            np = new KeywordCodeEntry (pszKeyword, iCode);
+            int hashval = hash (np->getKeyword());
+        np->setNext (m_hashTable[ hashval ]);
+            m_hashTable[hashval] = np;
+    } else                                      // already defined
+            np->setCode (iCode);
 }