--- ray/src/common/savestr.c 1992/11/21 21:46:59 2.3 +++ ray/src/common/savestr.c 2003/11/14 17:22:06 2.9 @@ -1,9 +1,6 @@ -/* Copyright 1988 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: savestr.c,v 2.9 2003/11/14 17:22:06 schorsch Exp $"; #endif - /* * savestr.c - routines for efficient string storage. * @@ -12,16 +9,24 @@ static char SCCSid[] = "$SunId$ LBL"; * All strings must be null-terminated. There is * no imposed length limit. * Strings stored with savestr(s) can be equated - * reliably using their pointer values. A tailored version - * of strcmp(s1,s2) is included. + * reliably using their pointer values. * Calls to savestr(s) and freestr(s) should be * balanced (obviously). The last call to freestr(s) * frees memory associated with the string; it should * never be referenced again. * - * 5/14/87 + * External symbols declared in standard.h */ +#include "copyright.h" + +#include +#include + +#include "rtmisc.h" +#include "rterror.h" +#include "rtio.h" + #ifndef NHASH #define NHASH 509 /* hash table size (prime!) */ #endif @@ -35,20 +40,15 @@ static S_HEAD *stab[NHASH]; #define hash(s) (shash(s)%NHASH) -extern char *savestr(), *strcpy(), *malloc(); - -#define NULL 0 - #define string(sp) ((char *)((sp)+1)) #define salloc(str) (S_HEAD *)malloc(sizeof(S_HEAD)+1+strlen(str)) -#define sfree(sp) free((char *)(sp)) +#define sfree(sp) free((void *)(sp)) char * -savestr(str) /* save a string */ -char *str; +savestr(char *str) /* save a string */ { register int hval; register S_HEAD *sp; @@ -73,8 +73,8 @@ char *str; } -freestr(s) /* free a string */ -char *s; +void +freestr(char *s) /* free a string */ { int hval; register S_HEAD *spl, *sp; @@ -97,12 +97,11 @@ char *s; int -shash(s) -register char *s; +shash(register char *s) { register int h = 0; while (*s) - h = (h<<1 & 0x7fff) ^ *s++; + h = (h<<1 & 0x7fff) ^ (*s++ & 0xff); return(h); }