Beispiel #1
0
static char *read_with_no_readline (char *prompt, int noecho)
{
    char *line;
#ifdef REAL_UNIX_SYSTEM
    int stdin_is_noecho = 0;
#endif
    char buf[1024];
    char *b;

    fprintf (stdout, "%s", prompt);
    fflush (stdout);
    if (noecho)
    {
#ifdef REAL_UNIX_SYSTEM
        if (isatty (fileno(stdin)))
        {
            (void) SLsystem ("stty -echo");   /* yuk */
            stdin_is_noecho = 1;
        }
#endif
    }

    line = buf;
    while (NULL == fgets (buf, sizeof (buf), stdin))
    {
#ifdef EINTR
        if (errno == EINTR)
        {
            if (-1 == SLang_handle_interrupt ())
            {
                line = NULL;
                break;
            }
            continue;
        }
#endif
        line = NULL;
        break;
    }
#ifdef REAL_UNIX_SYSTEM
    if (stdin_is_noecho)
        (void) SLsystem ("stty echo");
#endif
    if (line == NULL)
        return NULL;

    /* Remove the final newline */
    b = line;
    while (*b && (*b != '\n'))
        b++;
    *b = 0;

    return SLmake_string (line);
}
Beispiel #2
0
static int system_intrinsic (char *s)
{
   return SLsystem (s);
}
Beispiel #3
0
static char *read_input_line (SLang_RLine_Info_Type *rline, char *prompt, int noecho)
{
   char *line;
#ifdef REAL_UNIX_SYSTEM
   int stdin_is_noecho = 0;
#endif

   if (Use_Readline == 0)
     {
	char buf[1024];
	char *b;

	fprintf (stdout, "%s", prompt); fflush (stdout);
	if (noecho)
	  {
#ifdef REAL_UNIX_SYSTEM
	     if (isatty (fileno(stdin)))
	       {
		  (void) SLsystem ("stty -echo");   /* yuk */
		  stdin_is_noecho = 1;
	       }
#endif
	  }

	line = buf;
	while (NULL == fgets (buf, sizeof (buf), stdin))
	  {
#ifdef EINTR
	     if (errno == EINTR)
	       {
		  if (-1 == SLang_handle_interrupt ())
		    {
		       line = NULL;
		       break;
		    }
		  continue;
	       }
#endif
	     line = NULL;
	     break;
	  }
#ifdef REAL_UNIX_SYSTEM
	if (stdin_is_noecho)
	  (void) SLsystem ("stty echo");
#endif
	if (line == NULL)
	  return NULL;

	/* Remove the final newline */
	b = line;
	while (*b && (*b != '\n'))
	  b++;
	*b = 0;

	return SLmake_string (line);
     }
#if SYSTEM_SUPPORTS_SIGNALS
   init_tty ();
#endif
#if USE_GNU_READLINE
   (void) rline;
   if (noecho == 0)
     rl_redisplay_function = rl_redisplay;
   else
     {
	/* FIXME: What is the proper way to implement this in GNU readline? */
	(void) fputs (prompt, stdout); (void) fflush (stdout);
	rl_redisplay_function = redisplay_dummy;
     }
   line = readline (prompt);
   rl_redisplay_function = rl_redisplay;
#else
   SLtt_get_screen_size ();
   SLrline_set_display_width (rline, SLtt_Screen_Cols);
   (void) add_sigwinch_handlers ();
   Active_Rline_Info = rline;
   (void) SLrline_set_echo (rline, (noecho == 0));
   line = SLrline_read_line (rline, prompt, NULL);
   Active_Rline_Info = NULL;
#endif
#if SYSTEM_SUPPORTS_SIGNALS
   reset_tty ();
#else
   fputs ("\r\n", stdout);
   fflush (stdout);
#endif
   return line;
}