Annotation of src/usr.bin/mg/ttykbd.c, Revision 1.2
1.1 deraadt 1: /*
2: * Name: MG 2a
1.2 ! millert 3: * Terminfo keyboard driver using key files
1.1 deraadt 4: * Created: 22-Nov-1987 Mic Kaczmarczik (mic@emx.cc.utexas.edu)
5: */
6:
7: #include "def.h"
1.2 ! millert 8: #include "kbd.h"
1.1 deraadt 9: #ifdef XKEYS
1.2 ! millert 10: #include <term.h>
1.1 deraadt 11:
1.2 ! millert 12: #ifdef FKEYS
! 13: #include "key.h"
1.1 deraadt 14: /*
15: * Get keyboard character. Very simple if you use keymaps and keys files.
16: * Bob was right -- the old XKEYS code is not the right solution.
17: * FKEYS code is not usefull other than to help debug FKEYS code in
18: * extend.c.
19: */
20:
21: char *keystrings[] = { NULL } ;
1.2 ! millert 22:
! 23: int
! 24: dobindkey(str, func)
! 25: char *str;
! 26: char *func;
! 27: {
! 28: int i;
! 29: extern int bindkey(); /* XXX */
! 30:
! 31: for (i = 0; *str && i < MAXKEY; i++) {
! 32: /* XXX - how to convert numbers? */
! 33: if (*str != '\\')
! 34: key.k_chars[i] = *str;
! 35: else {
! 36: switch(*++str) {
! 37: case 't': case 'T':
! 38: key.k_chars[i] = '\t';
! 39: break;
! 40: case 'n': case 'N':
! 41: key.k_chars[i] = '\n';
! 42: break;
! 43: case 'r': case 'R':
! 44: key.k_chars[i] = '\r';
! 45: break;
! 46: case 'e': case 'E':
! 47: key.k_chars[i] = CCHR('[');
! 48: break;
! 49: }
! 50: }
! 51: str++;
! 52: }
! 53: key.k_count = i;
! 54: return(bindkey(&map_table[0].p_map, func, key.k_chars, key.k_count));
! 55: }
1.1 deraadt 56: #endif
57:
58: /*
1.2 ! millert 59: * Turn on function keys using keypad_xmit, then load a keys file, if
! 60: * available. The keys file is located in the same manner as the startup
! 61: * file is, depending on what startupfile() does on your system.
1.1 deraadt 62: */
63: extern int ttputc();
64:
65: ttykeymapinit()
66: {
1.2 ! millert 67: char *cp;
! 68: #ifdef FKEYS
! 69: /* Bind keypad function keys. */
! 70: if (key_left)
! 71: dobindkey(key_left, "backward-char");
! 72: if (key_left)
! 73: dobindkey(key_left, "backward-char");
! 74: if (key_right)
! 75: dobindkey(key_right, "forward-char");
! 76: if (key_up)
! 77: dobindkey(key_up, "previous-line");
! 78: if (key_down)
! 79: dobindkey(key_down, "next-line");
! 80: if (key_beg)
! 81: dobindkey(key_beg, "beginning-of-line");
! 82: if (key_end)
! 83: dobindkey(key_end, "end-of-line");
! 84: if (key_npage)
! 85: dobindkey(key_npage, "scroll-up");
! 86: if (key_ppage)
! 87: dobindkey(key_ppage, "scroll-down");
! 88: #endif
1.1 deraadt 89: #ifndef NO_STARTUP
90: if (cp = gettermtype()) {
1.2 ! millert 91: extern char *startupfile();
1.1 deraadt 92: if (((cp = startupfile(cp)) != NULL)
93: && (load(cp) != TRUE))
94: ewprintf("Error reading key initialization file");
95: }
96: #endif
1.2 ! millert 97: if (keypad_xmit) /* turn on keypad */
! 98: putpad(keypad_xmit, 1);
1.1 deraadt 99: }
100:
101: /*
102: * Clean up the keyboard -- called by tttidy()
103: */
104: ttykeymaptidy()
105: {
106:
1.2 ! millert 107: if (keypad_local)
! 108: putpad(keypad_local, 1); /* turn off keypad */
1.1 deraadt 109: }
110:
111: #endif