summaryrefslogtreecommitdiff
path: root/server/zstring.c
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>1997-09-14 17:50:06 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>1997-09-14 17:50:06 +0000
commitac16f380e349fa39ec7e26bccb5456cb300006a5 (patch)
treec07ca88af97b4f6b77d28a2dc723d2e4621ed302 /server/zstring.c
parentd33e482744fad80d95cdd89ed380c5b8401e49bf (diff)
Pull in sources from zephyr locker. See /mit/zephyr/repository for
detailed change information.
Diffstat (limited to 'server/zstring.c')
-rw-r--r--server/zstring.c253
1 files changed, 116 insertions, 137 deletions
diff --git a/server/zstring.c b/server/zstring.c
index 6b5aed3..955e0b8 100644
--- a/server/zstring.c
+++ b/server/zstring.c
@@ -12,177 +12,156 @@
*/
#include <zephyr/mit-copyright.h>
+#include "zserver.h"
#ifndef lint
#ifndef SABER
-static char rcsid_zstring_c[] =
- "$Id$";
+static const char rcsid_zstring_c[] =
+"$Id$";
#endif
#endif
-#include <mit-copyright.h>
+static String *zhash[STRING_HASH_TABLE_SIZE];
-#include <ctype.h>
-#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];
-
-#ifdef __STDC__
-# define P(s) s
-#else
-# define P(s) ()
-#endif
-
-extern unsigned long hash P((Zconst char *s));
-extern char *strsave P((Zconst char *s));
-#undef P
-
-ZSTRING *
-make_zstring(s, downcase)
- char *s;
- int downcase;
+String *
+make_string(s, downcase)
+ char *s;
+ int downcase;
{
- char *new_s,*p;
- ZSTRING *new_z,*hp;
- int i;
-
- if (downcase) {
- new_s = strsave(s);
- p = new_s;
- while(*p) {
- if (isascii(*p) && isupper(*p))
- *p = tolower(*p);
- p++;
+ char *new_s,*p;
+ String *new_z,*hp;
+ int i;
+
+ if (downcase) {
+ new_s = strsave(s);
+ p = new_s;
+ while(*p) {
+ if (isascii(*p) && isupper(*p))
+ *p = tolower(*p);
+ p++;
+ }
+ } else {
+ new_s = s;
}
- } else {
- new_s = s;
- }
- new_z = find_zstring(new_s,0);
- if (new_z != NULL) {
- if (downcase)
- free(new_s);
- new_z->ref_count++;
- return(new_z);
- }
-
- /* Initialize new ZSTRING */
-
- if (!downcase)
- new_s = strsave(s);
- new_z = (ZSTRING *) malloc(sizeof(ZSTRING));
- new_z->string = new_s;
- new_z->ref_count = 1;
+ new_z = find_string(new_s,0);
+ if (new_z != NULL) {
+ if (downcase)
+ free(new_s);
+ new_z->ref_count++;
+ return(new_z);
+ }
+
+ /* Initialize new String */
+
+ if (!downcase)
+ new_s = strsave(s);
+ new_z = (String *) malloc(sizeof(String));
+ new_z->string = new_s;
+ new_z->ref_count = 1;
- /* Add to beginning of hash table */
- 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[i] = new_z;
-
- return(new_z);
+ /* Add to beginning of hash table */
+ new_z->hash_val = hash(new_s);
+ i = new_z->hash_val % STRING_HASH_TABLE_SIZE;
+ hp = zhash[i];
+ new_z->next = hp;
+ if (hp != NULL)
+ hp->prev = new_z;
+ new_z->prev = NULL;
+ zhash[i] = new_z;
+
+ return new_z;
}
void
-free_zstring(z)
- ZSTRING *z;
+free_string(z)
+ String *z;
{
- if (z == (ZSTRING *) NULL)
- return;
-
- z->ref_count--;
- if (z->ref_count > 0)
- return;
-
- /* delete zstring completely */
- if(z->prev == NULL)
- zhash[hash(z->string) % ZSTRING_HASH_TABLE_SIZE] = z->next;
- else
- z->prev->next = z->next;
+ if (z == (String *) NULL)
+ return;
+
+ z->ref_count--;
+ if (z->ref_count > 0)
+ return;
+
+ /* delete string completely */
+ if(z->prev == NULL)
+ zhash[hash(z->string) % STRING_HASH_TABLE_SIZE] = z->next;
+ else
+ z->prev->next = z->next;
- if (z->next != NULL)
- z->next->prev = z->prev;
+ if (z->next != NULL)
+ z->next->prev = z->prev;
- free(z->string);
- free(z);
- return;
+ free(z->string);
+ free(z);
}
-ZSTRING *
-find_zstring(s,downcase)
- char *s;
- int downcase;
+String *
+find_string(s,downcase)
+ char *s;
+ int downcase;
{
- char *new_s,*p;
- ZSTRING *z;
-
- if (downcase) {
- new_s = strsave(s);
- p = new_s;
- while (*p) {
- if (isascii(*p) && isupper(*p))
- *p = tolower(*p);
- p++;
+ char *new_s,*p;
+ String *z;
+
+ if (downcase) {
+ new_s = strsave(s);
+ p = new_s;
+ while (*p) {
+ if (isascii(*p) && isupper(*p))
+ *p = tolower(*p);
+ p++;
+ }
+ } else {
+ new_s = s;
}
- } else {
- new_s = s;
- }
- z = zhash[hash(new_s) % ZSTRING_HASH_TABLE_SIZE];
- while (z != (ZSTRING *)NULL) {
- if (strcmp(new_s,z->string) == 0)
- break;
- z = z->next;
- }
+ z = zhash[hash(new_s) % STRING_HASH_TABLE_SIZE];
+ while (z != NULL) {
+ if (strcmp(new_s, z->string) == 0)
+ break;
+ z = z->next;
+ }
- if (downcase)
- free(new_s);
+ if (downcase)
+ free(new_s);
- return(z);
+ return z;
}
int
-comp_zstring(a,b)
- ZSTRING *a, *b;
+comp_string(a,b)
+ String *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));
+ 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;
+print_string_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;
+ String *p;
+ int i;
+
+ for(i = 0; i < STRING_HASH_TABLE_SIZE; i++) {
+ p = zhash[i];
+ while (p != (String *) NULL) {
+ fprintf(f,"[%d] %s\n",p->ref_count,p->string);
+ p = p->next;
+ }
}
- }
- return;
}
-ZSTRING *
-dup_zstring(z)
- ZSTRING *z;
+String *
+dup_string(z)
+ String *z;
{
- z->ref_count++;
- return(z);
+ z->ref_count++;
+ return z;
}
+