diff options
Diffstat (limited to 'lib/libmytinfo/addstr.c')
| -rw-r--r-- | lib/libmytinfo/addstr.c | 88 | 
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/libmytinfo/addstr.c b/lib/libmytinfo/addstr.c new file mode 100644 index 000000000000..50fb4111f9b4 --- /dev/null +++ b/lib/libmytinfo/addstr.c @@ -0,0 +1,88 @@ +/* + * addstr.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:34:01 + * + */ + +#include "defs.h" +#include <term.h> + +#include <ctype.h> + +#ifdef USE_SCCS_IDS +static char const SCCSid[] = "@(#) mytinfo addstr.c 3.2 92/02/01 public domain, By Ross Ridge"; +#endif +/* + * I think this routine could be improved, as it is now it searches a + * linked list of strbufs for one that has enough room left for the + * string. The only thing else I can think of doing would be to  + * expand a buffer by realloc and then fix the string pointers if it + * moves. + */ + +static struct strbuf *strbuf = NULL; +    +struct strbuf * +_endstr() { +	register struct strbuf *p; + +	p = strbuf; +	strbuf = NULL; +	return p; +} + +char * +_addstr(s) +register char *s; { +	register struct strbuf *p; +	register int l; + +	if (s == NULL) { +		strbuf = NULL; +		return NULL; +	} + +	if (strbuf == NULL) { +		strbuf = (struct strbuf *) malloc(sizeof(struct strbuf)); +		if (strbuf == NULL) +			return NULL; +		strbuf->len = 0; +		strbuf->next = NULL; +	} +	l = strlen(s) + 1; +	if (l > MAX_CHUNK) +		return NULL; +	p = strbuf; +	while (l + p->len > MAX_CHUNK) { +		if (p->next == NULL) { +			p->next = (struct strbuf *) +					malloc(sizeof(struct strbuf)); +			p = p->next; +			if (p == NULL) +				return NULL; +			p->len = 0; +			p->next = NULL; +			break; +		} +		p = p->next; +	} +	s = strcpy(p->buf + p->len, s); +	p->len += l; +	return s; +} + +void +_del_strs(p) +TERMINAL *p; { +	struct strbuf *q; + +	q = p->strbuf; +	while(q != NULL) { +		p->strbuf = q->next;  +		free((anyptr) q); +		q = p->strbuf; +	} +}  | 
