1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * slsprepend() saves a null-terminated key + string somewhere and inserts a
   9:  * pointer to the key at the head of list slslist. Returns a pointer to
  10:  * the somewhere, or a null pointer if out of memory.
  11:  */
  12: #include "macro.h"
  13: #include "null.h"
  14: #include "slslist.h"
  15: 
  16: char *
  17: slsprepend(key, string, slslist)
  18:     char *key;          /* key string */
  19:     char *string;           /* non-key string */
  20:     SLSLIST *slslist;       /* pointer to list head block */
  21: {
  22:     char *malloc();         /* memory allocator */
  23:     char *strcpy();         /* string copy */
  24:     int strlen();           /* string length */
  25:     SLSBLK *slsbptr;        /* pointer to list block */
  26:     unsigned int klen;      /* key length */
  27:     unsigned int slen;      /* string length */
  28: 
  29:     if (slslist == NULL)
  30:         return(NULL);
  31:     klen = strlen(key);
  32:     slen = strlen(string);
  33:     slslist->maxkey = MAX(slslist->maxkey, klen);
  34:     slslist->maxstr = MAX(slslist->maxstr, slen);
  35:     if ((slsbptr = (SLSBLK *) malloc(sizeof(SLSBLK))) == NULL ||
  36:         (slsbptr->key = malloc(klen+1)) == NULL ||
  37:         (slsbptr->string = malloc(slen+1)) == NULL)
  38:         {
  39:         warn("out of memory");
  40:         return(NULL);
  41:         }
  42:     strcpy(slsbptr->key, key);
  43:     strcpy(slsbptr->string, string);
  44:     if (slslist->head == NULL)
  45:         {
  46:         slsbptr->next = NULL;
  47:         slslist->head = slslist->tail = slsbptr;
  48:         }
  49:     else    {
  50:         slsbptr->next = slslist->head;
  51:         slslist->head = slsbptr;
  52:         }
  53:     slslist->nk++;
  54:     return(slsbptr->key);
  55: }

Defined functions

slsprepend defined in line 16; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 385
Valid CSS Valid XHTML 1.0 Strict