xref: /minix3/lib/libedit/chared.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $	*/
23e1db26aSLionel Sambuc 
33e1db26aSLionel Sambuc /*-
43e1db26aSLionel Sambuc  * Copyright (c) 1992, 1993
53e1db26aSLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
63e1db26aSLionel Sambuc  *
73e1db26aSLionel Sambuc  * This code is derived from software contributed to Berkeley by
83e1db26aSLionel Sambuc  * Christos Zoulas of Cornell University.
93e1db26aSLionel Sambuc  *
103e1db26aSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
113e1db26aSLionel Sambuc  * modification, are permitted provided that the following conditions
123e1db26aSLionel Sambuc  * are met:
133e1db26aSLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
143e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
153e1db26aSLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
163e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
173e1db26aSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
183e1db26aSLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
193e1db26aSLionel Sambuc  *    may be used to endorse or promote products derived from this software
203e1db26aSLionel Sambuc  *    without specific prior written permission.
213e1db26aSLionel Sambuc  *
223e1db26aSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233e1db26aSLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243e1db26aSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253e1db26aSLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263e1db26aSLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273e1db26aSLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283e1db26aSLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293e1db26aSLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303e1db26aSLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313e1db26aSLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323e1db26aSLionel Sambuc  * SUCH DAMAGE.
333e1db26aSLionel Sambuc  *
343e1db26aSLionel Sambuc  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
353e1db26aSLionel Sambuc  */
363e1db26aSLionel Sambuc 
373e1db26aSLionel Sambuc /*
383e1db26aSLionel Sambuc  * el.chared.h: Character editor interface
393e1db26aSLionel Sambuc  */
403e1db26aSLionel Sambuc #ifndef _h_el_chared
413e1db26aSLionel Sambuc #define	_h_el_chared
423e1db26aSLionel Sambuc 
433e1db26aSLionel Sambuc #include <ctype.h>
443e1db26aSLionel Sambuc #include <string.h>
453e1db26aSLionel Sambuc 
463e1db26aSLionel Sambuc #include "histedit.h"
473e1db26aSLionel Sambuc 
483e1db26aSLionel Sambuc #define	EL_MAXMACRO	10
493e1db26aSLionel Sambuc 
503e1db26aSLionel Sambuc /*
513e1db26aSLionel Sambuc  * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
523e1db26aSLionel Sambuc  * like real vi: i.e. the transition from command<->insert modes moves
533e1db26aSLionel Sambuc  * the cursor.
543e1db26aSLionel Sambuc  *
553e1db26aSLionel Sambuc  * On the other hand we really don't want to move the cursor, because
563e1db26aSLionel Sambuc  * all the editing commands don't include the character under the cursor.
573e1db26aSLionel Sambuc  * Probably the best fix is to make all the editing commands aware of
583e1db26aSLionel Sambuc  * this fact.
593e1db26aSLionel Sambuc  */
603e1db26aSLionel Sambuc #define	VI_MOVE
613e1db26aSLionel Sambuc 
623e1db26aSLionel Sambuc 
633e1db26aSLionel Sambuc typedef struct c_macro_t {
643e1db26aSLionel Sambuc 	int	  level;
653e1db26aSLionel Sambuc 	int	  offset;
663e1db26aSLionel Sambuc 	Char	**macro;
673e1db26aSLionel Sambuc } c_macro_t;
683e1db26aSLionel Sambuc 
693e1db26aSLionel Sambuc /*
703e1db26aSLionel Sambuc  * Undo information for vi - no undo in emacs (yet)
713e1db26aSLionel Sambuc  */
723e1db26aSLionel Sambuc typedef struct c_undo_t {
733e1db26aSLionel Sambuc 	ssize_t	 len;			/* length of saved line */
743e1db26aSLionel Sambuc 	int	 cursor;		/* position of saved cursor */
753e1db26aSLionel Sambuc 	Char	*buf;			/* full saved text */
763e1db26aSLionel Sambuc } c_undo_t;
773e1db26aSLionel Sambuc 
783e1db26aSLionel Sambuc /* redo for vi */
793e1db26aSLionel Sambuc typedef struct c_redo_t {
803e1db26aSLionel Sambuc 	Char	*buf;			/* redo insert key sequence */
813e1db26aSLionel Sambuc 	Char	*pos;
823e1db26aSLionel Sambuc 	Char	*lim;
833e1db26aSLionel Sambuc 	el_action_t	cmd;		/* command to redo */
843e1db26aSLionel Sambuc 	Char	ch;			/* char that invoked it */
853e1db26aSLionel Sambuc 	int	count;
863e1db26aSLionel Sambuc 	int	action;			/* from cv_action() */
873e1db26aSLionel Sambuc } c_redo_t;
883e1db26aSLionel Sambuc 
893e1db26aSLionel Sambuc /*
903e1db26aSLionel Sambuc  * Current action information for vi
913e1db26aSLionel Sambuc  */
923e1db26aSLionel Sambuc typedef struct c_vcmd_t {
933e1db26aSLionel Sambuc 	int	 action;
943e1db26aSLionel Sambuc 	Char	*pos;
953e1db26aSLionel Sambuc } c_vcmd_t;
963e1db26aSLionel Sambuc 
973e1db26aSLionel Sambuc /*
983e1db26aSLionel Sambuc  * Kill buffer for emacs
993e1db26aSLionel Sambuc  */
1003e1db26aSLionel Sambuc typedef struct c_kill_t {
1013e1db26aSLionel Sambuc 	Char	*buf;
1023e1db26aSLionel Sambuc 	Char	*last;
1033e1db26aSLionel Sambuc 	Char	*mark;
1043e1db26aSLionel Sambuc } c_kill_t;
1053e1db26aSLionel Sambuc 
1063e1db26aSLionel Sambuc typedef void (*el_zfunc_t)(EditLine *, void *);
107*0a6a1f1dSLionel Sambuc typedef const char *(*el_afunc_t)(void *, const char *);
1083e1db26aSLionel Sambuc 
1093e1db26aSLionel Sambuc /*
1103e1db26aSLionel Sambuc  * Note that we use both data structures because the user can bind
1113e1db26aSLionel Sambuc  * commands from both editors!
1123e1db26aSLionel Sambuc  */
1133e1db26aSLionel Sambuc typedef struct el_chared_t {
1143e1db26aSLionel Sambuc 	c_undo_t	c_undo;
1153e1db26aSLionel Sambuc 	c_kill_t	c_kill;
1163e1db26aSLionel Sambuc 	c_redo_t	c_redo;
1173e1db26aSLionel Sambuc 	c_vcmd_t	c_vcmd;
1183e1db26aSLionel Sambuc 	c_macro_t	c_macro;
1193e1db26aSLionel Sambuc 	el_zfunc_t	c_resizefun;
120*0a6a1f1dSLionel Sambuc 	el_afunc_t	c_aliasfun;
1213e1db26aSLionel Sambuc 	void *		c_resizearg;
122*0a6a1f1dSLionel Sambuc 	void *		c_aliasarg;
1233e1db26aSLionel Sambuc } el_chared_t;
1243e1db26aSLionel Sambuc 
1253e1db26aSLionel Sambuc 
1263e1db26aSLionel Sambuc #define	STRQQ		"\"\""
1273e1db26aSLionel Sambuc 
1283e1db26aSLionel Sambuc #define	isglob(a)	(strchr("*[]?", (a)) != NULL)
1293e1db26aSLionel Sambuc 
1303e1db26aSLionel Sambuc #define	NOP		0x00
1313e1db26aSLionel Sambuc #define	DELETE		0x01
1323e1db26aSLionel Sambuc #define	INSERT		0x02
1333e1db26aSLionel Sambuc #define	YANK		0x04
1343e1db26aSLionel Sambuc 
1353e1db26aSLionel Sambuc #define	CHAR_FWD	(+1)
1363e1db26aSLionel Sambuc #define	CHAR_BACK	(-1)
1373e1db26aSLionel Sambuc 
1383e1db26aSLionel Sambuc #define	MODE_INSERT	0
1393e1db26aSLionel Sambuc #define	MODE_REPLACE	1
1403e1db26aSLionel Sambuc #define	MODE_REPLACE_1	2
1413e1db26aSLionel Sambuc 
1423e1db26aSLionel Sambuc #include "common.h"
1433e1db26aSLionel Sambuc #include "vi.h"
1443e1db26aSLionel Sambuc #include "emacs.h"
1453e1db26aSLionel Sambuc #include "search.h"
1463e1db26aSLionel Sambuc #include "fcns.h"
1473e1db26aSLionel Sambuc 
1483e1db26aSLionel Sambuc 
1493e1db26aSLionel Sambuc protected int	 cv__isword(Int);
1503e1db26aSLionel Sambuc protected int	 cv__isWord(Int);
1513e1db26aSLionel Sambuc protected void	 cv_delfini(EditLine *);
1523e1db26aSLionel Sambuc protected Char	*cv__endword(Char *, Char *, int, int (*)(Int));
1533e1db26aSLionel Sambuc protected int	 ce__isword(Int);
1543e1db26aSLionel Sambuc protected void	 cv_undo(EditLine *);
1553e1db26aSLionel Sambuc protected void	 cv_yank(EditLine *, const Char *, int);
1563e1db26aSLionel Sambuc protected Char	*cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int));
1573e1db26aSLionel Sambuc protected Char	*cv_prev_word(Char *, Char *, int, int (*)(Int));
1583e1db26aSLionel Sambuc protected Char	*c__next_word(Char *, Char *, int, int (*)(Int));
1593e1db26aSLionel Sambuc protected Char	*c__prev_word(Char *, Char *, int, int (*)(Int));
1603e1db26aSLionel Sambuc protected void	 c_insert(EditLine *, int);
1613e1db26aSLionel Sambuc protected void	 c_delbefore(EditLine *, int);
1623e1db26aSLionel Sambuc protected void	 c_delbefore1(EditLine *);
1633e1db26aSLionel Sambuc protected void	 c_delafter(EditLine *, int);
1643e1db26aSLionel Sambuc protected void	 c_delafter1(EditLine *);
1653e1db26aSLionel Sambuc protected int	 c_gets(EditLine *, Char *, const Char *);
1663e1db26aSLionel Sambuc protected int	 c_hpos(EditLine *);
1673e1db26aSLionel Sambuc 
1683e1db26aSLionel Sambuc protected int	 ch_init(EditLine *);
1693e1db26aSLionel Sambuc protected void	 ch_reset(EditLine *, int);
1703e1db26aSLionel Sambuc protected int	 ch_resizefun(EditLine *, el_zfunc_t, void *);
171*0a6a1f1dSLionel Sambuc protected int	 ch_aliasfun(EditLine *, el_afunc_t, void *);
1723e1db26aSLionel Sambuc protected int	 ch_enlargebufs(EditLine *, size_t);
1733e1db26aSLionel Sambuc protected void	 ch_end(EditLine *);
1743e1db26aSLionel Sambuc 
1753e1db26aSLionel Sambuc #endif /* _h_el_chared */
176