Beispiel #1
0
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;
}
Beispiel #2
0
void initialize_readline(void)
{
	rl_readline_name = "occtl";
	rl_attempted_completion_function = occtl_completion;
	rl_completion_entry_function = command_generator;
	rl_completion_query_items = 20;
#ifdef HAVE_ORIG_READLINE
	rl_clear_signals();
#endif
	ocsignal(SIGINT, handle_sigint);
}
Beispiel #3
0
// 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("", 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 = "\"";
}
Beispiel #4
0
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
}
Beispiel #5
0
GNUReadlineUI::~GNUReadlineUI()
{
  write_history(m_histfile.c_str());
  rl_clear_signals();
}