Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Patrick Palka <patrick@parcs.ath.cx>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Consolidate the custom TUI query hook with default query hook
Date: Thu, 08 Jan 2015 15:50:00 -0000	[thread overview]
Message-ID: <54AEA745.2060703@redhat.com> (raw)
In-Reply-To: <1420730248-18521-1-git-send-email-patrick@parcs.ath.cx>

On 01/08/2015 03:17 PM, Patrick Palka wrote:
> Hi Pedro,
> 
> This is what I have so far.  It seems to work well.  Thoughts?

Nice!

> --- a/gdb/utils.c
> +++ b/gdb/utils.c
> @@ -1198,12 +1198,11 @@ compile_rx_or_error (regex_t *pattern, const char *rx, const char *message)
>  static int ATTRIBUTE_PRINTF (1, 0)
>  defaulted_query (const char *ctlstr, const char defchar, va_list args)
>  {
> -  int answer;
>    int ans2;
>    int retval;
>    int def_value;
>    char def_answer, not_def_answer;
> -  char *y_string, *n_string, *question;
> +  char *y_string, *n_string, *question, *prompt;
>    /* Used to add duration we waited for user to respond to
>       prompt_for_continue_wait_time.  */
>    struct timeval prompt_started, prompt_ended, prompt_delta;
> @@ -1263,62 +1262,31 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
>  
>    /* Format the question outside of the loop, to avoid reusing args.  */
>    question = xstrvprintf (ctlstr, args);
> +  prompt = xstrprintf ("%s%s(%s or %s) %s",

Add _() here, for the "or".

> -      printf_filtered (_("(%s or %s) "), y_string, n_string);

Notice here we had it.

> -
> -      if (annotation_level > 1)
> -	printf_filtered (("\n\032\032query\n"));
> +      char *response, answer = EOF;
>  
> -      wrap_here ("");
>        gdb_flush (gdb_stdout);
> +      response = gdb_readline_wrapper (prompt);
> +      if (response != NULL)
> +	answer = response[0];
> +      xfree (response);
>  
> -      answer = fgetc (stdin);
> -
> -      /* We expect fgetc to block until a character is read.  But
> -         this may not be the case if the terminal was opened with
> -         the NONBLOCK flag.  In that case, if there is nothing to
> -         read on stdin, fgetc returns EOF, but also sets the error
> -         condition flag on stdin and errno to EAGAIN.  With a true
> -         EOF, stdin's error condition flag is not set.
> -
> -         A situation where this behavior was observed is a pseudo
> -         terminal on AIX.  */
> -      while (answer == EOF && ferror (stdin) && errno == EAGAIN)
> -        {
> -          /* Not a real EOF.  Wait a little while and try again until
> -             we read something.  */
> -          clearerr (stdin);
> -          gdb_usleep (10000);
> -          answer = fgetc (stdin);
> -        }
> -
> -      clearerr (stdin);		/* in case of C-d */
>        if (answer == EOF)	/* C-d */
>  	{
>  	  printf_filtered ("EOF [assumed %c]\n", def_answer);
>  	  retval = def_value;
>  	  break;
>  	}

Can you move this a bit above, and write the check in
terms of response, like this?

        if (response == NULL)	/* C-d */
  	{
  	  printf_filtered ("EOF [assumed %c]\n", def_answer);
  	  retval = def_value;
  	  break;
  	}

I think that's a little bit clearer.  What got me to that was that
you made "answer" a char (from int), which may be signed or unsigned,
depending on host, and then the >= 'a' check further below looked
suspicious, though I see that it's unreachable for the EOF case.  I think
that way there'll no be reference to EOF at all in the
code (except in the printf string).

Other than that, if this passes testing, that it's OK with me.

Thanks for doing this.

-- 
Pedro Alves


  reply	other threads:[~2015-01-08 15:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08  3:51 [PATCH] TUI: rewrite tui_query_hook() Patrick Palka
2015-01-08 11:03 ` Pedro Alves
2015-01-08 12:40   ` Patrick Palka
2015-01-08 13:53     ` Pedro Alves
2015-01-08 14:10       ` Patrick Palka
2015-01-08 14:14         ` Patrick Palka
2015-01-08 14:25         ` Patrick Palka
2015-01-08 15:17   ` [PATCH] Consolidate the custom TUI query hook with default query hook Patrick Palka
2015-01-08 15:50     ` Pedro Alves [this message]
2015-01-08 13:31 ` [PATCH] TUI: rewrite tui_query_hook() Eli Zaretskii
2015-01-08 13:43   ` Patrick Palka
2015-01-08 13:57     ` Pedro Alves
2015-01-08 14:14     ` Eli Zaretskii
2015-01-08 14:27       ` Patrick Palka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54AEA745.2060703@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=patrick@parcs.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox