void readline_status_mode (cli_context_t *ctx, const keymap_entry_t map[]) { int i; Keymap stkmap; readline_cli_ctx = ctx; rl_callback_handler_install (NULL, &readline_status_callback); /* Backup current keymap-name */ readline_keymap = g_strdup (rl_get_keymap_name (rl_get_keymap ())); /* New keymap for status mode */ stkmap = rl_make_bare_keymap (); /* Fill out the keymap and display it. */ g_printf ("\n"); for (i = 0; map[i].keyseq; i++) { rl_set_key (map[i].keyseq, rl_named_function (map[i].named_function), stkmap); if (map[i].readable_keyseq) { g_printf (" (%s) %s\n", map[i].readable_keyseq, map[i].readable_function ? map[i].readable_function : map[i].named_function); } } g_printf ("\n"); rl_set_keymap (stkmap); }
int rline_get_keyseq (struct rline *rline, const char *named_function, std_list keyseq_list) { rl_command_func_t *func; char **invoking_keyseqs = NULL; char **invoking_keyseqs_cur = NULL; char *new_keyseq = NULL; int len; if (!keyseq_list) return -1; func = rl_named_function (named_function); if (func == 0) return 0; invoking_keyseqs = rl_invoking_keyseqs (func); invoking_keyseqs_cur = invoking_keyseqs; while (invoking_keyseqs_cur && (*invoking_keyseqs_cur)) { new_keyseq = (char *)cgdb_malloc ((2 * strlen (*invoking_keyseqs_cur)) + 1); if (rl_translate_keyseq (*invoking_keyseqs_cur, new_keyseq, &len)) { free (new_keyseq); free (*invoking_keyseqs_cur); /* Can't do much about readline failing, just continue on. */ continue; } /* If the append function breaks, in serious trouble */ std_list_append (keyseq_list, new_keyseq); free (*invoking_keyseqs_cur); invoking_keyseqs_cur++; } free (invoking_keyseqs); return 0; }