static int findbind(KEYMAP *map, PF fun, char *buf, size_t len) { KEYMAP *newmap; PF nfun; char buf2[16], keybuf[16]; int c; /* XXX - 256 ? */ for (c = 0; c < 256; c++) { nfun = doscan(map, c, &newmap); if (nfun == fun) { getkeyname(buf, len, c); return (TRUE); } if (nfun == NULL) { if (findbind(newmap, fun, buf2, sizeof(buf2)) == TRUE) { getkeyname(keybuf, sizeof(keybuf), c); (void)snprintf(buf, len, "%s %s", keybuf, buf2); return (TRUE); } } } return (FALSE); }
static int showall(struct buffer *bp, KEYMAP *map, char *prefix) { KEYMAP *newmap; char buf[80], keybuf[16]; PF fun; int c; if (addline(bp, "") == FALSE) return (FALSE); /* XXX - 256 ? */ for (c = 0; c < 256; c++) { fun = doscan(map, c, &newmap); if (fun == rescan || fun == selfinsert) continue; getkeyname(buf, sizeof(buf), c); (void)snprintf(keybuf, sizeof(keybuf), "%s%s ", prefix, buf); if (fun == NULL) { if (showall(bp, newmap, keybuf) == FALSE) return (FALSE); } else { if (addlinef(bp, "%-16s%s", keybuf, function_name(fun)) == FALSE) return (FALSE); } } return (TRUE); }
/* * Do the input for local-set-key, global-set-key and define-key * then call remap to do the work. */ static int dobind(KEYMAP *curmap, const char *p, int unbind) { KEYMAP *pref_map = NULL; PF funct; char bprompt[80], *bufp, *pep; int c, s, n; if (macrodef) { /* * Keystrokes aren't collected. Not hard, but pretty useless. * Would not work for function keys in any case. */ ewprintf("Can't rebind key in macro"); return (FALSE); } if (inmacro) { for (s = 0; s < maclcur->l_used - 1; s++) { if (doscan(curmap, c = CHARMASK(maclcur->l_text[s]), &curmap) != NULL) { if (remap(curmap, c, NULL, NULL) != TRUE) return (FALSE); } } (void)doscan(curmap, c = maclcur->l_text[s], NULL); maclcur = maclcur->l_fp; } else { n = strlcpy(bprompt, p, sizeof(bprompt)); if (n >= sizeof(bprompt)) n = sizeof(bprompt) - 1; pep = bprompt + n; for (;;) { ewprintf("%s", bprompt); pep[-1] = ' '; pep = getkeyname(pep, sizeof(bprompt) - (pep - bprompt), c = getkey(FALSE)); if (doscan(curmap, c, &curmap) != NULL) break; *pep++ = '-'; *pep = '\0'; } } if (unbind) funct = rescan; else { if ((bufp = eread("%s to command: ", bprompt, sizeof(bprompt), EFFUNC | EFNEW, bprompt)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); if (((funct = name_function(bprompt)) == NULL) ? (pref_map = name_map(bprompt)) == NULL : funct == NULL) { ewprintf("[No match]"); return (FALSE); } } return (remap(curmap, c, funct, pref_map)); }
int config_load_keymap( INI_FILE * ini, const char * section, KEYMAP * keymap, KEYNAME * keyname ) { int i = 0; int err; while( keymap[i].emukey ) { err = ini_file_read_uint( ini, section, getkeyname(keymap[i].emukey, keyname), &keymap[i].phykey ); if( err ) goto err; i++; } return 0; err: return -1; }
int platform_load_keymap( const char * section, const char * ini_path, KEYMAP * keymap, KEYNAME * keyname ) { int i = 0; INI_FILE * ini = ini_file_open( ini_path, INI_OPEN_MODE_READ ); if( ini == NULL ) goto err; while( keymap[i].emukey ) { ini_file_read_uint( ini, section, getkeyname(keymap[i].emukey, keyname), &keymap[i].phykey ); i++; } ini_file_close( ini ); return 0; err: TRACE_LOG("error!"); return -1; }
int getkey(int flag) { int c; if (flag && !pushed) { if (prompt[0] != '\0' && ttwait(2000)) { /* avoid problems with % */ ewprintf("%s", prompt); /* put the cursor back */ update(CMODE); epresf = KCLEAR; } if (promptp > prompt) *(promptp - 1) = ' '; } if (pushed) { c = pushedc; pushed = FALSE; } else c = ttgetc(); if (bs_map) { if (c == CCHR('H')) c = CCHR('?'); else if (c == CCHR('?')) c = CCHR('H'); } if (use_metakey && (c & METABIT)) { pushedc = c & ~METABIT; pushed = TRUE; c = CCHR('['); } if (flag && promptp < &prompt[PROMPTL - 5]) { promptp = getkeyname(promptp, sizeof(prompt) - (promptp - prompt) - 1, c); *promptp++ = '-'; *promptp = '\0'; } return (c); }
/* * Printf style formatting. This is called by both "ewprintf" and "ereply" * to provide formatting services to their clients. The move to the start * of the echo line, and the erase to the end of the echo line, is done by * the caller. * %c prints the "name" of the supplied character. * %k prints the name of the current key (and takes no arguments). * %d prints a decimal integer * %o prints an octal integer * %p prints a pointer * %s prints a string * %ld prints a long word * Anything else is echoed verbatim */ static void eformat(const char *fp, va_list ap) { char kname[NKNAME], tmp[100], *cp; int c; while ((c = *fp++) != '\0') { if (c != '%') eputc(c); else { c = *fp++; switch (c) { case 'c': getkeyname(kname, sizeof(kname), va_arg(ap, int)); eputs(kname); break; case 'k': for (cp = kname, c = 0; c < key.k_count; c++) { if (c) *cp++ = ' '; cp = getkeyname(cp, sizeof(kname) - (cp - kname) - 1, key.k_chars[c]); } eputs(kname); break; case 'd': eputi(va_arg(ap, int), 10); break; case 'o': eputi(va_arg(ap, int), 8); break; case 'p': snprintf(tmp, sizeof(tmp), "%p", va_arg(ap, void *)); eputs(tmp); break; case 's': eputs(va_arg(ap, char *)); break; case 'l': /* explicit longword */ c = *fp++; switch (c) { case 'd': eputl(va_arg(ap, long), 10); break; default: eputc(c); break; } break; default: eputc(c); } } } }
void ___ldfix___(void){ getkeyname(); }
/* ARGSUSED */ int desckey(int f, int n) { KEYMAP *curmap; PF funct; int c, m, i, num; char *pep; char dprompt[80]; if (inmacro) return (TRUE); /* ignore inside keyboard macro */ num = strlcpy(dprompt, "Describe key briefly: ", sizeof(dprompt)); if (num >= sizeof(dprompt)) num = sizeof(dprompt) - 1; pep = dprompt + num; key.k_count = 0; m = curbp->b_nmodes; curmap = curbp->b_modes[m]->p_map; for (;;) { for (;;) { ewprintf("%s", dprompt); pep[-1] = ' '; pep = getkeyname(pep, sizeof(dprompt) - (pep - dprompt), key.k_chars[key.k_count++] = c = getkey(FALSE)); if ((funct = doscan(curmap, c, &curmap)) != NULL) break; *pep++ = '-'; *pep = '\0'; } if (funct != rescan) break; if (ISUPPER(key.k_chars[key.k_count - 1])) { funct = doscan(curmap, TOLOWER(key.k_chars[key.k_count - 1]), &curmap); if (funct == NULL) { *pep++ = '-'; *pep = '\0'; continue; } if (funct != rescan) break; } nextmode: if (--m < 0) break; curmap = curbp->b_modes[m]->p_map; for (i = 0; i < key.k_count; 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; } } *pep++ = '-'; *pep = '\0'; } found: if (funct == rescan || funct == selfinsert) ewprintf("%k is not bound to any function"); else if ((pep = (char *)function_name(funct)) != NULL) ewprintf("%k runs the command %s", pep); else ewprintf("%k is bound to an unnamed function"); return (TRUE); }
const char * GetSysKeyName( int syskey ) { return getkeyname( syskey, syskeyname ); }