summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-05-24 10:43:22 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-05-24 10:43:22 +0000
commita362f5a3bc8fb4f28a7cf27e55a956db6b1585a1 (patch)
tree68d97d7cc1ca08fa7ff7d87b17fa6eb9af5b7352 /usr.bin/mg
parent8a16edcb82485ab189d1f1167ca787bedc144a3b (diff)
Make the keymap/mode table growable in runtime.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/extend.c11
-rw-r--r--usr.bin/mg/kbd.h10
-rw-r--r--usr.bin/mg/keymap.c91
-rw-r--r--usr.bin/mg/main.c4
-rw-r--r--usr.bin/mg/modes.c4
6 files changed, 76 insertions, 47 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 9615c1c14aa..a3648be8d56 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.20 2001/05/24 10:10:00 art Exp $ */
+/* $OpenBSD: def.h,v 1.21 2001/05/24 10:43:16 art Exp $ */
/*
* This file is the general header file for all parts
@@ -569,7 +569,6 @@ extern int ttcol;
extern int tttop;
extern int ttbot;
extern int tthue;
-extern int nmaps;
extern int defb_nmodes;
extern int defb_flag;
extern const char cinfo[];
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c
index 5ef729af5df..74759eae0b1 100644
--- a/usr.bin/mg/extend.c
+++ b/usr.bin/mg/extend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extend.c,v 1.16 2001/05/24 09:47:33 art Exp $ */
+/* $OpenBSD: extend.c,v 1.17 2001/05/24 10:43:17 art Exp $ */
/*
* Extended (M-X) commands, rebinding, and startup file processing.
@@ -263,6 +263,7 @@ static KEYMAP *
realocmap(curmap)
KEYMAP *curmap;
{
+ MAPS *mps;
KEYMAP *mp;
int i;
@@ -281,11 +282,11 @@ realocmap(curmap)
mp->map_element[i].k_funcp = curmap->map_element[i].k_funcp;
mp->map_element[i].k_prefmap = curmap->map_element[i].k_prefmap;
}
- for (i = nmaps; i--;) {
- if (map_table[i].p_map == curmap)
- map_table[i].p_map = mp;
+ for (mps = maps; mps != NULL; mps = mps->p_next) {
+ if (mps->p_map == curmap)
+ mps->p_map = mp;
else
- fixmap(curmap, mp, map_table[i].p_map);
+ fixmap(curmap, mp, mps->p_map);
}
ele = &mp->map_element[ele - &curmap->map_element[0]];
return mp;
diff --git a/usr.bin/mg/kbd.h b/usr.bin/mg/kbd.h
index ea3dfa990dc..62c2e0b296c 100644
--- a/usr.bin/mg/kbd.h
+++ b/usr.bin/mg/kbd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kbd.h,v 1.11 2001/05/24 09:47:34 art Exp $ */
+/* $OpenBSD: kbd.h,v 1.12 2001/05/24 10:43:18 art Exp $ */
/*
* kbd.h: type definitions for symbol.c and kbd.c for mg experimental
@@ -38,16 +38,20 @@ typedef struct keymap_s KEYMAPE(1) KEYMAP;
typedef struct MAPS_S {
KEYMAP *p_map;
char *p_name;
+ struct MAPS_S *p_next;
} MAPS;
-extern MAPS map_table[];
-extern KEYMAP *fundamental_map;
+extern MAPS *maps;
+extern MAPS fundamental_mode;
+#define fundamental_map (fundamental_mode.p_map)
int dobindkey __P((KEYMAP *, char *, char *));
KEYMAP *name_map __P((char *));
MAPS *name_mode __P((char *));
PF doscan __P((KEYMAP *, int, KEYMAP **));
char *map_name __P((KEYMAP *));
+void maps_init(void);
+int maps_add(KEYMAP *, char *);
extern MAP_ELEMENT *ele;
extern MAPS *defb_modes[];
diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index 2bb7b482686..89685fe86cc 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymap.c,v 1.12 2001/05/24 09:47:34 art Exp $ */
+/* $OpenBSD: keymap.c,v 1.13 2001/05/24 10:43:18 art Exp $ */
/*
* Keyboard maps. This is character set dependent. The terminal specific
@@ -575,6 +575,8 @@ static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
};
#endif /* !NO_DIRED */
+MAPS fundamental_mode = { (KEYMAP *)&fundmap, "fundamental", };
+
/*
* give names to the maps, for use by help etc. If the map is to be bindable,
* it must also be listed in the function name table below with the same
@@ -584,66 +586,87 @@ static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
* modes.c also.
*/
-MAPS map_table[] = {
- /* fundamental map MUST be first entry */
- {(KEYMAP *) & fundmap, "fundamental"},
- {(KEYMAP *) & fillmap, "fill"},
- {(KEYMAP *) & indntmap, "indent"},
- {(KEYMAP *) & blinkmap, "blink"},
+static MAPS map_table[] = {
+ {(KEYMAP *) &fillmap, "fill",},
+ {(KEYMAP *) &indntmap, "indent",},
+ {(KEYMAP *) &blinkmap, "blink",},
#ifdef NOTAB
- {(KEYMAP *) & notabmap, "notab"},
+ {(KEYMAP *) &notabmap, "notab",},
#endif /* NOTAB */
- {(KEYMAP *) & overwmap, "overwrite"},
- {(KEYMAP *) & metamap, "esc prefix"},
- {(KEYMAP *) & cXmap, "c-x prefix"},
- {(KEYMAP *) & cX4map, "c-x 4 prefix"},
- {(KEYMAP *) & extramap1, "extra prefix 1"},
- {(KEYMAP *) & extramap2, "extra prefix 2"},
- {(KEYMAP *) & extramap3, "extra prefix 3"},
- {(KEYMAP *) & extramap4, "extra prefix 4"},
- {(KEYMAP *) & extramap5, "extra prefix 5"},
+ {(KEYMAP *) &overwmap, "overwrite",},
+ {(KEYMAP *) &metamap, "esc prefix",},
+ {(KEYMAP *) &cXmap, "c-x prefix",},
+ {(KEYMAP *) &cX4map, "c-x 4 prefix",},
+ {(KEYMAP *) &extramap1, "extra prefix 1",},
+ {(KEYMAP *) &extramap2, "extra prefix 2",},
+ {(KEYMAP *) &extramap3, "extra prefix 3",},
+ {(KEYMAP *) &extramap4, "extra prefix 4",},
+ {(KEYMAP *) &extramap5, "extra prefix 5",},
#ifndef NO_HELP
- {(KEYMAP *) & helpmap, "help"},
+ {(KEYMAP *) &helpmap, "help",},
#endif
#ifndef NO_DIRED
- {(KEYMAP *) & diredmap, "dired"},
+ {(KEYMAP *) &diredmap, "dired",},
#endif
+ {NULL, NULL},
};
-#define NMAPS (sizeof map_table/sizeof(MAPS))
-int nmaps = NMAPS; /* for use by rebind in extend.c */
+MAPS *maps;
+
+void
+maps_init(void)
+{
+ int i;
+ MAPS *mp;
+
+ maps = &fundamental_mode;
+ for (i = 0; map_table[i].p_name != NULL; i++) {
+ mp = &map_table[i];
+ mp->p_next = maps;
+ maps = mp;
+ }
+}
+
+int
+maps_add(KEYMAP *map, char *name)
+{
+ MAPS *mp;
+
+ if ((mp = malloc(sizeof(*mp))) == NULL)
+ return FALSE;
-KEYMAP *fundamental_map = (KEYMAP *)&fundmap;
+ mp->p_name = name;
+ mp->p_map = map;
+ mp->p_next = maps;
+ maps = mp;
+
+ return TRUE;
+}
char *
-map_name(map)
- KEYMAP *map;
+map_name(KEYMAP *map)
{
- MAPS *mp = &map_table[0];
+ MAPS *mp;
- do {
+ for (mp = maps; mp != NULL; mp = mp->p_next)
if (mp->p_map == map)
return mp->p_name;
- } while (++mp < &map_table[NMAPS]);
return NULL;
}
MAPS *
-name_mode(name)
- char *name;
+name_mode(char *name)
{
- MAPS *mp = &map_table[0];
+ MAPS *mp;
- do {
+ for (mp = maps; mp != NULL; mp = mp->p_next)
if (strcmp(mp->p_name, name) == 0)
return mp;
- } while (++mp < &map_table[NMAPS]);
return NULL;
}
KEYMAP *
-name_map(name)
- char *name;
+name_map(char *name)
{
MAPS *mp;
return (mp = name_mode(name)) == NULL ? NULL : mp->p_map;
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index 491f6b1d5e6..9f3c7ca3f4d 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,10 +1,11 @@
-/* $OpenBSD: main.c,v 1.11 2001/05/24 09:47:34 art Exp $ */
+/* $OpenBSD: main.c,v 1.12 2001/05/24 10:43:19 art Exp $ */
/*
* Mainline.
*/
#include "def.h"
+#include "kbd.h"
#include "funmap.h"
#ifndef NO_MACRO
@@ -37,6 +38,7 @@ main(argc, argv)
dirinit(); /* Get current directory. */
#endif /* !NO_DIR */
edinit(); /* Buffers, windows. */
+ maps_init(); /* Keymaps and modes. */
funmap_init(); /* Functions. */
ttykeymapinit(); /* Symbols, bindings. */
diff --git a/usr.bin/mg/modes.c b/usr.bin/mg/modes.c
index ab196ce4d52..0defd16c9a3 100644
--- a/usr.bin/mg/modes.c
+++ b/usr.bin/mg/modes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: modes.c,v 1.5 2001/05/24 03:05:25 mickey Exp $ */
+/* $OpenBSD: modes.c,v 1.6 2001/05/24 10:43:21 art Exp $ */
/*
* Commands to toggle modes. Without an argument, these functions will
@@ -12,7 +12,7 @@
static int changemode __P((int, int, char *));
int defb_nmodes = 0;
-MAPS *defb_modes[PBMODES] = { &map_table[0] };
+MAPS *defb_modes[PBMODES] = { &fundamental_mode };
int defb_flag = 0;
static int