static bool getLine(int inp) { CACHE_REGS rl_instream = GLOBAL_Stream[inp].file; const unsigned char *myrl_line = NULL; StreamDesc *s = GLOBAL_Stream + inp; bool shouldPrompt = Yap_DoPrompt(s); /* window of vulnerability opened */ LOCAL_PrologMode |= ConsoleGetcMode; if (true || shouldPrompt) { // no output so far rl_set_signals(); myrl_line = (unsigned char *)readline(LOCAL_Prompt); rl_clear_signals(); } else { rl_set_signals(); myrl_line = (unsigned char *)readline(NULL); rl_clear_signals(); } /* Do it the gnu way */ LOCAL_PrologMode &= ~ConsoleGetcMode; #if HAVE_RL_PENDING_SIGNAL if (rl_pending_signal()) { LOCAL_PrologMode |= InterruptMode; } #endif if (LOCAL_PrologMode & InterruptMode) { Yap_HandleSIGINT(); } else { LOCAL_newline = true; } strncpy(LOCAL_Prompt, RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT); /* window of vulnerability closed */ if (myrl_line == NULL) return false; if (myrl_line[0] != '\0' && myrl_line[1] != '\0') { add_history((char *)myrl_line); write_history(history_file); fflush(NULL); } s->u.irl.ptr = s->u.irl.buf = myrl_line; myrl_line = NULL; return true; }
GNUReadlineUI::GNUReadlineUI(const std::string & histfile) : UI(), m_histfile(histfile) { rl_set_signals(); rl_cleanup_after_signal(); using_history(); read_history(m_histfile.c_str()); }
// Set everything up void gnu_readline_init() { using_history(); rl_bind_key(')', gnu_readline_paren_bounce); rl_bind_key(']', gnu_readline_paren_bounce); #if 0 rl_bind_keyseq("[D", highlight_paren); #endif rl_completion_entry_function = &gnu_readline_tab_complete; rl_variable_bind("rl_catch_signals", 0); rl_clear_signals(); rl_set_signals(); rl_completer_quote_characters = "\""; }
/* Make sure the terminal is set up, initialize readline, and prompt. */ static void _rl_callback_newline () { rl_initialize (); if (in_handler == 0) { in_handler = 1; (*rl_prep_term_function) (_rl_meta_flag); #if defined (HANDLE_SIGNALS) rl_set_signals (); #endif } readline_internal_setup (); }
void shell_interactive(shell_context_t *ctx) { ctx->shell_exit = 0; #ifndef WITH_READLINE char *line; while(!ctx->shell_exit) { fputs("jzboot> ", stdout); fflush(stdout); line = fgets(ctx->linebuf, sizeof(ctx->linebuf), stdin); if(line == NULL) break; shell_execute(ctx, line); } #else rl_completion_entry_function = shell_completion; completion_context = ctx; rl_set_signals(); rl_filename_quote_characters = "\" "; while(!ctx->shell_exit) { char *line = readline("jzboot> "); if(line == NULL) { break; } add_history(line); shell_execute(ctx, line); free(line); } rl_clear_signals(); #endif }