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