home *** CD-ROM | disk | FTP | other *** search
- /*
- l_strbuf.c
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #include "strbuf.h"
-
- retcode
- buf_add(struct buf_s *bp, byteptr s, uint len)
- {
- #define SLICE 128
- byte c;
-
- while (bp->len+len > bp->alen) {
- if (bp->alen == 0)
- bp->buf = malloc(SLICE);
- else
- bp->buf = (byteptr) realloc((char*)(bp->buf),
- bp->alen+SLICE);
- if (!bp->buf)
- return ERR_MALLOC_FAILED;
- bp->alen += SLICE;
- }
- memcpy((char*)(bp->buf + bp->len), (char*)s, len);
- bp->len += len;
- c = s[len-1];
- if (isupper(c))
- bp->last_char = UPPER;
- else if (islower(c) || c == '_')
- bp->last_char = LOWER;
- else if (isdigit(c))
- bp->last_char = DIGIT;
- else
- bp->last_char = PUNCT;
-
- return OK;
- }
-
-
- void
- buf_free(struct buf_s *bp)
- {
- if (bp->alen)
- free((char*)(bp->buf));
- memset(bp, 0, sizeof(struct buf_s));
- }
-