static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,

                                           const char *language,

                                           kbd_layout_t *k)

{

    FILE *f;

    char * filename;

    char line[1024];

    int len;



    filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);

    f = filename ? fopen(filename, "r") : NULL;

    g_free(filename);

    if (!f) {

        fprintf(stderr, "Could not read keymap file: '%s'\n", language);

        return NULL;

    }



    if (!k) {

        k = g_malloc0(sizeof(kbd_layout_t));

    }



    for(;;) {

        if (fgets(line, 1024, f) == NULL) {

            break;

        }

        len = strlen(line);

        if (len > 0 && line[len - 1] == '\n') {

            line[len - 1] = '\0';

        }

        if (line[0] == '#') {

            continue;

        }

        if (!strncmp(line, "map ", 4)) {

            continue;

        }

        if (!strncmp(line, "include ", 8)) {

            parse_keyboard_layout(table, line + 8, k);

        } else {

            char *end_of_keysym = line;

            while (*end_of_keysym != 0 && *end_of_keysym != ' ') {

                end_of_keysym++;

            }

            if (*end_of_keysym) {

                int keysym;

                *end_of_keysym = 0;

                keysym = get_keysym(table, line);

                if (keysym == 0) {

                    /* fprintf(stderr, "Warning: unknown keysym %s\n", line);*/

                } else {

                    const char *rest = end_of_keysym + 1;

                    int keycode = strtol(rest, NULL, 0);



                    if (strstr(rest, "numlock")) {

                        add_to_key_range(&k->keypad_range, keycode);

                        add_to_key_range(&k->numlock_range, keysym);

                        /* fprintf(stderr, "keypad keysym %04x keycode %d\n",

                                   keysym, keycode); */

                    }



                    if (strstr(rest, "shift")) {

                        keycode |= SCANCODE_SHIFT;

                    }

                    if (strstr(rest, "altgr")) {

                        keycode |= SCANCODE_ALTGR;

                    }

                    if (strstr(rest, "ctrl")) {

                        keycode |= SCANCODE_CTRL;

                    }



                    add_keysym(line, keysym, keycode, k);



                    if (strstr(rest, "addupper")) {

                        char *c;

                        for (c = line; *c; c++) {

                            *c = qemu_toupper(*c);

                        }

                        keysym = get_keysym(table, line);

                        if (keysym) {

                            add_keysym(line, keysym,

                                       keycode | SCANCODE_SHIFT, k);

                        }

                    }

                }

            }

        }

    }

    fclose(f);

    return k;

}

static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,

                                           const char *language,

                                           kbd_layout_t *k)

{

    FILE *f;

    char * filename;

    char line[1024];

    int len;



    filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);

    f = filename ? fopen(filename, "r") : NULL;

    g_free(filename);

    if (!f) {

        fprintf(stderr, "Could not read keymap file: '%s'\n", language);

        return NULL;

    }



    if (!k) {

        k = g_malloc0(sizeof(kbd_layout_t));

    }



    for(;;) {

        if (fgets(line, 1024, f) == NULL) {

            break;

        }

        len = strlen(line);

        if (len > 0 && line[len - 1] == '\n') {

            line[len - 1] = '\0';

        }

        if (line[0] == '#') {

            continue;

        }

        if (!strncmp(line, "map ", 4)) {

            continue;

        }

        if (!strncmp(line, "include ", 8)) {

            parse_keyboard_layout(table, line + 8, k);

        } else {

            char *end_of_keysym = line;

            while (*end_of_keysym != 0 && *end_of_keysym != ' ') {

                end_of_keysym++;

            }

            if (*end_of_keysym) {

                int keysym;

                *end_of_keysym = 0;

                keysym = get_keysym(table, line);

                if (keysym == 0) {

                    

                } else {

                    const char *rest = end_of_keysym + 1;

                    int keycode = strtol(rest, NULL, 0);



                    if (strstr(rest, "numlock")) {

                        add_to_key_range(&k->keypad_range, keycode);

                        add_to_key_range(&k->numlock_range, keysym);

                        



                    }



                    if (strstr(rest, "shift")) {

                        keycode |= SCANCODE_SHIFT;

                    }

                    if (strstr(rest, "altgr")) {

                        keycode |= SCANCODE_ALTGR;

                    }

                    if (strstr(rest, "ctrl")) {

                        keycode |= SCANCODE_CTRL;

                    }



                    add_keysym(line, keysym, keycode, k);



                    if (strstr(rest, "addupper")) {

                        char *c;

                        for (c = line; *c; c++) {

                            *c = qemu_toupper(*c);

                        }

                        keysym = get_keysym(table, line);

                        if (keysym) {

                            add_keysym(line, keysym,

                                       keycode | SCANCODE_SHIFT, k);

                        }

                    }

                }

            }

        }

    }

    fclose(f);

    return k;

}

        k = g_malloc0(sizeof(kbd_layout_t));
static kbd_layout_t *FUNC_0(const name2keysym_t *table,

                                           const char *language,

                                           kbd_layout_t *k)

{

    FILE *f;

    char * VAR_0;

    char VAR_1[1024];

    int VAR_2;



    VAR_0 = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);

    f = VAR_0 ? fopen(VAR_0, "r") : NULL;

    g_free(VAR_0);

    if (!f) {

        fprintf(stderr, "Could not read keymap file: '%s'\n", language);

        return NULL;

    }



    if (!k) {

        k = g_malloc0(sizeof(kbd_layout_t));

    }



    for(;;) {

        if (fgets(VAR_1, 1024, f) == NULL) {

            break;

        }

        VAR_2 = strlen(VAR_1);

        if (VAR_2 > 0 && VAR_1[VAR_2 - 1] == '\n') {

            VAR_1[VAR_2 - 1] = '\0';

        }

        if (VAR_1[0] == '#') {

            continue;

        }

        if (!strncmp(VAR_1, "map ", 4)) {

            continue;

        }

        if (!strncmp(VAR_1, "include ", 8)) {

            FUNC_0(table, VAR_1 + 8, k);

        } else {

            char *VAR_3 = VAR_1;

            while (*VAR_3 != 0 && *VAR_3 != ' ') {

                VAR_3++;

            }

            if (*VAR_3) {

                int VAR_4;

                *VAR_3 = 0;

                VAR_4 = get_keysym(table, VAR_1);

                if (VAR_4 == 0) {

                    

                } else {

                    const char *VAR_5 = VAR_3 + 1;

                    int VAR_6 = strtol(VAR_5, NULL, 0);



                    if (strstr(VAR_5, "numlock")) {

                        add_to_key_range(&k->keypad_range, VAR_6);

                        add_to_key_range(&k->numlock_range, VAR_4);

                        



                    }



                    if (strstr(VAR_5, "shift")) {

                        VAR_6 |= SCANCODE_SHIFT;

                    }

                    if (strstr(VAR_5, "altgr")) {

                        VAR_6 |= SCANCODE_ALTGR;

                    }

                    if (strstr(VAR_5, "ctrl")) {

                        VAR_6 |= SCANCODE_CTRL;

                    }



                    add_keysym(VAR_1, VAR_4, VAR_6, k);



                    if (strstr(VAR_5, "addupper")) {

                        char *VAR_7;

                        for (VAR_7 = VAR_1; *VAR_7; VAR_7++) {

                            *VAR_7 = qemu_toupper(*VAR_7);

                        }

                        VAR_4 = get_keysym(table, VAR_1);

                        if (VAR_4) {

                            add_keysym(VAR_1, VAR_4,

                                       VAR_6 | SCANCODE_SHIFT, k);

                        }

                    }

                }

            }

        }

    }

    fclose(f);

    return k;

}

static kbd_layout_t *FUNC_0(const name2keysym_t *table,
const char *language,
kbd_layout_t *k)
{ FILE *f; char * VAR_0; char VAR_1[1024]; int VAR_2; VAR_0 = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language); f = VAR_0 ? fopen(VAR_0, "r") : NULL; g_free(VAR_0); if (!f) { fprintf(stderr, "Could not read keymap file: '%s'\n", language); return NULL; } if (!k) { k = g_malloc0(sizeof(kbd_layout_t)); } for(;;) { if (fgets(VAR_1, 1024, f) == NULL) { break; } VAR_2 = strlen(VAR_1); if (VAR_2 > 0 && VAR_1[VAR_2 - 1] == '\n') { VAR_1[VAR_2 - 1] = '\0'; } if (VAR_1[0] == '#') { continue; } if (!strncmp(VAR_1, "map ", 4)) { continue; } if (!strncmp(VAR_1, "include ", 8)) { FUNC_0(table, VAR_1 + 8, k); } else { char *VAR_3 = VAR_1; while (*VAR_3 != 0 && *VAR_3 != ' ') { VAR_3++; } if (*VAR_3) { int VAR_4; *VAR_3 = 0; VAR_4 = get_keysym(table, VAR_1); if (VAR_4 == 0) { } else { const char *VAR_5 = VAR_3 + 1; int VAR_6 = strtol(VAR_5, NULL, 0); if (strstr(VAR_5, "numlock")) { add_to_key_range(&k->keypad_range, VAR_6); add_to_key_range(&k->numlock_range, VAR_4); } if (strstr(VAR_5, "shift")) { VAR_6 |= SCANCODE_SHIFT; } if (strstr(VAR_5, "altgr")) { VAR_6 |= SCANCODE_ALTGR; } if (strstr(VAR_5, "ctrl")) { VAR_6 |= SCANCODE_CTRL; } add_keysym(VAR_1, VAR_4, VAR_6, k); if (strstr(VAR_5, "addupper")) { char *VAR_7; for (VAR_7 = VAR_1; *VAR_7; VAR_7++) { *VAR_7 = qemu_toupper(*VAR_7); } VAR_4 = get_keysym(table, VAR_1); if (VAR_4) { add_keysym(VAR_1, VAR_4,
VAR_6 | SCANCODE_SHIFT, k); } } } } } } fclose(f); return k; }