Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Ingham <jingham@apple.com>
To: Andrew Cagney <cagney@gnu.org>
Cc: Daniel Jacobowitz <drow@mvista.com>, gdb-patches@sources.redhat.com
Subject: Re: report valid values for all errors for enum variables...
Date: Tue, 28 Oct 2003 19:35:00 -0000	[thread overview]
Message-ID: <07B0DBEF-097E-11D8-A22C-000A958F4C44@apple.com> (raw)
In-Reply-To: <3F9D4B94.7040502@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 18 bytes --]

Sure, how 'bout:


[-- Attachment #2: var_enum.patch --]
[-- Type: application/octet-stream, Size: 3125 bytes --]

Index: cli-setshow.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-setshow.c,v
retrieving revision 1.13
diff -p -r1.13 cli-setshow.c
*** cli-setshow.c	4 Aug 2003 17:08:23 -0000	1.13
--- cli-setshow.c	28 Oct 2003 19:31:08 -0000
*************** do_setshow_command (char *arg, int from_
*** 197,252 ****
  	  {
  	    int i;
  	    int len;
! 	    int nmatches;
  	    const char *match = NULL;
  	    char *p;
  
! 	    /* if no argument was supplied, print an informative error message */
! 	    if (arg == NULL)
  	      {
! 		char msg[1024];
! 		strcpy (msg, "Requires an argument. Valid arguments are ");
  		for (i = 0; c->enums[i]; i++)
  		  {
  		    if (i != 0)
! 		      strcat (msg, ", ");
! 		    strcat (msg, c->enums[i]);
  		  }
! 		strcat (msg, ".");
! 		error ("%s", msg);
  	      }
- 
- 	    p = strchr (arg, ' ');
- 
- 	    if (p)
- 	      len = p - arg;
- 	    else
- 	      len = strlen (arg);
- 
- 	    nmatches = 0;
- 	    for (i = 0; c->enums[i]; i++)
- 	      if (strncmp (arg, c->enums[i], len) == 0)
- 		{
- 		  if (c->enums[i][len] == '\0')
- 		    {
- 		      match = c->enums[i];
- 		      nmatches = 1;
- 		      break; /* exact match. */
- 		    }
- 		  else
- 		    {
- 		      match = c->enums[i];
- 		      nmatches++;
- 		    }
- 		}
- 
- 	    if (nmatches <= 0)
- 	      error ("Undefined item: \"%s\".", arg);
- 
- 	    if (nmatches > 1)
- 	      error ("Ambiguous item \"%s\".", arg);
- 
- 	    *(const char **) c->var = match;
  	  }
  	  break;
  	default:
--- 197,257 ----
  	  {
  	    int i;
  	    int len;
! 	    int nmatches = 0;
  	    const char *match = NULL;
  	    char *p;
  
! 	    if (arg != NULL)
  	      {
! 		p = strchr (arg, ' ');
! 		
! 		if (p)
! 		  len = p - arg;
! 		else
! 		  len = strlen (arg);
! 		
! 		nmatches = 0;
! 		for (i = 0; c->enums[i]; i++)
! 		  if (strncmp (arg, c->enums[i], len) == 0)
! 		    {
! 		      if (c->enums[i][len] == '\0')
! 			{
! 			  match = c->enums[i];
! 			  nmatches = 1;
! 			  break; /* exact match. */
! 			}
! 		      else
! 			{
! 			  match = c->enums[i];
! 			  nmatches++;
! 			}
! 		    }
! 	      }
! 	    if (nmatches == 1)
! 	      *(const char **) c->var = match;
! 	    else
! 	      {
! 		/* If there was an error, print an informative
! 		   error message.  */
! 		struct ui_file *tmp_error_stream = mem_fileopen ();
! 		make_cleanup_ui_file_delete (tmp_error_stream);
! 
! 		if (arg == NULL)
! 		  fprintf_unfiltered (tmp_error_stream, "Requires an argument.");
! 		else if (nmatches <= 0)
! 		  fprintf_unfiltered (tmp_error_stream, "Undefined item: \"%s\".", arg);		
! 		else if (nmatches > 1)
! 		  fprintf_unfiltered  (tmp_error_stream, "Ambiguous item \"%s\".", arg);
! 		fprintf_unfiltered (tmp_error_stream, " Valid values are ");
  		for (i = 0; c->enums[i]; i++)
  		  {
  		    if (i != 0)
! 		      fprintf_unfiltered (tmp_error_stream, ", ");
! 		    fprintf_unfiltered (tmp_error_stream, c->enums[i]);
  		  }
! 		fprintf_unfiltered (tmp_error_stream, ".");
! 		error_stream (tmp_error_stream);
  	      }
  	  }
  	  break;
  	default:

[-- Attachment #3: Type: text/plain, Size: 911 bytes --]



Jim

On Oct 27, 2003, at 8:45 AM, Andrew Cagney wrote:

> Jim,
>
> Since you're looking a that code, can you please tweak it so that it 
> uses a mem_file instead of the 1024 byte stack buffer.
>
> Is there a test case?
>
> Andrew
>
> +               /* If there was an error, print an informative
> +                  error message.  */
>                 char msg[1024];
> !               if (arg == NULL)
> !                 strcpy (msg, "Requires an argument.");
> !               else if (nmatches <= 0)
> !                 sprintf (msg, "Undefined item: \"%s\".", arg);
> !               else if (nmatches > 1)
> !                 sprintf  (msg, "Ambiguous item \"%s\".", arg);
> !               strcat (msg, " Valid values are ");
>                 for (i = 0; c->enums[i]; i++)
>                   {
>
>
--
Jim Ingham                                   jingham@apple.com
Developer Tools
Apple Computer


  reply	other threads:[~2003-10-28 19:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-28  2:02 Jim Ingham
2003-10-28  4:03 ` Daniel Jacobowitz
2003-10-28 16:08   ` Andrew Cagney
2003-10-28 19:35     ` Jim Ingham [this message]
2003-10-29 15:15       ` Andrew Cagney
2003-10-29 19:03         ` Jim Ingham

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=07B0DBEF-097E-11D8-A22C-000A958F4C44@apple.com \
    --to=jingham@apple.com \
    --cc=cagney@gnu.org \
    --cc=drow@mvista.com \
    --cc=gdb-patches@sources.redhat.com \
    /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