]> git.proxmox.com Git - qemu.git/blobdiff - ui/keymaps.c
rng-egd: remove redundant free
[qemu.git] / ui / keymaps.c
index 78c7ea375cc9906c2ed8518d8428a2389d33f002..80d658d907d3d5671ccc7c5c3ceb21f587eea56d 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "keymaps.h"
-#include "sysemu.h"
+#include "sysemu/sysemu.h"
 
 static int get_keysym(const name2keysym_t *table,
                      const char *name)
@@ -33,6 +33,12 @@ static int get_keysym(const name2keysym_t *table,
         if (!strcmp(p->name, name))
             return p->keysym;
     }
+    if (name[0] == 'U' && strlen(name) == 5) { /* try unicode Uxxxx */
+        char *end;
+        int ret = (int)strtoul(name + 1, &end, 16);
+        if (*end == '\0' && ret > 0)
+          return ret;
+    }
     return 0;
 }
 
@@ -52,7 +58,7 @@ static void add_to_key_range(struct key_range **krp, int code) {
        }
     }
     if (kr == NULL) {
-       kr = qemu_mallocz(sizeof(*kr));
+       kr = g_malloc0(sizeof(*kr));
         kr->start = kr->end = code;
         kr->next = *krp;
         *krp = kr;
@@ -92,15 +98,17 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
     int len;
 
     filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
-
-    if (!k)
-       k = qemu_mallocz(sizeof(kbd_layout_t));
-    if (!(filename && (f = fopen(filename, "r")))) {
+    f = filename ? fopen(filename, "r") : NULL;
+    g_free(filename);
+    if (!f) {
        fprintf(stderr,
                "Could not read keymap file: '%s'\n", language);
        return NULL;
     }
-    qemu_free(filename);
+
+    if (!k)
+       k = g_malloc0(sizeof(kbd_layout_t));
+
     for(;;) {
        if (fgets(line, 1024, f) == NULL)
             break;
@@ -125,28 +133,30 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
                     //             fprintf(stderr, "Warning: unknown keysym %s\n", line);
                } else {
                    const char *rest = end_of_keysym + 1;
-                   char *rest2;
-                   int keycode = strtol(rest, &rest2, 0);
+                    int keycode = strtol(rest, NULL, 0);
 
-                   if (rest && strstr(rest, "numlock")) {
+                    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 (rest && strstr(rest, "shift"))
+                    if (strstr(rest, "shift")) {
                        keycode |= SCANCODE_SHIFT;
-                   if (rest && strstr(rest, "altgr"))
+                    }
+                    if (strstr(rest, "altgr")) {
                        keycode |= SCANCODE_ALTGR;
-                   if (rest && strstr(rest, "ctrl"))
+                    }
+                    if (strstr(rest, "ctrl")) {
                        keycode |= SCANCODE_CTRL;
+                    }
 
                    add_keysym(line, keysym, keycode, k);
 
-                   if (rest && strstr(rest, "addupper")) {
+                    if (strstr(rest, "addupper")) {
                        char *c;
                        for (c = line; *c; c++)
-                           *c = toupper(*c);
+                           *c = qemu_toupper(*c);
                        keysym = get_keysym(table, line);
                        if (keysym)
                            add_keysym(line, keysym, keycode | SCANCODE_SHIFT, k);