=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/kbd.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- src/usr.bin/mg/kbd.c 2001/05/23 16:14:00 1.6 +++ src/usr.bin/mg/kbd.c 2001/05/23 20:19:44 1.7 @@ -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 @@ * 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 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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