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.
16148834Sstefanf * 3. Neither the name of the University nor the names of its contributors
171573Srgrimes *    may be used to endorse or promote products derived from this software
181573Srgrimes *    without specific prior written permission.
191573Srgrimes *
201573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301573Srgrimes * SUCH DAMAGE.
311573Srgrimes *
321573Srgrimes *	@(#)chared.h	8.1 (Berkeley) 6/4/93
33238178Spfg *	$NetBSD: chared.h,v 1.18 2009/02/15 21:55:23 christos Exp $
3484260Sobrien * $FreeBSD$
351573Srgrimes */
361573Srgrimes
371573Srgrimes/*
381573Srgrimes * el.chared.h: Character editor interface
391573Srgrimes */
401573Srgrimes#ifndef _h_el_chared
4184260Sobrien#define	_h_el_chared
421573Srgrimes
431573Srgrimes#include <ctype.h>
441573Srgrimes#include <string.h>
451573Srgrimes
461573Srgrimes#include "histedit.h"
471573Srgrimes
4884260Sobrien#define	EL_MAXMACRO	10
491573Srgrimes
501573Srgrimes/*
51108533Sschweikh * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
521573Srgrimes * like real vi: i.e. the transition from command<->insert modes moves
531573Srgrimes * the cursor.
541573Srgrimes *
558870Srgrimes * On the other hand we really don't want to move the cursor, because
561573Srgrimes * all the editing commands don't include the character under the cursor.
571573Srgrimes * Probably the best fix is to make all the editing commands aware of
581573Srgrimes * this fact.
591573Srgrimes */
6084260Sobrien#define	VI_MOVE
611573Srgrimes
621573Srgrimes
631573Srgrimestypedef struct c_macro_t {
6484260Sobrien	int	  level;
65148834Sstefanf	int	  offset;
6684260Sobrien	char	**macro;
671573Srgrimes} c_macro_t;
681573Srgrimes
698870Srgrimes/*
70148834Sstefanf * Undo information for vi - no undo in emacs (yet)
711573Srgrimes */
721573Srgrimestypedef struct c_undo_t {
73238178Spfg	ssize_t	 len;			/* length of saved line */
74148834Sstefanf	int	 cursor;		/* position of saved cursor */
75148834Sstefanf	char	*buf;			/* full saved text */
761573Srgrimes} c_undo_t;
771573Srgrimes
78148834Sstefanf/* redo for vi */
79148834Sstefanftypedef struct c_redo_t {
80148834Sstefanf	char	*buf;			/* redo insert key sequence */
81148834Sstefanf	char	*pos;
82148834Sstefanf	char	*lim;
83148834Sstefanf	el_action_t	cmd;		/* command to redo */
84148834Sstefanf	char	ch;			/* char that invoked it */
85148834Sstefanf	int	count;
86148834Sstefanf	int	action;			/* from cv_action() */
87148834Sstefanf} c_redo_t;
88148834Sstefanf
891573Srgrimes/*
901573Srgrimes * Current action information for vi
911573Srgrimes */
921573Srgrimestypedef struct c_vcmd_t {
9384260Sobrien	int	 action;
9484260Sobrien	char	*pos;
951573Srgrimes} c_vcmd_t;
961573Srgrimes
971573Srgrimes/*
981573Srgrimes * Kill buffer for emacs
991573Srgrimes */
1001573Srgrimestypedef struct c_kill_t {
10184260Sobrien	char	*buf;
10284260Sobrien	char	*last;
10384260Sobrien	char	*mark;
1041573Srgrimes} c_kill_t;
1051573Srgrimes
1061573Srgrimes/*
1071573Srgrimes * Note that we use both data structures because the user can bind
1081573Srgrimes * commands from both editors!
1091573Srgrimes */
1101573Srgrimestypedef struct el_chared_t {
11184260Sobrien	c_undo_t	c_undo;
11284260Sobrien	c_kill_t	c_kill;
113148834Sstefanf	c_redo_t	c_redo;
11484260Sobrien	c_vcmd_t	c_vcmd;
11584260Sobrien	c_macro_t	c_macro;
1161573Srgrimes} el_chared_t;
1171573Srgrimes
1181573Srgrimes
11984260Sobrien#define	STRQQ		"\"\""
1201573Srgrimes
12184260Sobrien#define	isglob(a)	(strchr("*[]?", (a)) != NULL)
12284260Sobrien#define	isword(a)	(isprint(a))
1231573Srgrimes
12484260Sobrien#define	NOP		0x00
12584260Sobrien#define	DELETE		0x01
12684260Sobrien#define	INSERT		0x02
127148834Sstefanf#define	YANK		0x04
1281573Srgrimes
129148834Sstefanf#define	CHAR_FWD	(+1)
130148834Sstefanf#define	CHAR_BACK	(-1)
1311573Srgrimes
13284260Sobrien#define	MODE_INSERT	0
13384260Sobrien#define	MODE_REPLACE	1
13484260Sobrien#define	MODE_REPLACE_1	2
1351573Srgrimes
1361573Srgrimes#include "common.h"
1371573Srgrimes#include "vi.h"
1381573Srgrimes#include "emacs.h"
1391573Srgrimes#include "search.h"
1401573Srgrimes#include "fcns.h"
1411573Srgrimes
1421573Srgrimes
14384260Sobrienprotected int	 cv__isword(int);
144148834Sstefanfprotected int	 cv__isWord(int);
14584260Sobrienprotected void	 cv_delfini(EditLine *);
146148834Sstefanfprotected char	*cv__endword(char *, char *, int, int (*)(int));
14784260Sobrienprotected int	 ce__isword(int);
148148834Sstefanfprotected void	 cv_undo(EditLine *);
149148834Sstefanfprotected void	 cv_yank(EditLine *, const char *, int);
15084260Sobrienprotected char	*cv_next_word(EditLine*, char *, char *, int, int (*)(int));
151148834Sstefanfprotected char	*cv_prev_word(char *, char *, int, int (*)(int));
15284260Sobrienprotected char	*c__next_word(char *, char *, int, int (*)(int));
15384260Sobrienprotected char	*c__prev_word(char *, char *, int, int (*)(int));
15484260Sobrienprotected void	 c_insert(EditLine *, int);
15584260Sobrienprotected void	 c_delbefore(EditLine *, int);
156148834Sstefanfprotected void	 c_delbefore1(EditLine *);
15784260Sobrienprotected void	 c_delafter(EditLine *, int);
158148834Sstefanfprotected void	 c_delafter1(EditLine *);
159148834Sstefanfprotected int	 c_gets(EditLine *, char *, const char *);
16084260Sobrienprotected int	 c_hpos(EditLine *);
1611573Srgrimes
16284260Sobrienprotected int	 ch_init(EditLine *);
163148834Sstefanfprotected void	 ch_reset(EditLine *, int);
16492917Sobrienprotected int	 ch_enlargebufs(EditLine *, size_t);
16584260Sobrienprotected void	 ch_end(EditLine *);
1661573Srgrimes
1671573Srgrimes#endif /* _h_el_chared */
168