int boot_(Module m) { char* dummy = NULL; controller_init(&rwcli_controller); // Authenticate in case of RW.MSG mode rwcli_user_mode_t user_mode = RWCLI_USER_MODE_NONE; if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_RWMSG) { user_mode = rift_authenticate(&rift_cmdargs); if (user_mode == RWCLI_USER_MODE_INVALID) { printf("\nERROR: Invalid username/password\n"); exit(-1); } } rwcli_zsh_plugin_init(rwcli_controller.agent_type, user_mode); rwcli_set_messaging_hook(messaging_hook); rwcli_set_history_hook(history_hook); // Always load the rwmsg_agent module, If netconf is enabled then // this module will only receive logging notifications if (load_module("zsh/rwmsg_agent", NULL, 0) != 0) { printf("\nCRITICAL: Loading the messaging agent module failed\n"); fflush(stdout); return -1; } // Load the agent that is required if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_NETCONF) { if (load_module("zsh/rwnetconf_agent", NULL, 0) != 0) { printf("\nCRITICAL: Loading the netconf agent module failed\n"); fflush(stdout); return -1; } rwcli_controller.is_netconf_agent_loaded = true; } /* Register the completion widget */ rwcli_controller.w_comp = addzlefunction("rift-complete", rift_complete, 0); Keymap km = openkeymap("main"); rwcli_controller.t_orig_tab_bind = keybind(km, "\t", &dummy); bindkey(km, "\t", refthingy(rwcli_controller.w_comp->first), NULL); /* Bind ? to generate help */ rwcli_controller.w_gen_help = addzlefunction("rift-gen-help", rift_generate_help, 0); bindkey(km, "?", refthingy(rwcli_controller.w_gen_help->first), NULL); /* Set the lookup hook */ rw_lookup_fn = rift_lookup; /* Set the prompt hook */ addprepromptfn(rift_prompt); return 0; }
void init_readline(char *UNUSED(prompt)) { DPRINTF1(DEBUG_READLINE, "Initialising readline version %x", rl_readline_version); rl_add_defun("rlwrap-accept-line", my_accept_line,-1); rl_add_defun("rlwrap-accept-line-and-forget", my_accept_line_and_forget,-1); rl_add_defun("rlwrap-call-editor", munge_line_in_editor, -1); rl_add_defun("rlwrap-direct-keypress", direct_keypress, -1); rl_add_defun("rlwrap-hotkey", handle_hotkey, -1); rl_add_defun("rlwrap-hotkey-ignore-history", handle_hotkey_ignore_history, -1); /* only useful while debugging */ rl_add_defun("rlwrap-dump-all-keybindings", dump_all_keybindings,-1); rl_add_defun("rlwrap-debug-ad-hoc", debug_ad_hoc, -1); /* the old rlwrap bindable function names with underscores are deprecated: */ rl_add_defun("rlwrap_accept_line_and_forget", please_update_alaf,-1); rl_add_defun("rlwrap_call_editor", please_update_ce,-1); rl_variable_bind("blink-matching-paren","on"); /* Shouldn't this be on by default? */ bindkey('\n', my_accept_line, "emacs-standard; vi-insert; vi-command"); bindkey('\r', my_accept_line, "emacs-standard; vi-insert; vi-command"); bindkey(15, my_accept_line_and_forget, "emacs-standard; vi-insert; vi-command"); /* ascii #15 (Control-O) is unused in readline's emacs and vi keymaps */ if (multiline_separator) bindkey(30, munge_line_in_editor, "emacs-standard;vi-insert;vi-command"); /* CTRL-^: unused in vi-insert-mode, hardly used in emacs (doubles arrow-up) */ /* rl_variable_bind("gnah","gnerp"); It is not possible to create new readline variables (only functions) */ rl_catch_signals = 0; rl_initialize(); /* This has to happen *before* we set rl_redisplay_function, otherwise readline will not bother to call tgetent(), will be agnostic about terminal capabilities and hence not be able to honour e.g. a set horizontal-scroll-mode off in .inputrc */ using_history(); rl_redisplay_function = my_redisplay; rl_completion_entry_function = (rl_compentry_func_t *) & my_completion_function; rl_catch_signals = FALSE; rl_catch_sigwinch = FALSE; saved_rl_state.input_buffer = mysavestring(pre_given ? pre_given : ""); /* Even though the pre-given input won't be displayed before the first cooking takes place, we still want it to be accepted when the user presses ENTER before that (e.g. because she already knows the pre-given input and wants to accept that) */ saved_rl_state.point = strlen(saved_rl_state.input_buffer); saved_rl_state.raw_prompt = mysavestring(""); saved_rl_state.cooked_prompt = NULL; }
virtual void key(int code, bool isdown, int unicode) { if(!capture || code < -8 || code > SDLK_MENU) return; keym *km; while((km = findbinda(bindcmd))) { bindkey(km, ""); } // clear existing binds to this cmd if(bindc(code, bindcmd)) parent->init(); // re-init all bindings else conoutf("\f3could not bind key"); }
void init_readline(char *prompt) { DPRINTF1(DEBUG_READLINE, "Initialising readline version %x", rl_readline_version); rl_add_defun("rlwrap-accept-line", my_accept_line,-1); rl_add_defun("rlwrap-accept-line-and-forget", my_accept_line_and_forget,-1); rl_add_defun("rlwrap-dump-all-keybindings", dump_all_keybindings,-1); rl_add_defun("rlwrap-call-editor", munge_line_in_editor, -1); /* rlwrap bindable function names with underscores are deprecated: */ rl_add_defun("rlwrap_accept_line_and_forget", please_update_alaf,-1); rl_add_defun("rlwrap_call_editor", please_update_ce,-1); rl_variable_bind("blink-matching-paren","on"); /* Shouldn't this be on by default? */ bindkey('\n', my_accept_line, "emacs-standard; vi-insert; vi-command"); bindkey('\r', my_accept_line, "emacs-standard; vi-insert; vi-command"); bindkey(15, my_accept_line_and_forget, "emacs-standard; vi-insert; vi-command"); /* ascii #15 (Control-O) is unused in readline's emacs and vi keymaps */ if (multiline_separator) bindkey(30, munge_line_in_editor, "emacs-standard;vi-insert;vi-command"); /* CTRL-^: unused in vi-insert-mode, hardly used in emacs (doubles arrow-up) */ if (debug) bindkey(7, dump_all_keybindings,"emacs-standard; vi-insert; vi-move; vi-command" /* "emacs-ctlx; emacs-meta" */); /* CTRL-G */ /* rl_variable_bind("gnah","gnerp"); It is not possible to create new readline variables (only functions) */ rl_catch_signals = 0; rl_initialize(); /* This has to happen *before* we set rl_redisplay_function, otherwise readline will not bother to call tgetent(), will be agnostic about terminal capabilities and hence not be able to honour e.g. a set horizontal-scroll-mode off in .inputrc */ using_history(); rl_redisplay_function = my_redisplay; rl_completion_entry_function = (rl_compentry_func_t *) & my_completion_function; rl_catch_signals = FALSE; rl_catch_sigwinch = FALSE; saved_rl_state.input_buffer = mysavestring(""); saved_rl_state.raw_prompt = mysavestring(""); saved_rl_state.cooked_prompt = NULL; }
/* * Wrapper for bindkey() that converts escapes. */ int dobindkey(KEYMAP *map, const char *func, const char *str) { int i; for (i = 0; *str && i < MAXKEY; i++) { /* XXX - convert numbers w/ strol()? */ if (*str == '^' && *(str + 1) != '\0') { key.k_chars[i] = CCHR(toupper(*++str)); } else if (*str == '\\' && *(str + 1) != '\0') { switch (*++str) { case '^': key.k_chars[i] = '^'; break; case 't': case 'T': key.k_chars[i] = '\t'; break; case 'n': case 'N': key.k_chars[i] = '\n'; break; case 'r': case 'R': key.k_chars[i] = '\r'; break; case 'e': case 'E': key.k_chars[i] = CCHR('['); break; case '\\': key.k_chars[i] = '\\'; break; } } else key.k_chars[i] = *str; str++; } key.k_count = i; return (bindkey(&map, func, key.k_chars, key.k_count)); }
/* * excline - run a line from a load file or eval-expression. If FKEYS is * defined, duplicate functionality of dobind so function key values don't * have to fit in type char. */ int excline(char *line) { PF fp; struct line *lp, *np; int status, c, f, n; char *funcp, *tmp; char *argp = NULL; long nl; #ifdef FKEYS int bind; KEYMAP *curmap; #define BINDARG 0 /* this arg is key to bind (local/global set key) */ #define BINDNO 1 /* not binding or non-quoted BINDARG */ #define BINDNEXT 2 /* next arg " (define-key) */ #define BINDDO 3 /* already found key to bind */ #define BINDEXT 1 /* space for trailing \0 */ #else /* FKEYS */ #define BINDEXT 0 #endif /* FKEYS */ lp = NULL; if (macrodef || inmacro) { ewprintf("Not now!"); return (FALSE); } f = 0; n = 1; funcp = skipwhite(line); if (*funcp == '\0') return (TRUE); /* No error on blank lines */ line = parsetoken(funcp); if (*line != '\0') { *line++ = '\0'; line = skipwhite(line); if (ISDIGIT(*line) || *line == '-') { argp = line; line = parsetoken(line); } } if (argp != NULL) { f = FFARG; nl = strtol(argp, &tmp, 10); if (*tmp != '\0') return (FALSE); if (nl >= INT_MAX || nl <= INT_MIN) return (FALSE); n = (int)nl; } if ((fp = name_function(funcp)) == NULL) { ewprintf("Unknown function: %s", funcp); return (FALSE); } #ifdef FKEYS if (fp == bindtokey || fp == unbindtokey) { bind = BINDARG; curmap = fundamental_map; } else if (fp == localbind || fp == localunbind) { bind = BINDARG; curmap = curbp->b_modes[curbp->b_nmodes]->p_map; } else if (fp == redefine_key) bind = BINDNEXT; else bind = BINDNO; #endif /* FKEYS */ /* Pack away all the args now... */ if ((np = lalloc(0)) == FALSE) return (FALSE); np->l_fp = np->l_bp = maclcur = np; while (*line != '\0') { argp = skipwhite(line); if (*argp == '\0') break; line = parsetoken(argp); if (*argp != '"') { if (*argp == '\'') ++argp; if ((lp = lalloc((int) (line - argp) + BINDEXT)) == NULL) { status = FALSE; goto cleanup; } bcopy(argp, ltext(lp), (int)(line - argp)); #ifdef FKEYS /* don't count BINDEXT */ lp->l_used--; if (bind == BINDARG) bind = BINDNO; #endif /* FKEYS */ } else { /* quoted strings are special */ ++argp; #ifdef FKEYS if (bind != BINDARG) { #endif /* FKEYS */ lp = lalloc((int)(line - argp) + BINDEXT); if (lp == NULL) { status = FALSE; goto cleanup; } lp->l_used = 0; #ifdef FKEYS } else key.k_count = 0; #endif /* FKEYS */ while (*argp != '"' && *argp != '\0') { if (*argp != '\\') c = *argp++; else { switch (*++argp) { case 't': case 'T': c = CCHR('I'); break; case 'n': case 'N': c = CCHR('J'); break; case 'r': case 'R': c = CCHR('M'); break; case 'e': case 'E': c = CCHR('['); break; case '^': /* * split into two statements * due to bug in OSK cpp */ c = CHARMASK(*++argp); c = ISLOWER(c) ? CCHR(TOUPPER(c)) : CCHR(c); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c = *argp - '0'; if (argp[1] <= '7' && argp[1] >= '0') { c <<= 3; c += *++argp - '0'; if (argp[1] <= '7' && argp[1] >= '0') { c <<= 3; c += *++argp - '0'; } } break; #ifdef FKEYS case 'f': case 'F': c = *++argp - '0'; if (ISDIGIT(argp[1])) { c *= 10; c += *++argp - '0'; } c += KFIRST; break; #endif /* FKEYS */ default: c = CHARMASK(*argp); break; } argp++; } #ifdef FKEYS if (bind == BINDARG) key.k_chars[key.k_count++] = c; else #endif /* FKEYS */ lp->l_text[lp->l_used++] = c; } if (*line) line++; } #ifdef FKEYS switch (bind) { case BINDARG: bind = BINDDO; break; case BINDNEXT: lp->l_text[lp->l_used] = '\0'; if ((curmap = name_map(lp->l_text)) == NULL) { ewprintf("No such mode: %s", lp->l_text); status = FALSE; free(lp); goto cleanup; } free(lp); bind = BINDARG; break; default: #endif /* FKEYS */ lp->l_fp = np->l_fp; lp->l_bp = np; np->l_fp = lp; np = lp; #ifdef FKEYS } #endif /* FKEYS */ } #ifdef FKEYS switch (bind) { default: ewprintf("Bad args to set key"); status = FALSE; break; case BINDDO: if (fp != unbindtokey && fp != localunbind) { lp->l_text[lp->l_used] = '\0'; status = bindkey(&curmap, lp->l_text, key.k_chars, key.k_count); } else status = bindkey(&curmap, NULL, key.k_chars, key.k_count); break; case BINDNO: #endif /* FKEYS */ inmacro = TRUE; maclcur = maclcur->l_fp; status = (*fp)(f, n); inmacro = FALSE; #ifdef FKEYS } #endif /* FKEYS */ cleanup: lp = maclcur->l_fp; while (lp != maclcur) { np = lp->l_fp; free(lp); lp = np; } free(lp); return (status); }
int boot_(Module m) { char* dummy = NULL; // Initialize the trace module and set appropriate severity rift_init_trace(); recv_buf = (uint8_t*)calloc(sizeof(uint8_t), RW_CLI_MAX_BUF); recv_buf_len = RW_CLI_MAX_BUF; // Decide the RW.CLI communication mode with RW.MgmtAgent if (rift_cmdargs.use_netconf == -1) { const char* agent_mode = rw_getenv("RWMGMT_AGENT_MODE"); if (agent_mode && strcmp(agent_mode, "XML") == 0) { // If the agent mode is XML only RW.MSG mode is possible. Override the // command line option for netconf and opt for RW.MSG mode. rift_cmdargs.use_netconf = 0; } else { // Transport mode not chosen in command line and not XML mode. Choose // Netconf mode by default. rift_cmdargs.use_netconf = 1; } } // Authenticate in case of RW.MSG mode rwcli_transport_mode_t transport_mode = RWCLI_TRANSPORT_MODE_NETCONF; rwcli_user_mode_t user_mode = RWCLI_USER_MODE_NONE; if (!rift_cmdargs.use_netconf) { user_mode = rift_authenticate(&rift_cmdargs); if (user_mode == RWCLI_USER_MODE_INVALID) { printf("\nERROR: Invalid username/password\n"); exit(-1); } transport_mode = RWCLI_TRANSPORT_MODE_RWMSG; } rwcli_zsh_plugin_init(transport_mode, user_mode); rwcli_set_messaging_hook(messaging_hook); rwcli_set_history_hook(history_hook); // To support background processes and job control, there should // be multiple channels available msg_channel_init(&rwcli_agent_ch); msg_channel_create(&rwcli_agent_ch); // Always load the rwmsg_agent module, If netconf is enabled then // this module will only receive logging notifications if (load_module("zsh/rwmsg_agent", NULL, 0) != 0) { printf("\nCRITICAL: Loading the messaging agent module failed\n"); fflush(stdout); return -1; } // Load the agent that is required if (rift_cmdargs.use_netconf) { if (load_module("zsh/rwnetconf_agent", NULL, 0) != 0) { printf("\nCRITICAL: Loading the netconf agent module failed\n"); fflush(stdout); return -1; } } /* Register the completion widget */ w_comp = addzlefunction("rift-complete", rift_complete, 0); Keymap km = openkeymap("main"); t_orig_tab_bind = keybind(km, "\t", &dummy); bindkey(km, "\t", refthingy(w_comp->first), NULL); /* Bind ? to generate help */ w_gen_help = addzlefunction("rift-gen-help", rift_generate_help, 0); bindkey(km, "?", refthingy(w_gen_help->first), NULL); /* Set the lookup hook */ rw_lookup_fn = rift_lookup; /* Set the prompt hook */ addprepromptfn(rift_prompt); return 0; }