1 // SPDX-License-Identifier: GPL-2.0+
2 /* makemapdata.c
3 * originally written by: Kirk Reiser.
4 *
5 ** Copyright (C) 2002 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
7 */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <libgen.h>
12 #include <string.h>
13 #include <linux/version.h>
14 #include <ctype.h>
15 #include "utils.h"
16
17 static char buffer[256];
18
get_define(void)19 static int get_define(void)
20 {
21 char *c;
22
23 while (fgets(buffer, sizeof(buffer)-1, infile)) {
24 lc++;
25 if (strncmp(buffer, "#define", 7))
26 continue;
27 c = buffer + 7;
28 while (*c == ' ' || *c == '\t')
29 c++;
30 def_name = c;
31 while (*c && *c != ' ' && *c != '\t' && *c != '\n')
32 c++;
33 if (!*c || *c == '\n')
34 continue;
35 *c++ = '\0';
36 while (*c == ' ' || *c == '\t' || *c == '(')
37 c++;
38 def_val = c;
39 while (*c && *c != '\n' && *c != ')')
40 c++;
41 *c++ = '\0';
42 return 1;
43 }
44 fclose(infile);
45 infile = 0;
46 return 0;
47 }
48
49 int
main(int argc,char * argv[])50 main(int argc, char *argv[])
51 {
52 int value, i;
53 struct st_key *this;
54 const char *dir_name, *spk_dir_name;
55 char *cp;
56
57 dir_name = getenv("TOPDIR");
58 if (!dir_name)
59 dir_name = ".";
60 spk_dir_name = getenv("SPKDIR");
61 if (!spk_dir_name)
62 spk_dir_name = "drivers/accessibility/speakup";
63 bzero(key_table, sizeof(key_table));
64 add_key("shift", 1, is_shift);
65 add_key("altgr", 2, is_shift);
66 add_key("ctrl", 4, is_shift);
67 add_key("alt", 8, is_shift);
68 add_key("spk", 16, is_shift);
69 add_key("double", 32, is_shift);
70
71 open_input(dir_name, "include/linux/input.h");
72 while (get_define()) {
73 if (strncmp(def_name, "KEY_", 4))
74 continue;
75 value = atoi(def_val);
76 if (value > 0 && value < MAXKEYVAL)
77 add_key(def_name, value, is_input);
78 }
79
80 open_input(dir_name, "include/uapi/linux/input-event-codes.h");
81 while (get_define()) {
82 if (strncmp(def_name, "KEY_", 4))
83 continue;
84 value = atoi(def_val);
85 if (value > 0 && value < MAXKEYVAL)
86 add_key(def_name, value, is_input);
87 }
88
89 open_input(spk_dir_name, "spk_priv_keyinfo.h");
90 while (get_define()) {
91 if (strlen(def_val) > 5) {
92 //if (def_val[0] == '(')
93 // def_val++;
94 cp = strchr(def_val, '+');
95 if (!cp)
96 continue;
97 if (cp[-1] == ' ')
98 cp[-1] = '\0';
99 *cp++ = '\0';
100 this = find_key(def_val);
101 while (*cp == ' ')
102 cp++;
103 if (!this || *cp < '0' || *cp > '9')
104 continue;
105 value = this->value+atoi(cp);
106 } else if (!strncmp(def_val, "0x", 2))
107 sscanf(def_val+2, "%x", &value);
108 else if (*def_val >= '0' && *def_val <= '9')
109 value = atoi(def_val);
110 else
111 continue;
112 add_key(def_name, value, is_spk);
113 }
114
115 printf("struct st_key_init init_key_data[] = {\n");
116 for (i = 0; i < HASHSIZE; i++) {
117 this = &key_table[i];
118 if (!this->name)
119 continue;
120 do {
121 printf("\t{ \"%s\", %d, %d, },\n", this->name, this->value, this->shift);
122 this = this->next;
123 } while (this);
124 }
125 printf("\t{ \".\", 0, 0 }\n};\n");
126
127 exit(0);
128 }
129