xref: /openbsd/lib/libedit/chared.h (revision aed0ee81)
1*aed0ee81Snicm /*	$OpenBSD: chared.h,v 1.9 2010/06/30 00:05:35 nicm Exp $	*/
2*aed0ee81Snicm /*	$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 #include <ctype.h>
45df930be7Sderaadt #include <string.h>
46df930be7Sderaadt 
47df930be7Sderaadt #include "histedit.h"
48df930be7Sderaadt 
49df930be7Sderaadt #define	EL_MAXMACRO	10
50df930be7Sderaadt 
51df930be7Sderaadt /*
52*aed0ee81Snicm  * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
53df930be7Sderaadt  * like real vi: i.e. the transition from command<->insert modes moves
54df930be7Sderaadt  * the cursor.
55df930be7Sderaadt  *
56df930be7Sderaadt  * On the other hand we really don't want to move the cursor, because
57df930be7Sderaadt  * all the editing commands don't include the character under the cursor.
58df930be7Sderaadt  * Probably the best fix is to make all the editing commands aware of
59df930be7Sderaadt  * this fact.
60df930be7Sderaadt  */
61df930be7Sderaadt #define	VI_MOVE
62df930be7Sderaadt 
63df930be7Sderaadt 
64df930be7Sderaadt typedef struct c_macro_t {
65df930be7Sderaadt 	int	  level;
666e02e073Sotto 	int	  offset;
67*aed0ee81Snicm 	Char	**macro;
68df930be7Sderaadt } c_macro_t;
69df930be7Sderaadt 
70df930be7Sderaadt /*
71d484b7d0Sotto  * Undo information for vi - no undo in emacs (yet)
72df930be7Sderaadt  */
73df930be7Sderaadt typedef struct c_undo_t {
74*aed0ee81Snicm 	ssize_t	 len;			/* length of saved line */
75d484b7d0Sotto 	int	 cursor;		/* position of saved cursor */
76*aed0ee81Snicm 	Char	*buf;			/* full saved text */
77df930be7Sderaadt } c_undo_t;
78df930be7Sderaadt 
79d484b7d0Sotto /* redo for vi */
80d484b7d0Sotto typedef struct c_redo_t {
81*aed0ee81Snicm 	Char	*buf;			/* redo insert key sequence */
82*aed0ee81Snicm 	Char	*pos;
83*aed0ee81Snicm 	Char	*lim;
84d484b7d0Sotto 	el_action_t	cmd;		/* command to redo */
85*aed0ee81Snicm 	Char	ch;			/* char that invoked it */
86d484b7d0Sotto 	int	count;
87d484b7d0Sotto 	int	action;			/* from cv_action() */
88d484b7d0Sotto } c_redo_t;
89d484b7d0Sotto 
90df930be7Sderaadt /*
91df930be7Sderaadt  * Current action information for vi
92df930be7Sderaadt  */
93df930be7Sderaadt typedef struct c_vcmd_t {
94df930be7Sderaadt 	int	 action;
95*aed0ee81Snicm 	Char	*pos;
96df930be7Sderaadt } c_vcmd_t;
97df930be7Sderaadt 
98df930be7Sderaadt /*
99df930be7Sderaadt  * Kill buffer for emacs
100df930be7Sderaadt  */
101df930be7Sderaadt typedef struct c_kill_t {
102*aed0ee81Snicm 	Char	*buf;
103*aed0ee81Snicm 	Char	*last;
104*aed0ee81Snicm 	Char	*mark;
105df930be7Sderaadt } c_kill_t;
106df930be7Sderaadt 
107df930be7Sderaadt /*
108df930be7Sderaadt  * Note that we use both data structures because the user can bind
109df930be7Sderaadt  * commands from both editors!
110df930be7Sderaadt  */
111df930be7Sderaadt typedef struct el_chared_t {
112df930be7Sderaadt 	c_undo_t	c_undo;
113df930be7Sderaadt 	c_kill_t	c_kill;
114d484b7d0Sotto 	c_redo_t	c_redo;
115df930be7Sderaadt 	c_vcmd_t	c_vcmd;
116df930be7Sderaadt 	c_macro_t	c_macro;
117df930be7Sderaadt } el_chared_t;
118df930be7Sderaadt 
119df930be7Sderaadt 
120df930be7Sderaadt #define	STRQQ		"\"\""
121df930be7Sderaadt 
122df930be7Sderaadt #define	isglob(a)	(strchr("*[]?", (a)) != NULL)
123df930be7Sderaadt 
124df930be7Sderaadt #define	NOP		0x00
125df930be7Sderaadt #define	DELETE		0x01
126df930be7Sderaadt #define	INSERT		0x02
127d484b7d0Sotto #define	YANK		0x04
128df930be7Sderaadt 
129d484b7d0Sotto #define	CHAR_FWD	(+1)
130d484b7d0Sotto #define	CHAR_BACK	(-1)
131df930be7Sderaadt 
132df930be7Sderaadt #define	MODE_INSERT	0
133df930be7Sderaadt #define	MODE_REPLACE	1
134df930be7Sderaadt #define	MODE_REPLACE_1	2
135df930be7Sderaadt 
136df930be7Sderaadt #include "common.h"
137df930be7Sderaadt #include "vi.h"
138df930be7Sderaadt #include "emacs.h"
139df930be7Sderaadt #include "search.h"
140df930be7Sderaadt #include "fcns.h"
141df930be7Sderaadt 
142df930be7Sderaadt 
143*aed0ee81Snicm protected int	 cv__isword(Int);
144*aed0ee81Snicm protected int	 cv__isWord(Int);
145c72b5b24Smillert protected void	 cv_delfini(EditLine *);
146*aed0ee81Snicm protected Char	*cv__endword(Char *, Char *, int, int (*)(Int));
147*aed0ee81Snicm protected int	 ce__isword(Int);
148d484b7d0Sotto protected void	 cv_undo(EditLine *);
149*aed0ee81Snicm protected void	 cv_yank(EditLine *, const Char *, int);
150*aed0ee81Snicm protected Char	*cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int));
151*aed0ee81Snicm protected Char	*cv_prev_word(Char *, Char *, int, int (*)(Int));
152*aed0ee81Snicm protected Char	*c__next_word(Char *, Char *, int, int (*)(Int));
153*aed0ee81Snicm protected Char	*c__prev_word(Char *, Char *, int, int (*)(Int));
154c72b5b24Smillert protected void	 c_insert(EditLine *, int);
155c72b5b24Smillert protected void	 c_delbefore(EditLine *, int);
156*aed0ee81Snicm protected void	 c_delbefore1(EditLine *);
157c72b5b24Smillert protected void	 c_delafter(EditLine *, int);
158*aed0ee81Snicm protected void	 c_delafter1(EditLine *);
159*aed0ee81Snicm protected int	 c_gets(EditLine *, Char *, const Char *);
160c72b5b24Smillert protected int	 c_hpos(EditLine *);
161df930be7Sderaadt 
162c72b5b24Smillert protected int	 ch_init(EditLine *);
163*aed0ee81Snicm protected void	 ch_reset(EditLine *, int);
164d484b7d0Sotto protected int	 ch_enlargebufs(EditLine *, size_t);
165c72b5b24Smillert protected void	 ch_end(EditLine *);
166df930be7Sderaadt 
167df930be7Sderaadt #endif /* _h_el_chared */
168