Exemplo n.º 1
0
/* Ask user a y-or-n question and return 1 iff answer is yes.
 * Takes three args which are given to printf to print the question.
 * The first, a control string, should end in "? ".
 * It should NOT say how to answer, because we do that here. */
int query(char *ctlstr, int arg1, int arg2)
{
  /*FIXME: move this function to use a variadic argument list */
  register int answer;

  /* Automatically answer "yes" if input is not from a terminal. */
#if 0
  if (!input_from_terminal_p())
    return 1;
#endif /* 0 */

  while (1) {
      printf("%s %i%i", ctlstr, arg1, arg2);
      printf("(y or n) ");
      fflush(stdout);
      answer = fgetc(stdin);
      clearerr(stdin);		/* in case of C-d */
      if (answer != '\n') {
          while (fgetc(stdin) != '\n') {
              clearerr(stdin);
          }
      }
      if (answer >= 'a') {
          answer -= 040;
      }
      if (answer == 'Y') {
          return 1;
      }
      if (answer == 'N') {
          return 0;
      }
      printf("Please answer y or n.\n");
  }
}
Exemplo n.º 2
0
static int
tui_query_hook (const char * msg, va_list argp)
{
  int retval;
  int ans2;
  int answer;

  /* Automatically answer "yes" if input is not from a terminal.  */
  if (!input_from_terminal_p ())
    return 1;

  echo ();
  while (1)
    {
      wrap_here ("");		/* Flush any buffered output */
      gdb_flush (gdb_stdout);

      vfprintf_filtered (gdb_stdout, msg, argp);
      printf_filtered ("(y or n) ");

      wrap_here ("");
      gdb_flush (gdb_stdout);

      answer = tui_getc (stdin);
      clearerr (stdin);		/* in case of C-d */
      if (answer == EOF)	/* C-d */
	{
	  retval = 1;
	  break;
	}
      /* Eat rest of input line, to EOF or newline */
      if (answer != '\n')
	do
	  {
            ans2 = tui_getc (stdin);
	    clearerr (stdin);
	  }
	while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');

      if (answer >= 'a')
	answer -= 040;
      if (answer == 'Y')
	{
	  retval = 1;
	  break;
	}
      if (answer == 'N')
	{
	  retval = 0;
	  break;
	}
      printf_filtered ("Please answer y or n.\n");
    }
  noecho ();
  return retval;
}
Exemplo n.º 3
0
char *
handle_line_of_input (struct buffer *cmd_line_buffer,
		      char *rl, int repeat, char *annotation_suffix)
{
  char *p1;
  char *cmd;

  if (rl == NULL)
    return (char *) EOF;

  cmd = command_line_append_input_line (cmd_line_buffer, rl);
  if (cmd == NULL)
    return NULL;

  /* We have a complete command line now.  Prepare for the next
     command, but leave ownership of memory to the buffer .  */
  cmd_line_buffer->used_size = 0;

  if (annotation_level > 1 && instream == stdin)
    {
      printf_unfiltered (("\n\032\032post-"));
      puts_unfiltered (annotation_suffix);
      printf_unfiltered (("\n"));
    }

#define SERVER_COMMAND_PREFIX "server "
  if (startswith (cmd, SERVER_COMMAND_PREFIX))
    {
      /* Note that we don't set `saved_command_line'.  Between this
         and the check in dont_repeat, this insures that repeating
         will still do the right thing.  */
      return cmd + strlen (SERVER_COMMAND_PREFIX);
    }

  /* Do history expansion if that is wished.  */
  if (history_expansion_p && instream == stdin
      && ISATTY (instream))
    {
      char *history_value;
      int expanded;

      expanded = history_expand (cmd, &history_value);
      if (expanded)
	{
	  size_t len;

	  /* Print the changes.  */
	  printf_unfiltered ("%s\n", history_value);

	  /* If there was an error, call this function again.  */
	  if (expanded < 0)
	    {
	      xfree (history_value);
	      return cmd;
	    }

	  /* history_expand returns an allocated string.  Just replace
	     our buffer with it.  */
	  len = strlen (history_value);
	  xfree (buffer_finish (cmd_line_buffer));
	  cmd_line_buffer->buffer = history_value;
	  cmd_line_buffer->buffer_size = len + 1;
	  cmd = history_value;
	}
    }

  /* If we just got an empty line, and that is supposed to repeat the
     previous command, return the previously saved command.  */
  for (p1 = cmd; *p1 == ' ' || *p1 == '\t'; p1++)
    ;
  if (repeat && *p1 == '\0')
    return saved_command_line;

  /* Add command to history if appropriate.  Note: lines consisting
     solely of comments are also added to the command history.  This
     is useful when you type a command, and then realize you don't
     want to execute it quite yet.  You can comment out the command
     and then later fetch it from the value history and remove the
     '#'.  The kill ring is probably better, but some people are in
     the habit of commenting things out.  */
  if (*cmd != '\0' && input_from_terminal_p ())
    gdb_add_history (cmd);

  /* Save into global buffer if appropriate.  */
  if (repeat)
    {
      xfree (saved_command_line);
      saved_command_line = xstrdup (cmd);
      return saved_command_line;
    }
  else
    return cmd;
}
Exemplo n.º 4
0
/* NOTE: 1999-04-30 This is the asynchronous version of the
   command_line_input function; command_line_input will become
   obsolete once we use the event loop as the default mechanism in
   GDB.  */
static void
command_line_handler (char *rl)
{
    static char *linebuffer = 0;
    static unsigned linelength = 0;
    char *p;
    char *p1;
    char *nline;
    int repeat = (instream == stdin);

    if (annotation_level > 1 && instream == stdin)
    {
        printf_unfiltered (("\n\032\032post-"));
        puts_unfiltered (async_annotation_suffix);
        printf_unfiltered (("\n"));
    }

    if (linebuffer == 0)
    {
        linelength = 80;
        linebuffer = (char *) xmalloc (linelength);
    }

    p = linebuffer;

    if (more_to_come)
    {
        strcpy (linebuffer, readline_input_state.linebuffer);
        p = readline_input_state.linebuffer_ptr;
        xfree (readline_input_state.linebuffer);
        more_to_come = 0;
    }

#ifdef STOP_SIGNAL
    if (job_control)
        signal (STOP_SIGNAL, handle_stop_sig);
#endif

    /* Make sure that all output has been output.  Some machines may let
       you get away with leaving out some of the gdb_flush, but not
       all.  */
    wrap_here ("");
    gdb_flush (gdb_stdout);
    gdb_flush (gdb_stderr);

    if (source_file_name != NULL)
        ++source_line_number;

    /* If we are in this case, then command_handler will call quit
       and exit from gdb.  */
    if (!rl || rl == (char *) EOF)
    {
        command_handler (0);
        return;			/* Lint.  */
    }
    if (strlen (rl) + 1 + (p - linebuffer) > linelength)
    {
        linelength = strlen (rl) + 1 + (p - linebuffer);
        nline = (char *) xrealloc (linebuffer, linelength);
        p += nline - linebuffer;
        linebuffer = nline;
    }
    p1 = rl;
    /* Copy line.  Don't copy null at end.  (Leaves line alone
       if this was just a newline).  */
    while (*p1)
        *p++ = *p1++;

    xfree (rl);			/* Allocated in readline.  */

    if (p > linebuffer && *(p - 1) == '\\')
    {
        *p = '\0';
        p--;			/* Put on top of '\'.  */

        readline_input_state.linebuffer = xstrdup (linebuffer);
        readline_input_state.linebuffer_ptr = p;

        /* We will not invoke a execute_command if there is more
        input expected to complete the command.  So, we need to
         print an empty prompt here.  */
        more_to_come = 1;
        display_gdb_prompt ("");
        return;
    }

#ifdef STOP_SIGNAL
    if (job_control)
        signal (STOP_SIGNAL, SIG_DFL);
#endif

#define SERVER_COMMAND_LENGTH 7
    server_command =
        (p - linebuffer > SERVER_COMMAND_LENGTH)
        && strncmp (linebuffer, "server ", SERVER_COMMAND_LENGTH) == 0;
    if (server_command)
    {
        /* Note that we don't set `line'.  Between this and the check in
           dont_repeat, this insures that repeating will still do the
           right thing.  */
        *p = '\0';
        command_handler (linebuffer + SERVER_COMMAND_LENGTH);
        display_gdb_prompt (0);
        return;
    }

    /* Do history expansion if that is wished.  */
    if (history_expansion_p && instream == stdin
            && ISATTY (instream))
    {
        char *history_value;
        int expanded;

        *p = '\0';		/* Insert null now.  */
        expanded = history_expand (linebuffer, &history_value);
        if (expanded)
        {
            /* Print the changes.  */
            printf_unfiltered ("%s\n", history_value);

            /* If there was an error, call this function again.  */
            if (expanded < 0)
            {
                xfree (history_value);
                return;
            }
            if (strlen (history_value) > linelength)
            {
                linelength = strlen (history_value) + 1;
                linebuffer = (char *) xrealloc (linebuffer, linelength);
            }
            strcpy (linebuffer, history_value);
            p = linebuffer + strlen (linebuffer);
        }
        xfree (history_value);
    }

    /* If we just got an empty line, and that is supposed to repeat the
       previous command, return the value in the global buffer.  */
    if (repeat && p == linebuffer && *p != '\\')
    {
        command_handler (saved_command_line);
        display_gdb_prompt (0);
        return;
    }

    for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
    if (repeat && !*p1)
    {
        command_handler (saved_command_line);
        display_gdb_prompt (0);
        return;
    }

    *p = 0;

    /* Add line to history if appropriate.  */
    if (*linebuffer && input_from_terminal_p ())
        add_history (linebuffer);

    /* Note: lines consisting solely of comments are added to the command
       history.  This is useful when you type a command, and then
       realize you don't want to execute it quite yet.  You can comment
       out the command and then later fetch it from the value history
       and remove the '#'.  The kill ring is probably better, but some
       people are in the habit of commenting things out.  */
    if (*p1 == '#')
        *p1 = '\0';			/* Found a comment.  */

    /* Save into global buffer if appropriate.  */
    if (repeat)
    {
        if (linelength > saved_command_line_size)
        {
            saved_command_line = xrealloc (saved_command_line, linelength);
            saved_command_line_size = linelength;
        }
        strcpy (saved_command_line, linebuffer);
        if (!more_to_come)
        {
            command_handler (saved_command_line);
            display_gdb_prompt (0);
        }
        return;
    }

    command_handler (linebuffer);
    display_gdb_prompt (0);
    return;
}