]> pd.if.org Git - pd_readline/blob - mg/ttykbd.c
Added mg from an OpenBSD mirror site. Many thanks to the OpenBSD team and the mg...
[pd_readline] / mg / ttykbd.c
1 /*      $OpenBSD: ttykbd.c,v 1.16 2012/04/12 04:47:59 lum 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 "def.h"
12 #include "kbd.h"
13
14 #ifdef  XKEYS
15 #include <term.h>
16
17 #ifdef  FKEYS
18 /*
19  * Get keyboard character.  Very simple if you use keymaps and keys files.
20  * Bob was right -- the old XKEYS code is not the right solution.
21  * FKEYS code is not useful other than to help debug FKEYS code in
22  * extend.c.
23  */
24
25 char    *keystrings[] = {NULL};
26 #endif /* FKEYS */
27
28 /*
29  * Turn on function keys using keypad_xmit, then load a keys file, if
30  * available.  The keys file is located in the same manner as the startup
31  * file is, depending on what startupfile() does on your system.
32  */
33 void
34 ttykeymapinit(void)
35 {
36         char    *cp;
37
38 #ifdef FKEYS
39         /* Bind keypad function keys. */
40         if (key_left)
41                 dobindkey(fundamental_map, "backward-char", key_left);
42         if (key_right)
43                 dobindkey(fundamental_map, "forward-char", key_right);
44         if (key_up)
45                 dobindkey(fundamental_map, "previous-line", key_up);
46         if (key_down)
47                 dobindkey(fundamental_map, "next-line", key_down);
48         if (key_beg)
49                 dobindkey(fundamental_map, "beginning-of-line", key_beg);
50         else if (key_home)
51                 dobindkey(fundamental_map, "beginning-of-line", key_home);
52         if (key_end)
53                 dobindkey(fundamental_map, "end-of-line", key_end);
54         if (key_npage)
55                 dobindkey(fundamental_map, "scroll-up", key_npage);
56         if (key_ppage)
57                 dobindkey(fundamental_map, "scroll-down", key_ppage);
58         if (key_dc)
59                 dobindkey(fundamental_map, "delete-char", key_dc);
60 #endif /* FKEYS */
61
62         if ((cp = getenv("TERM"))) {
63                 if (((cp = startupfile(cp)) != NULL) && (load(cp) != TRUE))
64                         ewprintf("Error reading key initialization file");
65         }
66         if (keypad_xmit)
67                 /* turn on keypad */
68                 putpad(keypad_xmit, 1);
69 }
70
71 /*
72  * Clean up the keyboard -- called by tttidy()
73  */
74 void
75 ttykeymaptidy(void)
76 {
77         if (keypad_local)
78                 /* turn off keypad */
79                 putpad(keypad_local, 1);
80 }
81
82 #else
83
84 void
85 ttykeymapinit(void)
86 {
87 }
88
89 #endif /* XKEYS */