| 1 |
/* keymaps.c -- Functions and keymaps for the GNU Readline library. */ |
| 2 |
|
| 3 |
/* Copyright (C) 1988,1989 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This file is part of GNU Readline, a library for reading lines |
| 6 |
of text with interactive input and history editing. |
| 7 |
|
| 8 |
Readline is free software; you can redistribute it and/or modify it |
| 9 |
under the terms of the GNU General Public License as published by the |
| 10 |
Free Software Foundation; either version 1, or (at your option) any |
| 11 |
later version. |
| 12 |
|
| 13 |
Readline is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with Readline; see the file COPYING. If not, write to the Free |
| 20 |
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 21 |
|
| 22 |
|
| 23 |
/* |
| 24 |
|
| 25 |
.VERSION |
| 26 |
051021 last modif |
| 27 |
|
| 28 |
*/ |
| 29 |
|
| 30 |
#define READLINE_LIBRARY |
| 31 |
|
| 32 |
#if defined (HAVE_STDLIB_H) |
| 33 |
# include <stdlib.h> |
| 34 |
#else |
| 35 |
# include "ansi_stdlib.h" |
| 36 |
#endif /* HAVE_STDLIB_H */ |
| 37 |
|
| 38 |
#include "rlconf.h" |
| 39 |
#include "keymaps.h" |
| 40 |
#include "emacs_keymap.c" |
| 41 |
|
| 42 |
#if defined (VI_MODE) |
| 43 |
#include "vi_keymap.c" |
| 44 |
#endif |
| 45 |
|
| 46 |
extern int rl_do_lowercase_version (); |
| 47 |
extern int rl_rubout (), rl_insert (); |
| 48 |
|
| 49 |
#if defined (STATIC_MALLOC) |
| 50 |
static char *xmalloc (), *xrealloc (); |
| 51 |
#else |
| 52 |
extern char *xmalloc (), *xrealloc (); |
| 53 |
#endif /* STATIC_MALLOC */ |
| 54 |
|
| 55 |
/* **************************************************************** */ |
| 56 |
/* */ |
| 57 |
/* Functions for manipulating Keymaps. */ |
| 58 |
/* */ |
| 59 |
/* **************************************************************** */ |
| 60 |
|
| 61 |
|
| 62 |
/* Return a new, empty keymap. |
| 63 |
Free it with free() when you are done. */ |
| 64 |
Keymap |
| 65 |
rl_make_bare_keymap () |
| 66 |
{ |
| 67 |
register int i; |
| 68 |
Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY)); |
| 69 |
|
| 70 |
for (i = 0; i < KEYMAP_SIZE; i++) |
| 71 |
{ |
| 72 |
keymap[i].type = ISFUNC; |
| 73 |
keymap[i].function = (Function *)NULL; |
| 74 |
} |
| 75 |
|
| 76 |
for (i = 'A'; i < ('Z' + 1); i++) |
| 77 |
{ |
| 78 |
keymap[i].type = ISFUNC; |
| 79 |
keymap[i].function = rl_do_lowercase_version; |
| 80 |
} |
| 81 |
|
| 82 |
return (keymap); |
| 83 |
} |
| 84 |
|
| 85 |
/* Return a new keymap which is a copy of MAP. */ |
| 86 |
Keymap |
| 87 |
rl_copy_keymap (map) |
| 88 |
Keymap map; |
| 89 |
{ |
| 90 |
register int i; |
| 91 |
Keymap temp = rl_make_bare_keymap (); |
| 92 |
|
| 93 |
for (i = 0; i < KEYMAP_SIZE; i++) |
| 94 |
{ |
| 95 |
temp[i].type = map[i].type; |
| 96 |
temp[i].function = map[i].function; |
| 97 |
} |
| 98 |
return (temp); |
| 99 |
} |
| 100 |
|
| 101 |
/* Return a new keymap with the printing characters bound to rl_insert, |
| 102 |
the uppercase Meta characters bound to run their lowercase equivalents, |
| 103 |
and the Meta digits bound to produce numeric arguments. */ |
| 104 |
Keymap |
| 105 |
rl_make_keymap () |
| 106 |
{ |
| 107 |
register int i; |
| 108 |
Keymap newmap; |
| 109 |
|
| 110 |
newmap = rl_make_bare_keymap (); |
| 111 |
|
| 112 |
/* All ASCII printing characters are self-inserting. */ |
| 113 |
for (i = ' '; i < 126; i++) |
| 114 |
newmap[i].function = rl_insert; |
| 115 |
|
| 116 |
newmap[TAB].function = rl_insert; |
| 117 |
newmap[RUBOUT].function = rl_rubout; |
| 118 |
newmap[CTRL('H')].function = rl_rubout; |
| 119 |
|
| 120 |
#if KEYMAP_SIZE > 128 |
| 121 |
/* Printing characters in some 8-bit character sets. */ |
| 122 |
for (i = 128; i < 160; i++) |
| 123 |
newmap[i].function = rl_insert; |
| 124 |
|
| 125 |
/* ISO Latin-1 printing characters should self-insert. */ |
| 126 |
for (i = 160; i < 256; i++) |
| 127 |
newmap[i].function = rl_insert; |
| 128 |
#endif /* KEYMAP_SIZE > 128 */ |
| 129 |
|
| 130 |
return (newmap); |
| 131 |
} |
| 132 |
|
| 133 |
/* Free the storage associated with MAP. */ |
| 134 |
void |
| 135 |
rl_discard_keymap (map) |
| 136 |
Keymap (map); |
| 137 |
{ |
| 138 |
int i; |
| 139 |
|
| 140 |
if (!map) |
| 141 |
return; |
| 142 |
|
| 143 |
for (i = 0; i < KEYMAP_SIZE; i++) |
| 144 |
{ |
| 145 |
switch (map[i].type) |
| 146 |
{ |
| 147 |
case ISFUNC: |
| 148 |
break; |
| 149 |
|
| 150 |
case ISKMAP: |
| 151 |
rl_discard_keymap ((Keymap)map[i].function); |
| 152 |
break; |
| 153 |
|
| 154 |
case ISMACR: |
| 155 |
free ((char *)map[i].function); |
| 156 |
break; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
#if defined (STATIC_MALLOC) |
| 162 |
|
| 163 |
/* **************************************************************** */ |
| 164 |
/* */ |
| 165 |
/* xmalloc and xrealloc () */ |
| 166 |
/* */ |
| 167 |
/* **************************************************************** */ |
| 168 |
|
| 169 |
static void memory_error_and_abort (); |
| 170 |
|
| 171 |
static char * |
| 172 |
xmalloc (bytes) |
| 173 |
int bytes; |
| 174 |
{ |
| 175 |
char *temp = (char *)malloc ((size_t)bytes); |
| 176 |
|
| 177 |
if (!temp) |
| 178 |
memory_error_and_abort (); |
| 179 |
return (temp); |
| 180 |
} |
| 181 |
|
| 182 |
static char * |
| 183 |
xrealloc (pointer, bytes) |
| 184 |
char *pointer; |
| 185 |
int bytes; |
| 186 |
{ |
| 187 |
char *temp; |
| 188 |
|
| 189 |
if (!pointer) |
| 190 |
temp = (char *)malloc ((size_t)bytes); |
| 191 |
else |
| 192 |
temp = (char *)realloc (pointer, bytes); |
| 193 |
|
| 194 |
if (!temp) |
| 195 |
memory_error_and_abort (); |
| 196 |
return (temp); |
| 197 |
} |
| 198 |
|
| 199 |
static void |
| 200 |
memory_error_and_abort () |
| 201 |
{ |
| 202 |
fprintf (stderr, "readline: Out of virtual memory!\n"); |
| 203 |
abort (); |
| 204 |
} |
| 205 |
#endif /* STATIC_MALLOC */ |