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