~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/userspace-api/media/rc/keytable.c.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/userspace-api/media/rc/keytable.c.rst (Version linux-6.12-rc7) and /Documentation/userspace-api/media/rc/keytable.c.rst (Version linux-5.8.18)


  1 .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1. !!   1 .. Permission is granted to copy, distribute and/or modify this
                                                   >>   2 .. document under the terms of the GNU Free Documentation License,
                                                   >>   3 .. Version 1.1 or any later version published by the Free Software
                                                   >>   4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
                                                   >>   5 .. and no Back-Cover Texts. A copy of the license is included at
                                                   >>   6 .. Documentation/userspace-api/media/fdl-appendix.rst.
                                                   >>   7 ..
                                                   >>   8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
  2                                                     9 
  3 file: uapi/v4l/keytable.c                          10 file: uapi/v4l/keytable.c
  4 =========================                          11 =========================
  5                                                    12 
  6 .. code-block:: c                                  13 .. code-block:: c
  7                                                    14 
  8     /* keytable.c - This program allows checki     15     /* keytable.c - This program allows checking/replacing keys at IR
  9                                                    16 
 10        Copyright (C) 2006-2009 Mauro Carvalho <     17        Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@kernel.org>
 11                                                    18 
 12        This program is free software; you can      19        This program is free software; you can redistribute it and/or modify
 13        it under the terms of the GNU General P     20        it under the terms of the GNU General Public License as published by
 14        the Free Software Foundation, version 2     21        the Free Software Foundation, version 2 of the License.
 15                                                    22 
 16        This program is distributed in the hope     23        This program is distributed in the hope that it will be useful,
 17        but WITHOUT ANY WARRANTY; without even      24        but WITHOUT ANY WARRANTY; without even the implied warranty of
 18        MERCHANTABILITY or FITNESS FOR A PARTIC     25        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19        GNU General Public License for more det     26        GNU General Public License for more details.
 20      */                                            27      */
 21                                                    28 
 22     #include <ctype.h>                             29     #include <ctype.h>
 23     #include <errno.h>                             30     #include <errno.h>
 24     #include <fcntl.h>                             31     #include <fcntl.h>
 25     #include <stdio.h>                             32     #include <stdio.h>
 26     #include <stdlib.h>                            33     #include <stdlib.h>
 27     #include <string.h>                            34     #include <string.h>
 28     #include <linux/input.h>                       35     #include <linux/input.h>
 29     #include <sys/ioctl.h>                         36     #include <sys/ioctl.h>
 30                                                    37 
 31     #include "parse.h"                             38     #include "parse.h"
 32                                                    39 
 33     void prtcode (int *codes)                      40     void prtcode (int *codes)
 34     {                                              41     {
 35             struct parse_key *p;                   42             struct parse_key *p;
 36                                                    43 
 37             for (p=keynames;p->name!=NULL;p++)     44             for (p=keynames;p->name!=NULL;p++) {
 38                     if (p->value == (unsigned)     45                     if (p->value == (unsigned)codes[1]) {
 39                             printf("scancode 0     46                             printf("scancode 0x%04x = %s (0x%02x)\\n", codes[0], p->name, codes[1]);
 40                             return;                47                             return;
 41                     }                              48                     }
 42             }                                      49             }
 43                                                    50 
 44             if (isprint (codes[1]))                51             if (isprint (codes[1]))
 45                     printf("scancode %d = '%c'     52                     printf("scancode %d = '%c' (0x%02x)\\n", codes[0], codes[1], codes[1]);
 46             else                                   53             else
 47                     printf("scancode %d = 0x%0     54                     printf("scancode %d = 0x%02x\\n", codes[0], codes[1]);
 48     }                                              55     }
 49                                                    56 
 50     int parse_code(char *string)                   57     int parse_code(char *string)
 51     {                                              58     {
 52             struct parse_key *p;                   59             struct parse_key *p;
 53                                                    60 
 54             for (p=keynames;p->name!=NULL;p++)     61             for (p=keynames;p->name!=NULL;p++) {
 55                     if (!strcasecmp(p->name, s     62                     if (!strcasecmp(p->name, string)) {
 56                             return p->value;       63                             return p->value;
 57                     }                              64                     }
 58             }                                      65             }
 59             return -1;                             66             return -1;
 60     }                                              67     }
 61                                                    68 
 62     int main (int argc, char *argv[])              69     int main (int argc, char *argv[])
 63     {                                              70     {
 64             int fd;                                71             int fd;
 65             unsigned int i, j;                     72             unsigned int i, j;
 66             int codes[2];                          73             int codes[2];
 67                                                    74 
 68             if (argc<2 || argc>4) {                75             if (argc<2 || argc>4) {
 69                     printf ("usage: %s <device     76                     printf ("usage: %s <device> to get table; or\\n"
 70                             "       %s <device     77                             "       %s <device> <scancode> <keycode>\\n"
 71                             "       %s <device     78                             "       %s <device> <keycode_file>n",*argv,*argv,*argv);
 72                     return -1;                     79                     return -1;
 73             }                                      80             }
 74                                                    81 
 75             if ((fd = open(argv[1], O_RDONLY))     82             if ((fd = open(argv[1], O_RDONLY)) < 0) {
 76                     perror("Couldn't open inpu     83                     perror("Couldn't open input device");
 77                     return(-1);                    84                     return(-1);
 78             }                                      85             }
 79                                                    86 
 80             if (argc==4) {                         87             if (argc==4) {
 81                     int value;                     88                     int value;
 82                                                    89 
 83                     value=parse_code(argv[3]);     90                     value=parse_code(argv[3]);
 84                                                    91 
 85                     if (value==-1) {               92                     if (value==-1) {
 86                             value = strtol(arg     93                             value = strtol(argv[3], NULL, 0);
 87                             if (errno)             94                             if (errno)
 88                                     perror("va     95                                     perror("value");
 89                     }                              96                     }
 90                                                    97 
 91                     codes [0] = (unsigned) str     98                     codes [0] = (unsigned) strtol(argv[2], NULL, 0);
 92                     codes [1] = (unsigned) val     99                     codes [1] = (unsigned) value;
 93                                                   100 
 94                     if(ioctl(fd, EVIOCSKEYCODE    101                     if(ioctl(fd, EVIOCSKEYCODE, codes))
 95                             perror ("EVIOCSKEY    102                             perror ("EVIOCSKEYCODE");
 96                                                   103 
 97                     if(ioctl(fd, EVIOCGKEYCODE    104                     if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
 98                             prtcode(codes);       105                             prtcode(codes);
 99                     return 0;                     106                     return 0;
100             }                                     107             }
101                                                   108 
102             if (argc==3) {                        109             if (argc==3) {
103                     FILE *fin;                    110                     FILE *fin;
104                     int value;                    111                     int value;
105                     char *scancode, *keycode,     112                     char *scancode, *keycode, s[2048];
106                                                   113 
107                     fin=fopen(argv[2],"r");       114                     fin=fopen(argv[2],"r");
108                     if (fin==NULL) {              115                     if (fin==NULL) {
109                             perror ("opening k    116                             perror ("opening keycode file");
110                             return -1;            117                             return -1;
111                     }                             118                     }
112                                                   119 
113                     /* Clears old table */        120                     /* Clears old table */
114                     for (j = 0; j < 256; j++)     121                     for (j = 0; j < 256; j++) {
115                             for (i = 0; i < 25    122                             for (i = 0; i < 256; i++) {
116                                     codes[0] =    123                                     codes[0] = (j << 8) | i;
117                                     codes[1] =    124                                     codes[1] = KEY_RESERVED;
118                                     ioctl(fd,     125                                     ioctl(fd, EVIOCSKEYCODE, codes);
119                             }                     126                             }
120                     }                             127                     }
121                                                   128 
122                     while (fgets(s,sizeof(s),f    129                     while (fgets(s,sizeof(s),fin)) {
123                             scancode=strtok(s,    130                             scancode=strtok(s,"\\n\\t =:");
124                             if (!scancode) {      131                             if (!scancode) {
125                                     perror ("p    132                                     perror ("parsing input file scancode");
126                                     return -1;    133                                     return -1;
127                             }                     134                             }
128                             if (!strcasecmp(sc    135                             if (!strcasecmp(scancode, "scancode")) {
129                                     scancode =    136                                     scancode = strtok(NULL,"\\n\\t =:");
130                                     if (!scanc    137                                     if (!scancode) {
131                                             pe    138                                             perror ("parsing input file scancode");
132                                             re    139                                             return -1;
133                                     }             140                                     }
134                             }                     141                             }
135                                                   142 
136                             keycode=strtok(NUL    143                             keycode=strtok(NULL,"\\n\\t =:(");
137                             if (!keycode) {       144                             if (!keycode) {
138                                     perror ("p    145                                     perror ("parsing input file keycode");
139                                     return -1;    146                                     return -1;
140                             }                     147                             }
141                                                   148 
142                             // printf ("parsin    149                             // printf ("parsing %s=%s:", scancode, keycode);
143                             value=parse_code(k    150                             value=parse_code(keycode);
144                             // printf ("\\tval    151                             // printf ("\\tvalue=%d\\n",value);
145                                                   152 
146                             if (value==-1) {      153                             if (value==-1) {
147                                     value = st    154                                     value = strtol(keycode, NULL, 0);
148                                     if (errno)    155                                     if (errno)
149                                             pe    156                                             perror("value");
150                             }                     157                             }
151                                                   158 
152                             codes [0] = (unsig    159                             codes [0] = (unsigned) strtol(scancode, NULL, 0);
153                             codes [1] = (unsig    160                             codes [1] = (unsigned) value;
154                                                   161 
155                             // printf("\\t%04x    162                             // printf("\\t%04x=%04x\\n",codes[0], codes[1]);
156                             if(ioctl(fd, EVIOC    163                             if(ioctl(fd, EVIOCSKEYCODE, codes)) {
157                                     fprintf(st    164                                     fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]);
158                                     perror ("E    165                                     perror ("EVIOCSKEYCODE");
159                             }                     166                             }
160                                                   167 
161                             if(ioctl(fd, EVIOC    168                             if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
162                                     prtcode(co    169                                     prtcode(codes);
163                     }                             170                     }
164                     return 0;                     171                     return 0;
165             }                                     172             }
166                                                   173 
167             /* Get scancode table */              174             /* Get scancode table */
168             for (j = 0; j < 256; j++) {           175             for (j = 0; j < 256; j++) {
169                     for (i = 0; i < 256; i++)     176                     for (i = 0; i < 256; i++) {
170                             codes[0] = (j << 8    177                             codes[0] = (j << 8) | i;
171                             if (!ioctl(fd, EVI    178                             if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED)
172                                     prtcode(co    179                                     prtcode(codes);
173                     }                             180                     }
174             }                                     181             }
175             return 0;                             182             return 0;
176     }                                             183     }
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php