chared.h revision 84260
11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1992, 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * This code is derived from software contributed to Berkeley by
61573Srgrimes * Christos Zoulas of Cornell University.
71573Srgrimes *
81573Srgrimes * Redistribution and use in source and binary forms, with or without
91573Srgrimes * modification, are permitted provided that the following conditions
101573Srgrimes * are met:
111573Srgrimes * 1. Redistributions of source code must retain the above copyright
121573Srgrimes *    notice, this list of conditions and the following disclaimer.
131573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer in the
151573Srgrimes *    documentation and/or other materials provided with the distribution.
161573Srgrimes * 3. All advertising materials mentioning features or use of this software
171573Srgrimes *    must display the following acknowledgement:
181573Srgrimes *	This product includes software developed by the University of
191573Srgrimes *	California, Berkeley and its contributors.
201573Srgrimes * 4. Neither the name of the University nor the names of its contributors
211573Srgrimes *    may be used to endorse or promote products derived from this software
221573Srgrimes *    without specific prior written permission.
231573Srgrimes *
241573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341573Srgrimes * SUCH DAMAGE.
351573Srgrimes *
361573Srgrimes *	@(#)chared.h	8.1 (Berkeley) 6/4/93
3784260Sobrien *	$NetBSD: chared.h,v 1.5 2000/09/04 22:06:29 lukem Exp $
3884260Sobrien * $FreeBSD: head/lib/libedit/chared.h 84260 2001-10-01 08:41:27Z obrien $
391573Srgrimes */
401573Srgrimes
411573Srgrimes/*
421573Srgrimes * el.chared.h: Character editor interface
431573Srgrimes */
441573Srgrimes#ifndef _h_el_chared
4584260Sobrien#define	_h_el_chared
461573Srgrimes
471573Srgrimes#include <ctype.h>
481573Srgrimes#include <string.h>
491573Srgrimes
501573Srgrimes#include "histedit.h"
511573Srgrimes
5284260Sobrien#define	EL_MAXMACRO	10
531573Srgrimes
541573Srgrimes/*
551573Srgrimes * This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works
561573Srgrimes * like real vi: i.e. the transition from command<->insert modes moves
571573Srgrimes * the cursor.
581573Srgrimes *
598870Srgrimes * On the other hand we really don't want to move the cursor, because
601573Srgrimes * all the editing commands don't include the character under the cursor.
611573Srgrimes * Probably the best fix is to make all the editing commands aware of
621573Srgrimes * this fact.
631573Srgrimes */
6484260Sobrien#define	VI_MOVE
651573Srgrimes
661573Srgrimes
671573Srgrimestypedef struct c_macro_t {
6884260Sobrien	int	  level;
6984260Sobrien	char	**macro;
7084260Sobrien	char	 *nline;
711573Srgrimes} c_macro_t;
721573Srgrimes
738870Srgrimes/*
741573Srgrimes * Undo information for both vi and emacs
751573Srgrimes */
761573Srgrimestypedef struct c_undo_t {
7784260Sobrien	int	 action;
7884260Sobrien	size_t	 isize;
7984260Sobrien	size_t	 dsize;
8084260Sobrien	char	*ptr;
8184260Sobrien	char	*buf;
821573Srgrimes} c_undo_t;
831573Srgrimes
841573Srgrimes/*
851573Srgrimes * Current action information for vi
861573Srgrimes */
871573Srgrimestypedef struct c_vcmd_t {
8884260Sobrien	int	 action;
8984260Sobrien	char	*pos;
9084260Sobrien	char	*ins;
911573Srgrimes} c_vcmd_t;
921573Srgrimes
931573Srgrimes/*
941573Srgrimes * Kill buffer for emacs
951573Srgrimes */
961573Srgrimestypedef struct c_kill_t {
9784260Sobrien	char	*buf;
9884260Sobrien	char	*last;
9984260Sobrien	char	*mark;
1001573Srgrimes} c_kill_t;
1011573Srgrimes
1021573Srgrimes/*
1031573Srgrimes * Note that we use both data structures because the user can bind
1041573Srgrimes * commands from both editors!
1051573Srgrimes */
1061573Srgrimestypedef struct el_chared_t {
10784260Sobrien	c_undo_t	c_undo;
10884260Sobrien	c_kill_t	c_kill;
10984260Sobrien	c_vcmd_t	c_vcmd;
11084260Sobrien	c_macro_t	c_macro;
1111573Srgrimes} el_chared_t;
1121573Srgrimes
1131573Srgrimes
11484260Sobrien#define	STReof		"^D\b\b"
11584260Sobrien#define	STRQQ		"\"\""
1161573Srgrimes
11784260Sobrien#define	isglob(a)	(strchr("*[]?", (a)) != NULL)
11884260Sobrien#define	isword(a)	(isprint(a))
1191573Srgrimes
12084260Sobrien#define	NOP		0x00
12184260Sobrien#define	DELETE		0x01
12284260Sobrien#define	INSERT		0x02
12384260Sobrien#define	CHANGE		0x04
1241573Srgrimes
12584260Sobrien#define	CHAR_FWD	0
12684260Sobrien#define	CHAR_BACK	1
1271573Srgrimes
12884260Sobrien#define	MODE_INSERT	0
12984260Sobrien#define	MODE_REPLACE	1
13084260Sobrien#define	MODE_REPLACE_1	2
1311573Srgrimes
1321573Srgrimes#include "common.h"
1331573Srgrimes#include "vi.h"
1341573Srgrimes#include "emacs.h"
1351573Srgrimes#include "search.h"
1361573Srgrimes#include "fcns.h"
1371573Srgrimes
1381573Srgrimes
13984260Sobrienprotected int	 cv__isword(int);
14084260Sobrienprotected void	 cv_delfini(EditLine *);
14184260Sobrienprotected char	*cv__endword(char *, char *, int);
14284260Sobrienprotected int	 ce__isword(int);
14384260Sobrienprotected int	 c___isword(int);
14484260Sobrienprotected void	 cv_undo(EditLine *, int, size_t, char *);
14584260Sobrienprotected char	*cv_next_word(EditLine*, char *, char *, int, int (*)(int));
14684260Sobrienprotected char	*cv_prev_word(EditLine*, char *, char *, int, int (*)(int));
14784260Sobrienprotected char	*c__next_word(char *, char *, int, int (*)(int));
14884260Sobrienprotected char	*c__prev_word(char *, char *, int, int (*)(int));
14984260Sobrienprotected void	 c_insert(EditLine *, int);
15084260Sobrienprotected void	 c_delbefore(EditLine *, int);
15184260Sobrienprotected void	 c_delafter(EditLine *, int);
15284260Sobrienprotected int	 c_gets(EditLine *, char *);
15384260Sobrienprotected int	 c_hpos(EditLine *);
1541573Srgrimes
15584260Sobrienprotected int	 ch_init(EditLine *);
15684260Sobrienprotected void	 ch_reset(EditLine *);
15784260Sobrienprotected int	 ch_enlargebufs	__P((EditLine *, size_t));
15884260Sobrienprotected void	 ch_end(EditLine *);
1591573Srgrimes
1601573Srgrimes#endif /* _h_el_chared */
161