0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <stdlib.h>
0010 #include <stdio.h>
0011 #include <libgen.h>
0012 #include <string.h>
0013 #include <linux/version.h>
0014 #include <ctype.h>
0015 #include "utils.h"
0016
0017 static char buffer[256];
0018
0019 static int get_define(void)
0020 {
0021 char *c;
0022
0023 while (fgets(buffer, sizeof(buffer)-1, infile)) {
0024 lc++;
0025 if (strncmp(buffer, "#define", 7))
0026 continue;
0027 c = buffer + 7;
0028 while (*c == ' ' || *c == '\t')
0029 c++;
0030 def_name = c;
0031 while (*c && *c != ' ' && *c != '\t' && *c != '\n')
0032 c++;
0033 if (!*c || *c == '\n')
0034 continue;
0035 *c++ = '\0';
0036 while (*c == ' ' || *c == '\t' || *c == '(')
0037 c++;
0038 def_val = c;
0039 while (*c && *c != '\n' && *c != ')')
0040 c++;
0041 *c++ = '\0';
0042 return 1;
0043 }
0044 fclose(infile);
0045 infile = 0;
0046 return 0;
0047 }
0048
0049 int
0050 main(int argc, char *argv[])
0051 {
0052 int value, i;
0053 struct st_key *this;
0054 const char *dir_name;
0055 char *cp;
0056
0057 dir_name = getenv("TOPDIR");
0058 if (!dir_name)
0059 dir_name = ".";
0060 bzero(key_table, sizeof(key_table));
0061 add_key("shift", 1, is_shift);
0062 add_key("altgr", 2, is_shift);
0063 add_key("ctrl", 4, is_shift);
0064 add_key("alt", 8, is_shift);
0065 add_key("spk", 16, is_shift);
0066 add_key("double", 32, is_shift);
0067
0068 open_input(dir_name, "include/linux/input.h");
0069 while (get_define()) {
0070 if (strncmp(def_name, "KEY_", 4))
0071 continue;
0072 value = atoi(def_val);
0073 if (value > 0 && value < MAXKEYVAL)
0074 add_key(def_name, value, is_input);
0075 }
0076
0077 open_input(dir_name, "include/uapi/linux/input-event-codes.h");
0078 while (get_define()) {
0079 if (strncmp(def_name, "KEY_", 4))
0080 continue;
0081 value = atoi(def_val);
0082 if (value > 0 && value < MAXKEYVAL)
0083 add_key(def_name, value, is_input);
0084 }
0085
0086 open_input(dir_name, "drivers/accessibility/speakup/spk_priv_keyinfo.h");
0087 while (get_define()) {
0088 if (strlen(def_val) > 5) {
0089
0090
0091 cp = strchr(def_val, '+');
0092 if (!cp)
0093 continue;
0094 if (cp[-1] == ' ')
0095 cp[-1] = '\0';
0096 *cp++ = '\0';
0097 this = find_key(def_val);
0098 while (*cp == ' ')
0099 cp++;
0100 if (!this || *cp < '0' || *cp > '9')
0101 continue;
0102 value = this->value+atoi(cp);
0103 } else if (!strncmp(def_val, "0x", 2))
0104 sscanf(def_val+2, "%x", &value);
0105 else if (*def_val >= '0' && *def_val <= '9')
0106 value = atoi(def_val);
0107 else
0108 continue;
0109 add_key(def_name, value, is_spk);
0110 }
0111
0112 printf("struct st_key_init init_key_data[] = {\n");
0113 for (i = 0; i < HASHSIZE; i++) {
0114 this = &key_table[i];
0115 if (!this->name)
0116 continue;
0117 do {
0118 printf("\t{ \"%s\", %d, %d, },\n", this->name, this->value, this->shift);
0119 this = this->next;
0120 } while (this);
0121 }
0122 printf("\t{ \".\", 0, 0 }\n};\n");
0123
0124 exit(0);
0125 }