+static const char *find_action(struct input_event *ev, const char *buf)
+{
+ const char *action = NULL;
+ int i;
+
+ // map event
+ for (i = 0; i < n_evt; i++) {
+ if (ev) {
+ if (ev->type == evt_tab[i].n_type && ev->code == evt_tab[i].n_code && ev->value == evt_tab[i].value) {
+ action = evt_tab[i].desc;
+ break;
+ }
+ }
+
+ if (buf) {
+ if (strncmp(buf, evt_tab[i].desc, strlen(buf)) == 0) {
+ action = evt_tab[i].desc;
+ break;
+ }
+ }
+ }
+
+ // get action
+ if (action) {
+ for (i = 0; i < n_act; i++) {
+ if (strstr(action, act_tab[i].key)) {
+ action = act_tab[i].action;
+ break;
+ }
+ }
+ }
+
+ return action;
+}
+
+static void parse_conf_file(const char *filename)
+{
+ parser_t *parser;
+ char *tokens[2];
+
+ parser = config_open2(filename, fopen_for_read);
+
+ if (parser) {
+ while (config_read(parser, tokens, 2, 2, "# \t", PARSE_NORMAL)) {
+ act_tab = xrealloc_vector(act_tab, 1, n_act);
+ act_tab[n_act].key = xstrdup(tokens[0]);
+ act_tab[n_act].action = xstrdup(tokens[1]);
+ n_act++;
+ }
+ config_close(parser);
+ } else {
+ act_tab = (void*)f_act_tab;
+ n_act = ARRAY_SIZE(f_act_tab);
+ }
+}
+
+static void parse_map_file(const char *filename)
+{
+ parser_t *parser;
+ char *tokens[6];
+
+ parser = config_open2(filename, fopen_for_read);
+
+ if (parser) {
+ while (config_read(parser, tokens, 6, 6, "# \t", PARSE_NORMAL)) {
+ evt_tab = xrealloc_vector(evt_tab, 1, n_evt);
+ evt_tab[n_evt].s_type = xstrdup(tokens[0]);
+ evt_tab[n_evt].n_type = xstrtou(tokens[1], 16);
+ evt_tab[n_evt].s_code = xstrdup(tokens[2]);
+ evt_tab[n_evt].n_code = xatou16(tokens[3]);
+ evt_tab[n_evt].value = xatoi_positive(tokens[4]);
+ evt_tab[n_evt].desc = xstrdup(tokens[5]);
+ n_evt++;
+ }
+ config_close(parser);
+ } else {
+ evt_tab = (void*)f_evt_tab;
+ n_evt = ARRAY_SIZE(f_evt_tab);
+ }
+}
+