Home | History | Annotate | Line # | Download | only in libedit
chared.h revision 1.26
      1 /*	$NetBSD: chared.h,v 1.26 2016/02/16 19:08:41 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Christos Zoulas of Cornell University.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
     35  */
     36 
     37 /*
     38  * el.chared.h: Character editor interface
     39  */
     40 #ifndef _h_el_chared
     41 #define	_h_el_chared
     42 
     43 #include <ctype.h>
     44 #include <string.h>
     45 
     46 #define	EL_MAXMACRO	10
     47 
     48 /*
     49  * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
     50  * like real vi: i.e. the transition from command<->insert modes moves
     51  * the cursor.
     52  *
     53  * On the other hand we really don't want to move the cursor, because
     54  * all the editing commands don't include the character under the cursor.
     55  * Probably the best fix is to make all the editing commands aware of
     56  * this fact.
     57  */
     58 #define	VI_MOVE
     59 
     60 
     61 typedef struct c_macro_t {
     62 	int	  level;
     63 	int	  offset;
     64 	Char	**macro;
     65 } c_macro_t;
     66 
     67 /*
     68  * Undo information for vi - no undo in emacs (yet)
     69  */
     70 typedef struct c_undo_t {
     71 	ssize_t	 len;			/* length of saved line */
     72 	int	 cursor;		/* position of saved cursor */
     73 	Char	*buf;			/* full saved text */
     74 } c_undo_t;
     75 
     76 /* redo for vi */
     77 typedef struct c_redo_t {
     78 	Char	*buf;			/* redo insert key sequence */
     79 	Char	*pos;
     80 	Char	*lim;
     81 	el_action_t	cmd;		/* command to redo */
     82 	Char	ch;			/* char that invoked it */
     83 	int	count;
     84 	int	action;			/* from cv_action() */
     85 } c_redo_t;
     86 
     87 /*
     88  * Current action information for vi
     89  */
     90 typedef struct c_vcmd_t {
     91 	int	 action;
     92 	Char	*pos;
     93 } c_vcmd_t;
     94 
     95 /*
     96  * Kill buffer for emacs
     97  */
     98 typedef struct c_kill_t {
     99 	Char	*buf;
    100 	Char	*last;
    101 	Char	*mark;
    102 } c_kill_t;
    103 
    104 typedef void (*el_zfunc_t)(EditLine *, void *);
    105 typedef const char *(*el_afunc_t)(void *, const char *);
    106 
    107 /*
    108  * Note that we use both data structures because the user can bind
    109  * commands from both editors!
    110  */
    111 typedef struct el_chared_t {
    112 	c_undo_t	c_undo;
    113 	c_kill_t	c_kill;
    114 	c_redo_t	c_redo;
    115 	c_vcmd_t	c_vcmd;
    116 	c_macro_t	c_macro;
    117 	el_zfunc_t	c_resizefun;
    118 	el_afunc_t	c_aliasfun;
    119 	void *		c_resizearg;
    120 	void *		c_aliasarg;
    121 } el_chared_t;
    122 
    123 
    124 #define	STRQQ		"\"\""
    125 
    126 #define	isglob(a)	(strchr("*[]?", (a)) != NULL)
    127 
    128 #define	NOP		0x00
    129 #define	DELETE		0x01
    130 #define	INSERT		0x02
    131 #define	YANK		0x04
    132 
    133 #define	CHAR_FWD	(+1)
    134 #define	CHAR_BACK	(-1)
    135 
    136 #define	MODE_INSERT	0
    137 #define	MODE_REPLACE	1
    138 #define	MODE_REPLACE_1	2
    139 
    140 
    141 protected int	 cv__isword(wint_t);
    142 protected int	 cv__isWord(wint_t);
    143 protected void	 cv_delfini(EditLine *);
    144 protected Char	*cv__endword(Char *, Char *, int, int (*)(wint_t));
    145 protected int	 ce__isword(wint_t);
    146 protected void	 cv_undo(EditLine *);
    147 protected void	 cv_yank(EditLine *, const Char *, int);
    148 protected Char	*cv_next_word(EditLine*, Char *, Char *, int, int (*)(wint_t));
    149 protected Char	*cv_prev_word(Char *, Char *, int, int (*)(wint_t));
    150 protected Char	*c__next_word(Char *, Char *, int, int (*)(wint_t));
    151 protected Char	*c__prev_word(Char *, Char *, int, int (*)(wint_t));
    152 protected void	 c_insert(EditLine *, int);
    153 protected void	 c_delbefore(EditLine *, int);
    154 protected void	 c_delbefore1(EditLine *);
    155 protected void	 c_delafter(EditLine *, int);
    156 protected void	 c_delafter1(EditLine *);
    157 protected int	 c_gets(EditLine *, Char *, const Char *);
    158 protected int	 c_hpos(EditLine *);
    159 
    160 protected int	 ch_init(EditLine *);
    161 protected void	 ch_reset(EditLine *, int);
    162 protected int	 ch_resizefun(EditLine *, el_zfunc_t, void *);
    163 protected int	 ch_aliasfun(EditLine *, el_afunc_t, void *);
    164 protected int	 ch_enlargebufs(EditLine *, size_t);
    165 protected void	 ch_end(EditLine *);
    166 
    167 #endif /* _h_el_chared */
    168