Annotation of GNUtools/debug/gdb/readline/keymaps.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.