From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31260 invoked by alias); 28 Oct 2003 19:35:35 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 31253 invoked from network); 28 Oct 2003 19:35:34 -0000 Received: from unknown (HELO mail-out3.apple.com) (17.254.13.22) by sources.redhat.com with SMTP; 28 Oct 2003 19:35:34 -0000 Received: from mailgate1.apple.com (a17-128-100-225.apple.com [17.128.100.225]) by mail-out3.apple.com (8.12.10/8.12.9) with ESMTP id h9SJZYrY011161 for ; Tue, 28 Oct 2003 11:35:34 -0800 (PST) Received: from scv2.apple.com (scv2.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id ; Tue, 28 Oct 2003 11:35:02 -0800 Received: from [17.201.22.245] (inghji6.apple.com [17.201.22.245]) by scv2.apple.com (8.12.9/8.12.9) with ESMTP id h9SJZGEV017542; Tue, 28 Oct 2003 11:35:16 -0800 (PST) In-Reply-To: <3F9D4B94.7040502@gnu.org> References: <20031028040347.GA26218@nevyn.them.org> <3F9D4B94.7040502@gnu.org> Mime-Version: 1.0 (Apple Message framework v606) Content-Type: multipart/mixed; boundary=Apple-Mail-4-1015761172 Message-Id: <07B0DBEF-097E-11D8-A22C-000A958F4C44@apple.com> Cc: Daniel Jacobowitz , gdb-patches@sources.redhat.com From: Jim Ingham Subject: Re: report valid values for all errors for enum variables... Date: Tue, 28 Oct 2003 19:35:00 -0000 To: Andrew Cagney X-SW-Source: 2003-10/txt/msg00816.txt.bz2 --Apple-Mail-4-1015761172 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 18 Sure, how 'bout: --Apple-Mail-4-1015761172 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="var_enum.patch" Content-Disposition: attachment; filename=var_enum.patch Content-length: 3125 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: --Apple-Mail-4-1015761172 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 911 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 --Apple-Mail-4-1015761172--