示例#1
0
/* Expand key code - returns TRUE if successful. */
static int expand_key(const char *key, GSList **out)
{
	GSList *tmp;
	const char *start;
	int last_hyphen;

	/* meta-^W^Gf -> ^[-^W-^G-f */
        start = NULL; last_hyphen = TRUE;
	for (; *key != '\0'; key++) {
		if (start != NULL) {
			if (i_isalnum(*key) || *key == '_') {
                                /* key combo continues */
				continue;
			}

			if (!expand_combo(start, key-1, out))
                                return FALSE;
			expand_out_char(*out, '-');
                        start = NULL;
		}

		if (*key == '-') {
			if (last_hyphen) {
                                expand_out_char(*out, '-');
                                expand_out_char(*out, '-');
			}
			last_hyphen = !last_hyphen;
		} else if (*key == '^') {
                        /* ctrl-code */
			if (key[1] != '\0')
				key++;

			expand_out_char(*out, '^');
			expand_out_char(*out, *key);
			expand_out_char(*out, '-');
                        last_hyphen = FALSE; /* optional */
		} else if (last_hyphen && i_isalnum(*key) && !i_isdigit(*key)) {
                        /* possibly beginning of keycombo */
			start = key;
                        last_hyphen = FALSE;
		} else {
			expand_out_char(*out, *key);
			expand_out_char(*out, '-');
                        last_hyphen = FALSE; /* optional */
		}
	}

	if (start != NULL)
		return expand_combo(start, key-1, out);

	for (tmp = *out; tmp != NULL; tmp = tmp->next) {
		GString *str = tmp->data;

		g_string_truncate(str, str->len-1);
	}

        return TRUE;
}
示例#2
0
文件: keyboard.c 项目: ahf/irssi
/* Expand key code - returns TRUE if successful. */
static int expand_key(const char *key, GSList **out, int *limit)
{
	GSList *tmp;
	const char *start;
	int last_hyphen;

	if ((*limit)-- < 0) {
		return FALSE;
	}

	/* meta-^W^Gf -> ^[-^W-^G-f */
        start = NULL; last_hyphen = TRUE;
	for (; *key != '\0'; key++) {
		if (start != NULL) {
			if (i_isalnum(*key) || *key == '_') {
                                /* key combo continues */
				continue;
			}

			if (!expand_combo(start, key-1, out, limit))
                                return FALSE;
			expand_out_char(*out, '-');
                        start = NULL;
		}

		if (*key == '-') {
			if (last_hyphen) {
                                expand_out_char(*out, '-');
                                expand_out_char(*out, '-');
			}
			last_hyphen = !last_hyphen;
		} else if (*key == '^') {
			expand_out_char(*out, '^');

                        /* ctrl-code */
			if (key[1] != '\0' && key[1] != '-') {
				key++;
				expand_out_char(*out, *key);
			}
			else {
				/* escaped syntax for ^, see gui-readline.c */
				expand_out_char(*out, '-');
			}

			expand_out_char(*out, '-');
                        last_hyphen = FALSE; /* optional */
		} else if (last_hyphen && i_isalpha(*key)) {
                        /* possibly beginning of keycombo */
			start = key;
                        last_hyphen = FALSE;
		} else if (g_utf8_validate(key, -1, NULL)) {
			/* Assume we are looking at the start of a
			 * multibyte sequence we will receive as-is,
			 * so add it to the list as-is.
			 */
			const char *p, *end = g_utf8_next_char(key);
			for (p = key; p != end; p++)
				expand_out_char(*out, *p);
			expand_out_char(*out, '-');
			/* The for loop skips past the remaining character.
			 * Nasty, I know...
			 */
			key = end - 1;
			last_hyphen = FALSE;
		} else {
			expand_out_char(*out, *key);
			expand_out_char(*out, '-');
                        last_hyphen = FALSE; /* optional */
		}
	}

	if (start != NULL)
		return expand_combo(start, key-1, out, limit);

	for (tmp = *out; tmp != NULL; tmp = tmp->next) {
		GString *str = tmp->data;

		g_string_truncate(str, str->len-1);
	}

        return TRUE;
}