1 /* $OpenBSD: ttykbd.c,v 1.22 2023/03/30 19:00:02 op Exp $ */
2
3 /* This file is in the public domain. */
4
5 /*
6 * Name: MG 2a
7 * Terminfo keyboard driver using key files
8 * Created: 22-Nov-1987 Mic Kaczmarczik (mic@emx.cc.utexas.edu)
9 */
10
11 #include <sys/queue.h>
12 #include <signal.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <term.h>
16
17 #include "def.h"
18 #include "kbd.h"
19
20 /*
21 * Get keyboard character. Very simple if you use keymaps and keys files.
22 */
23
24 char *keystrings[] = {NULL};
25
26 /*
27 * Turn on function keys using keypad_xmit, then load a keys file, if
28 * available. The keys file is located in the same manner as the startup
29 * file is, depending on what startupfile() does on your system.
30 */
31 void
ttykeymapinit(void)32 ttykeymapinit(void)
33 {
34 char *cp, file[NFILEN];
35 FILE *ffp;
36
37 /* Bind keypad function keys. */
38 if (key_left)
39 dobindkey(fundamental_map, "backward-char", key_left);
40 if (key_right)
41 dobindkey(fundamental_map, "forward-char", key_right);
42 if (key_up)
43 dobindkey(fundamental_map, "previous-line", key_up);
44 if (key_down)
45 dobindkey(fundamental_map, "next-line", key_down);
46 if (key_beg)
47 dobindkey(fundamental_map, "beginning-of-line", key_beg);
48 else if (key_home)
49 dobindkey(fundamental_map, "beginning-of-line", key_home);
50 if (key_end)
51 dobindkey(fundamental_map, "end-of-line", key_end);
52 if (key_npage)
53 dobindkey(fundamental_map, "scroll-up", key_npage);
54 if (key_ppage)
55 dobindkey(fundamental_map, "scroll-down", key_ppage);
56 if (key_ic)
57 dobindkey(fundamental_map, "overwrite-mode", key_ic);
58 if (key_dc)
59 dobindkey(fundamental_map, "delete-char", key_dc);
60
61 if ((cp = getenv("TERM")) != NULL &&
62 (ffp = startupfile(cp, NULL, file, sizeof(file))) != NULL) {
63 if (load(ffp, file) != TRUE)
64 ewprintf("Error reading key initialization file");
65 (void)ffclose(ffp, NULL);
66 }
67 if (keypad_xmit)
68 /* turn on keypad */
69 putpad(keypad_xmit, 1);
70 }
71
72 /*
73 * Clean up the keyboard -- called by tttidy()
74 */
75 void
ttykeymaptidy(void)76 ttykeymaptidy(void)
77 {
78 if (keypad_local)
79 /* turn off keypad */
80 putpad(keypad_local, 1);
81 }
82