Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: <gdb-patches@sources.redhat.com>
Subject: Re: [RFC] GDB interpreters
Date: Tue, 21 May 2002 13:27:00 -0000	[thread overview]
Message-ID: <Pine.GSO.4.33.0205211128320.22131-100000@makita.cygnus.com> (raw)
In-Reply-To: <Pine.GSO.4.33.0205210910160.22131-100000@makita.cygnus.com>

On Tue, 21 May 2002, Keith Seitz wrote:

> Eli Zaretskii wrote:
>
> > Can we have completion on known interpreter names in these commands?  The
> > default completer function completes on symbols from the inferior, which
> > is really not a good idea in this case ;-)
>
> I can certainly look into that...

Ok, I admit, I know very little about the completer. However, I can copy
code as well as the next guy! :-)

How does this look? (This would be a patch for the file I posted
yesterday.)

Keith

*** interpreter.c.orig	Tue May 21 11:35:42 2002
--- interpreter.c	Tue May 21 11:35:46 2002
***************
*** 44,49 ****
--- 44,51 ----
  #include "event-loop.h"
  #include "event-top.h"
  #include "interpreter.h"
+ #include "completer.h"
+ #include "gdb_string.h"

  /* Functions local to this file. */
  static void initialize_interps (void);
*************** static void set_interpreter_cmd (char *a
*** 52,57 ****
--- 54,60 ----
  				 struct cmd_list_element *c);
  static void list_interpreter_cmd (char *args, int from_tty);
  static void do_set_interpreter (int not_an_fd);
+ static char **interpreter_completer (char *text, char *word);

  /* The magic initialization routine for this module. */

*************** interpreter_exec_cmd (char *args, int fr
*** 555,560 ****
--- 558,620 ----
    gdb_interpreter_set_quiet (interp_to_use, old_quiet);
  }

+ /* List the possible interpreters which could complete the given text. */
+
+ static char **
+ interpreter_completer (char *text, char *word)
+ {
+   int alloced, textlen;
+   int num_matches;
+   char **matches;
+   struct gdb_interpreter *interp;
+
+   /* We expect only a very limited number of interpreters, so just
+      allocate room for all of them. */
+   for (interp = interp_list; interp != NULL; interp = interp->next)
+     ++alloced;
+   matches = (char **) xmalloc (alloced * sizeof (char *));
+
+   num_matches = 0;
+   textlen = strlen (text);
+   for (interp = interp_list; interp != NULL; interp = interp->next)
+     {
+       if (strncmp (interp->name, text, textlen) == 0)
+ 	{
+ 	  matches[num_matches] =
+ 	    (char *) xmalloc (strlen (word) + strlen (interp->name) + 1);
+ 	  if (word == text)
+ 	    strcpy (matches[num_matches], interp->name);
+ 	  else if (word > text)
+ 	    {
+ 	      /* Return some portion of interp->name */
+ 	      strcpy (matches[num_matches], interp->name + (word - text));
+ 	    }
+ 	  else
+ 	    {
+ 	      /* Return some of text plus interp->name */
+ 	      strncpy (matches[num_matches], word, text - word);
+ 	      matches[num_matches][text - word] = '\0';
+ 	      strcat (matches[num_matches], interp->name);
+ 	    }
+ 	  ++num_matches;
+ 	}
+     }
+
+   if (num_matches == 0)
+     {
+       xfree (matches);
+       matches = NULL;
+     }
+   else if (num_matches < alloced)
+     {
+       matches = (char **) xrealloc ((char *) matches, ((num_matches + 1)
+ 						       * sizeof (char *)));
+       matches[num_matches] = NULL;
+     }
+
+   return matches;
+ }
+
  /* _initialize_interpreter - This just adds the "set interpreter" and
   * "info interpreters" commands.
   */
*************** _initialize_interpreter (void)
*** 574,582 ****
  	   list_interpreter_cmd,
  	   "List the interpreters currently available in gdb.", &infolist);

!   add_cmd ("interpreter-exec", class_support,
  	   interpreter_exec_cmd,
  	   "Execute a command in an interpreter.  It takes two arguments:\n\
  The first argument is the name of the interpreter to use.\n\
  The second argument is the command to execute.\n", &cmdlist);
  }
--- 634,643 ----
  	   list_interpreter_cmd,
  	   "List the interpreters currently available in gdb.", &infolist);

!   c = add_cmd ("interpreter-exec", class_support,
  	       interpreter_exec_cmd,
  	       "Execute a command in an interpreter.  It takes two arguments:\n\
  The first argument is the name of the interpreter to use.\n\
  The second argument is the command to execute.\n", &cmdlist);
+   set_cmd_completer (c, interpreter_completer);
  }


  parent reply	other threads:[~2002-05-21 18:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-20 13:46 Keith Seitz
2002-05-20 22:10 ` Eli Zaretskii
2002-05-21  9:14   ` Keith Seitz
2002-05-21  9:23     ` Keith Seitz
2002-05-21 13:27     ` Keith Seitz [this message]
2002-05-21 18:41       ` Eli Zaretskii
2002-05-24 15:00       ` Andrew Cagney
2002-05-24 15:38 ` Andrew Cagney
2002-05-24 16:20   ` Keith Seitz
2002-05-28 17:26   ` Keith Seitz

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=Pine.GSO.4.33.0205211128320.22131-100000@makita.cygnus.com \
    --to=keiths@redhat.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