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