1 /* $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 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 * $FreeBSD$ 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 an 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 int offset; 67 Char **macro; 68 } c_macro_t; 69 70 /* 71 * Undo information for vi - no undo in emacs (yet) 72 */ 73 typedef struct c_undo_t { 74 ssize_t len; /* length of saved line */ 75 int cursor; /* position of saved cursor */ 76 Char *buf; /* full saved text */ 77 } c_undo_t; 78 79 /* redo for vi */ 80 typedef struct c_redo_t { 81 Char *buf; /* redo insert key sequence */ 82 Char *pos; 83 Char *lim; 84 el_action_t cmd; /* command to redo */ 85 Char ch; /* char that invoked it */ 86 int count; 87 int action; /* from cv_action() */ 88 } c_redo_t; 89 90 /* 91 * Current action information for vi 92 */ 93 typedef struct c_vcmd_t { 94 int action; 95 Char *pos; 96 } c_vcmd_t; 97 98 /* 99 * Kill buffer for emacs 100 */ 101 typedef struct c_kill_t { 102 Char *buf; 103 Char *last; 104 Char *mark; 105 } c_kill_t; 106 107 typedef void (*el_zfunc_t)(EditLine *, void *); 108 typedef const char *(*el_afunc_t)(void *, const char *); 109 110 /* 111 * Note that we use both data structures because the user can bind 112 * commands from both editors! 113 */ 114 typedef struct el_chared_t { 115 c_undo_t c_undo; 116 c_kill_t c_kill; 117 c_redo_t c_redo; 118 c_vcmd_t c_vcmd; 119 c_macro_t c_macro; 120 el_zfunc_t c_resizefun; 121 el_afunc_t c_aliasfun; 122 void * c_resizearg; 123 void * c_aliasarg; 124 } el_chared_t; 125 126 127 #define STRQQ "\"\"" 128 129 #define isglob(a) (strchr("*[]?", (a)) != NULL) 130 131 #define NOP 0x00 132 #define DELETE 0x01 133 #define INSERT 0x02 134 #define YANK 0x04 135 136 #define CHAR_FWD (+1) 137 #define CHAR_BACK (-1) 138 139 #define MODE_INSERT 0 140 #define MODE_REPLACE 1 141 #define MODE_REPLACE_1 2 142 143 #include "common.h" 144 #include "vi.h" 145 #include "emacs.h" 146 #include "search.h" 147 #include "fcns.h" 148 149 150 protected int cv__isword(Int); 151 protected int cv__isWord(Int); 152 protected void cv_delfini(EditLine *); 153 protected Char *cv__endword(Char *, Char *, int, int (*)(Int)); 154 protected int ce__isword(Int); 155 protected void cv_undo(EditLine *); 156 protected void cv_yank(EditLine *, const Char *, int); 157 protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int)); 158 protected Char *cv_prev_word(Char *, Char *, int, int (*)(Int)); 159 protected Char *c__next_word(Char *, Char *, int, int (*)(Int)); 160 protected Char *c__prev_word(Char *, Char *, int, int (*)(Int)); 161 protected void c_insert(EditLine *, int); 162 protected void c_delbefore(EditLine *, int); 163 protected void c_delbefore1(EditLine *); 164 protected void c_delafter(EditLine *, int); 165 protected void c_delafter1(EditLine *); 166 protected int c_gets(EditLine *, Char *, const Char *); 167 protected int c_hpos(EditLine *); 168 169 protected int ch_init(EditLine *); 170 protected void ch_reset(EditLine *, int); 171 protected int ch_resizefun(EditLine *, el_zfunc_t, void *); 172 protected int ch_aliasfun(EditLine *, el_afunc_t, void *); 173 protected int ch_enlargebufs(EditLine *, size_t); 174 protected void ch_end(EditLine *); 175 176 #endif /* _h_el_chared */ 177