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