+ if ((c1 >= '0' && c1 <= '9') &&
+ ((c2 >= '0' && c1 <= '9') || c2 == '\0'))
+ d = atoi(&name_ptr[4]);
+
+ if (d >= 1 && d <= KSYM_NUM_FKEYS)
+ key = KSYM_F1 + (Key)(d - 1);
+ }
+ else if (strPrefix(name_ptr, "XK_"))
+ {
+ i = 0;
+
+ do
+ {
+ if (strEqual(name_ptr, translate_key[i].x11name))
+ {
+ key = translate_key[i].key;
+ break;
+ }
+ }
+ while (translate_key[++i].x11name);
+ }
+ else if (strPrefix(name_ptr, "0x"))
+ {
+ unsigned int value = 0;
+
+ name_ptr += 2;
+
+ while (name_ptr)
+ {
+ char c = *name_ptr++;
+ int d = -1;
+
+ if (c >= '0' && c <= '9')
+ d = (int)(c - '0');
+ else if (c >= 'a' && c <= 'f')
+ d = (int)(c - 'a' + 10);
+ else if (c >= 'A' && c <= 'F')
+ d = (int)(c - 'A' + 10);
+
+ if (d == -1)
+ {
+ value = -1;
+ break;
+ }
+
+ value = value * 16 + d;
+ }
+
+ if (value != -1)
+ key = (Key)value;
+ }
+
+ *keysym = key;
+ }
+}
+
+char *getKeyNameFromKey(Key key)
+{
+ char *name;
+
+ translate_keyname(&key, NULL, &name, TRANSLATE_KEYSYM_TO_KEYNAME);
+ return name;
+}
+
+char *getX11KeyNameFromKey(Key key)
+{
+ char *x11name;
+
+ translate_keyname(&key, &x11name, NULL, TRANSLATE_KEYSYM_TO_X11KEYNAME);
+ return x11name;
+}
+
+Key getKeyFromKeyName(char *name)
+{
+ Key key;
+
+ translate_keyname(&key, NULL, &name, TRANSLATE_KEYNAME_TO_KEYSYM);
+ return key;
+}
+
+Key getKeyFromX11KeyName(char *x11name)
+{
+ Key key;
+
+ translate_keyname(&key, &x11name, NULL, TRANSLATE_X11KEYNAME_TO_KEYSYM);
+ return key;
+}
+
+char getCharFromKey(Key key)
+{
+ static struct
+ {
+ Key key;
+ byte key_char;
+ } translate_key_char[] =
+ {
+ // special (non-ASCII) keys (ISO-8859-1)
+ { KSYM_degree, CHAR_BYTE_DEGREE },
+ { KSYM_Adiaeresis, CHAR_BYTE_UMLAUT_A },
+ { KSYM_Odiaeresis, CHAR_BYTE_UMLAUT_O },
+ { KSYM_Udiaeresis, CHAR_BYTE_UMLAUT_U },
+ { KSYM_adiaeresis, CHAR_BYTE_UMLAUT_a },
+ { KSYM_odiaeresis, CHAR_BYTE_UMLAUT_o },
+ { KSYM_udiaeresis, CHAR_BYTE_UMLAUT_u },
+ { KSYM_ssharp, CHAR_BYTE_SHARP_S },
+
+ // end-of-array identifier
+ { 0, 0 }
+ };
+
+ char *keyname = getKeyNameFromKey(key);
+ char c = 0;
+
+ if (strlen(keyname) == 1)
+ c = keyname[0];
+ else if (strEqual(keyname, "space"))
+ c = ' ';
+ else
+ {
+ int i = 0;
+
+ do
+ {
+ if (key == translate_key_char[i].key)
+ {
+ c = translate_key_char[i].key_char;
+
+ break;
+ }
+ }
+ while (translate_key_char[++i].key_char);
+ }
+
+ return c;
+}
+
+char getValidConfigValueChar(char c)
+{
+ if (c == '#' || // used to mark comments
+ c == '\\') // used to mark continued lines
+ c = 0;
+
+ return c;
+}
+
+
+// ----------------------------------------------------------------------------
+// functions to translate string identifiers to integer or boolean value
+// ----------------------------------------------------------------------------
+
+int get_integer_from_string(char *s)
+{
+ // check for the most common case first
+ if (s[0] >= '0' && s[0] <= '9')
+ return atoi(s);
+
+ char *s_lower = getStringToLower(s);
+ int result = -1;
+
+ if (strEqual(s_lower, "false") ||
+ strEqual(s_lower, "no") ||
+ strEqual(s_lower, "off"))
+ result = 0;
+ else if (strEqual(s_lower, "true") ||
+ strEqual(s_lower, "yes") ||
+ strEqual(s_lower, "on"))
+ result = 1;
+ else
+ result = atoi(s);
+
+ free(s_lower);
+
+ return result;
+}
+
+boolean get_boolean_from_string(char *s)
+{
+ char *s_lower = getStringToLower(s);
+ boolean result = FALSE;
+
+ if (strEqual(s_lower, "true") ||
+ strEqual(s_lower, "yes") ||
+ strEqual(s_lower, "on") ||
+ get_integer_from_string(s) == 1)
+ result = TRUE;
+
+ free(s_lower);
+
+ return result;
+}
+
+int get_switch3_from_string(char *s)
+{
+ char *s_lower = getStringToLower(s);
+ int result = FALSE;
+
+ if (strEqual(s_lower, "true") ||
+ strEqual(s_lower, "yes") ||
+ strEqual(s_lower, "on") ||
+ get_integer_from_string(s) == 1)
+ result = TRUE;
+ else if (strEqual(s_lower, "auto"))
+ result = AUTO;
+
+ free(s_lower);
+
+ return result;
+}
+
+int get_player_nr_from_string(char *s)
+{
+ static char *player_text[] =
+ {
+ "player_1",
+ "player_2",
+ "player_3",
+ "player_4",
+
+ NULL
+ };
+
+ char *s_lower = getStringToLower(s);
+ int result = 0;
+ int i;
+
+ for (i = 0; player_text[i] != NULL; i++)
+ if (strEqual(s_lower, player_text[i]))
+ result = i;
+
+ free(s_lower);
+
+ return result;
+}
+
+
+// ----------------------------------------------------------------------------
+// functions for generic lists
+// ----------------------------------------------------------------------------
+
+ListNode *newListNode(void)
+{
+ return checked_calloc(sizeof(ListNode));
+}
+
+void addNodeToList(ListNode **node_first, char *key, void *content)
+{
+ ListNode *node_new = newListNode();
+
+ node_new->key = getStringCopy(key);
+ node_new->content = content;
+ node_new->next = *node_first;
+
+ if (*node_first)
+ (*node_first)->prev = node_new;
+
+ *node_first = node_new;
+}
+
+void deleteNodeFromList(ListNode **node_first, char *key,
+ void (*destructor_function)(void *))
+{
+ if (node_first == NULL || *node_first == NULL)
+ return;
+
+ if (strEqual((*node_first)->key, key))
+ {
+ // after first recursion, (*node_first)->prev->next == *node_first,
+ // so *node_first would be overwritten with (*node_first)->next
+ // => use a copy of *node_first (and later of (*node_first)->next)
+ ListNode *node = *node_first;
+ ListNode *node_next = node->next;
+
+ checked_free(node->key);
+
+ if (destructor_function)
+ destructor_function(node->content);
+
+ if (node->prev)
+ node->prev->next = node->next;
+
+ if (node->next)
+ node->next->prev = node->prev;
+
+ checked_free(node);
+
+ // after removing node, set list pointer to next valid list node
+ // (this is important if the first node of the list was deleted)
+ *node_first = node_next;
+ }
+ else
+ {
+ deleteNodeFromList(&(*node_first)->next, key, destructor_function);
+ }
+}
+
+ListNode *getNodeFromKey(ListNode *node_first, char *key)
+{
+ if (node_first == NULL)
+ return NULL;
+
+ if (strEqual(node_first->key, key))
+ return node_first;
+ else
+ return getNodeFromKey(node_first->next, key);
+}
+
+int getNumNodes(ListNode *node_first)
+{
+ return (node_first ? 1 + getNumNodes(node_first->next) : 0);
+}
+
+#if 0
+static void dumpList(ListNode *node_first)
+{
+ ListNode *node = node_first;
+
+ while (node)
+ {
+ Debug("internal:dumpList", "['%s' (%d)]", node->key,
+ ((struct ListNodeInfo *)node->content)->num_references);
+ node = node->next;
+ }
+
+ Debug("internal:dumpList", "[%d nodes]", getNumNodes(node_first));
+}
+#endif