summaryrefslogtreecommitdiff
path: root/server/zstring.c
diff options
context:
space:
mode:
authorGravatar Lucien Van Elsen <lwvanels@mit.edu>1991-12-04 08:25:09 +0000
committerGravatar Lucien Van Elsen <lwvanels@mit.edu>1991-12-04 08:25:09 +0000
commit1bd4094341bcada53540b6f51833c30d61f1dcd6 (patch)
tree917cfd1e4ff9e34dcf7f7a7aaaa78d875bf6d0b8 /server/zstring.c
parentfe7095d1dc0a6a79810cc2e81df3fa70370385be (diff)
Converted back to ANSI C (with ifdef's for standard C)
Diffstat (limited to 'server/zstring.c')
-rw-r--r--server/zstring.c77
1 files changed, 61 insertions, 16 deletions
diff --git a/server/zstring.c b/server/zstring.c
index 575adc9..f9377da 100644
--- a/server/zstring.c
+++ b/server/zstring.c
@@ -1,19 +1,34 @@
-/*
- * Copyright (C) 1991 by the Massachusetts Institute of Technology.
- * For copying and distribution information, see the file "mit-copyright.h".
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains the main loop of the Zephyr server
+ *
+ * Created by: Lucien W. Van Elsen
*
* $Source$
- * $Id$
* $Author$
+ *
+ * Copyright (c) 1991 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
*/
+#include <zephyr/mit-copyright.h>
+
+#ifndef lint
+#ifndef SABER
+static char rcsid_zstring_c[] =
+ "$Id$";
+#endif
+#endif
+
#include <mit-copyright.h>
#include <ctype.h>
-#ifdef __STDC__
+#if defined(__STDC__) && !defined(__HIGHC__) && !defined(SABER)
#include <stdlib.h>
#endif
#include <string.h>
+
+#include <zephyr/zephyr.h>
#include "zstring.h"
static ZSTRING *zhash[ZSTRING_HASH_TABLE_SIZE];
@@ -24,8 +39,8 @@ static ZSTRING *zhash[ZSTRING_HASH_TABLE_SIZE];
# define P(s) ()
#endif
-extern unsigned long hash P((const char *s));
-extern char *strsave P((const char *s));
+extern unsigned long hash P((Zconst char *s));
+extern char *strsave P((Zconst char *s));
#undef P
ZSTRING *
@@ -35,7 +50,7 @@ make_zstring(s, downcase)
{
char *new_s,*p;
ZSTRING *new_z,*hp;
- int hash_val;
+ int i;
if (downcase) {
new_s = strsave(s);
@@ -61,19 +76,20 @@ make_zstring(s, downcase)
if (!downcase)
new_s = strsave(s);
- new_z = malloc(sizeof(ZSTRING));
+ new_z = (ZSTRING *) malloc(sizeof(ZSTRING));
new_z->string = new_s;
new_z->len = strlen(new_s);
new_z->ref_count = 1;
/* Add to beginning of hash table */
- hash_val = hash(new_s) % ZSTRING_HASH_TABLE_SIZE;
- hp = zhash[hash_val];
+ new_z->hash_val = hash(new_s);
+ i = new_z->hash_val % ZSTRING_HASH_TABLE_SIZE;
+ hp = zhash[i];
new_z->next = hp;
if (hp != NULL)
hp->prev = new_z;
new_z->prev = NULL;
- zhash[hash_val] = new_z;
+ zhash[i] = new_z;
return(new_z);
}
@@ -82,8 +98,8 @@ void
free_zstring(z)
ZSTRING *z;
{
- ZSTRING *hp;
- int hash_val;
+ if (z == (ZSTRING *) NULL)
+ return;
z->ref_count--;
if (z->ref_count > 0)
@@ -137,8 +153,37 @@ find_zstring(s,downcase)
}
int
-eq_zstring(a,b)
+comp_zstring(a,b)
ZSTRING *a, *b;
{
- return(a == b);
+ if (a->hash_val > b->hash_val)
+ return(1);
+ if (a->hash_val < b->hash_val)
+ return(-1);
+ return(strcmp(a->string,b->string));
+}
+
+void
+print_zstring_table(f)
+ FILE *f;
+{
+ ZSTRING *p;
+ int i;
+
+ for(i=0;i<ZSTRING_HASH_TABLE_SIZE;i++) {
+ p = zhash[i];
+ while (p != (ZSTRING *) NULL) {
+ fprintf(f,"[%d] %s\n",p->ref_count,p->string);
+ p = p->next;
+ }
+ }
+ return;
+}
+
+ZSTRING *
+dup_zstring(z)
+ ZSTRING *z;
+{
+ z->ref_count++;
+ return(z);
}