keymap.c revision 2417dc20f5147556d0ed4f95a37b1547fb4b0f2b
/*
* keymap - dump keymap of an evdev device or set a new keymap from a file
*
* Based on keyfuzz by Lennart Poettering <mzqrovna@0pointer.net>
* Adapted for udev-extras by Martin Pitt <martin.pitt@ubuntu.com>
*
* Copyright (C) 2006, Lennart Poettering
* Copyright (C) 2009, Canonical Ltd.
*
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* keymap is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with keymap; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <getopt.h>
#include "keys-from-name.h"
#include "keys-to-name.h"
#define MAX_SCANCODES 1024
/* If keymap file is given without a path, assume this one; must end with '/' * */
#define DEFAULT_PATH "/lib/udev/keymaps/"
static int evdev_open(const char *dev)
{
int fd;
}
return -1;
}
return fd;
}
{
int codes[2];
return -2;
} else {
return -1;
}
}
return codes[1];
}
{
int codes[2];
return -1;
}
return 0;
}
{
int version;
return -1;
}
return 0;
}
{
return -1;
}
return 0;
}
/* Return a lower-case string with KEY_ prefix removed */
static const char* format_keyname(const char* key) {
static char result[101];
const char* s;
int len;
return result;
}
static int dump_table(int fd) {
int scancode, r = -1;
goto fail;
goto fail;
r = 0;
int keycode;
if (keycode != -2)
r = -1;
break;
}
else
}
fail:
return r;
}
int r = 0;
int line = 0;
FILE* f;
if (!f) {
r = -1;
goto fail;
}
while (!feof(f)) {
char s[256], *p;
if (!fgets(s, sizeof(s), f))
break;
line++;
p = s+strspn(s, "\t ");
if (*p == '#' || *p == '\n')
continue;
char t[105] = "KEY_UNKNOWN";
const struct key *k;
r = -1;
continue;
}
if (!(k = lookup_key(t, strlen(t)))) {
r = -1;
continue;
}
new_keycode = k->id;
}
r = -1;
goto fail;
}
r = -1;
goto fail;
}
if (new_keycode != old_keycode)
}
fail:
return r;
}
static const char* default_keymap_path(const char* path)
{
return result;
}
return path;
}
{
static int cur_scancode = 0;
/* save scan code for next EV_KEY event */
/* key press */
}
static void interactive(int fd)
{
struct input_event ev;
int run = 1;
/* grab input device */
puts("Press ESC to finish");
while (run) {
case -1:
perror("read");
run = 0;
break;
case 0:
run = 0;
break;
default:
/* stop on Escape key release */
run = 0;
break;
}
}
/* release input device */
}
{
{}
};
int fd = -1;
int opt_interactive = 0;
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'h':
printf("Usage: keymap <event device> [<map file>]\n\n");
return 0;
case 'i':
opt_interactive = 1;
break;
default:
return 1;
}
}
return 2;
}
return 3;
else {
if (opt_interactive)
else
dump_table(fd);
}
return 0;
}