diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-23 20:19:45 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-23 20:19:45 +0000 |
commit | 8a89bd425d9f56c4867e33e957f8e9658a4b69d6 (patch) | |
tree | 1f9eafc20cd91cac26cf98512d334ea6ef0bf8ac /usr.bin/mg | |
parent | 68f295288cb4bb561e8bca5509d2f1ad67cfdb3b (diff) |
Add an argument to doscan which is a pointer to a KEYMAP pointer.
If that argument is not NULL, we set it to the k_prefmap of the pressed
key if there is one.
This is what most of the users of doscan did anyway, but they did it through
leaked global state.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/extend.c | 15 | ||||
-rw-r--r-- | usr.bin/mg/help.c | 13 | ||||
-rw-r--r-- | usr.bin/mg/kbd.c | 44 | ||||
-rw-r--r-- | usr.bin/mg/kbd.h | 4 |
4 files changed, 36 insertions, 40 deletions
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c index 5f5ed3d14e4..17c9bc90d20 100644 --- a/usr.bin/mg/extend.c +++ b/usr.bin/mg/extend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extend.c,v 1.7 2001/05/23 16:13:59 art Exp $ */ +/* $OpenBSD: extend.c,v 1.8 2001/05/23 20:19:44 art Exp $ */ /* * Extended (M-X) commands, rebinding, and startup file processing. @@ -339,15 +339,14 @@ dobind(curmap, p, unbind) #ifndef NO_STARTUP if (inmacro) { for (s = 0; s < maclcur->l_used - 1; s++) { - if (doscan(curmap, c = CHARMASK(maclcur->l_text[s])) + if (doscan(curmap, c = CHARMASK(maclcur->l_text[s]), &curmap) != NULL) { if (remap(curmap, c, NULL, (KEYMAP *)NULL) != TRUE) return FALSE; } - curmap = ele->k_prefmap; } - (VOID)doscan(curmap, c = maclcur->l_text[s]); + (VOID)doscan(curmap, c = maclcur->l_text[s], NULL); maclcur = maclcur->l_fp; } else { #endif /* !NO_STARTUP */ @@ -358,11 +357,10 @@ dobind(curmap, p, unbind) ewprintf("%s", prompt); pep[-1] = ' '; pep = keyname(pep, c = getkey(FALSE)); - if (doscan(curmap, c) != NULL) + if (doscan(curmap, c, &curmap) != NULL) break; *pep++ = '-'; *pep = '\0'; - curmap = ele->k_prefmap; } #ifndef NO_STARTUP } @@ -409,13 +407,12 @@ bindkey(mapp, fname, keys, kcount) return FALSE; } while (--kcount) { - if (doscan(curmap, c = *keys++) != NULL) { + if (doscan(curmap, c = *keys++, &curmap) != NULL) { if (remap(curmap, c, NULL, (KEYMAP *)NULL) != TRUE) return FALSE; } - curmap = ele->k_prefmap; } - (VOID)doscan(curmap, c = *keys); + (VOID)doscan(curmap, c = *keys, NULL); return remap(curmap, c, funct, pref_map); } diff --git a/usr.bin/mg/help.c b/usr.bin/mg/help.c index 8358a3884eb..3062a2c01ee 100644 --- a/usr.bin/mg/help.c +++ b/usr.bin/mg/help.c @@ -1,4 +1,4 @@ -/* $OpenBSD: help.c,v 1.5 2001/05/23 16:14:00 art Exp $ */ +/* $OpenBSD: help.c,v 1.6 2001/05/23 20:19:44 art Exp $ */ /* * Help functions for Mg 2 @@ -52,21 +52,19 @@ desckey(f, n) pep[-1] = ' '; pep = keyname(pep, key.k_chars[key.k_count++] = c = getkey(FALSE)); - if ((funct = doscan(curmap, c)) != NULL) + if ((funct = doscan(curmap, c, &curmap)) != NULL) break; *pep++ = '-'; *pep = '\0'; - curmap = ele->k_prefmap; } if (funct != rescan) break; if (ISUPPER(key.k_chars[key.k_count - 1])) { funct = doscan(curmap, - TOLOWER(key.k_chars[key.k_count - 1])); + TOLOWER(key.k_chars[key.k_count - 1]), &curmap); if (funct == NULL) { *pep++ = '-'; *pep = '\0'; - curmap = ele->k_prefmap; continue; } if (funct != rescan) @@ -77,14 +75,13 @@ nextmode: break; curmap = curbp->b_modes[m]->p_map; for (i = 0; i < key.k_count; i++) { - funct = doscan(curmap, key.k_chars[i]); + funct = doscan(curmap, key.k_chars[i], &curmap); if (funct != NULL) { if (i == key.k_count - 1 && funct != rescan) goto found; funct = rescan; goto nextmode; } - curmap = ele->k_prefmap; } *pep++ = '-'; *pep = '\0'; @@ -207,7 +204,7 @@ help_help(f, n) return FALSE; ewprintf("a b c: "); do { - funct = doscan(kp, getkey(FALSE)); + funct = doscan(kp, getkey(FALSE), NULL); } while (funct == NULL || funct == help_help); #ifndef NO_MACRO if (macrodef && macrocount < MAXMACRO) diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c index 84dce3e5f09..c68c7de9f60 100644 --- a/usr.bin/mg/kbd.c +++ b/usr.bin/mg/kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd.c,v 1.6 2001/05/23 16:14:00 art Exp $ */ +/* $OpenBSD: kbd.c,v 1.7 2001/05/23 20:19:44 art Exp $ */ /* * Terminal independent keyboard handling. @@ -131,12 +131,14 @@ getkey(flag) * keymap element the keyboard was found in as a side effect. */ PF -doscan(map, c) +doscan(map, c, newmap) KEYMAP *map; int c; + KEYMAP **newmap; { MAP_ELEMENT *elec = &map->map_element[0]; MAP_ELEMENT *last = &map->map_element[map->map_num]; + PF ret; while (elec < last && c > elec->k_num) elec++; @@ -144,8 +146,13 @@ doscan(map, c) /* used by prefix and binding code */ ele = elec; if (elec >= last || c < elec->k_base) - return map->map_default; - return elec->k_funcp[c - elec->k_base]; + ret = map->map_default; + else + ret = elec->k_funcp[c - elec->k_base]; + if (ret == NULL && newmap != NULL) + *newmap = elec->k_prefmap; + + return ret; } int @@ -160,8 +167,8 @@ doin() curmap = curbp->b_modes[curbp->b_nmodes]->p_map; key.k_count = 0; while ((funct = doscan(curmap, (key.k_chars[key.k_count++] = - getkey(TRUE)))) == NULL) - curmap = ele->k_prefmap; + getkey(TRUE)), &curmap)) == NULL) + /*nothing*/; #ifndef NO_MACRO if (macrodef && macrocount < MAXMACRO) macro[macrocount++].m_funct = funct; @@ -184,17 +191,16 @@ rescan(f, n) c = TOLOWER(key.k_chars[key.k_count - 1]); curmap = curbp->b_modes[mode]->p_map; for (i = 0; i < key.k_count - 1; i++) { - if ((fp = doscan(curmap, (key.k_chars[i]))) + if ((fp = doscan(curmap, (key.k_chars[i]), &curmap)) != NULL) break; - curmap = ele->k_prefmap; } if (fp == NULL) { - if ((fp = doscan(curmap, c)) == NULL) + if ((fp = doscan(curmap, c, NULL)) == NULL) while ((fp = doscan(curmap, key.k_chars[key.k_count++] = - getkey(TRUE))) == NULL) - curmap = ele->k_prefmap; + getkey(TRUE), &curmap)) == NULL) + /*nothing*/; if (fp != rescan) { #ifndef NO_MACRO if (macrodef && macrocount <= MAXMACRO) @@ -210,14 +216,13 @@ rescan(f, n) return ABORT; curmap = curbp->b_modes[mode]->p_map; for (i = 0; i < key.k_count; i++) { - if ((fp = doscan(curmap, (key.k_chars[i]))) != NULL) + if ((fp = doscan(curmap, (key.k_chars[i]), &curmap)) != NULL) break; - curmap = ele->k_prefmap; } if (fp == NULL) { while ((fp = doscan(curmap, key.k_chars[i++] = - getkey(TRUE))) == NULL) - curmap = ele->k_prefmap; + getkey(TRUE), &curmap)) == NULL) + /*nothing*/; key.k_count = i; } if (fp != rescan && i >= key.k_count - 1) { @@ -249,8 +254,7 @@ universal_argument(f, n) if (c >= '0' && c <= '9') return digit_argument(f, nn); curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while ((funct = doscan(curmap, c)) == NULL) { - curmap = ele->k_prefmap; + while ((funct = doscan(curmap, c, &curmap)) == NULL) { key.k_chars[key.k_count++] = c = getkey(TRUE); } if (funct != universal_argument) { @@ -288,8 +292,7 @@ digit_argument(f, n) key.k_chars[0] = c; key.k_count = 1; curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while ((funct = doscan(curmap, c)) == NULL) { - curmap = ele->k_prefmap; + while ((funct = doscan(curmap, c, &curmap)) == NULL) { key.k_chars[key.k_count++] = c = getkey(TRUE); } #ifndef NO_MACRO @@ -328,8 +331,7 @@ negative_argument(f, n) key.k_chars[0] = c; key.k_count = 1; curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while ((funct = doscan(curmap, c)) == NULL) { - curmap = ele->k_prefmap; + while ((funct = doscan(curmap, c, &curmap)) == NULL) { key.k_chars[key.k_count++] = c = getkey(TRUE); } #ifndef NO_MACRO diff --git a/usr.bin/mg/kbd.h b/usr.bin/mg/kbd.h index b92846859e0..34dd413401f 100644 --- a/usr.bin/mg/kbd.h +++ b/usr.bin/mg/kbd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd.h,v 1.6 2001/05/23 16:18:56 art Exp $ */ +/* $OpenBSD: kbd.h,v 1.7 2001/05/23 20:19:44 art Exp $ */ /* * kbd.h: type definitions for symbol.c and kbd.c for mg experimental @@ -50,7 +50,7 @@ typedef struct { int dobindkey __P((KEYMAP *, char *, char *)); KEYMAP *name_map __P((char *)); MAPS *name_mode __P((char *)); -PF doscan __P((KEYMAP *, int)); +PF doscan __P((KEYMAP *, int, KEYMAP **)); PF name_function __P((char *)); char *function_name __P((PF)); char *map_name __P((KEYMAP *)); |