keymaps: correct keymaps.c following Qemu coding style

It's hard to read because of the confused coding
style in this file. Let's correct it following Qemu
coding style.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gonglei 2014-12-08 19:39:05 +08:00 committed by Gerd Hoffmann
parent 525965b85d
commit 43948386bb

View File

@ -30,15 +30,17 @@ static int get_keysym(const name2keysym_t *table,
{ {
const name2keysym_t *p; const name2keysym_t *p;
for(p = table; p->name != NULL; p++) { for(p = table; p->name != NULL; p++) {
if (!strcmp(p->name, name)) if (!strcmp(p->name, name)) {
return p->keysym; return p->keysym;
} }
}
if (name[0] == 'U' && strlen(name) == 5) { /* try unicode Uxxxx */ if (name[0] == 'U' && strlen(name) == 5) { /* try unicode Uxxxx */
char *end; char *end;
int ret = (int)strtoul(name + 1, &end, 16); int ret = (int)strtoul(name + 1, &end, 16);
if (*end == '\0' && ret > 0) if (*end == '\0' && ret > 0) {
return ret; return ret;
} }
}
return 0; return 0;
} }
@ -46,8 +48,9 @@ static int get_keysym(const name2keysym_t *table,
static void add_to_key_range(struct key_range **krp, int code) { static void add_to_key_range(struct key_range **krp, int code) {
struct key_range *kr; struct key_range *kr;
for (kr = *krp; kr; kr = kr->next) { for (kr = *krp; kr; kr = kr->next) {
if (code >= kr->start && code <= kr->end) if (code >= kr->start && code <= kr->end) {
break; break;
}
if (code == kr->start - 1) { if (code == kr->start - 1) {
kr->start--; kr->start--;
break; break;
@ -67,13 +70,13 @@ static void add_to_key_range(struct key_range **krp, int code) {
static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k) { static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k) {
if (keysym < MAX_NORMAL_KEYCODE) { if (keysym < MAX_NORMAL_KEYCODE) {
//fprintf(stderr,"Setting keysym %s (%d) to %d\n",line,keysym,keycode); /* fprintf(stderr,"Setting keysym %s (%d) to %d\n",
line, keysym, keycode); */
k->keysym2keycode[keysym] = keycode; k->keysym2keycode[keysym] = keycode;
} else { } else {
if (k->extra_count >= MAX_EXTRA_COUNT) { if (k->extra_count >= MAX_EXTRA_COUNT) {
fprintf(stderr, fprintf(stderr, "Warning: Could not assign keysym %s (0x%x)"
"Warning: Could not assign keysym %s (0x%x) because of memory constraints.\n", " because of memory constraints.\n", line, keysym);
line, keysym);
} else { } else {
#if 0 #if 0
fprintf(stderr, "Setting %d: %d,%d\n", fprintf(stderr, "Setting %d: %d,%d\n",
@ -101,36 +104,41 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
f = filename ? fopen(filename, "r") : NULL; f = filename ? fopen(filename, "r") : NULL;
g_free(filename); g_free(filename);
if (!f) { if (!f) {
fprintf(stderr, fprintf(stderr, "Could not read keymap file: '%s'\n", language);
"Could not read keymap file: '%s'\n", language);
return NULL; return NULL;
} }
if (!k) if (!k) {
k = g_malloc0(sizeof(kbd_layout_t)); k = g_malloc0(sizeof(kbd_layout_t));
}
for(;;) { for(;;) {
if (fgets(line, 1024, f) == NULL) if (fgets(line, 1024, f) == NULL) {
break; break;
}
len = strlen(line); len = strlen(line);
if (len > 0 && line[len - 1] == '\n') if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\0'; line[len - 1] = '\0';
if (line[0] == '#') }
if (line[0] == '#') {
continue; continue;
if (!strncmp(line, "map ", 4)) }
if (!strncmp(line, "map ", 4)) {
continue; continue;
}
if (!strncmp(line, "include ", 8)) { if (!strncmp(line, "include ", 8)) {
parse_keyboard_layout(table, line + 8, k); parse_keyboard_layout(table, line + 8, k);
} else { } else {
char *end_of_keysym = line; char *end_of_keysym = line;
while (*end_of_keysym != 0 && *end_of_keysym != ' ') while (*end_of_keysym != 0 && *end_of_keysym != ' ') {
end_of_keysym++; end_of_keysym++;
}
if (*end_of_keysym) { if (*end_of_keysym) {
int keysym; int keysym;
*end_of_keysym = 0; *end_of_keysym = 0;
keysym = get_keysym(table, line); keysym = get_keysym(table, line);
if (keysym == 0) { if (keysym == 0) {
// fprintf(stderr, "Warning: unknown keysym %s\n", line); /* fprintf(stderr, "Warning: unknown keysym %s\n", line);*/
} else { } else {
const char *rest = end_of_keysym + 1; const char *rest = end_of_keysym + 1;
int keycode = strtol(rest, NULL, 0); int keycode = strtol(rest, NULL, 0);
@ -138,7 +146,8 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
if (strstr(rest, "numlock")) { if (strstr(rest, "numlock")) {
add_to_key_range(&k->keypad_range, keycode); add_to_key_range(&k->keypad_range, keycode);
add_to_key_range(&k->numlock_range, keysym); add_to_key_range(&k->numlock_range, keysym);
//fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode); /* fprintf(stderr, "keypad keysym %04x keycode %d\n",
keysym, keycode); */
} }
if (strstr(rest, "shift")) { if (strstr(rest, "shift")) {
@ -155,11 +164,14 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
if (strstr(rest, "addupper")) { if (strstr(rest, "addupper")) {
char *c; char *c;
for (c = line; *c; c++) for (c = line; *c; c++) {
*c = qemu_toupper(*c); *c = qemu_toupper(*c);
}
keysym = get_keysym(table, line); keysym = get_keysym(table, line);
if (keysym) if (keysym) {
add_keysym(line, keysym, keycode | SCANCODE_SHIFT, k); add_keysym(line, keysym,
keycode | SCANCODE_SHIFT, k);
}
} }
} }
} }
@ -180,20 +192,24 @@ int keysym2scancode(void *kbd_layout, int keysym)
{ {
kbd_layout_t *k = kbd_layout; kbd_layout_t *k = kbd_layout;
if (keysym < MAX_NORMAL_KEYCODE) { if (keysym < MAX_NORMAL_KEYCODE) {
if (k->keysym2keycode[keysym] == 0) if (k->keysym2keycode[keysym] == 0) {
fprintf(stderr, "Warning: no scancode found for keysym %d\n", fprintf(stderr, "Warning: no scancode found for keysym %d\n",
keysym); keysym);
}
return k->keysym2keycode[keysym]; return k->keysym2keycode[keysym];
} else { } else {
int i; int i;
#ifdef XK_ISO_Left_Tab #ifdef XK_ISO_Left_Tab
if (keysym == XK_ISO_Left_Tab) if (keysym == XK_ISO_Left_Tab) {
keysym = XK_Tab; keysym = XK_Tab;
}
#endif #endif
for (i = 0; i < k->extra_count; i++) for (i = 0; i < k->extra_count; i++) {
if (k->keysym2keycode_extra[i].keysym == keysym) if (k->keysym2keycode_extra[i].keysym == keysym) {
return k->keysym2keycode_extra[i].keycode; return k->keysym2keycode_extra[i].keycode;
} }
}
}
return 0; return 0;
} }
@ -202,9 +218,11 @@ int keycode_is_keypad(void *kbd_layout, int keycode)
kbd_layout_t *k = kbd_layout; kbd_layout_t *k = kbd_layout;
struct key_range *kr; struct key_range *kr;
for (kr = k->keypad_range; kr; kr = kr->next) for (kr = k->keypad_range; kr; kr = kr->next) {
if (keycode >= kr->start && keycode <= kr->end) if (keycode >= kr->start && keycode <= kr->end) {
return 1; return 1;
}
}
return 0; return 0;
} }
@ -213,8 +231,10 @@ int keysym_is_numlock(void *kbd_layout, int keysym)
kbd_layout_t *k = kbd_layout; kbd_layout_t *k = kbd_layout;
struct key_range *kr; struct key_range *kr;
for (kr = k->numlock_range; kr; kr = kr->next) for (kr = k->numlock_range; kr; kr = kr->next) {
if (keysym >= kr->start && keysym <= kr->end) if (keysym >= kr->start && keysym <= kr->end) {
return 1; return 1;
}
}
return 0; return 0;
} }