xref: /netbsd-src/lib/libedit/chared.h (revision bb64d9f1ced66a660699c8c7493fa13eff478293)
1*bb64d9f1Schristos /*	$NetBSD: chared.h,v 1.30 2016/05/22 19:44:26 christos Exp $	*/
22543e3e6Slukem 
36dc2f1dbScgd /*-
46dc2f1dbScgd  * Copyright (c) 1992, 1993
56dc2f1dbScgd  *	The Regents of the University of California.  All rights reserved.
66dc2f1dbScgd  *
76dc2f1dbScgd  * This code is derived from software contributed to Berkeley by
86dc2f1dbScgd  * Christos Zoulas of Cornell University.
96dc2f1dbScgd  *
106dc2f1dbScgd  * Redistribution and use in source and binary forms, with or without
116dc2f1dbScgd  * modification, are permitted provided that the following conditions
126dc2f1dbScgd  * are met:
136dc2f1dbScgd  * 1. Redistributions of source code must retain the above copyright
146dc2f1dbScgd  *    notice, this list of conditions and the following disclaimer.
156dc2f1dbScgd  * 2. Redistributions in binary form must reproduce the above copyright
166dc2f1dbScgd  *    notice, this list of conditions and the following disclaimer in the
176dc2f1dbScgd  *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
196dc2f1dbScgd  *    may be used to endorse or promote products derived from this software
206dc2f1dbScgd  *    without specific prior written permission.
216dc2f1dbScgd  *
226dc2f1dbScgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
236dc2f1dbScgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
246dc2f1dbScgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
256dc2f1dbScgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
266dc2f1dbScgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
276dc2f1dbScgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
286dc2f1dbScgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
296dc2f1dbScgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
306dc2f1dbScgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
316dc2f1dbScgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
326dc2f1dbScgd  * SUCH DAMAGE.
336dc2f1dbScgd  *
346dc2f1dbScgd  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
356dc2f1dbScgd  */
366dc2f1dbScgd 
376dc2f1dbScgd /*
386dc2f1dbScgd  * el.chared.h: Character editor interface
396dc2f1dbScgd  */
406dc2f1dbScgd #ifndef _h_el_chared
416dc2f1dbScgd #define	_h_el_chared
426dc2f1dbScgd 
436dc2f1dbScgd /*
442ecb0fb7Schristos  * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
456dc2f1dbScgd  * like real vi: i.e. the transition from command<->insert modes moves
466dc2f1dbScgd  * the cursor.
476dc2f1dbScgd  *
486dc2f1dbScgd  * On the other hand we really don't want to move the cursor, because
496dc2f1dbScgd  * all the editing commands don't include the character under the cursor.
506dc2f1dbScgd  * Probably the best fix is to make all the editing commands aware of
516dc2f1dbScgd  * this fact.
526dc2f1dbScgd  */
536dc2f1dbScgd #define	VI_MOVE
546dc2f1dbScgd 
556dc2f1dbScgd /*
56a17c7fe4Schristos  * Undo information for vi - no undo in emacs (yet)
576dc2f1dbScgd  */
586dc2f1dbScgd typedef struct c_undo_t {
595c894153Schristos 	ssize_t	 len;			/* length of saved line */
60a17c7fe4Schristos 	int	 cursor;		/* position of saved cursor */
610594af80Schristos 	wchar_t	*buf;			/* full saved text */
626dc2f1dbScgd } c_undo_t;
636dc2f1dbScgd 
6439f224afSchristos /* redo for vi */
6539f224afSchristos typedef struct c_redo_t {
660594af80Schristos 	wchar_t	*buf;			/* redo insert key sequence */
670594af80Schristos 	wchar_t	*pos;
680594af80Schristos 	wchar_t	*lim;
6939f224afSchristos 	el_action_t	cmd;		/* command to redo */
700594af80Schristos 	wchar_t	ch;			/* char that invoked it */
7139f224afSchristos 	int	count;
7239f224afSchristos 	int	action;			/* from cv_action() */
7339f224afSchristos } c_redo_t;
7439f224afSchristos 
756dc2f1dbScgd /*
766dc2f1dbScgd  * Current action information for vi
776dc2f1dbScgd  */
786dc2f1dbScgd typedef struct c_vcmd_t {
796dc2f1dbScgd 	int	 action;
800594af80Schristos 	wchar_t	*pos;
816dc2f1dbScgd } c_vcmd_t;
826dc2f1dbScgd 
836dc2f1dbScgd /*
846dc2f1dbScgd  * Kill buffer for emacs
856dc2f1dbScgd  */
866dc2f1dbScgd typedef struct c_kill_t {
870594af80Schristos 	wchar_t	*buf;
880594af80Schristos 	wchar_t	*last;
890594af80Schristos 	wchar_t	*mark;
906dc2f1dbScgd } c_kill_t;
916dc2f1dbScgd 
927741aae9Schristos typedef void (*el_zfunc_t)(EditLine *, void *);
93e06822a7Schristos typedef const char *(*el_afunc_t)(void *, const char *);
947741aae9Schristos 
956dc2f1dbScgd /*
966dc2f1dbScgd  * Note that we use both data structures because the user can bind
976dc2f1dbScgd  * commands from both editors!
986dc2f1dbScgd  */
996dc2f1dbScgd typedef struct el_chared_t {
1006dc2f1dbScgd 	c_undo_t	c_undo;
1016dc2f1dbScgd 	c_kill_t	c_kill;
10239f224afSchristos 	c_redo_t	c_redo;
1036dc2f1dbScgd 	c_vcmd_t	c_vcmd;
1047741aae9Schristos 	el_zfunc_t	c_resizefun;
105e06822a7Schristos 	el_afunc_t	c_aliasfun;
1067741aae9Schristos 	void *		c_resizearg;
107e06822a7Schristos 	void *		c_aliasarg;
1086dc2f1dbScgd } el_chared_t;
1096dc2f1dbScgd 
1106dc2f1dbScgd 
1116dc2f1dbScgd #define	STRQQ		"\"\""
1126dc2f1dbScgd 
1136dc2f1dbScgd #define	isglob(a)	(strchr("*[]?", (a)) != NULL)
1146dc2f1dbScgd 
1156dc2f1dbScgd #define	NOP		0x00
1166dc2f1dbScgd #define	DELETE		0x01
1176dc2f1dbScgd #define	INSERT		0x02
11839f224afSchristos #define	YANK		0x04
1196dc2f1dbScgd 
12039f224afSchristos #define	CHAR_FWD	(+1)
12139f224afSchristos #define	CHAR_BACK	(-1)
1226dc2f1dbScgd 
1236dc2f1dbScgd #define	MODE_INSERT	0
1246dc2f1dbScgd #define	MODE_REPLACE	1
1256dc2f1dbScgd #define	MODE_REPLACE_1	2
1266dc2f1dbScgd 
1276dc2f1dbScgd 
128a2d6b270Schristos libedit_private int	 cv__isword(wint_t);
129a2d6b270Schristos libedit_private int	 cv__isWord(wint_t);
130a2d6b270Schristos libedit_private void	 cv_delfini(EditLine *);
131a2d6b270Schristos libedit_private wchar_t *cv__endword(wchar_t *, wchar_t *, int, int (*)(wint_t));
132a2d6b270Schristos libedit_private int	 ce__isword(wint_t);
133a2d6b270Schristos libedit_private void	 cv_undo(EditLine *);
134a2d6b270Schristos libedit_private void	 cv_yank(EditLine *, const wchar_t *, int);
135a2d6b270Schristos libedit_private wchar_t *cv_next_word(EditLine*, wchar_t *, wchar_t *, int,
1360594af80Schristos 			int (*)(wint_t));
137a2d6b270Schristos libedit_private wchar_t *cv_prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
138a2d6b270Schristos libedit_private wchar_t *c__next_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
139a2d6b270Schristos libedit_private wchar_t *c__prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t));
140a2d6b270Schristos libedit_private void	 c_insert(EditLine *, int);
141a2d6b270Schristos libedit_private void	 c_delbefore(EditLine *, int);
142a2d6b270Schristos libedit_private void	 c_delbefore1(EditLine *);
143a2d6b270Schristos libedit_private void	 c_delafter(EditLine *, int);
144a2d6b270Schristos libedit_private void	 c_delafter1(EditLine *);
145a2d6b270Schristos libedit_private int	 c_gets(EditLine *, wchar_t *, const wchar_t *);
146a2d6b270Schristos libedit_private int	 c_hpos(EditLine *);
1476dc2f1dbScgd 
148a2d6b270Schristos libedit_private int	 ch_init(EditLine *);
149*bb64d9f1Schristos libedit_private void	 ch_reset(EditLine *);
150a2d6b270Schristos libedit_private int	 ch_resizefun(EditLine *, el_zfunc_t, void *);
151a2d6b270Schristos libedit_private int	 ch_aliasfun(EditLine *, el_afunc_t, void *);
152a2d6b270Schristos libedit_private int	 ch_enlargebufs(EditLine *, size_t);
153a2d6b270Schristos libedit_private void	 ch_end(EditLine *);
1546dc2f1dbScgd 
1556dc2f1dbScgd #endif /* _h_el_chared */
156