Oh GACK! src-clean doesn't quite work that easily since cleandist rebuilds the
[unix-history] / gnu / usr.bin / gdb / readline / keymaps.c
CommitLineData
04497f0b
NW
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#include "keymaps.h"
23#include "emacs_keymap.c"
24
25#ifdef VI_MODE
26#include "vi_keymap.c"
27#endif
28
29/* Remove these declarations when we have a complete libgnu.a. */
30#define STATIC_MALLOC
31#ifndef STATIC_MALLOC
32extern char *xmalloc (), *xrealloc ();
33#else
34static char *xmalloc (), *xrealloc ();
35#endif
36
37/* **************************************************************** */
38/* */
39/* Functions for manipulating Keymaps. */
40/* */
41/* **************************************************************** */
42
43
44/* Return a new, empty keymap.
45 Free it with free() when you are done. */
46Keymap
47rl_make_bare_keymap ()
48{
49 register int i;
50 Keymap keymap = (Keymap)xmalloc (128 * sizeof (KEYMAP_ENTRY));
51
52 for (i = 0; i < 128; i++)
53 {
54 keymap[i].type = ISFUNC;
55 keymap[i].function = (Function *)NULL;
56 }
57
58 for (i = 'A'; i < ('Z' + 1); i++)
59 {
60 keymap[i].type = ISFUNC;
61 keymap[i].function = rl_do_lowercase_version;
62 }
63
64 return (keymap);
65}
66
67/* Return a new keymap which is a copy of MAP. */
68Keymap
69rl_copy_keymap (map)
70 Keymap map;
71{
72 register int i;
73 Keymap temp = rl_make_bare_keymap ();
74
75 for (i = 0; i < 128; i++)
76 {
77 temp[i].type = map[i].type;
78 temp[i].function = map[i].function;
79 }
80 return (temp);
81}
82
83/* Return a new keymap with the printing characters bound to rl_insert,
84 the uppercase Meta characters bound to run their lowercase equivalents,
85 and the Meta digits bound to produce numeric arguments. */
86Keymap
87rl_make_keymap ()
88{
89 extern rl_insert (), rl_rubout (), rl_do_lowercase_version ();
90 extern rl_digit_argument ();
91 register int i;
92 Keymap newmap;
93
94 newmap = rl_make_bare_keymap ();
95
96 /* All printing characters are self-inserting. */
97 for (i = ' '; i < 126; i++)
98 newmap[i].function = rl_insert;
99
100 newmap[TAB].function = rl_insert;
101 newmap[RUBOUT].function = rl_rubout;
102
103 return (newmap);
104}
105
106/* Free the storage associated with MAP. */
107rl_discard_keymap (map)
108 Keymap (map);
109{
110 int i;
111
112 if (!map)
113 return;
114
115 for (i = 0; i < 128; i++)
116 {
117 switch (map[i].type)
118 {
119 case ISFUNC:
120 break;
121
122 case ISKMAP:
123 rl_discard_keymap ((Keymap)map[i].function);
124 break;
125
126 case ISMACR:
127 free ((char *)map[i].function);
128 break;
129 }
130 }
131}
132
133#ifdef STATIC_MALLOC
134\f
135/* **************************************************************** */
136/* */
137/* xmalloc and xrealloc () */
138/* */
139/* **************************************************************** */
140
141static char *
142xmalloc (bytes)
143 int bytes;
144{
145 static memory_error_and_abort ();
146 char *temp = (char *)malloc (bytes);
147
148 if (!temp)
149 memory_error_and_abort ();
150 return (temp);
151}
152
153static char *
154xrealloc (pointer, bytes)
155 char *pointer;
156 int bytes;
157{
158 static memory_error_and_abort ();
159 char *temp = (char *)realloc (pointer, bytes);
160
161 if (!temp)
162 memory_error_and_abort ();
163 return (temp);
164}
165
166static
167memory_error_and_abort ()
168{
169 fprintf (stderr, "readline: Out of virtual memory!\n");
170 abort ();
171}
172#endif /* STATIC_MALLOC */