From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30176 invoked by alias); 21 May 2002 18:34:33 -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 30128 invoked from network); 21 May 2002 18:34:30 -0000 Received: from unknown (HELO cygnus.com) (205.180.83.203) by sources.redhat.com with SMTP; 21 May 2002 18:34:30 -0000 Received: from makita.cygnus.com (makita.sfbay.redhat.com [192.168.30.83]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id LAA15263 for ; Tue, 21 May 2002 11:34:30 -0700 (PDT) Received: from localhost (keiths@localhost) by makita.cygnus.com (8.8.8+Sun/8.6.4) with ESMTP id LAA23362 for ; Tue, 21 May 2002 11:34:29 -0700 (PDT) X-Authentication-Warning: makita.cygnus.com: keiths owned process doing -bs Date: Tue, 21 May 2002 13:27:00 -0000 From: Keith Seitz X-X-Sender: To: Subject: Re: [RFC] GDB interpreters In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-05/txt/msg00839.txt.bz2 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); }