/*
 * $Header: /udir/vixie/src/mail11/d-1.7beta/RCS/text.c,v 1.2 1991/09/23 01:37:22 vixie Exp $
 */

#include <stdio.h>
#include "text.h"

#ifdef __STDC__
char *malloc (unsigned);
#else
char *malloc ();
#endif

void
TEXT_Erase (ptr)
struct text_msg *ptr;
{
    ptr->head = ptr->tail = NULL;
}


struct text_msg *
TEXT_Init ()
{
    struct text_msg *ptr = (struct text_msg *) malloc(sizeof(struct text_msg));
    TEXT_Erase (ptr);
    return ptr;
}


void
TEXT_Append (ptr, buf, length)
struct text_msg *ptr;
char *buf;
int length;
{
    struct text_line *line =
	(struct text_line *) malloc (sizeof (struct text_line) + length);

    line->next = NULL;
    strncpy (line->text, buf, length);
    line->text[length] = '\0';
    line->length = length;

    if (ptr->head == NULL)
	ptr->head = ptr->tail = line;
    else {
	ptr->tail->next = line;
	ptr->tail = line;
    }
}
