This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA]: Apropos patch


Stan Shebs <shebs@apple.com> writes:


> "Daniel Berlin+list.gdb-patches" wrote:
> > 
> > It includes documentation, a test case (which uses a slightly weird
> > regexp so it only finds one thing, and we make sure it only found one
> > thing), and all the apropriate changelog entries.
> 
> You're going to hate this, but now that I see the example in the manual,
> I'm wondering why "prefix:" and "command:" are on separate lines?
> Why not just imitate the syntax that comes out of the help command -
> 
> 	set symbol-reloading -- <help string>
> 	show symbol-reloading -- <help string>
> 
> Another advantage is that users can then cut-n-paste from the apropos
> output more easily.

Okay, new patch attached that does as you ask.
I added more testcases as well.

> 
> 
> Just needs approval from one of us, not both!  I must confess to being
> a bit mystified by the test though - why use "handle" as the match
> string, and do I understand right, you're requiring that it be the
> first output from apropos?

i now use "apropos <the handle regex>", "apropos apropos", and
"apropos handle a signal", which tests all the various things that
could go wrong (excluding screwing up your regex, which will properly
give you the error from the regex engine), like making sure multiple
word aproposes work, etc.
Index: command.c
===================================================================
RCS file: /cvs/src/src/gdb/command.c,v
retrieving revision 1.3
diff -r1.3 command.c
30c30
< 
---
> #include "gnu-regex.h"
372a373,450
> /* Recursively walk the commandlist structures, and print out the
>    documentation of commands that match our regex in either their
>    name, or their documentation.
> */
> void apropos_cmd_helper (struct ui_file *stream, struct cmd_list_element *commandlist,
> 			 struct re_pattern_buffer *regex, char *prefix)
> {
>   register struct cmd_list_element *c;
>   int returnvalue=1; /*Needed to avoid double printing*/
>   /* Walk through the commands */
>   for (c=commandlist;c;c=c->next)
>     {
>       if (c->name != NULL)
> 	{
> 	  /* Try to match against the name*/
> 	  returnvalue=re_search(regex,c->name,strlen(c->name),0,strlen(c->name),NULL);
> 	  if (returnvalue >= 0)
> 	    {
> 	      /* Stolen from help_cmd_list. We don't directly use
> 	       * help_cmd_list because it doesn't let us print out
> 	       * single commands
> 	       */
> 	      fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
> 	      print_doc_line (stream, c->doc);
> 	      fputs_filtered ("\n", stream);
> 	      returnvalue=0; /*Set this so we don't print it again.*/
> 	    }
> 	}
>       if (c->doc != NULL && returnvalue != 0)
> 	{
> 	  /* Try to match against documentation */
> 	  if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
> 	    {
> 	      /* Stolen from help_cmd_list. We don't directly use
> 	       * help_cmd_list because it doesn't let us print out
> 	       * single commands
> 	       */
> 	      fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
> 	      print_doc_line (stream, c->doc);
> 	      fputs_filtered ("\n", stream);
> 	    }
> 	}
>       /* Check if this command has subcommands */
>       if (c->prefixlist != NULL)
> 	{
> 	  /* Recursively call ourselves on the subcommand list,
> 	     passing the right prefix in.
> 	  */
> 
> 	  apropos_cmd_helper(stream,*c->prefixlist,regex,c->prefixname);
> 	}
>     }
> }
> /* Search through names of commands and documentations for a certain
>    regular expression.
> */
> void apropos_command (char *searchstr, int from_tty)
> {
>   extern struct cmd_list_element *cmdlist; /*This is the main command list*/
>   regex_t pattern;
>   char *pattern_fastmap;
>   char errorbuffer[512];
>   pattern_fastmap=calloc(256,sizeof(char));
> 
>   if (regcomp(&pattern,searchstr,REG_ICASE) == 0)
>     {
>       pattern.fastmap=pattern_fastmap;
>       re_compile_fastmap(&pattern);
>       apropos_cmd_helper(gdb_stdout,cmdlist,&pattern,"");
>     }
>   else
>     {
>       regerror(regcomp(&pattern,searchstr,REG_ICASE),NULL,errorbuffer,512);
>       fprintf_filtered(gdb_stdout,"Error with regular expression:%s\n",errorbuffer);
>     }
>   free(pattern_fastmap);
> }
> 
1695a1774
>   add_com ("apropos", class_support, apropos_command, "Search for commands by a regex");
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.164
diff -r1.164 ChangeLog
0a1,7
> 2000-03-22  Daniel Berlin  <dan@cgsoftware.com>
> 	* command.c (apropos_cmd_helper): New function, meat of the
> 	apropos command.
> 	(apropos_command): New apropos command to search command
> 	names/documentation for regular expressions.
> 	(_initialize_command): Add the apropos command.
> 
Index: testsuite/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.9
diff -r1.9 ChangeLog
0a1,4
> 2000-03-22  Daniel Berlin   <dan@cgsoftware.com>
> 
> 	* gdb.base/help.exp: Added test for new apropos command.
> 
Index: testsuite/gdb.base/help.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/help.exp,v
retrieving revision 1.1.1.4
diff -r1.1.1.4 help.exp
542a543,548
> # test apropos regex
> gdb_test "apropos \\\(print\[\^ bsiedf\\\".\]\\\)" "handle -- Specify how to handle a signal"
> # test apropos >1 word string
> gdb_test "apropos handle a signal" "handle -- Specify how to handle a signal"
> # test apropos apropos
> gdb_test "apropos apropos" "apropos -- Search for commands by a regex"
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.4
diff -r1.4 gdb.texinfo
1320a1321,1339
> @kindex apropos
> @item apropos @var{args}
> The @code{apropos @var{args}} command searches through all of the @value{GDBN}
> commands, and their documentation, for the regular expression specified in
> @var{args}. It prints out all matches found. For example:
> 
> @smallexample
> apropos reload
> @end smallexample
> 
> @noindent results in:
> 
> @smallexample
> @group
> set symbol-reloading -- Set dynamic symbol table reloading multiple times in one run
> show symbol-reloading -- Show dynamic symbol table reloading multiple times in one run
> @end group
> @end smallexample
> 
Index: doc/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/doc/ChangeLog,v
retrieving revision 1.9
diff -r1.9 ChangeLog
0a1,4
> 2000-03-22  Daniel Berlin  <dan@cgsoftware.com>
> 
> 	* gdb.texinfo: Add documentation for the apropos command.
> 

> 
> Stan

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]