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]

[RFA]: Apropos patch


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.

Let me know if i can check it in, i believe it needs approval from
Stan Shebs, and Fernando Nasser.

--Dan
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: 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)
> 	    {
> 	      /* We have a match, print out the documentation, prefixed
> 		 if necessary.
> 	      */
> 	      if (prefix != NULL)
> 		fprintf_filtered(stream,"\nprefix:%s\ncommand:%s\ndescription:%s\n\n",prefix,c->name,c->doc);
> 	      else
> 		fprintf_filtered(stream,"\ncommand:%s\ndescription:%s\n\n", c->name,c->doc);
> 	      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)
> 	    {
> 	      /* We have a match, print out the documentation,
> 		 prefixed if necessary.
> 	      */
> 	      if (prefix != NULL)
> 		fprintf_filtered(stream,"\nprefix:%s\ncommand:%s\ndescription:%s\n\n",prefix,c->name,c->doc);
> 	      else
> 		fprintf_filtered(stream,"\ncommand:%s\ndescription:%s\n\n", c->name, c->doc);
> 	    }
> 	}
>       /* 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,NULL);
>     }
>   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: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.4
diff -r1.4 gdb.texinfo
1320a1321,1344
> @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
> prefix:set
> command:symbol-reloading
> description:Set dynamic symbol table reloading multiple times in one run.
> 
> prefix:show
> command:symbol-reloading
> description: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.
> 
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
> gdb_test "apropos \\\(print\[\^ bsiedf\\\".\]\\\)" "\ncommand:handle\[\r\n\]+description:\[\^:\]+"

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