1/*-
2 * Copyright (c) 1991, 1993, 1994
3 *	The Regents of the University of California.  All rights reserved.
4 * Copyright (c) 1991, 1993, 1994, 1995, 1996
5 *	Keith Bostic.  All rights reserved.
6 *
7 * See the LICENSE file for redistribution information.
8 */
9
10typedef struct _texth TEXTH;		/* TEXT list head structure. */
11TAILQ_HEAD(_texth, _text);
12
13/* Cut buffers. */
14struct _cb {
15	SLIST_ENTRY(_cb) q;		/* Linked list of cut buffers. */
16	TEXTH	 textq[1];		/* Linked list of TEXT structures. */
17	/* XXXX Needed ? Can non ascii-chars be cut buffer names ? */
18	CHAR_T	 name;			/* Cut buffer name. */
19	size_t	 len;			/* Total length of cut text. */
20
21#define	CB_LMODE	0x01		/* Cut was in line mode. */
22	u_int8_t flags;
23};
24
25/* Lines/blocks of text. */
26struct _text {				/* Text: a linked list of lines. */
27	TAILQ_ENTRY(_text) q;		/* Linked list of text structures. */
28	CHAR_T	*lb;			/* Line buffer. */
29	size_t	 lb_len;		/* Line buffer length. */
30	size_t	 len;			/* Line length. */
31
32	/* These fields are used by the vi text input routine. */
33	recno_t	 lno;			/* 1-N: file line. */
34
35#define	ENTIRE_LINE	((size_t)-1)	/* cno: end of the line. */
36	size_t	 cno;			/* 0-N: file character in line. */
37	size_t	 ai;			/* 0-N: autoindent bytes. */
38	size_t	 insert;		/* 0-N: bytes to insert (push). */
39	size_t	 offset;		/* 0-N: initial, unerasable chars. */
40	size_t	 owrite;		/* 0-N: chars to overwrite. */
41	size_t	 R_erase;		/* 0-N: 'R' erase count. */
42	size_t	 sv_cno;		/* 0-N: Saved line cursor. */
43	size_t	 sv_len;		/* 0-N: Saved line length. */
44
45	/*
46	 * These fields returns information from the vi text input routine.
47	 *
48	 * The termination condition.  Note, this field is only valid if the
49	 * text input routine returns success.
50	 *	TERM_BS:	User backspaced over the prompt.
51	 *	TERM_CEDIT:	User entered <edit-char>.
52	 *	TERM_CR:	User entered <carriage-return>; no data.
53	 *	TERM_ESC:	User entered <escape>; no data.
54	 *	TERM_OK:	Data available.
55	 *	TERM_SEARCH:	Incremental search.
56	 */
57	enum {
58	    TERM_BS, TERM_CEDIT, TERM_CR, TERM_ESC, TERM_OK, TERM_SEARCH
59	} term;
60};
61
62/*
63 * Get named buffer 'name'.
64 * Translate upper-case buffer names to lower-case buffer names.
65 */
66#define	CBNAME(sp, cbp, nch) do {					\
67	CHAR_T L__name;							\
68	L__name = isupper(nch) ? tolower(nch) : (nch);			\
69	SLIST_FOREACH(cbp, sp->gp->cutq, q)				\
70		if (cbp->name == L__name)				\
71			break;						\
72} while (0)
73
74/* Flags to the cut() routine. */
75#define	CUT_LINEMODE	0x01		/* Cut in line mode. */
76#define	CUT_NUMOPT	0x02		/* Numeric buffer: optional. */
77#define	CUT_NUMREQ	0x04		/* Numeric buffer: required. */
78