xref: /minix3/external/bsd/nvi/dist/common/cut.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: cut.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc  */
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc static const char sccsid[] = "Id: cut.c,v 10.18 2001/06/25 15:19:09 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:09 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: cut.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc 
2584d9c625SLionel Sambuc #include <bitstring.h>
2684d9c625SLionel Sambuc #include <ctype.h>
2784d9c625SLionel Sambuc #include <errno.h>
2884d9c625SLionel Sambuc #include <fcntl.h>
2984d9c625SLionel Sambuc #include <limits.h>
3084d9c625SLionel Sambuc #include <stdio.h>
3184d9c625SLionel Sambuc #include <stdlib.h>
3284d9c625SLionel Sambuc #include <string.h>
3384d9c625SLionel Sambuc 
3484d9c625SLionel Sambuc #include "common.h"
3584d9c625SLionel Sambuc 
3684d9c625SLionel Sambuc static void	cb_rotate __P((SCR *));
3784d9c625SLionel Sambuc 
3884d9c625SLionel Sambuc /*
3984d9c625SLionel Sambuc  * cut --
4084d9c625SLionel Sambuc  *	Put a range of lines/columns into a TEXT buffer.
4184d9c625SLionel Sambuc  *
4284d9c625SLionel Sambuc  * There are two buffer areas, both found in the global structure.  The first
4384d9c625SLionel Sambuc  * is the linked list of all the buffers the user has named, the second is the
4484d9c625SLionel Sambuc  * unnamed buffer storage.  There is a pointer, too, which is the current
4584d9c625SLionel Sambuc  * default buffer, i.e. it may point to the unnamed buffer or a named buffer
4684d9c625SLionel Sambuc  * depending on into what buffer the last text was cut.  Logically, in both
4784d9c625SLionel Sambuc  * delete and yank operations, if the user names a buffer, the text is cut
4884d9c625SLionel Sambuc  * into it.  If it's a delete of information on more than a single line, the
4984d9c625SLionel Sambuc  * contents of the numbered buffers are rotated up one, the contents of the
5084d9c625SLionel Sambuc  * buffer named '9' are discarded, and the text is cut into the buffer named
5184d9c625SLionel Sambuc  * '1'.  The text is always cut into the unnamed buffer.
5284d9c625SLionel Sambuc  *
5384d9c625SLionel Sambuc  * In all cases, upper-case buffer names are the same as lower-case names,
5484d9c625SLionel Sambuc  * with the exception that they cause the buffer to be appended to instead
5584d9c625SLionel Sambuc  * of replaced.  Note, however, that if text is appended to a buffer, the
5684d9c625SLionel Sambuc  * default buffer only contains the appended text, not the entire contents
5784d9c625SLionel Sambuc  * of the buffer.
5884d9c625SLionel Sambuc  *
5984d9c625SLionel Sambuc  * !!!
6084d9c625SLionel Sambuc  * The contents of the default buffer would disappear after most operations
6184d9c625SLionel Sambuc  * in historic vi.  It's unclear that this is useful, so we don't bother.
6284d9c625SLionel Sambuc  *
6384d9c625SLionel Sambuc  * When users explicitly cut text into the numeric buffers, historic vi became
6484d9c625SLionel Sambuc  * genuinely strange.  I've never been able to figure out what was supposed to
6584d9c625SLionel Sambuc  * happen.  It behaved differently if you deleted text than if you yanked text,
6684d9c625SLionel Sambuc  * and, in the latter case, the text was appended to the buffer instead of
6784d9c625SLionel Sambuc  * replacing the contents.  Hopefully it's not worth getting right, and here
6884d9c625SLionel Sambuc  * we just treat the numeric buffers like any other named buffer.
6984d9c625SLionel Sambuc  *
7084d9c625SLionel Sambuc  * PUBLIC: int cut __P((SCR *, ARG_CHAR_T *, MARK *, MARK *, int));
7184d9c625SLionel Sambuc  */
7284d9c625SLionel Sambuc int
cut(SCR * sp,ARG_CHAR_T * namep,MARK * fm,MARK * tm,int flags)7384d9c625SLionel Sambuc cut(SCR *sp, ARG_CHAR_T *namep, MARK *fm, MARK *tm, int flags)
7484d9c625SLionel Sambuc {
7584d9c625SLionel Sambuc 	CB *cbp;
7684d9c625SLionel Sambuc 	ARG_CHAR_T name = '\0';
7784d9c625SLionel Sambuc 	db_recno_t lno;
7884d9c625SLionel Sambuc 	int append, copy_one, copy_def;
7984d9c625SLionel Sambuc 
8084d9c625SLionel Sambuc 	/*
8184d9c625SLionel Sambuc 	 * If the user specified a buffer, put it there.  (This may require
8284d9c625SLionel Sambuc 	 * a copy into the numeric buffers.  We do the copy so that we don't
8384d9c625SLionel Sambuc 	 * have to reference count and so we don't have to deal with things
8484d9c625SLionel Sambuc 	 * like appends to buffers that are used multiple times.)
8584d9c625SLionel Sambuc 	 *
8684d9c625SLionel Sambuc 	 * Otherwise, if it's supposed to be put in a numeric buffer (usually
8784d9c625SLionel Sambuc 	 * a delete) put it there.  The rules for putting things in numeric
8884d9c625SLionel Sambuc 	 * buffers were historically a little strange.  There were three cases.
8984d9c625SLionel Sambuc 	 *
9084d9c625SLionel Sambuc 	 *	1: Some motions are always line mode motions, which means
9184d9c625SLionel Sambuc 	 *	   that the cut always goes into the numeric buffers.
9284d9c625SLionel Sambuc 	 *	2: Some motions aren't line mode motions, e.g. d10w, but
9384d9c625SLionel Sambuc 	 *	   can cross line boundaries.  For these commands, if the
9484d9c625SLionel Sambuc 	 *	   cut crosses a line boundary, it goes into the numeric
9584d9c625SLionel Sambuc 	 *	   buffers.  This includes most of the commands.
9684d9c625SLionel Sambuc 	 *	3: Some motions aren't line mode motions, e.g. d`<char>,
9784d9c625SLionel Sambuc 	 *	   but always go into the numeric buffers, regardless.  This
9884d9c625SLionel Sambuc 	 *	   was the commands: % ` / ? ( ) N n { } -- and nvi adds ^A.
9984d9c625SLionel Sambuc 	 *
10084d9c625SLionel Sambuc 	 * Otherwise, put it in the unnamed buffer.
10184d9c625SLionel Sambuc 	 */
10284d9c625SLionel Sambuc 	append = copy_one = copy_def = 0;
10384d9c625SLionel Sambuc 	if (namep != NULL) {
10484d9c625SLionel Sambuc 		name = *namep;
10584d9c625SLionel Sambuc 		if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
10684d9c625SLionel Sambuc 		    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
10784d9c625SLionel Sambuc 			copy_one = 1;
10884d9c625SLionel Sambuc 			cb_rotate(sp);
10984d9c625SLionel Sambuc 		}
11084d9c625SLionel Sambuc 		if ((append = ISUPPER(name))) {
11184d9c625SLionel Sambuc 			if (!copy_one)
11284d9c625SLionel Sambuc 				copy_def = 1;
11384d9c625SLionel Sambuc 			name = TOLOWER(name);
11484d9c625SLionel Sambuc 		}
11584d9c625SLionel Sambuc namecb:		CBNAME(sp, cbp, name);
11684d9c625SLionel Sambuc 	} else if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
11784d9c625SLionel Sambuc 	    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
11884d9c625SLionel Sambuc 		name = L('1');
11984d9c625SLionel Sambuc 		cb_rotate(sp);
12084d9c625SLionel Sambuc 		goto namecb;
12184d9c625SLionel Sambuc 	} else
12284d9c625SLionel Sambuc 		cbp = &sp->wp->dcb_store;
12384d9c625SLionel Sambuc 
12484d9c625SLionel Sambuc copyloop:
12584d9c625SLionel Sambuc 	/*
12684d9c625SLionel Sambuc 	 * If this is a new buffer, create it and add it into the list.
12784d9c625SLionel Sambuc 	 * Otherwise, if it's not an append, free its current contents.
12884d9c625SLionel Sambuc 	 */
12984d9c625SLionel Sambuc 	if (cbp == NULL) {
13084d9c625SLionel Sambuc 		CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB));
13184d9c625SLionel Sambuc 		cbp->name = name;
13284d9c625SLionel Sambuc 		TAILQ_INIT(&cbp->textq);
13384d9c625SLionel Sambuc 		LIST_INSERT_HEAD(&sp->wp->cutq, cbp, q);
13484d9c625SLionel Sambuc 	} else if (!append) {
13584d9c625SLionel Sambuc 		text_lfree(&cbp->textq);
13684d9c625SLionel Sambuc 		cbp->len = 0;
13784d9c625SLionel Sambuc 		cbp->flags = 0;
13884d9c625SLionel Sambuc 	}
13984d9c625SLionel Sambuc 
14084d9c625SLionel Sambuc 
14184d9c625SLionel Sambuc 	/* In line mode, it's pretty easy, just cut the lines. */
14284d9c625SLionel Sambuc 	if (LF_ISSET(CUT_LINEMODE)) {
14384d9c625SLionel Sambuc 		cbp->flags |= CB_LMODE;
14484d9c625SLionel Sambuc 		for (lno = fm->lno; lno <= tm->lno; ++lno)
14584d9c625SLionel Sambuc 			if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp))
14684d9c625SLionel Sambuc 				goto cut_line_err;
14784d9c625SLionel Sambuc 	} else {
14884d9c625SLionel Sambuc 		/*
14984d9c625SLionel Sambuc 		 * Get the first line.  A length of ENTIRE_LINE causes cut_line
15084d9c625SLionel Sambuc 		 * to cut from the MARK to the end of the line.
15184d9c625SLionel Sambuc 		 */
15284d9c625SLionel Sambuc 		if (cut_line(sp, fm->lno, fm->cno, fm->lno != tm->lno ?
15384d9c625SLionel Sambuc 		    ENTIRE_LINE : (tm->cno - fm->cno) + 1, cbp))
15484d9c625SLionel Sambuc 			goto cut_line_err;
15584d9c625SLionel Sambuc 
15684d9c625SLionel Sambuc 		/* Get the intermediate lines. */
15784d9c625SLionel Sambuc 		for (lno = fm->lno; ++lno < tm->lno;)
15884d9c625SLionel Sambuc 			if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp))
15984d9c625SLionel Sambuc 				goto cut_line_err;
16084d9c625SLionel Sambuc 
16184d9c625SLionel Sambuc 		/* Get the last line. */
16284d9c625SLionel Sambuc 		if (tm->lno != fm->lno &&
16384d9c625SLionel Sambuc 		    cut_line(sp, lno, 0, tm->cno + 1, cbp))
16484d9c625SLionel Sambuc 			goto cut_line_err;
16584d9c625SLionel Sambuc 	}
16684d9c625SLionel Sambuc 
16784d9c625SLionel Sambuc 	append = 0;		/* Only append to the named buffer. */
16884d9c625SLionel Sambuc 	sp->wp->dcbp = cbp;	/* Repoint the default buffer on each pass. */
16984d9c625SLionel Sambuc 
17084d9c625SLionel Sambuc 	if (copy_one) {		/* Copy into numeric buffer 1. */
17184d9c625SLionel Sambuc 		name = L('1');
17284d9c625SLionel Sambuc 		CBNAME(sp, cbp, name);
17384d9c625SLionel Sambuc 		copy_one = 0;
17484d9c625SLionel Sambuc 		goto copyloop;
17584d9c625SLionel Sambuc 	}
17684d9c625SLionel Sambuc 	if (copy_def) {		/* Copy into the default buffer. */
17784d9c625SLionel Sambuc 		cbp = &sp->wp->dcb_store;
17884d9c625SLionel Sambuc 		copy_def = 0;
17984d9c625SLionel Sambuc 		goto copyloop;
18084d9c625SLionel Sambuc 	}
18184d9c625SLionel Sambuc 	return (0);
18284d9c625SLionel Sambuc 
18384d9c625SLionel Sambuc cut_line_err:
18484d9c625SLionel Sambuc 	text_lfree(&cbp->textq);
18584d9c625SLionel Sambuc 	cbp->len = 0;
18684d9c625SLionel Sambuc 	cbp->flags = 0;
18784d9c625SLionel Sambuc 	return (1);
18884d9c625SLionel Sambuc }
18984d9c625SLionel Sambuc 
19084d9c625SLionel Sambuc /*
19184d9c625SLionel Sambuc  * cb_rotate --
19284d9c625SLionel Sambuc  *	Rotate the numbered buffers up one.
19384d9c625SLionel Sambuc  */
19484d9c625SLionel Sambuc static void
cb_rotate(SCR * sp)19584d9c625SLionel Sambuc cb_rotate(SCR *sp)
19684d9c625SLionel Sambuc {
19784d9c625SLionel Sambuc 	CB *cbp, *del_cbp;
19884d9c625SLionel Sambuc 
19984d9c625SLionel Sambuc 	del_cbp = NULL;
20084d9c625SLionel Sambuc 	LIST_FOREACH(cbp, &sp->wp->cutq, q)
20184d9c625SLionel Sambuc 		switch(cbp->name) {
20284d9c625SLionel Sambuc 		case L('1'):
20384d9c625SLionel Sambuc 			cbp->name = L('2');
20484d9c625SLionel Sambuc 			break;
20584d9c625SLionel Sambuc 		case L('2'):
20684d9c625SLionel Sambuc 			cbp->name = L('3');
20784d9c625SLionel Sambuc 			break;
20884d9c625SLionel Sambuc 		case L('3'):
20984d9c625SLionel Sambuc 			cbp->name = L('4');
21084d9c625SLionel Sambuc 			break;
21184d9c625SLionel Sambuc 		case L('4'):
21284d9c625SLionel Sambuc 			cbp->name = L('5');
21384d9c625SLionel Sambuc 			break;
21484d9c625SLionel Sambuc 		case L('5'):
21584d9c625SLionel Sambuc 			cbp->name = L('6');
21684d9c625SLionel Sambuc 			break;
21784d9c625SLionel Sambuc 		case L('6'):
21884d9c625SLionel Sambuc 			cbp->name = L('7');
21984d9c625SLionel Sambuc 			break;
22084d9c625SLionel Sambuc 		case L('7'):
22184d9c625SLionel Sambuc 			cbp->name = L('8');
22284d9c625SLionel Sambuc 			break;
22384d9c625SLionel Sambuc 		case L('8'):
22484d9c625SLionel Sambuc 			cbp->name = L('9');
22584d9c625SLionel Sambuc 			break;
22684d9c625SLionel Sambuc 		case L('9'):
22784d9c625SLionel Sambuc 			del_cbp = cbp;
22884d9c625SLionel Sambuc 			break;
22984d9c625SLionel Sambuc 		}
23084d9c625SLionel Sambuc 	if (del_cbp != NULL) {
23184d9c625SLionel Sambuc 		LIST_REMOVE(del_cbp, q);
23284d9c625SLionel Sambuc 		text_lfree(&del_cbp->textq);
23384d9c625SLionel Sambuc 		free(del_cbp);
23484d9c625SLionel Sambuc 	}
23584d9c625SLionel Sambuc }
23684d9c625SLionel Sambuc 
23784d9c625SLionel Sambuc /*
23884d9c625SLionel Sambuc  * cut_line --
23984d9c625SLionel Sambuc  *	Cut a portion of a single line.
24084d9c625SLionel Sambuc  *
24184d9c625SLionel Sambuc  * PUBLIC: int cut_line __P((SCR *, db_recno_t, size_t, size_t, CB *));
24284d9c625SLionel Sambuc  */
24384d9c625SLionel Sambuc int
cut_line(SCR * sp,db_recno_t lno,size_t fcno,size_t clen,CB * cbp)24484d9c625SLionel Sambuc cut_line(SCR *sp, db_recno_t lno, size_t fcno, size_t clen, CB *cbp)
24584d9c625SLionel Sambuc {
24684d9c625SLionel Sambuc 	TEXT *tp;
24784d9c625SLionel Sambuc 	size_t len;
24884d9c625SLionel Sambuc 	CHAR_T *p;
24984d9c625SLionel Sambuc 
25084d9c625SLionel Sambuc 	/* Get the line. */
25184d9c625SLionel Sambuc 	if (db_get(sp, lno, DBG_FATAL, &p, &len))
25284d9c625SLionel Sambuc 		return (1);
25384d9c625SLionel Sambuc 
25484d9c625SLionel Sambuc 	/* Create a TEXT structure that can hold the entire line. */
25584d9c625SLionel Sambuc 	if ((tp = text_init(sp, NULL, 0, len)) == NULL)
25684d9c625SLionel Sambuc 		return (1);
25784d9c625SLionel Sambuc 
25884d9c625SLionel Sambuc 	/*
25984d9c625SLionel Sambuc 	 * If the line isn't empty and it's not the entire line,
26084d9c625SLionel Sambuc 	 * copy the portion we want, and reset the TEXT length.
26184d9c625SLionel Sambuc 	 */
26284d9c625SLionel Sambuc 	if (len != 0) {
26384d9c625SLionel Sambuc 		if (clen == ENTIRE_LINE)
26484d9c625SLionel Sambuc 			clen = len - fcno;
26584d9c625SLionel Sambuc 		MEMCPYW(tp->lb, p + fcno, clen);
26684d9c625SLionel Sambuc 		tp->len = clen;
26784d9c625SLionel Sambuc 	}
26884d9c625SLionel Sambuc 
26984d9c625SLionel Sambuc 	/* Append to the end of the cut buffer. */
27084d9c625SLionel Sambuc 	TAILQ_INSERT_TAIL(&cbp->textq, tp, q);
27184d9c625SLionel Sambuc 	cbp->len += tp->len;
27284d9c625SLionel Sambuc 
27384d9c625SLionel Sambuc 	return (0);
27484d9c625SLionel Sambuc }
27584d9c625SLionel Sambuc 
27684d9c625SLionel Sambuc /*
27784d9c625SLionel Sambuc  * cut_close --
27884d9c625SLionel Sambuc  *	Discard all cut buffers.
27984d9c625SLionel Sambuc  *
28084d9c625SLionel Sambuc  * PUBLIC: void cut_close __P((WIN *));
28184d9c625SLionel Sambuc  */
28284d9c625SLionel Sambuc void
cut_close(WIN * wp)28384d9c625SLionel Sambuc cut_close(WIN *wp)
28484d9c625SLionel Sambuc {
28584d9c625SLionel Sambuc 	CB *cbp;
28684d9c625SLionel Sambuc 
28784d9c625SLionel Sambuc 	/* Free cut buffer list. */
28884d9c625SLionel Sambuc 	while ((cbp = LIST_FIRST(&wp->cutq)) != NULL) {
28984d9c625SLionel Sambuc 		if (!TAILQ_EMPTY(&cbp->textq))
29084d9c625SLionel Sambuc 			text_lfree(&cbp->textq);
29184d9c625SLionel Sambuc 		LIST_REMOVE(cbp, q);
29284d9c625SLionel Sambuc 		free(cbp);
29384d9c625SLionel Sambuc 	}
29484d9c625SLionel Sambuc 
29584d9c625SLionel Sambuc 	/* Free default cut storage. */
29684d9c625SLionel Sambuc 	cbp = &wp->dcb_store;
29784d9c625SLionel Sambuc 	if (!TAILQ_EMPTY(&cbp->textq))
29884d9c625SLionel Sambuc 		text_lfree(&cbp->textq);
29984d9c625SLionel Sambuc }
30084d9c625SLionel Sambuc 
30184d9c625SLionel Sambuc /*
30284d9c625SLionel Sambuc  * text_init --
30384d9c625SLionel Sambuc  *	Allocate a new TEXT structure.
30484d9c625SLionel Sambuc  *
30584d9c625SLionel Sambuc  * PUBLIC: TEXT *text_init __P((SCR *, const CHAR_T *, size_t, size_t));
30684d9c625SLionel Sambuc  */
30784d9c625SLionel Sambuc TEXT *
text_init(SCR * sp,const CHAR_T * p,size_t len,size_t total_len)30884d9c625SLionel Sambuc text_init(SCR *sp, const CHAR_T *p, size_t len, size_t total_len)
30984d9c625SLionel Sambuc {
31084d9c625SLionel Sambuc 	TEXT *tp;
31184d9c625SLionel Sambuc 
31284d9c625SLionel Sambuc 	CALLOC(sp, tp, TEXT *, 1, sizeof(TEXT));
31384d9c625SLionel Sambuc 	if (tp == NULL)
31484d9c625SLionel Sambuc 		return (NULL);
31584d9c625SLionel Sambuc 	/* ANSI C doesn't define a call to malloc(3) for 0 bytes. */
31684d9c625SLionel Sambuc 	if ((tp->lb_len = total_len * sizeof(CHAR_T)) != 0) {
31784d9c625SLionel Sambuc 		MALLOC(sp, tp->lb, CHAR_T *, tp->lb_len * sizeof(CHAR_T));
31884d9c625SLionel Sambuc 		if (tp->lb == NULL) {
31984d9c625SLionel Sambuc 			free(tp);
32084d9c625SLionel Sambuc 			return (NULL);
32184d9c625SLionel Sambuc 		}
32284d9c625SLionel Sambuc 		if (p != NULL && len != 0)
32384d9c625SLionel Sambuc 			MEMCPYW(tp->lb, p, len);
32484d9c625SLionel Sambuc 	}
32584d9c625SLionel Sambuc 	tp->len = len;
32684d9c625SLionel Sambuc 	return (tp);
32784d9c625SLionel Sambuc }
32884d9c625SLionel Sambuc 
32984d9c625SLionel Sambuc /*
33084d9c625SLionel Sambuc  * text_lfree --
33184d9c625SLionel Sambuc  *	Free a chain of text structures.
33284d9c625SLionel Sambuc  *
33384d9c625SLionel Sambuc  * PUBLIC: void text_lfree __P((TEXTH *));
33484d9c625SLionel Sambuc  */
33584d9c625SLionel Sambuc void
text_lfree(TEXTH * headp)33684d9c625SLionel Sambuc text_lfree(TEXTH *headp)
33784d9c625SLionel Sambuc {
33884d9c625SLionel Sambuc 	TEXT *tp;
33984d9c625SLionel Sambuc 
34084d9c625SLionel Sambuc 	while ((tp = TAILQ_FIRST(headp)) != NULL) {
34184d9c625SLionel Sambuc 		TAILQ_REMOVE(headp, tp, q);
34284d9c625SLionel Sambuc 		text_free(tp);
34384d9c625SLionel Sambuc 	}
34484d9c625SLionel Sambuc }
34584d9c625SLionel Sambuc 
34684d9c625SLionel Sambuc /*
34784d9c625SLionel Sambuc  * text_free --
34884d9c625SLionel Sambuc  *	Free a text structure.
34984d9c625SLionel Sambuc  *
35084d9c625SLionel Sambuc  * PUBLIC: void text_free __P((TEXT *));
35184d9c625SLionel Sambuc  */
35284d9c625SLionel Sambuc void
text_free(TEXT * tp)35384d9c625SLionel Sambuc text_free(TEXT *tp)
35484d9c625SLionel Sambuc {
35584d9c625SLionel Sambuc 	if (tp->lb != NULL)
35684d9c625SLionel Sambuc 		free(tp->lb);
35784d9c625SLionel Sambuc 	free(tp);
35884d9c625SLionel Sambuc }
359