Esempio n. 1
0
void *
ConsoleUI::threadMain(void *arg) {
	rl_callback_handler_install("", ConsoleUICallbacks::lineRead);
	while (!quit) {
		while (canRead()) {
			lineProcessed = false;
			rl_callback_read_char();
			if (lineProcessed && rl_prompt != NULL && rl_prompt[0] != '\0') {
				// If a line has been processed, reset the prompt
				// so we don't see it again after an Enter.
				rl_set_prompt("");
				rl_display_prompt = NULL;
				rl_redisplay();
			}
		}

		pthread_mutex_lock(&outputLock);
		if (!output.empty()) {
			processOutput();
			pthread_cond_broadcast(&outputCond);
		}
		pthread_mutex_unlock(&outputLock);

		usleep(10000);
	}
	rl_callback_handler_remove();
	return NULL;
}
Esempio n. 2
0
void jl_input_line_callback(char *input)
{
    int end=0, doprint=1;
    if (!input || ios_eof(ios_stdin)) {
        end = 1;
        rl_ast = NULL;
    }
    else if (!rl_ast) {
        // In vi mode, it's possible for this function to be called w/o a
        // previous call to return_callback.
        rl_ast = jl_parse_input_line(rl_line_buffer);
    }

    if (rl_ast != NULL) {
        doprint = !ends_with_semicolon(input);
        add_history_permanent(input);
        jl_putc('\n', jl_uv_stdout);
        free(input);
    }

    callback_en = 0;
    rl_callback_handler_remove();
    handle_input(rl_ast, end, doprint);
    rl_ast = NULL;
}
Esempio n. 3
0
/* readline hook to process the entered command */
static void
rl_docmd(char *line)
{
	char buf[NPH_BUF_SIZE];	/* space for an input line */

	/* EOF */
	if (line == NULL)
	{
		rl_callback_handler_remove();
		sighandler_state = HANDLER_DEFAULT;
		ph_close(ph, 0);
		exit(0);
	}

	/* blank line */
	if (*line == '\0')
	{
		free(line);
		return;
	}

	add_history(line);
	strlcpy(buf, line, sizeof(buf));
	free(line);

	/* do command */
	nph_command(buf);
	putchar('\n');
}
Esempio n. 4
0
int_fast8_t exitCLI()
{
    char command[500];
    int r;

    if(data.fifoON == 1)
    {
        sprintf(command, "rm %s", data.fifoname);
        r = system(command);
    }

    main_free();


    if(Listimfile==1) {
        if(system("rm imlist.txt")==-1)
        {
            printERROR(__FILE__,__func__,__LINE__,"system() error");
            exit(0);
        }
    }

    rl_callback_handler_remove();


    printf("Closing PID %ld (prompt process)\n", (long) getpid());
    exit(0);
    return 0;
}
void edit_deinit(const char *history_file,
		 int (*filter_cb)(void *ctx, const char *cmd))
{
	rl_set_prompt("");
	rl_replace_line("", 0);
	rl_redisplay();
	rl_callback_handler_remove();
	readline_free_completions();

	eloop_unregister_read_sock(STDIN_FILENO);

	if (history_file) {
		/* Save command history, excluding lines that may contain
		 * passwords. */
		HIST_ENTRY *h;
		history_set_pos(0);
		while ((h = current_history())) {
			char *p = h->line;
			while (*p == ' ' || *p == '\t')
				p++;
			if (filter_cb && filter_cb(edit_cb_ctx, p)) {
				h = remove_history(where_history());
				if (h) {
					free(h->line);
					free(h->data);
					free(h);
				} else
					next_history();
			} else
				next_history();
		}
		write_history(history_file);
	}
}
Esempio n. 6
0
/* Change the function to be invoked every time there is a character
   ready on stdin.  This is used when the user sets the editing off,
   therefore bypassing readline, and letting gdb handle the input
   itself, via gdb_readline2.  Also it is used in the opposite case in
   which the user sets editing on again, by restoring readline
   handling of the input.  */
static void
change_line_handler (void)
{
  /* NOTE: this operates on input_fd, not instream.  If we are reading
     commands from a file, instream will point to the file.  However in
     async mode, we always read commands from a file with editing
     off.  This means that the 'set editing on/off' will have effect
     only on the interactive session.  */

  if (async_command_editing_p)
    {
      /* Turn on editing by using readline.  */
      call_readline = rl_callback_read_char_wrapper;
      input_handler = command_line_handler;
    }
  else
    {
      /* Turn off editing by using gdb_readline2.  */
      rl_callback_handler_remove ();
      call_readline = gdb_readline2;

      /* Set up the command handler as well, in case we are called as
         first thing from .gdbinit.  */
      input_handler = command_line_handler;
    }
}
Esempio n. 7
0
void shutdown_app(void)
{
	if(g_context.sock >= 0)
	{
		close(g_context.sock);
		g_context.sock = -1;
	}
	if(g_context.outsock >= 0)
	{
		close(g_context.outsock);
		g_context.outsock = -1;
	}
	if(g_context.errsock >= 0)
	{
		close(g_context.errsock);
		g_context.errsock = -1;
	}
	if(g_context.fssock >= 0)
	{
		close(g_context.fssock);
		g_context.fssock = -1;
	}

	if(!g_context.args.script)
	{
		rl_callback_handler_remove();
	}
}
Esempio n. 8
0
void readline_constructor_impl::impl::stop()
{
  if (current_readline == NULL) {
    // We're already stopped
    return;
  }

  assert(detail::current_readline == this);
  stdin_reader_.cancel();
  redisplay_timer_.cancel();
  rl_callback_handler_remove();
  detail::current_readline = NULL;
  std::cout << std::endl;

  if (!history_file_.empty()) {
    boost::filesystem::create_directories(history_file_.parent_path());
    if (0 == write_history(history_file_.c_str())) {
      if (0 != history_truncate_file(
            history_file_.c_str(), history_length
          )) {
        throw relasio_error("error truncating history\n");
      }
    } else {
      throw relasio_error("error writing history\n");
    }
  }
}
Esempio n. 9
0
char* displayCmdLine(WINDOW *win){
	curs_set(2);
	winCommandMode = win;
	wmove (win, 1, 1);
	//wprintw(winCommandMode, prompt);
	wrefresh(win);

	//rl_bind_key(RETURN, io_handle_enter);
	rl_redisplay_function = (rl_voidfunc_t*)rl_redisplay_mod;

	wprintw(winCommandMode, prompt);
	char* line = readline(prompt);
	add_history(line);
	// for testing history
	//line = readline(prompt);
	wmove (win, 1, 11);
	wprintw(winCommandMode, line);
	wrefresh(win);
	return line;


	rl_callback_handler_install(prompt, handle_line);

	while (prog_running) {
		usleep(10);
		rl_callback_read_char();
	}
	rl_callback_handler_remove();
	//handle_command(rl_line_buffer);
	return rl_line_buffer;
} 
Esempio n. 10
0
char *ssc_input_read_string(char *str, int size)
{
#if USE_READLINE
    char *input;

    /* disable readline callbacks */
    if (ssc_input_handler_f)
        rl_callback_handler_remove();

    rl_reset_line_state();

    /* read a string a feed to 'str' */
    input = readline(ssc_input_prompt);
    strncpy(str, input, size - 1);
    str[size - 1] = 0;

    /* free the copy malloc()'ed by readline */
    free(input);

    /* reinstall the func */
    if (ssc_input_handler_f)
        rl_callback_handler_install(ssc_input_prompt, ssc_input_handler_f);

    rl_redisplay();

    return str;
#else
    return fgets(str, size, stdin);
#endif
}
Esempio n. 11
0
static char *
readline_until_enter_or_signal(const char *prompt, int *signal)
{
    char * not_done_reading = "";
    fd_set selectset;

    *signal = 0;
#ifdef HAVE_RL_CATCH_SIGNAL
    rl_catch_signals = 0;
#endif

    rl_callback_handler_install (prompt, rlhandler);
    FD_ZERO(&selectset);

    completed_input_string = not_done_reading;

    while (completed_input_string == not_done_reading) {
        int has_input = 0, err = 0;

        while (!has_input)
        {               struct timeval timeout = {0, 100000}; /* 0.1 seconds */

            /* [Bug #1552726] Only limit the pause if an input hook has been
               defined.  */
            struct timeval *timeoutp = NULL;
            if (PyOS_InputHook)
                timeoutp = &timeout;
            FD_SET(fileno(rl_instream), &selectset);
            /* select resets selectset if no input was available */
            has_input = select(fileno(rl_instream) + 1, &selectset,
                               NULL, NULL, timeoutp);
            err = errno;
            if(PyOS_InputHook) PyOS_InputHook();
        }

        if (has_input > 0) {
            rl_callback_read_char();
        }
        else if (err == EINTR) {
            int s;
#ifdef WITH_THREAD
            PyEval_RestoreThread(_PyOS_ReadlineTState);
#endif
            s = PyErr_CheckSignals();
#ifdef WITH_THREAD
            PyEval_SaveThread();
#endif
            if (s < 0) {
                rl_free_line_state();
                rl_cleanup_after_signal();
                rl_callback_handler_remove();
                *signal = 1;
                completed_input_string = NULL;
            }
        }
    }

    return completed_input_string;
}
Esempio n. 12
0
void ReadLineAgent::make_sane()
{
#if WITH_READLINE
    // No need to read any longer
    rl_callback_handler_remove();
#endif
    current_prompter = 0;
}
Esempio n. 13
0
int tty_cmd(int argc, char **argv)
{
	g_context.ttymode = 1;
	rl_callback_handler_remove();
	rl_callback_handler_install("", cli_handler);

	return 0;
}
Esempio n. 14
0
void
gdb_rl_callback_handler_remove (void)
{
  gdb_assert (current_ui == main_ui);

  rl_callback_handler_remove ();
  callback_handler_installed = 0;
}
Esempio n. 15
0
void ssc_input_remove_handler(void)
{
#if USE_READLINE
  rl_callback_handler_remove();
#else
  /* nop */
#endif
  ssc_input_handler_f = NULL;
}
Esempio n. 16
0
void
cleanup(void)
{
  if (init)
    return;

  input_hide();
  rl_callback_handler_remove();
}
Esempio n. 17
0
/*
  Unregister the current readline handler and pop it from R's readline
  stack, followed by re-registering the previous one.
*/
static void popReadline(void)
{
  if(ReadlineStack.current > -1) {
     rl_callback_handler_remove();
     ReadlineStack.fun[ReadlineStack.current--] = NULL;
     if(ReadlineStack.current > -1 && ReadlineStack.fun[ReadlineStack.current])
	rl_callback_handler_install("", ReadlineStack.fun[ReadlineStack.current]);
  }
}
Esempio n. 18
0
File: client.c Progetto: jpmuga/bird
void
cleanup(void)
{
  if (input_initialized)
    {
      input_initialized = 0;
      input_hide();
      rl_callback_handler_remove();
    }
}
Esempio n. 19
0
int close_cmd(int argc, char **argv)
{
	if(g_context.args.script == 0)
	{
		rl_callback_handler_remove();
		rl_callback_handler_install("", cli_handler);
	}
	g_context.exit = 1;
	return 0;
}
Esempio n. 20
0
void
console_exit(void)
{
#ifdef	USE_READLINE
  rl_callback_handler_remove();
#if RL_VERSION_MAJOR >= 4
	rl_cleanup_after_signal();
#endif
	rl_reset_terminal(NULL);
#endif
}
Esempio n. 21
0
    int main() {

        printf("Start.\n");
	rl_bind_key(RETURN, io_handle_enter);
        rl_callback_handler_install(prompt, handle_line);

        while (running) {
            usleep(10);
            rl_callback_read_char();
        }
        rl_callback_handler_remove();
    }
Esempio n. 22
0
void ncl_finalize(void)
{
	NCL_CMD_PRINTIN();

	/* Freeing command line interpretor context */
	ncl_cmd_finalize();

	rl_callback_handler_remove();

	if (gNclCtx.main_loop)
		g_main_loop_unref(gNclCtx.main_loop);
}
Esempio n. 23
0
Controller::~Controller()
{
	rl_callback_handler_remove();

	delete stdinWatcher;

	for(std::map<std::string, CommandParser*>::iterator iter = commands->begin(); iter != commands->end(); iter++)
	{
		delete iter->second;
	}
	delete commands;
}
Esempio n. 24
0
int main(int argc, char *argv[])
{
	GOptionContext *context;
	GError *err = NULL;
	struct sigaction sa;
	GIOChannel *io;
	GObexTransportType transport;

	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, options, NULL);

	g_option_context_parse(context, &argc, &argv, &err);
	if (err != NULL) {
		g_printerr("%s\n", err->message);
		g_error_free(err);
		g_option_context_free(context);
		exit(EXIT_FAILURE);
	}

	if (option_packet)
		transport = G_OBEX_TRANSPORT_PACKET;
	else
		transport = G_OBEX_TRANSPORT_STREAM;

	if (option_bluetooth)
		io = bluetooth_connect(transport);
	else
		io = unix_connect(transport);

	if (io == NULL) {
		g_option_context_free(context);
		exit(EXIT_FAILURE);
	}

	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = sig_term;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);

	main_loop = g_main_loop_new(NULL, FALSE);

	g_main_loop_run(main_loop);

	rl_callback_handler_remove();
	clear_history();
	g_obex_unref(obex);
	g_option_context_free(context);
	g_main_loop_unref(main_loop);

	exit(EXIT_SUCCESS);
}
Esempio n. 25
0
int main(int argc, char *argv[]) {
  char prompt[100];
  int readline_fd;
  fd_set fds;
  pid_t pid;

  pipe(fd); // [0]=read end, [1]=write end
  pid = fork();
  if (pid < 0) goto done;
  if (pid == (pid_t)0) { /* child here */
    sleep(10);
    close(fd[1]); // close write end
    return 0;
  }
  /* parent here */
  close(fd[1]);

  snprintf(prompt,sizeof(prompt),"('quit' to exit)%% ");
  using_history();

  /**************************************************
   * handle keyboard interactive input.
   *************************************************/
  rl_callback_handler_install(prompt, cb_linehandler);
  readline_fd = fileno(rl_instream);
  while(running) {
    FD_ZERO(&fds);
    FD_SET(readline_fd, &fds);
    FD_SET(fd[0], &fds);

    if ( select(FD_SETSIZE,&fds,NULL,NULL,NULL) < 0) {
      fprintf(stderr,"select: %s\n", strerror(errno));
      goto done;
    }

    /* handle user input, but terminate on server io/close */
    if (FD_ISSET(readline_fd, &fds)) rl_callback_read_char();
    if (FD_ISSET(fd[0], &fds)) { 
      fprintf(stderr,"Connection closed.\n");
      running=0;
    }
  }

 done:
  rl_callback_handler_remove();
  close(fd[0]); // close read end of pipe
  return 0;
}
Esempio n. 26
0
void
readline_status_mode_exit (void)
{
	Keymap active;

	g_assert (cli_context_in_status (readline_cli_ctx, CLI_ACTION_STATUS_REFRESH));

	active = rl_get_keymap ();

	rl_set_keymap (rl_get_keymap_by_name (readline_keymap));
	rl_discard_keymap (active);

	rl_callback_handler_remove ();
	g_free (readline_keymap);
	status_free (cli_context_status_entry (readline_cli_ctx)); // TODO: handle via cli_context_free or somesuch?
	cli_context_status_mode_exit (readline_cli_ctx);
}
Esempio n. 27
0
void ReadLineAgent::prompt(const string& prompt_string)
{
#if WITH_READLINE
    if (inputIsTerminal())
    {
	// Prompt using PROMPT_STRING
	rl_callback_handler_remove();
	rl_callback_handler_install(prompt_string.chars(),
				    readline_handler);
	current_prompter = this;
	return;
    }
#endif

    write(prompt_string.chars(), prompt_string.length());
    current_prompter = 0;
}
Esempio n. 28
0
File: loop.c Progetto: BUSHA/tg
void net_loop (int flags, int (*is_end)(void)) {
  while (!is_end ()) {
    struct pollfd fds[101];
    int cc = 0;
    if (flags & 3) {
      fds[0].fd = 0;
      fds[0].events = POLLIN;
      cc ++;
    }

    write_state_file ();
    int x = connections_make_poll_array (fds + cc, 101 - cc) + cc;
    double timer = next_timer_in ();
    if (timer > 1000) { timer = 1000; }
    if (poll (fds, x, timer) < 0) {
      work_timers ();
      continue;
    }
    work_timers ();
    if ((flags & 3) && (fds[0].revents & POLLIN)) {
      unread_messages = 0;
      if (flags & 1) {
        rl_callback_read_char ();
      } else {
        char *line = 0;        
        size_t len = 0;
        assert (getline (&line, &len, stdin) >= 0);
        got_it (line, strlen (line));
      }
    }
    connections_poll_result (fds + cc, x - cc);
    #ifdef USE_LUA
      lua_do_all ();
    #endif
    if (safe_quit && !queries_num) {
      printf ("All done. Exit\n");
      rl_callback_handler_remove ();
      exit (0);
    }
    if (unknown_user_list_pos) {
      do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list);
      unknown_user_list_pos = 0;
    }   
  }
}
Esempio n. 29
0
/* Disable command input through the standard CLI channels.  Used in
   the suspend proc for interpreters that use the standard gdb readline
   interface, like the cli & the mi.  */
void
gdb_disable_readline (void)
{
  /* FIXME - It is too heavyweight to delete and remake these every
     time you run an interpreter that needs readline.  It is probably
     better to have the interpreters cache these, which in turn means
     that this needs to be moved into interpreter specific code.  */

#if 0
  ui_file_delete (gdb_stdout);
  ui_file_delete (gdb_stderr);
  gdb_stdlog = NULL;
  gdb_stdtarg = NULL;
#endif

  rl_callback_handler_remove ();
  delete_file_handler (input_fd);
}
Esempio n. 30
0
/* save readline internal state in rl_state, redisplay the prompt
   (so that client output gets printed at the right place) */
void
save_rl_state()
{
  free(saved_rl_state.input_buffer); /* free(saved_rl_state.raw_prompt) */;
  saved_rl_state.input_buffer = mysavestring(rl_line_buffer);
  /* saved_rl_state.raw_prompt = mysavestring(rl_prompt); */
 
  saved_rl_state.point = rl_point;      /* and point    */
  rl_line_buffer[0] = '\0';
  if (saved_rl_state.already_saved)
    return;
  saved_rl_state.already_saved = 1;
  rl_delete_text(0, rl_end);    /* clear line  (after prompt) */
  rl_point = 0;
  my_redisplay();               /* and redisplay (this time without user input, cf the comments for the line_handler() function below) */
  rl_callback_handler_remove(); /* restore original terminal settings */
  rl_deprep_terminal();

}