]> andersk Git - moira.git/commitdiff
Initial revision
authormar <mar>
Tue, 2 Aug 1988 21:11:32 +0000 (21:11 +0000)
committermar <mar>
Tue, 2 Aug 1988 21:11:32 +0000 (21:11 +0000)
lib/hash.c [new file with mode: 0644]
lib/idno.c [new file with mode: 0644]

diff --git a/lib/hash.c b/lib/hash.c
new file mode 100644 (file)
index 0000000..18675c1
--- /dev/null
@@ -0,0 +1,134 @@
+/* $Header$
+ *
+ * Generic hash table routines.  Uses integer keys to store char * values.
+ */
+
+#include <ctype.h>
+#include "sms_app.h"
+#define NULL 0
+
+
+/* Create a hash table.  The size is just a hint, not a maximum. */
+
+struct hash *create_hash(size)
+int size;
+{
+    struct hash *h;
+
+    h = (struct hash *) malloc(sizeof(struct hash));
+    h->size = size;
+    h->data = (struct bucket **) malloc(size * sizeof(char *));
+    bzero(h->data, size * sizeof(char *));
+    return(h);
+}
+
+/* Lookup an object in the hash table.  Returns the value associated with
+ * the key, or NULL (thus NULL is not a very good value to store...)
+ */
+
+char *hash_lookup(h, key)
+struct hash *h;
+register int key;
+{
+    register struct bucket *b;
+
+    b = h->data[key % h->size];
+    while (b && b->key != key)
+      b = b->next;
+    if (b && b->key == key)
+      return(b->data);
+    else
+      return(NULL);
+}
+
+
+/* Update an existing object in the hash table.  Returns 1 if the object
+ * existed, or 0 if not.
+ */
+
+int hash_update(h, key, value)
+struct hash *h;
+register int key;
+char *value;
+{
+    register struct bucket *b;
+
+    b = h->data[key % h->size];
+    while (b && b->key != key)
+      b = b->next;
+    if (b && b->key == key) {
+       b->data = value;
+       return(1);
+    } else
+      return(0);
+}
+
+
+/* Store an item in the hash table.  Returns 0 if the key was not previously
+ * there, or 1 if it was.
+ */
+
+int hash_store(h, key, value)
+struct hash *h;
+register int key;
+char *value;
+{
+    register struct bucket *b, **p;
+
+    p = &(h->data[key % h->size]);
+    if (*p == NULL) {
+       b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+       b->next = NULL;
+       b->key = key;
+       b->data = value;
+       return(0);
+    }
+
+    for (b = *p; b && b->key != key; b = *p)
+      p = (struct bucket **) *p;
+    if (b && b->key == key) {
+       b->data = value;
+       return(1);
+    }
+    b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+    b->next = NULL;
+    b->key = key;
+    b->data = value;
+    return(0);
+}
+
+
+/* Search through the hash table for a given value.  For each piece of
+ * data with that value, call the callback proc with the corresponding key.
+ */
+
+hash_search(h, value, callback)
+struct hash *h;
+register char *value;
+void (*callback)();
+{
+    register struct bucket *b, **p;
+
+    for (p = &(h->data[h->size - 1]); p >= h->data; p--) {
+       for (b = *p; b; b = b->next) {
+           if (b->data == value)
+             (*callback)(b->key);
+       }
+    }
+}
+
+
+/* Deallocate all of the memory associated with a table */
+
+hash_destroy(h)
+struct hash *h;
+{
+    register struct bucket *b, **p, *b1;
+
+    for (p = &(h->data[h->size - 1]); p >= h->data; p--) {
+       for (b = *p; b; b = b1) {
+           b1 = b->next;
+           free(b);
+       }
+    }
+}
diff --git a/lib/idno.c b/lib/idno.c
new file mode 100644 (file)
index 0000000..7d11372
--- /dev/null
@@ -0,0 +1,49 @@
+/* $Header$
+ *
+ * Routines to encrypt ID's
+ */
+
+#include <strings.h>
+#include <ctype.h>
+
+
+/*     Function Name: RemoveHyphens
+ *     Description: Removes all hyphens from the string passed to it.
+ *     Arguments: str - the string to remove the hyphes from
+ *     Returns: none
+ */
+
+void
+RemoveHyphens(str)
+char *str;
+{
+    char *hyphen;
+
+    while ((hyphen = index(str, '-')) != (char *)0)
+       (void) strcpy(hyphen, hyphen + 1);
+}
+
+
+/*     Function Name: EncryptMITID
+ *     Description: Encrypts an mit ID number. 
+ *     Arguments: sbuf - the buffer to return the encrypted number in.
+ *                 idnumber - the id number (string).
+ *                 first, last - name of the person.
+ *     Returns: none.
+ */
+
+void
+EncryptID(sbuf, idnumber, first, last)
+char *sbuf, *idnumber, *first, *last;
+{
+    char salt[3];
+    extern char *crypt();
+
+    RemoveHyphens(idnumber);
+    salt[0] = tolower(last[0]);
+    salt[1] = tolower(first[0]);
+    salt[2] = 0;
+
+    (void) strcpy(sbuf, crypt(&idnumber[2], salt));
+}
+
This page took 0.048734 seconds and 5 git commands to generate.