gboolean ibus_key_event_from_string (const gchar *string, guint *keyval, guint *modifiers) { g_return_val_if_fail (string != NULL, FALSE); g_return_val_if_fail (keyval != NULL, FALSE); g_return_val_if_fail (modifiers != NULL, FALSE); gchar **tokens = NULL; gchar **p; gboolean retval = FALSE; tokens = g_strsplit (string, "+", 0); g_return_val_if_fail (tokens != NULL, FALSE); *keyval = 0; *modifiers = 0; for (p = tokens; *(p + 1) != NULL; p++) { gint i; for (i = 0; i < 32; i++) { if (g_strcmp0 (modifier_name[i], *p) != 0) continue; *modifiers |= (1 << i); break; } if (i == 32) { goto _out; } } *keyval = ibus_keyval_from_name (*p); if (*keyval != IBUS_KEY_VoidSymbol) retval = TRUE; _out: if (tokens) g_strfreev (tokens); return retval; }
static gboolean ibus_keymap_parse_line (gchar *str, KEYMAP keymap) { gchar *p1, *p2; gint i; guint keycode; guint keysym; const struct { const gchar *prefix; const gint len; } prefix [] = { { "keycode ", sizeof ("keycode ") - 1 }, { "shift keycode ", sizeof ("shift keycode ") - 1 }, { "capslock keycode ", sizeof ("capslock keycode ") - 1 }, { "shift capslock keycode ", sizeof ("shift capslock keycode ") - 1 }, { "altgr keycode ", sizeof ("altgr keycode ") - 1}, { "shift altgr keycode ", sizeof ("shift altgr keycode ") - 1}, { "numlock keycode ", sizeof ("numlock keycode ") - 1}, }; p1 = str; SKIP_SPACE(p1); if (*p1 == '#') return TRUE; if (strncmp (p1, "include ", sizeof ("include ") - 1) == 0) { p1 += sizeof ("include ") - 1; for (p2 = p1; *p2 != '\n'; p2++); *p2 = '\0'; return ibus_keymap_load (p1, keymap); } for (i = 0; i < sizeof (prefix) / sizeof (prefix[0]); i++) { if (strncmp (p1, prefix[i].prefix, prefix[i].len) == 0) { p1 += prefix[i].len; break; } } if (i >= sizeof (prefix) / sizeof (prefix[0])) return FALSE; keycode = (guint) strtoul (p1, &p2, 10); if (keycode == 0 && p1 == p2) return FALSE; if (keycode < 0 || keycode > 255) return FALSE; p1 = p2; if (*p1++ != ' ') return FALSE; if (*p1++ != '=') return FALSE; if (*p1++ != ' ') return FALSE; for (p2 = p1; *p2 != '\n' && *p2 != ' '; p2++); *p2 = '\0'; p2++; keysym = ibus_keyval_from_name (p1); if (keysym == IBUS_VoidSymbol) return FALSE; if (i == 0 && strncmp (p2, "addupper", sizeof ("addupper") - 1) == 0 && g_ascii_isalpha (*p1)) { gchar buf[] = "a"; buf[0] = g_ascii_toupper(*p1); keymap[keycode][0] = keymap[keycode][3] = keysym; keymap[keycode][1] = keymap[keycode][2] = ibus_keyval_from_name (buf); } else { keymap[keycode][i] = keysym; } return TRUE; }