Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Guillaume Leconte <guillaume.leconte@gmail.com>
To: gdb-patches@sourceware.org
Subject: Re: [patch] delete a range of display numbers
Date: Fri, 18 Feb 2011 10:30:00 -0000	[thread overview]
Message-ID: <AANLkTinN_Tes7oY=J4d3KgbmmW=r2A64tL1F-PSL+Z0p@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikgj9Pxw15Ryx=E=tkGqALaK+WOzrGykfrOggTY@mail.gmail.com>

This version fits more with the indentation style, and fixes a typo (I
omitted to change a call
to delete_display()). Sorry for the noise.

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 29ffbf5..deb1b80 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1558,12 +1558,16 @@ clear_displays (void)
 /* Delete the auto-display number NUM.  */

 static void
-delete_display (int num)
+delete_display (int num, int ignore)
 {
   struct display *d1, *d;

   if (!display_chain)
-    error (_("No display number %d."), num);
+    {
+      if (ignore)
+        return;
+      error (_("No display number %d."), num);
+    }

   if (display_chain->number == num)
     {
@@ -1575,7 +1579,11 @@ delete_display (int num)
     for (d = display_chain;; d = d->next)
       {
 	if (d->next == 0)
-	  error (_("No display number %d."), num);
+          {
+            if (ignore)
+              return;
+            error (_("No display number %d."), num);
+          }
 	if (d->next->number == num)
 	  {
 	    d1 = d->next;
@@ -1586,6 +1594,40 @@ delete_display (int num)
       }
 }

+static int
+set_int_from_str (char *str, int *result, char *end_delim)
+{
+  char *p;
+  int ret;
+  char *occurrence;
+
+  p = str;
+  ret = -1;
+
+  if (! str)
+    goto err;
+
+  while (p && *p && (' ' == *p || '\t' == *p))
+    p++;
+
+  while (p && *p && *p >= '0' && *p <= '9')
+    p++;
+
+  if (p && *p)
+    {
+      occurrence = strpbrk (p, end_delim);
+      if (! occurrence || occurrence != p)
+        goto err;
+    }
+
+  if (result)
+    *result = atoi (str);
+
+  ret = 0;
+ err:
+  return ret;
+}
+
 /* Delete some values from the auto-display chain.
    Specify the element numbers.  */

@@ -1595,7 +1637,8 @@ undisplay_command (char *args, int from_tty)
   char *p = args;
   char *p1;
   int num;
-
+  int lower, upper, i;
+  char *dash;
   if (args == 0)
     {
       if (query (_("Delete all auto-display expressions? ")))
@@ -1604,23 +1647,44 @@ undisplay_command (char *args, int from_tty)
       return;
     }

-  while (*p)
+  dash = strchr(p, '-');
+  if (dash) /* remove all the display IDs within a range */
+    {
+      if (-1 == set_int_from_str(p, &lower, "- \t"))
+        error (_("Arguments must be display numbers."));
+
+      p = dash+1;
+      while (p && *p && (' ' == *p || '\t' == *p))
+        p++;
+
+      if (-1 == set_int_from_str(p, &upper, " \t"))
+        error (_("Arguments must be display numbers."));
+
+      for (i = lower; i <= upper; i++)
+        delete_display(i, 1);
+
+      dont_repeat ();
+    }
+  else
     {
-      p1 = p;
-      while (*p1 >= '0' && *p1 <= '9')
-	p1++;
-      if (*p1 && *p1 != ' ' && *p1 != '\t')
-	error (_("Arguments must be display numbers."));
+      while (*p)
+        {
+          p1 = p;
+          while (*p1 >= '0' && *p1 <= '9')
+            p1++;
+          if (*p1 && *p1 != ' ' && *p1 != '\t')
+            error (_("Arguments must be display numbers."));

-      num = atoi (p);
+          num = atoi (p);

-      delete_display (num);
+          delete_display (num, 0);

-      p = p1;
-      while (*p == ' ' || *p == '\t')
-	p++;
+          p = p1;
+          while (*p == ' ' || *p == '\t')
+            p++;
+        }
+      dont_repeat ();
     }
-  dont_repeat ();
 }

 /* Display a single auto-display.


--
"A fellow of infinite jest, of most excellent fancy."


  reply	other threads:[~2011-02-18  9:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  9:47 Guillaume Leconte
2011-02-18 10:30 ` Guillaume Leconte [this message]
2011-02-18 11:08 ` Eli Zaretskii
2011-02-18 11:48   ` Guillaume Leconte
2011-02-18 12:17     ` Pedro Alves
2011-02-18 14:41       ` Guillaume Leconte
2011-02-18 15:14       ` Tom Tromey
2011-02-18 15:58         ` Pedro Alves
2011-02-18 16:48           ` Tom Tromey
2011-02-18 16:57             ` Pedro Alves
2011-02-18 17:41               ` Eli Zaretskii
2011-02-18 17:54                 ` Pedro Alves
2011-02-18 17:54                   ` Michael Snyder
2011-02-18 18:06                     ` Pedro Alves
2011-03-14 21:24                       ` [patch+docs] make 'disable|enable display' also accept ranges (Re: [patch] delete a range of display numbers) Pedro Alves
2011-03-14 21:34                         ` Eli Zaretskii
2011-03-15 14:43                           ` Pedro Alves
2011-02-18 18:17                     ` [patch] delete a range of display numbers Eli Zaretskii
2011-02-18 17:52       ` Michael Snyder
2011-02-18 17:57         ` Pedro Alves
2011-02-18 17:44 ` Michael Snyder

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='AANLkTinN_Tes7oY=J4d3KgbmmW=r2A64tL1F-PSL+Z0p@mail.gmail.com' \
    --to=guillaume.leconte@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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