From 1bd4094341bcada53540b6f51833c30d61f1dcd6 Mon Sep 17 00:00:00 2001 From: Lucien Van Elsen Date: Wed, 4 Dec 1991 08:25:09 +0000 Subject: Converted back to ANSI C (with ifdef's for standard C) --- server/zstring.c | 77 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 16 deletions(-) (limited to 'server/zstring.c') 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 + +#ifndef lint +#ifndef SABER +static char rcsid_zstring_c[] = + "$Id$"; +#endif +#endif + #include #include -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__HIGHC__) && !defined(SABER) #include #endif #include + +#include #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;iref_count,p->string); + p = p->next; + } + } + return; +} + +ZSTRING * +dup_zstring(z) + ZSTRING *z; +{ + z->ref_count++; + return(z); } -- cgit v1.2.3