LCOV - code coverage report
Current view: top level - dev/wscons - wskbdutil.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 157 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: wskbdutil.c,v 1.17 2018/01/22 12:20:54 fcambus Exp $  */
       2             : /*      $NetBSD: wskbdutil.c,v 1.7 1999/12/21 11:59:13 drochner Exp $   */
       3             : 
       4             : /*-
       5             :  * Copyright (c) 1997 The NetBSD Foundation, Inc.
       6             :  * All rights reserved.
       7             :  *
       8             :  * This code is derived from software contributed to The NetBSD Foundation
       9             :  * by Juergen Hannken-Illjes.
      10             :  *
      11             :  * Redistribution and use in source and binary forms, with or without
      12             :  * modification, are permitted provided that the following conditions
      13             :  * are met:
      14             :  * 1. Redistributions of source code must retain the above copyright
      15             :  *    notice, this list of conditions and the following disclaimer.
      16             :  * 2. Redistributions in binary form must reproduce the above copyright
      17             :  *    notice, this list of conditions and the following disclaimer in the
      18             :  *    documentation and/or other materials provided with the distribution.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
      21             :  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
      22             :  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
      23             :  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
      24             :  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      25             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      26             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      27             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      28             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      29             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      30             :  * POSSIBILITY OF SUCH DAMAGE.
      31             :  */
      32             : 
      33             : #include <sys/param.h>
      34             : #include <sys/errno.h>
      35             : #include <sys/systm.h>
      36             : #include <sys/malloc.h>
      37             : #include <dev/wscons/wsksymdef.h>
      38             : #include <dev/wscons/wsksymvar.h>
      39             : 
      40             : static struct compose_tab_s {
      41             :         keysym_t elem[2];
      42             :         keysym_t result;
      43             : } compose_tab[] = {
      44             :         { { KS_plus,                    KS_plus },              KS_numbersign },
      45             :         { { KS_a,                       KS_a },                 KS_at },
      46             :         { { KS_parenleft,               KS_parenleft },         KS_bracketleft },
      47             :         { { KS_slash,                   KS_slash },             KS_backslash },
      48             :         { { KS_parenright,              KS_parenright },        KS_bracketright },
      49             :         { { KS_parenleft,               KS_minus },             KS_braceleft },
      50             :         { { KS_slash,                   KS_minus },             KS_bar },
      51             :         { { KS_parenright,              KS_minus },             KS_braceright },
      52             :         { { KS_exclam,                  KS_exclam },            KS_exclamdown },
      53             :         { { KS_c,                       KS_slash },             KS_cent },
      54             :         { { KS_l,                       KS_minus },             KS_sterling },
      55             :         { { KS_y,                       KS_minus },             KS_yen },
      56             :         { { KS_s,                       KS_o },                 KS_section },
      57             :         { { KS_x,                       KS_o },                 KS_currency },
      58             :         { { KS_c,                       KS_o },                 KS_copyright },
      59             :         { { KS_less,                    KS_less },              KS_guillemotleft },
      60             :         { { KS_greater,                 KS_greater },           KS_guillemotright },
      61             :         { { KS_question,                KS_question },          KS_questiondown },
      62             :         { { KS_dead_acute,              KS_space },             KS_apostrophe },
      63             :         { { KS_dead_grave,              KS_space },             KS_grave },
      64             :         { { KS_dead_tilde,              KS_space },             KS_asciitilde },
      65             :         { { KS_dead_circumflex,         KS_space },             KS_asciicircum },
      66             :         { { KS_dead_diaeresis,          KS_space },             KS_quotedbl },
      67             :         { { KS_dead_cedilla,            KS_space },             KS_comma },
      68             :         { { KS_dead_circumflex,         KS_A },                 KS_Acircumflex },
      69             :         { { KS_dead_diaeresis,          KS_A },                 KS_Adiaeresis },
      70             :         { { KS_dead_grave,              KS_A },                 KS_Agrave },
      71             :         { { KS_dead_abovering,          KS_A },                 KS_Aring },
      72             :         { { KS_dead_tilde,              KS_A },                 KS_Atilde },
      73             :         { { KS_dead_cedilla,            KS_C },                 KS_Ccedilla },
      74             :         { { KS_dead_acute,              KS_E },                 KS_Eacute },
      75             :         { { KS_dead_circumflex,         KS_E },                 KS_Ecircumflex },
      76             :         { { KS_dead_diaeresis,          KS_E },                 KS_Ediaeresis },
      77             :         { { KS_dead_grave,              KS_E },                 KS_Egrave },
      78             :         { { KS_dead_acute,              KS_I },                 KS_Iacute },
      79             :         { { KS_dead_circumflex,         KS_I },                 KS_Icircumflex },
      80             :         { { KS_dead_diaeresis,          KS_I },                 KS_Idiaeresis },
      81             :         { { KS_dead_grave,              KS_I },                 KS_Igrave },
      82             :         { { KS_dead_tilde,              KS_N },                 KS_Ntilde },
      83             :         { { KS_dead_acute,              KS_O },                 KS_Oacute },
      84             :         { { KS_dead_circumflex,         KS_O },                 KS_Ocircumflex },
      85             :         { { KS_dead_diaeresis,          KS_O },                 KS_Odiaeresis },
      86             :         { { KS_dead_grave,              KS_O },                 KS_Ograve },
      87             :         { { KS_dead_tilde,              KS_O },                 KS_Otilde },
      88             :         { { KS_dead_acute,              KS_U },                 KS_Uacute },
      89             :         { { KS_dead_circumflex,         KS_U },                 KS_Ucircumflex },
      90             :         { { KS_dead_diaeresis,          KS_U },                 KS_Udiaeresis },
      91             :         { { KS_dead_grave,              KS_U },                 KS_Ugrave },
      92             :         { { KS_dead_acute,              KS_Y },                 KS_Yacute },
      93             :         { { KS_dead_acute,              KS_a },                 KS_aacute },
      94             :         { { KS_dead_circumflex,         KS_a },                 KS_acircumflex },
      95             :         { { KS_dead_diaeresis,          KS_a },                 KS_adiaeresis },
      96             :         { { KS_dead_grave,              KS_a },                 KS_agrave },
      97             :         { { KS_dead_abovering,          KS_a },                 KS_aring },
      98             :         { { KS_dead_tilde,              KS_a },                 KS_atilde },
      99             :         { { KS_dead_cedilla,            KS_c },                 KS_ccedilla },
     100             :         { { KS_dead_acute,              KS_e },                 KS_eacute },
     101             :         { { KS_dead_circumflex,         KS_e },                 KS_ecircumflex },
     102             :         { { KS_dead_diaeresis,          KS_e },                 KS_ediaeresis },
     103             :         { { KS_dead_grave,              KS_e },                 KS_egrave },
     104             :         { { KS_dead_acute,              KS_i },                 KS_iacute },
     105             :         { { KS_dead_circumflex,         KS_i },                 KS_icircumflex },
     106             :         { { KS_dead_diaeresis,          KS_i },                 KS_idiaeresis },
     107             :         { { KS_dead_grave,              KS_i },                 KS_igrave },
     108             :         { { KS_dead_tilde,              KS_n },                 KS_ntilde },
     109             :         { { KS_dead_acute,              KS_o },                 KS_oacute },
     110             :         { { KS_dead_circumflex,         KS_o },                 KS_ocircumflex },
     111             :         { { KS_dead_diaeresis,          KS_o },                 KS_odiaeresis },
     112             :         { { KS_dead_grave,              KS_o },                 KS_ograve },
     113             :         { { KS_dead_tilde,              KS_o },                 KS_otilde },
     114             :         { { KS_dead_acute,              KS_u },                 KS_uacute },
     115             :         { { KS_dead_circumflex,         KS_u },                 KS_ucircumflex },
     116             :         { { KS_dead_diaeresis,          KS_u },                 KS_udiaeresis },
     117             :         { { KS_dead_grave,              KS_u },                 KS_ugrave },
     118             :         { { KS_dead_acute,              KS_y },                 KS_yacute },
     119             :         { { KS_dead_diaeresis,          KS_y },                 KS_ydiaeresis },
     120             :         { { KS_quotedbl,                KS_A },                 KS_Adiaeresis },
     121             :         { { KS_quotedbl,                KS_E },                 KS_Ediaeresis },
     122             :         { { KS_quotedbl,                KS_I },                 KS_Idiaeresis },
     123             :         { { KS_quotedbl,                KS_O },                 KS_Odiaeresis },
     124             :         { { KS_quotedbl,                KS_U },                 KS_Udiaeresis },
     125             :         { { KS_quotedbl,                KS_a },                 KS_adiaeresis },
     126             :         { { KS_quotedbl,                KS_e },                 KS_ediaeresis },
     127             :         { { KS_quotedbl,                KS_i },                 KS_idiaeresis },
     128             :         { { KS_quotedbl,                KS_o },                 KS_odiaeresis },
     129             :         { { KS_quotedbl,                KS_u },                 KS_udiaeresis },
     130             :         { { KS_quotedbl,                KS_y },                 KS_ydiaeresis },
     131             :         { { KS_acute,                   KS_A },                 KS_Aacute },
     132             :         { { KS_asciicircum,             KS_A },                 KS_Acircumflex },
     133             :         { { KS_grave,                   KS_A },                 KS_Agrave },
     134             :         { { KS_asterisk,                KS_A },                 KS_Aring },
     135             :         { { KS_asciitilde,              KS_A },                 KS_Atilde },
     136             :         { { KS_cedilla,                 KS_C },                 KS_Ccedilla },
     137             :         { { KS_acute,                   KS_E },                 KS_Eacute },
     138             :         { { KS_asciicircum,             KS_E },                 KS_Ecircumflex },
     139             :         { { KS_grave,                   KS_E },                 KS_Egrave },
     140             :         { { KS_acute,                   KS_I },                 KS_Iacute },
     141             :         { { KS_asciicircum,             KS_I },                 KS_Icircumflex },
     142             :         { { KS_grave,                   KS_I },                 KS_Igrave },
     143             :         { { KS_asciitilde,              KS_N },                 KS_Ntilde },
     144             :         { { KS_acute,                   KS_O },                 KS_Oacute },
     145             :         { { KS_asciicircum,             KS_O },                 KS_Ocircumflex },
     146             :         { { KS_grave,                   KS_O },                 KS_Ograve },
     147             :         { { KS_asciitilde,              KS_O },                 KS_Otilde },
     148             :         { { KS_acute,                   KS_U },                 KS_Uacute },
     149             :         { { KS_asciicircum,             KS_U },                 KS_Ucircumflex },
     150             :         { { KS_grave,                   KS_U },                 KS_Ugrave },
     151             :         { { KS_acute,                   KS_Y },                 KS_Yacute },
     152             :         { { KS_acute,                   KS_a },                 KS_aacute },
     153             :         { { KS_asciicircum,             KS_a },                 KS_acircumflex },
     154             :         { { KS_grave,                   KS_a },                 KS_agrave },
     155             :         { { KS_asterisk,                KS_a },                 KS_aring },
     156             :         { { KS_asciitilde,              KS_a },                 KS_atilde },
     157             :         { { KS_cedilla,                 KS_c },                 KS_ccedilla },
     158             :         { { KS_acute,                   KS_e },                 KS_eacute },
     159             :         { { KS_asciicircum,             KS_e },                 KS_ecircumflex },
     160             :         { { KS_grave,                   KS_e },                 KS_egrave },
     161             :         { { KS_acute,                   KS_i },                 KS_iacute },
     162             :         { { KS_asciicircum,             KS_i },                 KS_icircumflex },
     163             :         { { KS_grave,                   KS_i },                 KS_igrave },
     164             :         { { KS_asciitilde,              KS_n },                 KS_ntilde },
     165             :         { { KS_acute,                   KS_o },                 KS_oacute },
     166             :         { { KS_asciicircum,             KS_o },                 KS_ocircumflex },
     167             :         { { KS_grave,                   KS_o },                 KS_ograve },
     168             :         { { KS_asciitilde,              KS_o },                 KS_otilde },
     169             :         { { KS_acute,                   KS_u },                 KS_uacute },
     170             :         { { KS_asciicircum,             KS_u },                 KS_ucircumflex },
     171             :         { { KS_grave,                   KS_u },                 KS_ugrave },
     172             :         { { KS_acute,                   KS_y },                 KS_yacute },
     173             :         { { KS_dead_caron,              KS_space },             KS_L2_caron },
     174             :         { { KS_dead_caron,              KS_S },                 KS_L2_Scaron },
     175             :         { { KS_dead_caron,              KS_Z },                 KS_L2_Zcaron },
     176             :         { { KS_dead_caron,              KS_s },                 KS_L2_scaron },
     177             :         { { KS_dead_caron,              KS_z },                 KS_L2_zcaron }
     178             : };
     179             : 
     180             : #define COMPOSE_SIZE    nitems(compose_tab)
     181             : 
     182             : static int compose_tab_inorder = 0;
     183             : 
     184             : inline int compose_tab_cmp(struct compose_tab_s *, struct compose_tab_s *);
     185             : keysym_t ksym_upcase(keysym_t);
     186             : void fillmapentry(const keysym_t *, int, struct wscons_keymap *);
     187             : 
     188             : inline int
     189           0 : compose_tab_cmp(struct compose_tab_s *i, struct compose_tab_s *j)
     190             : {
     191           0 :         if (i->elem[0] == j->elem[0])
     192           0 :                 return(i->elem[1] - j->elem[1]);
     193             :         else
     194           0 :                 return(i->elem[0] - j->elem[0]);
     195           0 : }
     196             : 
     197             : keysym_t
     198           0 : wskbd_compose_value(keysym_t *compose_buf)
     199             : {
     200             :         int i, j, r;
     201           0 :         struct compose_tab_s v;
     202             : 
     203           0 :         if (!compose_tab_inorder) {
     204             :                 /* Insertion sort. */
     205           0 :                 for (i = 1; i < COMPOSE_SIZE; i++) {
     206           0 :                         v = compose_tab[i];
     207             :                         /* find correct slot, moving others up */
     208           0 :                         for (j = i; --j >= 0 &&
     209           0 :                             compose_tab_cmp(&v, &compose_tab[j]) < 0;)
     210           0 :                                 compose_tab[j + 1] = compose_tab[j];
     211           0 :                         compose_tab[j + 1] = v;
     212             :                 }
     213           0 :                 compose_tab_inorder = 1;
     214           0 :         }
     215             : 
     216           0 :         for (j = 0, i = COMPOSE_SIZE; i != 0; i /= 2) {
     217           0 :                 if (compose_tab[j + i/2].elem[0] == compose_buf[0]) {
     218           0 :                         if (compose_tab[j + i/2].elem[1] == compose_buf[1])
     219           0 :                                 return(compose_tab[j + i/2].result);
     220           0 :                         r = compose_tab[j + i/2].elem[1] < compose_buf[1];
     221           0 :                 } else
     222           0 :                         r = compose_tab[j + i/2].elem[0] < compose_buf[0];
     223           0 :                 if (r) {
     224           0 :                         j += i/2 + 1;
     225           0 :                         i--;
     226           0 :                 }
     227             :         }
     228             : 
     229           0 :         return(KS_voidSymbol);
     230           0 : }
     231             : 
     232             : static const u_char latin1_to_upper[256] = {
     233             : /*      0  8  1  9  2  a  3  b  4  c  5  d  6  e  7  f               */
     234             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 0 */
     235             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 0 */
     236             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 1 */
     237             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 1 */
     238             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 2 */
     239             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 2 */
     240             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 3 */
     241             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 3 */
     242             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 4 */
     243             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 4 */
     244             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 5 */
     245             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 5 */
     246             :         0x00,  'A',  'B',  'C',  'D',  'E',  'F',  'G',         /* 6 */
     247             :          'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',         /* 6 */
     248             :          'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',         /* 7 */
     249             :          'X',  'Y',  'Z', 0x00, 0x00, 0x00, 0x00, 0x00,         /* 7 */
     250             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 8 */
     251             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 8 */
     252             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 9 */
     253             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* 9 */
     254             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* a */
     255             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* a */
     256             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* b */
     257             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* b */
     258             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* c */
     259             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* c */
     260             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* d */
     261             :         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         /* d */
     262             :         0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,         /* e */
     263             :         0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,         /* e */
     264             :         0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00,         /* f */
     265             :         0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0x00,         /* f */
     266             : };
     267             : 
     268             : keysym_t
     269           0 : ksym_upcase(keysym_t ksym)
     270             : {
     271           0 :         if (ksym >= KS_f1 && ksym <= KS_f20)
     272           0 :                 return(KS_F1 - KS_f1 + ksym);
     273             : 
     274           0 :         if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
     275           0 :             latin1_to_upper[ksym] != 0x00)
     276           0 :                 return(latin1_to_upper[ksym]);
     277             : 
     278           0 :         return(ksym);
     279           0 : }
     280             : 
     281             : void
     282           0 : fillmapentry(const keysym_t *kp, int len, struct wscons_keymap *mapentry)
     283             : {
     284           0 :         switch (len) {
     285             :         case 0:
     286           0 :                 mapentry->group1[0] = KS_voidSymbol;
     287           0 :                 mapentry->group1[1] = KS_voidSymbol;
     288           0 :                 mapentry->group2[0] = KS_voidSymbol;
     289           0 :                 mapentry->group2[1] = KS_voidSymbol;
     290           0 :                 break;
     291             : 
     292             :         case 1:
     293           0 :                 mapentry->group1[0] = kp[0];
     294           0 :                 mapentry->group1[1] = ksym_upcase(kp[0]);
     295           0 :                 mapentry->group2[0] = mapentry->group1[0];
     296           0 :                 mapentry->group2[1] = mapentry->group1[1];
     297           0 :                 break;
     298             : 
     299             :         case 2:
     300           0 :                 mapentry->group1[0] = kp[0];
     301           0 :                 mapentry->group1[1] = kp[1];
     302           0 :                 mapentry->group2[0] = mapentry->group1[0];
     303           0 :                 mapentry->group2[1] = mapentry->group1[1];
     304           0 :                 break;
     305             : 
     306             :         case 3:
     307           0 :                 mapentry->group1[0] = kp[0];
     308           0 :                 mapentry->group1[1] = kp[1];
     309           0 :                 mapentry->group2[0] = kp[2];
     310           0 :                 mapentry->group2[1] = ksym_upcase(kp[2]);
     311           0 :                 break;
     312             : 
     313             :         case 4:
     314           0 :                 mapentry->group1[0] = kp[0];
     315           0 :                 mapentry->group1[1] = kp[1];
     316           0 :                 mapentry->group2[0] = kp[2];
     317           0 :                 mapentry->group2[1] = kp[3];
     318           0 :                 break;
     319             : 
     320             :         }
     321           0 : }
     322             : 
     323             : void
     324           0 : wskbd_get_mapentry(const struct wskbd_mapdata *mapdata, int kc,
     325             :     struct wscons_keymap *mapentry)
     326             : {
     327             :         kbd_t cur;
     328             :         const keysym_t *kp;
     329             :         const struct wscons_keydesc *mp;
     330             :         int l;
     331             :         keysym_t ksg;
     332             : 
     333           0 :         mapentry->command = KS_voidSymbol;
     334           0 :         mapentry->group1[0] = KS_voidSymbol;
     335           0 :         mapentry->group1[1] = KS_voidSymbol;
     336           0 :         mapentry->group2[0] = KS_voidSymbol;
     337           0 :         mapentry->group2[1] = KS_voidSymbol;
     338             : 
     339           0 :         for (cur = mapdata->layout & ~KB_HANDLEDBYWSKBD; cur != 0; ) {
     340           0 :                 mp = mapdata->keydesc;
     341           0 :                 while (mp->map_size > 0) {
     342           0 :                         if (mp->name == cur)
     343             :                                 break;
     344           0 :                         mp++;
     345             :                 }
     346             : 
     347             :                 /* If map not found, return */
     348           0 :                 if (mp->map_size <= 0)
     349           0 :                         return;
     350             : 
     351           0 :                 for (kp = mp->map; kp < mp->map + mp->map_size; kp++) {
     352           0 :                         ksg = KS_GROUP(*kp);
     353           0 :                         if (ksg == KS_GROUP_Keycode &&
     354           0 :                             KS_VALUE(*kp) == kc) {
     355             :                                 /* First skip keycode and possible command */
     356           0 :                                 kp++;
     357           0 :                                 if (KS_GROUP(*kp) == KS_GROUP_Command ||
     358           0 :                                     *kp == KS_Cmd || *kp == KS_Cmd1 || *kp == KS_Cmd2)
     359           0 :                                         mapentry->command = *kp++;
     360             : 
     361           0 :                                 for (l = 0; kp + l < mp->map + mp->map_size;
     362           0 :                                     l++) {
     363           0 :                                         ksg = KS_GROUP(kp[l]);
     364           0 :                                         if (ksg == KS_GROUP_Keycode)
     365             :                                                 break;
     366             :                                 }
     367           0 :                                 if (l > 4)
     368           0 :                                         panic("wskbd_get_mapentry: %d(%d): bad entry",
     369           0 :                                               mp->name, *kp);
     370           0 :                                 fillmapentry(kp, l, mapentry);
     371           0 :                                 return;
     372             :                         }
     373             :                 }
     374             : 
     375           0 :                 cur = mp->base;
     376             :         }
     377           0 : }
     378             : 
     379             : void
     380           0 : wskbd_init_keymap(int newlen, struct wscons_keymap **map, int *maplen)
     381             : {
     382             :         int i;
     383             : 
     384           0 :         if (newlen != *maplen) {
     385           0 :                 if (*maplen > 0)
     386           0 :                         free(*map, M_DEVBUF,
     387           0 :                             *maplen * sizeof(struct wscons_keymap));
     388           0 :                 *maplen = newlen;
     389           0 :                 *map = mallocarray(newlen, sizeof(struct wscons_keymap),
     390             :                     M_DEVBUF, M_WAITOK);
     391           0 :         }
     392             : 
     393           0 :         for (i = 0; i < *maplen; i++) {
     394           0 :                 (*map)[i].command = KS_voidSymbol;
     395           0 :                 (*map)[i].group1[0] = KS_voidSymbol;
     396           0 :                 (*map)[i].group1[1] = KS_voidSymbol;
     397           0 :                 (*map)[i].group2[0] = KS_voidSymbol;
     398           0 :                 (*map)[i].group2[1] = KS_voidSymbol;
     399             :         }
     400           0 : }
     401             : 
     402             : int
     403           0 : wskbd_load_keymap(const struct wskbd_mapdata *mapdata, kbd_t layout,
     404             :     struct wscons_keymap **map, int *maplen)
     405             : {
     406             :         int i, s, kc, stack_ptr;
     407             :         const keysym_t *kp;
     408           0 :         const struct wscons_keydesc *mp, *stack[10];
     409             :         kbd_t cur;
     410             :         keysym_t ksg;
     411             : 
     412           0 :         for (cur = layout & ~KB_HANDLEDBYWSKBD, stack_ptr = 0;
     413           0 :              cur != 0; stack_ptr++) {
     414           0 :                 mp = mapdata->keydesc;
     415           0 :                 while (mp->map_size > 0) {
     416           0 :                         if (cur == 0 || mp->name == cur) {
     417             :                                 break;
     418             :                         }
     419           0 :                         mp++;
     420             :                 }
     421             : 
     422           0 :                 if (stack_ptr == nitems(stack))
     423           0 :                         panic("wskbd_load_keymap: %d: recursion too deep",
     424           0 :                               mapdata->layout);
     425           0 :                 if (mp->map_size <= 0)
     426           0 :                         return(EINVAL);
     427             : 
     428           0 :                 stack[stack_ptr] = mp;
     429           0 :                 cur = mp->base;
     430             :         }
     431             : 
     432           0 :         for (i = 0, s = stack_ptr - 1; s >= 0; s--) {
     433           0 :                 mp = stack[s];
     434           0 :                 for (kp = mp->map; kp < mp->map + mp->map_size; kp++) {
     435           0 :                         ksg = KS_GROUP(*kp);
     436           0 :                         if (ksg == KS_GROUP_Keycode && KS_VALUE(*kp) > i)
     437           0 :                                 i = KS_VALUE(*kp);
     438             :                 }
     439             :         }
     440             : 
     441           0 :         wskbd_init_keymap(i + 1, map, maplen);
     442             : 
     443           0 :         for (s = stack_ptr - 1; s >= 0; s--) {
     444           0 :                 mp = stack[s];
     445           0 :                 for (kp = mp->map; kp < mp->map + mp->map_size; ) {
     446           0 :                         ksg = KS_GROUP(*kp);
     447           0 :                         if (ksg != KS_GROUP_Keycode)
     448           0 :                                 panic("wskbd_load_keymap: %d(%d): bad entry",
     449           0 :                                       mp->name, *kp);
     450             : 
     451           0 :                         kc = KS_VALUE(*kp);
     452           0 :                         kp++;
     453             : 
     454           0 :                         if (KS_GROUP(*kp) == KS_GROUP_Command ||
     455           0 :                             *kp == KS_Cmd || *kp == KS_Cmd1 || *kp == KS_Cmd2) {
     456           0 :                                 (*map)[kc].command = *kp;
     457           0 :                                 kp++;
     458           0 :                         }
     459             : 
     460           0 :                         for (i = 0; kp + i < mp->map + mp->map_size; i++) {
     461           0 :                                 ksg = KS_GROUP(kp[i]);
     462           0 :                                 if (ksg == KS_GROUP_Keycode)
     463             :                                         break;
     464             :                         }
     465             : 
     466           0 :                         if (i > 4)
     467           0 :                                 panic("wskbd_load_keymap: %d(%d): bad entry",
     468           0 :                                       mp->name, *kp);
     469             : 
     470           0 :                         fillmapentry(kp, i, &(*map)[kc]);
     471             :                         kp += i;
     472             :                 }
     473             :         }
     474             : 
     475           0 :         return(0);
     476           0 : }

Generated by: LCOV version 1.13