[BACK]Return to ttykbd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/ttykbd.c, Revision 1.22

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