1: /* $Header$ */ 2: 3: /* 4: * Author: Peter J. Nicklin 5: */ 6: 7: /* 8: * slsappend() saves null-terminated key + string somewhere and inserts a 9: * pointer to the key at the tail 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: slsappend(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: slsbptr->next = NULL; 45: if (slslist->tail == NULL) 46: slslist->head = slslist->tail = slsbptr; 47: else 48: slslist->tail = slslist->tail->next = slsbptr; 49: slslist->nk++; 50: return(slsbptr->key); 51: }