void SC_TerminalClient::onInputRead(const boost::system::error_code &error, std::size_t bytes_transferred)
{
	if (error == boost::asio::error::operation_aborted) {
		postfl("SCLang Input: Quit requested\n");
		return;
	}

	if (error == boost::asio::error::eof) {
		postfl("SCLang Input: EOF. Will quit.\n");
		onQuit(0);
		return;
	}

	if (error) {
		postfl("SCLang Input: %s.\n", error.message().c_str());
		onQuit(1);
		return;
	}

	if (!error) {
#if HAVE_READLINE
		if (mUseReadline) {
			rl_callback_read_char();
			startInputRead();
			return;
		}
#endif
		pushCmdLine( inputBuffer.data(), bytes_transferred );
	}
}
Esempio n. 2
0
File: client.c Progetto: jpmuga/bird
static void
select_loop(void)
{
  int rv;
  while (1)
    {
      FD_ZERO(&select_fds);

      if (cstate != STATE_CMD_USER)
	FD_SET(server_fd, &select_fds);
      if (cstate != STATE_CMD_SERVER)
	FD_SET(0, &select_fds);

      rv = select(server_fd+1, &select_fds, NULL, NULL, NULL);
      if (rv < 0)
	{
	  if (errno == EINTR)
	    continue;
	  else
	    die("select: %m");
	}

      if (FD_ISSET(server_fd, &select_fds))
	{
	  server_read();
	  update_state();
	}

      if (FD_ISSET(0, &select_fds))
	{
	  rl_callback_read_char();
	  update_state();
	}
    }
}
void *SC_TerminalClient::readlineFunc( void *arg )
{
	readlineInit();

	SC_TerminalClient *client = static_cast<SC_TerminalClient*>(arg);

	HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
	HANDLE hnds[] = { client->mQuitInputEvent, hStdIn };

	bool shouldRun = true;
	while (shouldRun) {
		DWORD result = WaitForMultipleObjects( 2, hnds, false, INFINITE );

		if( result == WAIT_FAILED ) {
			postfl("readline: wait error.\n");
			client->onQuit(1);
			break;
		}

		int hIndex = result - WAIT_OBJECT_0;

		if( hIndex == 0 ) {
			postfl("readline: quit requested.\n");
			break;
		}

		if( hIndex == 1 ) {
			rl_callback_read_char();
		}
	}

	postfl("readline: stopped.\n");

	return NULL;
}
Esempio n. 4
0
/* Wrapper function for calling into the readline library.  The event
   loop expects the callback function to have a paramter, while
   readline expects none.  */
static void
rl_callback_read_char_wrapper (gdb_client_data client_data)
{
  rl_callback_read_char ();
  if (after_char_processing_hook)
    (*after_char_processing_hook) ();
}
Esempio n. 5
0
static void poll( void )
{
	fd_set rf, ef;
	int n;
	
	for(;;) {
		FD_ZERO(&rf);
		FD_ZERO(&ef);
		if( !waiting ){
			FD_SET( 0, &rf );
			FD_SET( 0, &ef );
		}
		FD_SET( packet_fd, &rf );
		FD_SET( packet_fd, &ef );
		n = select( packet_fd + 1, &rf, 0, &ef, 0 );

		if( n < 0 ) {
			perror( "select" );
			exit( EXIT_FAILURE );
		}
		
		if( FD_ISSET( 0, &rf ) || FD_ISSET( 0, &ef )) 
			rl_callback_read_char();
				
		if( FD_ISSET( packet_fd, &rf ) || FD_ISSET( packet_fd, &ef ))
			read_packet();
	}
}
Esempio n. 6
0
void
console_read_char(void)
{
#ifdef	USE_READLINE
	rl_callback_read_char();
#endif
}
Esempio n. 7
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. 8
0
File: bosh-main.c Progetto: rib/Bosh
gboolean
input_available_cb (GIOChannel *input, GIOCondition condition, gpointer data)
{
  g_return_val_if_fail (condition == G_IO_IN, TRUE);
  rl_callback_read_char ();
  return TRUE;
}
Esempio n. 9
0
int cli_init(struct parser_state *_state)
{
	const char *home;

	rl_readline_name = "nft";
	rl_instream  = stdin;
	rl_outstream = stdout;

	rl_callback_handler_install("nft> ", cli_complete);
	rl_attempted_completion_function = cli_completion;

	home = getenv("HOME");
	if (home == NULL)
		home = "";
	snprintf(histfile, sizeof(histfile), "%s/%s", home, CMDLINE_HISTFILE);

	read_history(histfile);
	history_set_pos(history_length);

	state	= _state;
	scanner = scanner_init(state);

	while (!eof)
		rl_callback_read_char();
	return 0;
}
Esempio n. 10
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;
}
void *SC_TerminalClient::readlineFunc( void *arg )
{
	readlineInit();

	SC_TerminalClient *client = static_cast<SC_TerminalClient*>(arg);

	fd_set fds;
	FD_ZERO(&fds);

	while(true) {
		FD_SET(STDIN_FD, &fds);
		FD_SET(client->mInputCtlPipe[0], &fds);

		if( select(FD_SETSIZE, &fds, NULL, NULL, NULL) < 0 ) {
			if( errno == EINTR ) continue;
			postfl("readline: select() error:\n%s\n", strerror(errno));
			client->onQuit(1);
			break;
		}

		if( FD_ISSET(client->mInputCtlPipe[0], &fds) ) {
			postfl("readline: quit requested\n");
			break;
		}

		if( FD_ISSET(STDIN_FD, &fds) ) {
			rl_callback_read_char();
		}
	}

	postfl("readline: stopped.\n");

	return NULL;
}
Esempio n. 12
0
static void
gdb_rl_callback_read_char_wrapper (gdb_client_data client_data)
{
  struct gdb_exception gdb_expt = exception_none;

  /* C++ exceptions can't normally be thrown across readline (unless
     it is built with -fexceptions, but it won't by default on many
     ABIs).  So we instead wrap the readline call with a sjlj-based
     TRY/CATCH, and rethrow the GDB exception once back in GDB.  */
  TRY_SJLJ
    {
      rl_callback_read_char ();
      if (after_char_processing_hook)
	(*after_char_processing_hook) ();
    }
  CATCH_SJLJ (ex, RETURN_MASK_ALL)
    {
      gdb_expt = ex;
    }
  END_CATCH_SJLJ

  /* Rethrow using the normal EH mechanism.  */
  if (gdb_expt.reason < 0)
    throw_exception (gdb_expt);
}
Esempio n. 13
0
int
main (int c, char **v)
{
  fd_set fds;
  int r;

  /* Install the line handler. */
  rl_callback_handler_install (prompt, cb_linehandler);

  /* Enter a simple event loop.  This waits until something is available
     to read on readline's input stream (defaults to standard input) and
     calls the builtin character read callback to read it.  It does not
     have to modify the user's terminal settings. */
  running = 1;
  while (running)
    {
      FD_ZERO (&fds);
      FD_SET (fileno (rl_instream), &fds);    

      r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
      if (r < 0 && errno != EINTR)
	{
	  perror ("rltest: select");
	  rl_callback_handler_remove ();
	  break;
	}

      if (FD_ISSET (fileno (rl_instream), &fds))
	rl_callback_read_char ();
    }

  printf ("rltest: Event loop has exited\n");
  return 0;
}
Esempio n. 14
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. 15
0
int
cli_rl_stdin (int fd, int idx, void *data,
              int poll_out, int poll_in, int poll_err)
{
        rl_callback_read_char ();

        return 0;
}
Esempio n. 16
0
void jl_readBuffer(char *base, ssize_t nread)
{
    char *start = base;
    while(*start != 0 && nread > 0) {
        rl_stuff_char(*start);
        start++;
        nread--;
    }
    rl_callback_read_char();
}
Esempio n. 17
0
static void stdin_read_callback (evutil_socket_t fd, short what, void *arg) {
  if (!readline_disabled && !read_one_string) {
    rl_callback_read_char ();
    return;
  }
  if (read_one_string) {
    char c;
    int r = read (0, &c, 1);
    if (r <= 0) {
      perror ("read");
      delete_stdin_event = 1;
      return;
    }
    if (c == '\n' || c == '\r') {
      one_string[one_string_len] = 0;
      one_string_read_end ();
      return;
    }
    if (one_string_len < MAX_ONE_STRING_LEN) {
      one_string[one_string_len ++] = c;
      if (!(one_string_flags & 1)) {
        printf ("%c", c);
        fflush (stdout);
      }
    }
    return;
  }

  if (line_buffer_pos == line_buffer_size) {
    line_buffer = realloc (line_buffer, line_buffer_size * 2 + 100);
    assert (line_buffer);
    line_buffer_size = line_buffer_size * 2 + 100;
    assert (line_buffer);
  }
  int r = read (0, line_buffer + line_buffer_pos, line_buffer_size - line_buffer_pos);
  if (r <= 0) {
    perror ("read");
    delete_stdin_event = 1;
    return;
  }
  line_buffer_pos += r;

  while (1) {
    int p = 0;
    while (p < line_buffer_pos && line_buffer[p] != '\n') { p ++; }
    if (p < line_buffer_pos) {
      line_buffer[p] = 0;
      interpreter (line_buffer);
      memmove (line_buffer, line_buffer + p + 1, line_buffer_pos - p - 1);
      line_buffer_pos -= (p + 1);
    } else {
      break;
    }
  }
}
Esempio n. 18
0
File: loop.c Progetto: AmesianX/tg
static void stdin_read_callback_all (int arg, short what, struct event *self) {
  if (!readline_disabled) {
    if (((long)arg) & 1) {
      rl_callback_read_char ();
    } else {
      char *line = 0;        
      size_t len = 0;
      assert (getline (&line, &len, stdin) >= 0);
      got_it (line, strlen (line));
    }
  } else {
    while (1) {
      if (line_buffer_pos == line_buffer_size) {
        line_buffer = realloc (line_buffer, line_buffer_size * 2 + 100);
        assert (line_buffer);
        line_buffer_size = line_buffer_size * 2 + 100;
        assert (line_buffer);
      }
      int r = read (0, line_buffer + line_buffer_pos, line_buffer_size - line_buffer_pos);
      //logprintf ("r = %d, size = %d, pos = %d, what = 0x%x, fd = %d\n", r, line_buffer_size, line_buffer_pos, (int)what, fd);
      if (r < 0) {
        perror ("read");
        delete_stdin_event = 1;
        break;
      }
      if (r == 0) {
        //struct event *ev = event_base_get_running_event (TLS->ev_base);
        //event_del (ev);
        //event_del (self);
        
        delete_stdin_event = 1;
        break;
      }
      line_buffer_pos += r;

      while (1) {
        int p = 0;
        while (p < line_buffer_pos && line_buffer[p] != '\n') { p ++; }
        if (p < line_buffer_pos) {
          if (((long)arg) & 1) {
            line_buffer[p] = 0;
            interpreter (line_buffer);
          } else {
            got_it (line_buffer, p + 1);
          }
          memmove (line_buffer, line_buffer + p + 1, line_buffer_pos - p - 1);
          line_buffer_pos -= (p + 1);
        } else {
          break;
        }
      }
      break;
    }
  }
}
Esempio n. 19
0
static gboolean ncl_prv_kbinput_cb(GIOChannel *source, GIOCondition condition,
				   gpointer data)
{
	rl_callback_read_char();
#ifdef HAVE_LIBEDIT
	/* Editline bug workaround: handler install with the original prompt
	   corrects EL_UNBUFFERED state without side-effects. */
	rl_callback_handler_install(NCL_PROMPT, ncl_parse_line);
#endif
	return TRUE;
}
Esempio n. 20
0
File: rline.cpp Progetto: cgdb/cgdb
int rline_rl_callback_read_char(struct rline *rline)
{
    if (!rline)
        return -1;

    /* Capture the last function used here.  */
    rline->rline_rl_last_func = rl_last_func;

    rl_callback_read_char();

    return 0;
}
Esempio n. 21
0
static gboolean prompt_read(GIOChannel *chan, GIOCondition cond,
							gpointer user_data)
{
	if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
		g_io_channel_unref(chan);
		return FALSE;
	}

	rl_callback_read_char();

	return TRUE;
}
Esempio n. 22
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. 23
0
int
cli_rl_stdin (int fd, int idx, int gen, void *data,
              int poll_out, int poll_in, int poll_err)
{
        struct cli_state *state = NULL;

        state = data;

        rl_callback_read_char ();

        event_handled (state->ctx->event_pool, fd, idx, gen);

        return 0;
}
Esempio n. 24
0
void readline_constructor_impl::impl::chars_available(
  boost::system::error_code const& ec,
  size_t bytes_transferred
)
{
  static_cast<void>(bytes_transferred);
  assert(bytes_transferred == 0);
  if (ec) {
    stop();
  } else {
    rl_callback_read_char();
    wait_for_chars();
  }
}
Esempio n. 25
0
static int cli_stdin_fn(sd_event_source *source,
			int fd,
			uint32_t mask,
			void *data)
{
	if (mask & EPOLLIN) {
		rl_callback_read_char();
		return 0;
	}

	if (mask & (EPOLLHUP | EPOLLERR))
		sd_event_exit(cli_event, 0);

	return 0;
}
Esempio n. 26
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. 27
0
File: io.c Progetto: dpc/xmppconsole
void io_nonblock_handle() {
    int count;
    struct timeval t;

    t.tv_sec = 0;
    t.tv_usec = 0;

    FD_SET(STDIN_FILENO, &fds);
    count = select(FD_SETSIZE, &fds, NULL, NULL, &t);
    if (count < 0) {
        exit(1);
    } else if (count == 0) {
        return;
    }
    rl_callback_read_char();
}
Esempio n. 28
0
File: mngr.c Progetto: jiangli/lacp
int
main_loop (void)
{
    fd_set readfds;
    int rc, numfds, sock, kkk;

    rl_callback_handler_install (get_prompt (), rl_read_cli);

    sock = GET_FILE_DESCRIPTOR (&main_sock);

    do {
        numfds = -1;
        FD_ZERO (&readfds);

        kkk = 0;			/* stdin for commands */
        FD_SET (kkk, &readfds);
        if (kkk > numfds)
            numfds = kkk;

        FD_SET (sock, &readfds);
        if (sock > numfds)
            numfds = sock;

        if (numfds < 0)
            numfds = 0;
        else
            numfds++;

        rc = select (numfds, &readfds, NULL, NULL, NULL);
        if (rc < 0) {		// Error
            if (EINTR == errno)
                continue;		// don't break
            printf ("FATAL_MODE:select failed: %s\n", strerror (errno));
            return -2;
        }

        if (FD_ISSET (0, &readfds)) {
            rl_callback_read_char ();
        }

        if (FD_ISSET (sock, &readfds)) {
            shutdown_flag |= read_uid ();
        }

    } while (!shutdown_flag);
    return 0;
}
Esempio n. 29
0
void ssc_input_read_char(int input_fd)
{
#if USE_READLINE
    if (ssc_input_handler_f)
        rl_callback_read_char();
#else
    char buf[65535];
    char * ptr = buf;
    ssize_t n;

    // important: there might be more than one commands in buf, but each command ends in '$'
    n = read(input_fd, buf, sizeof(buf) - 1);
    buf[n] = '\0';

    char * token;
    //int pos = 0;
    char delimiter = '$';
    if (strchr(buf, delimiter) == NULL) {
        printf("WARNING: Couldn't find delimiter char in the PIPE input -maybe buffer size is small??");
        exit(1);
    }

    while ((token = strsep(&ptr, "$")) != NULL) {
        if (n < 0) {
            perror("input: read");
        }
        else if (n > 0) {
            if (!strcmp(token, "")) {
                break;
            }
            char *tmpbuf;
            // not sure why n - 1 was used instead on n. Stange thing is that n - 1 worked in Linux but not in iOS
            ///buf[n - 1] = 0;
            //buf[n] = 0;
            tmpbuf = strdup((const char*)token);
            if (ssc_input_handler_f) {
                //printf("\n@@@@@@@@@ App >> Sofia: %s\n", tmpbuf);
                ssc_input_handler_f(tmpbuf);
            }
            ssc_input_refresh();
        }
    }


#endif
}
Esempio n. 30
0
char *
inp_readline(void)
{
    free(inp_line);
    inp_line = NULL;
    p_rl_timeout.tv_sec = inp_timeout / 1000;
    p_rl_timeout.tv_usec = inp_timeout % 1000 * 1000;
    FD_ZERO(&fds);
    FD_SET(fileno(rl_instream), &fds);
    errno = 0;
    r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout);
    if (r < 0) {
        if (errno != EINTR) {
            char *err_msg = strerror(errno);
            log_error("Readline failed: %s", err_msg);
        }
        return NULL;
    }

    if (FD_ISSET(fileno(rl_instream), &fds)) {
        rl_callback_read_char();

        if (rl_line_buffer &&
                rl_line_buffer[0] != '/' &&
                rl_line_buffer[0] != '\0' &&
                rl_line_buffer[0] != '\n') {
            prof_handle_activity();
        }

        ui_reset_idle_time();
        if (!get_password) {
            _inp_write(rl_line_buffer, rl_point);
        }
        inp_nonblocking(TRUE);
    } else {
        inp_nonblocking(FALSE);
        prof_handle_idle();
    }

    if (inp_line) {
        return strdup(inp_line);
    } else {
        return NULL;
    }
}