1: /* $Header$ */ 2: 3: /* 4: * Author: Peter J. Nicklin 5: */ 6: 7: /* 8: * pbaddkey() inserts a key at the head of the buffer. The buffer is not 9: * changed if key already exists. Returns integer NO if buffer exceeded, 10: * otherwise YES. 11: */ 12: #include "pdbuf.h" 13: #include "yesno.h" 14: 15: extern char *CURPBUF; /* current database buffer */ 16: 17: pbaddkey(key) 18: char *key; /* key string */ 19: { 20: register char *bp; /* buffer pointer */ 21: char *pbskipkey(); /* skip to next key */ 22: char *strncpy(); /* copy n characters */ 23: int klen; /* key string length */ 24: int pbcmpkey(); /* compare keys */ 25: int pbstretch(); /* stretch buffer */ 26: int strlen(); /* string length */ 27: 28: bp = CURPBUF; 29: while (*bp != _PBFS && *bp != '\0') 30: { 31: if (pbcmpkey(key, bp) == 0) 32: return(YES); /* key already exists */ 33: bp = pbskipkey(bp); 34: } 35: if (bp == CURPBUF && *bp != _PBFS) 36: { 37: *bp++ = _PBFS; /* prepare virgin buffer */ 38: *bp = '\0'; 39: } 40: klen = strlen(key); 41: if (pbstretch(CURPBUF, klen+1) == NO) 42: return(NO); 43: strncpy(CURPBUF, key, klen); /* insert key */ 44: CURPBUF[klen] = _PBKS; /* add key field separator */ 45: return(YES); 46: }