1313981Spfg/*	$NetBSD: chared.h,v 1.27 2016/02/16 22:53:14 christos Exp $	*/
2276881Sbapt
31573Srgrimes/*-
41573Srgrimes * Copyright (c) 1992, 1993
51573Srgrimes *	The Regents of the University of California.  All rights reserved.
61573Srgrimes *
71573Srgrimes * This code is derived from software contributed to Berkeley by
81573Srgrimes * Christos Zoulas of Cornell University.
91573Srgrimes *
101573Srgrimes * Redistribution and use in source and binary forms, with or without
111573Srgrimes * modification, are permitted provided that the following conditions
121573Srgrimes * are met:
131573Srgrimes * 1. Redistributions of source code must retain the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer.
151573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161573Srgrimes *    notice, this list of conditions and the following disclaimer in the
171573Srgrimes *    documentation and/or other materials provided with the distribution.
18148834Sstefanf * 3. Neither the name of the University nor the names of its contributors
191573Srgrimes *    may be used to endorse or promote products derived from this software
201573Srgrimes *    without specific prior written permission.
211573Srgrimes *
221573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321573Srgrimes * SUCH DAMAGE.
331573Srgrimes *
341573Srgrimes *	@(#)chared.h	8.1 (Berkeley) 6/4/93
3584260Sobrien * $FreeBSD: stable/11/lib/libedit/chared.h 313981 2017-02-20 03:33:59Z pfg $
361573Srgrimes */
371573Srgrimes
381573Srgrimes/*
391573Srgrimes * el.chared.h: Character editor interface
401573Srgrimes */
411573Srgrimes#ifndef _h_el_chared
4284260Sobrien#define	_h_el_chared
431573Srgrimes
4484260Sobrien#define	EL_MAXMACRO	10
451573Srgrimes
461573Srgrimes/*
47108533Sschweikh * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
481573Srgrimes * like real vi: i.e. the transition from command<->insert modes moves
491573Srgrimes * the cursor.
501573Srgrimes *
518870Srgrimes * On the other hand we really don't want to move the cursor, because
521573Srgrimes * all the editing commands don't include the character under the cursor.
531573Srgrimes * Probably the best fix is to make all the editing commands aware of
541573Srgrimes * this fact.
551573Srgrimes */
5684260Sobrien#define	VI_MOVE
571573Srgrimes
581573Srgrimes
591573Srgrimestypedef struct c_macro_t {
6084260Sobrien	int	  level;
61148834Sstefanf	int	  offset;
62276881Sbapt	Char	**macro;
631573Srgrimes} c_macro_t;
641573Srgrimes
658870Srgrimes/*
66148834Sstefanf * Undo information for vi - no undo in emacs (yet)
671573Srgrimes */
681573Srgrimestypedef struct c_undo_t {
69238178Spfg	ssize_t	 len;			/* length of saved line */
70148834Sstefanf	int	 cursor;		/* position of saved cursor */
71276881Sbapt	Char	*buf;			/* full saved text */
721573Srgrimes} c_undo_t;
731573Srgrimes
74148834Sstefanf/* redo for vi */
75148834Sstefanftypedef struct c_redo_t {
76276881Sbapt	Char	*buf;			/* redo insert key sequence */
77276881Sbapt	Char	*pos;
78276881Sbapt	Char	*lim;
79148834Sstefanf	el_action_t	cmd;		/* command to redo */
80276881Sbapt	Char	ch;			/* char that invoked it */
81148834Sstefanf	int	count;
82148834Sstefanf	int	action;			/* from cv_action() */
83148834Sstefanf} c_redo_t;
84148834Sstefanf
851573Srgrimes/*
861573Srgrimes * Current action information for vi
871573Srgrimes */
881573Srgrimestypedef struct c_vcmd_t {
8984260Sobrien	int	 action;
90276881Sbapt	Char	*pos;
911573Srgrimes} c_vcmd_t;
921573Srgrimes
931573Srgrimes/*
941573Srgrimes * Kill buffer for emacs
951573Srgrimes */
961573Srgrimestypedef struct c_kill_t {
97276881Sbapt	Char	*buf;
98276881Sbapt	Char	*last;
99276881Sbapt	Char	*mark;
1001573Srgrimes} c_kill_t;
1011573Srgrimes
102276881Sbapttypedef void (*el_zfunc_t)(EditLine *, void *);
103276881Sbapttypedef const char *(*el_afunc_t)(void *, const char *);
104276881Sbapt
1051573Srgrimes/*
1061573Srgrimes * Note that we use both data structures because the user can bind
1071573Srgrimes * commands from both editors!
1081573Srgrimes */
1091573Srgrimestypedef struct el_chared_t {
11084260Sobrien	c_undo_t	c_undo;
11184260Sobrien	c_kill_t	c_kill;
112148834Sstefanf	c_redo_t	c_redo;
11384260Sobrien	c_vcmd_t	c_vcmd;
11484260Sobrien	c_macro_t	c_macro;
115276881Sbapt	el_zfunc_t	c_resizefun;
116276881Sbapt	el_afunc_t	c_aliasfun;
117276881Sbapt	void *		c_resizearg;
118276881Sbapt	void *		c_aliasarg;
1191573Srgrimes} el_chared_t;
1201573Srgrimes
1211573Srgrimes
12284260Sobrien#define	STRQQ		"\"\""
1231573Srgrimes
12484260Sobrien#define	isglob(a)	(strchr("*[]?", (a)) != NULL)
1251573Srgrimes
12684260Sobrien#define	NOP		0x00
12784260Sobrien#define	DELETE		0x01
12884260Sobrien#define	INSERT		0x02
129148834Sstefanf#define	YANK		0x04
1301573Srgrimes
131148834Sstefanf#define	CHAR_FWD	(+1)
132148834Sstefanf#define	CHAR_BACK	(-1)
1331573Srgrimes
13484260Sobrien#define	MODE_INSERT	0
13584260Sobrien#define	MODE_REPLACE	1
13684260Sobrien#define	MODE_REPLACE_1	2
1371573Srgrimes
1381573Srgrimes
139313981Spfgprotected int	 cv__isword(wint_t);
140313981Spfgprotected int	 cv__isWord(wint_t);
14184260Sobrienprotected void	 cv_delfini(EditLine *);
142313981Spfgprotected Char	*cv__endword(Char *, Char *, int, int (*)(wint_t));
143313981Spfgprotected int	 ce__isword(wint_t);
144148834Sstefanfprotected void	 cv_undo(EditLine *);
145276881Sbaptprotected void	 cv_yank(EditLine *, const Char *, int);
146313981Spfgprotected Char	*cv_next_word(EditLine*, Char *, Char *, int, int (*)(wint_t));
147313981Spfgprotected Char	*cv_prev_word(Char *, Char *, int, int (*)(wint_t));
148313981Spfgprotected Char	*c__next_word(Char *, Char *, int, int (*)(wint_t));
149313981Spfgprotected Char	*c__prev_word(Char *, Char *, int, int (*)(wint_t));
15084260Sobrienprotected void	 c_insert(EditLine *, int);
15184260Sobrienprotected void	 c_delbefore(EditLine *, int);
152148834Sstefanfprotected void	 c_delbefore1(EditLine *);
15384260Sobrienprotected void	 c_delafter(EditLine *, int);
154148834Sstefanfprotected void	 c_delafter1(EditLine *);
155276881Sbaptprotected int	 c_gets(EditLine *, Char *, const Char *);
15684260Sobrienprotected int	 c_hpos(EditLine *);
1571573Srgrimes
15884260Sobrienprotected int	 ch_init(EditLine *);
159148834Sstefanfprotected void	 ch_reset(EditLine *, int);
160276881Sbaptprotected int	 ch_resizefun(EditLine *, el_zfunc_t, void *);
161276881Sbaptprotected int	 ch_aliasfun(EditLine *, el_afunc_t, void *);
16292917Sobrienprotected int	 ch_enlargebufs(EditLine *, size_t);
16384260Sobrienprotected void	 ch_end(EditLine *);
1641573Srgrimes
1651573Srgrimes#endif /* _h_el_chared */
166