The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/wscons/wsemul_vt100_keys.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: wsemul_vt100_keys.c,v 1.6 2004/03/24 17:26:53 drochner Exp $ */
    2 
    3 /*
    4  * Copyright (c) 1998
    5  *      Matthias Drochner.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   26  *
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_keys.c,v 1.6 2004/03/24 17:26:53 drochner Exp $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 
   35 #include <dev/wscons/wsdisplayvar.h>
   36 #include <dev/wscons/wsksymvar.h>
   37 #include <dev/wscons/wsksymdef.h>
   38 #include <dev/wscons/wsemul_vt100var.h>
   39 
   40 static char *vt100_fkeys[] = {
   41         "\033[11~",     /* F1 */
   42         "\033[12~",
   43         "\033[13~",             /* F1-F5 normally don't send codes */
   44         "\033[14~",
   45         "\033[15~",     /* F5 */
   46         "\033[17~",     /* F6 */
   47         "\033[18~",
   48         "\033[19~",
   49         "\033[20~",
   50         "\033[21~",
   51         "\033[23~",     /* VT100: ESC */
   52         "\033[24~",     /* VT100: BS */
   53         "\033[25~",     /* VT100: LF */
   54         "\033[26~",
   55         "\033[28~",     /* help */
   56         "\033[29~",     /* do */
   57         "\033[31~",
   58         "\033[32~",
   59         "\033[33~",
   60         "\033[34~",     /* F20 */
   61 };
   62 
   63 static char *vt100_pfkeys[] = {
   64         "\033OP",       /* PF1 */
   65         "\033OQ",
   66         "\033OR",
   67         "\033OS",       /* PF4 */
   68 };
   69 
   70 static char *vt100_numpad[] = {
   71         "\033Op",       /* KP 0 */
   72         "\033Oq",       /* KP 1 */
   73         "\033Or",       /* KP 2 */
   74         "\033Os",       /* KP 3 */
   75         "\033Ot",       /* KP 4 */
   76         "\033Ou",       /* KP 5 */
   77         "\033Ov",       /* KP 6 */
   78         "\033Ow",       /* KP 7 */
   79         "\033Ox",       /* KP 8 */
   80         "\033Oy",       /* KP 9 */
   81 };
   82 
   83 int
   84 wsemul_vt100_translate(void *cookie, keysym_t in, char **out)
   85 {
   86         struct wsemul_vt100_emuldata *edp = cookie;
   87         static char c;
   88 
   89         if (in >= KS_f1 && in <= KS_f20) {
   90                 *out = vt100_fkeys[in - KS_f1];
   91                 return (5);
   92         }
   93         if (in >= KS_F1 && in <= KS_F20) {
   94                 *out = vt100_fkeys[in - KS_F1];
   95                 return (5);
   96         }
   97         if (in >= KS_KP_F1 && in <= KS_KP_F4) {
   98                 *out = vt100_pfkeys[in - KS_KP_F1];
   99                 return (3);
  100         }
  101         if (edp->flags & VTFL_APPLKEYPAD) {
  102                 if (in >= KS_KP_0 && in <= KS_KP_9) {
  103                         *out = vt100_numpad[in - KS_KP_0];
  104                         return (3);
  105                 }
  106                 switch (in) {
  107                     case KS_KP_Tab:
  108                         *out = "\033OI";
  109                         return (3);
  110                     case KS_KP_Enter:
  111                         *out = "\033OM";
  112                         return (3);
  113                     case KS_KP_Multiply:
  114                         *out = "\033Oj";
  115                         return (3);
  116                     case KS_KP_Add:
  117                         *out = "\033Ok";
  118                         return (3);
  119                     case KS_KP_Separator:
  120                         *out = "\033Ol";
  121                         return (3);
  122                     case KS_KP_Subtract:
  123                         *out = "\033Om";
  124                         return (3);
  125                     case KS_KP_Decimal:
  126                         *out = "\033On";
  127                         return (3);
  128                     case KS_KP_Divide:
  129                         *out = "\033Oo";
  130                         return (3);
  131                 }
  132         } else {
  133                 if (!(in & 0x80)) {
  134                         c = in & 0xff; /* turn into ASCII */
  135                         *out = &c;
  136                         return (1);
  137                 }
  138         }
  139         switch (in) {
  140             case KS_Help:
  141                 *out = vt100_fkeys[15 - 1];
  142                 return (5);
  143             case KS_Execute: /* "Do" */
  144                 *out = vt100_fkeys[16 - 1];
  145                 return (5);
  146             case KS_Find:
  147                 *out = "\033[1~";
  148                 return (4);
  149             case KS_Insert:
  150             case KS_KP_Insert:
  151                 *out = "\033[2~";
  152                 return (4);
  153             case KS_KP_Delete:
  154                 *out = "\033[3~";
  155                 return (4);
  156             case KS_Select:
  157                 *out = "\033[4~";
  158                 return (4);
  159             case KS_Prior:
  160             case KS_KP_Prior:
  161                 *out = "\033[5~";
  162                 return (4);
  163             case KS_Next:
  164             case KS_KP_Next:
  165                 *out = "\033[6~";
  166                 return (4);
  167             case KS_Home:
  168             case KS_KP_Home:
  169                 *out = "\033[7~";
  170                 return (4);
  171             case KS_End:
  172             case KS_KP_End:
  173                 *out = "\033[8~";
  174                 return (4);
  175             case KS_Up:
  176             case KS_KP_Up:
  177                 if (edp->flags & VTFL_APPLCURSOR)
  178                         *out = "\033OA";
  179                 else
  180                         *out = "\033[A";
  181                 return (3);
  182             case KS_Down:
  183             case KS_KP_Down:
  184                 if (edp->flags & VTFL_APPLCURSOR)
  185                         *out = "\033OB";
  186                 else
  187                         *out = "\033[B";
  188                 return (3);
  189             case KS_Left:
  190             case KS_KP_Left:
  191                 if (edp->flags & VTFL_APPLCURSOR)
  192                         *out = "\033OD";
  193                 else
  194                         *out = "\033[D";
  195                 return (3);
  196             case KS_Right:
  197             case KS_KP_Right:
  198                 if (edp->flags & VTFL_APPLCURSOR)
  199                         *out = "\033OC";
  200                 else
  201                         *out = "\033[C";
  202                 return (3);
  203         }
  204         return (0);
  205 }

Cache object: 998222a54ab177ce65179952bfe6f191


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.