xref: /freebsd/contrib/libedit/chared.h (revision 02e9120893770924227138ba49df1edb3896112a)
1 /*	$NetBSD: chared.h,v 1.30 2016/05/22 19:44:26 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Christos Zoulas of Cornell University.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
35  */
36 
37 /*
38  * el.chared.h: Character editor interface
39  */
40 #ifndef _h_el_chared
41 #define	_h_el_chared
42 
43 /*
44  * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
45  * like real vi: i.e. the transition from command<->insert modes moves
46  * the cursor.
47  *
48  * On the other hand we really don't want to move the cursor, because
49  * all the editing commands don't include the character under the cursor.
50  * Probably the best fix is to make all the editing commands aware of
51  * this fact.
52  */
53 #define	VI_MOVE
54 
55 /*
56  * Undo information for vi - no undo in emacs (yet)
57  */
58 typedef struct c_undo_t {
59 	ssize_t	 len;			/* length of saved line */
60 	int	 cursor;		/* position of saved cursor */
61 	wchar_t	*buf;			/* full saved text */
62 } c_undo_t;
63 
64 /* redo for vi */
65 typedef struct c_redo_t {
66 	wchar_t	*buf;			/* redo insert key sequence */
67 	wchar_t	*pos;
68 	wchar_t	*lim;
69 	el_action_t	cmd;		/* command to redo */
70 	wchar_t	ch;			/* char that invoked it */
71 	int	count;
72 	int	action;			/* from cv_action() */
73 } c_redo_t;
74 
75 /*
76  * Current action information for vi
77  */
78 typedef struct c_vcmd_t {
79 	int	 action;
80 	wchar_t	*pos;
81 } c_vcmd_t;
82 
83 /*
84  * Kill buffer for emacs
85  */
86 typedef struct c_kill_t {
87 	wchar_t	*buf;
88 	wchar_t	*last;
89 	wchar_t	*mark;
90 } c_kill_t;
91 
92 typedef void (*el_zfunc_t)(EditLine *, void *);
93 typedef const char *(*el_afunc_t)(void *, const char *);
94 
95 /*
96  * Note that we use both data structures because the user can bind
97  * commands from both editors!
98  */
99 typedef struct el_chared_t {
100 	c_undo_t	c_undo;
101 	c_kill_t	c_kill;
102 	c_redo_t	c_redo;
103 	c_vcmd_t	c_vcmd;
104 	el_zfunc_t	c_resizefun;
105 	el_afunc_t	c_aliasfun;
106 	void *		c_resizearg;
107 	void *		c_aliasarg;
108 } el_chared_t;
109 
110 
111 #define	STRQQ		"\"\""
112 
113 #define	isglob(a)	(strchr("*[]?", (a)) != NULL)
114 
115 #define	NOP		0x00
116 #define	DELETE		0x01
117 #define	INSERT		0x02
118 #define	YANK		0x04
119 
120 #define	CHAR_FWD	(+1)
121 #define	CHAR_BACK	(-1)
122 
123 #define	MODE_INSERT	0
124 #define	MODE_REPLACE	1
125 #define	MODE_REPLACE_1	2
126 
127 
128 libedit_private int	 cv__isword(wint_t);
129 libedit_private int	 cv__isWord(wint_t);
130 libedit_private void	 cv_delfini(EditLine *);
131 libedit_private wchar_t *cv__endword(wchar_t *, wchar_t *, int, int (*)(wint_t));
132 libedit_private int	 ce__isword(wint_t);
133 libedit_private void	 cv_undo(EditLine *);
134 libedit_private void	 cv_yank(EditLine *, const wchar_t *, int);
135 libedit_private wchar_t *cv_next_word(EditLine*, wchar_t *, wchar_t *, int,
136 			int (*)(wint_t));
137 libedit_private wchar_t *cv_prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
138 libedit_private wchar_t *c__next_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
139 libedit_private wchar_t *c__prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
140 libedit_private void	 c_insert(EditLine *, int);
141 libedit_private void	 c_delbefore(EditLine *, int);
142 libedit_private void	 c_delbefore1(EditLine *);
143 libedit_private void	 c_delafter(EditLine *, int);
144 libedit_private void	 c_delafter1(EditLine *);
145 libedit_private int	 c_gets(EditLine *, wchar_t *, const wchar_t *);
146 libedit_private int	 c_hpos(EditLine *);
147 
148 libedit_private int	 ch_init(EditLine *);
149 libedit_private void	 ch_reset(EditLine *);
150 libedit_private int	 ch_resizefun(EditLine *, el_zfunc_t, void *);
151 libedit_private int	 ch_aliasfun(EditLine *, el_afunc_t, void *);
152 libedit_private int	 ch_enlargebufs(EditLine *, size_t);
153 libedit_private void	 ch_end(EditLine *);
154 
155 #endif /* _h_el_chared */
156