Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
savestr.c File Reference
#include "copyright.h"
#include <string.h>
#include <stdlib.h>
#include "rtmisc.h"
#include "rterror.h"
#include "rtio.h"

Go to the source code of this file.

Classes

struct  s_head

Defines

#define NHASH   2039 /* hash table size (prime!) */
#define hash(s)   (shash(s)%NHASH)
#define string(sp)   ((char *)((sp)+1))
#define salloc(str)   (S_HEAD *)malloc(sizeof(S_HEAD)+1+strlen(str))
#define sfree(sp)   free((void *)(sp))

Typedefs

typedef struct s_head S_HEAD

Functions

char * savestr (char *str)
void freestr (char *s)
int shash (register char *s)

Variables

static const char RCSid [] = "$Id: savestr.c,v 2.10 2004/03/04 16:34:34 greg Exp $"
static S_HEADstab [NHASH]

Class Documentation

struct s_head

Definition at line 34 of file savestr.c.

Collaboration diagram for s_head:
Class Members
struct s_head * next
int nl

Define Documentation

#define hash (   s)    (shash(s)%NHASH)

Definition at line 41 of file savestr.c.

#define NHASH   2039 /* hash table size (prime!) */

Definition at line 31 of file savestr.c.

#define salloc (   str)    (S_HEAD *)malloc(sizeof(S_HEAD)+1+strlen(str))

Definition at line 45 of file savestr.c.

#define sfree (   sp)    free((void *)(sp))

Definition at line 47 of file savestr.c.

#define string (   sp)    ((char *)((sp)+1))

Definition at line 43 of file savestr.c.


Typedef Documentation

typedef struct s_head S_HEAD

Function Documentation

void freestr ( char *  s)

Definition at line 77 of file savestr.c.

{
       int  hval;
       register S_HEAD  *spl, *sp;

       if (s == NULL)
              return;
       hval = hash(s);
       for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next)
              if (s == string(sp)) {
                     if (--sp->nl > 0)
                            return;
                     if (spl != NULL)
                            spl->next = sp->next;
                     else
                            stab[hval] = sp->next;
                     sfree(sp);
                     return;
              }
}

Here is the caller graph for this function:

char* savestr ( char *  str)

Definition at line 51 of file savestr.c.

{
       register int  hval;
       register S_HEAD  *sp;

       if (str == NULL)
              return(NULL);
       hval = hash(str);
       for (sp = stab[hval]; sp != NULL; sp = sp->next)
              if (!strcmp(str, string(sp))) {
                     sp->nl++;
                     return(string(sp));
              }
       if ((sp = salloc(str)) == NULL) {
              eputs("Out of memory in savestr\n");
              quit(1);
       }
       strcpy(string(sp), str);
       sp->nl = 1;
       sp->next = stab[hval];
       stab[hval] = sp;
       return(string(sp));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int shash ( register char *  s)

Definition at line 100 of file savestr.c.

{
       register int  h = 0;

       while (*s)
              h = (h<<1 & 0x7fff) ^ (*s++ & 0xff);
       return(h);
}

Variable Documentation

const char RCSid[] = "$Id: savestr.c,v 2.10 2004/03/04 16:34:34 greg Exp $" [static]

Definition at line 2 of file savestr.c.

S_HEAD* stab[NHASH] [static]

Definition at line 39 of file savestr.c.