1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * pbaddstring() adds an id=string to the tail of the buffer. If id already
   9:  * exists the corresponding string is replaced. Returns integer NO if
  10:  * buffer space exceeded, otherwise YES.
  11:  */
  12: #include "pdbuf.h"
  13: #include "yesno.h"
  14: 
  15: extern char *CURPBUF;           /* current database buffer */
  16: 
  17: pbaddstring(id, string)
  18:     register char *id;      /* string identifier */
  19:     char *string;           /* string argument */
  20: {
  21:     register char *bp;      /* buffer pointer */
  22:     char *pbskipfield();        /* skip to next non-key field */
  23:     char *strcpy();         /* string copy */
  24:     char *strncpy();        /* copy n characters */
  25:     int chgflen;            /* incremental field length */
  26:     int flen;           /* field length */
  27:     int pbstretch();        /* stretch buffer */
  28:     int slen;           /* string length */
  29:     int strlen();           /* string length */
  30: 
  31:     bp = CURPBUF;
  32:     slen = strlen(string);
  33:     chgflen = slen + 4;     /* add id= and field separator */
  34:     while (*(bp = pbskipfield(bp)) != '\0')
  35:         if (bp[0] == id[0] && bp[1] == id[1] && bp[2] == '=')
  36:             {
  37:             flen = pblenfield(bp);
  38:             chgflen -= (bp[flen]==_PBFS) ? flen+1 : flen;
  39:             break;
  40:             }
  41:     if (bp == CURPBUF)
  42:         {
  43:         *bp++ = _PBFS;      /* prepare virgin buffer */
  44:         *bp = '\0';
  45:         }
  46:     if (pbstretch(bp, chgflen) == NO)
  47:         return(NO);
  48:     bp[0] = id[0];          /* add id= */
  49:     bp[1] = id[1];
  50:     bp[2] = '=';
  51:     strncpy(bp+3, string, slen);    /* insert string */
  52:     bp[slen+3] = _PBFS;     /* add field separator */
  53:     return(YES);
  54: }

Defined functions

pbaddstring defined in line 17; used 3 times
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 665
Valid CSS Valid XHTML 1.0 Strict