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]

[RFC] Patch to add apropos command


Attached is a patch that adds a simple, functional, apropos for gdb.

it searchs all command names and command doc strings (case
insensitively) 
for the regex ".*<searchstr>.*".

It's not perfect, error checking is a bit lax, it just does nothing
when errors happen, rather than print out the error message.
It's also a little slower than i want it to be.
But it does search the name and docstring of every command, and
properly prints out the command and docstrings of the matching ones.
It also double prints if the name and docstring both match.
And if we are searching through a prefix, i really should have it
print out the prefix as well.
I'm sure i could think of a better regex too.

But, even given all that, it's pretty useful, even in current form.

I wanted to get some comments about usefulness before i go extending
it.
I'll happily make it do whatever people want.

Index: command.c
===================================================================
RCS file: /cvs/src/src/gdb/command.c,v
retrieving revision 1.2
diff -r1.2 command.c
30c30
< 
---
> #include "gnu-regex.h"
372a373,421
> void apropos_cmd_helper (stream, commandlist, regex)
> 	struct ui_file *stream;
> 	struct cmd_list_element *commandlist;
> 	struct re_pattern_buffer *regex;
> {
> 	int returnvalue;
> 	while (commandlist->next != NULL)
> 	{
> 		if (commandlist->name != NULL)
> 		{
> 			if ((returnvalue=re_search(regex,commandlist->name,strlen(commandlist->name),0,strlen(commandlist->name),NULL))>=0)
> 			{
> 				fprintf_filtered(stream,"\n%s\n%s\n\n", commandlist->name,commandlist->doc);
> 			}
> 		}
> 		if (commandlist->doc != NULL)
> 		{
> 			if ((returnvalue=re_search(regex,commandlist->doc,strlen(commandlist->doc),0,strlen(commandlist->doc),NULL)) >=0)
> 			{
> 				fprintf_filtered(stream,"\n%s\n%s\n\n", commandlist->name, commandlist->doc);
> 			}
> 			
> 		}	
> 		if (commandlist->prefixlist != NULL)
> 		{
> 			apropos_cmd_helper(stream,*(commandlist->prefixlist),regex);
> 		}
> 		commandlist=commandlist->next;
> 	}
> }
> 
> void apropos_command (char *searchstr, int from_tty)
> {
> 	extern struct cmd_list_element *cmdlist;
> 	regex_t pattern;
> 	char pattern_fastmap[256];
> 	char *newstr;
> 	newstr=calloc(strlen(searchstr)+4,sizeof(char));
> 
> 	strcat(newstr,".*");
> 	strcat(newstr,searchstr);
> 	strcat(newstr,".*");
> 	if (regcomp(&pattern,newstr,REG_ICASE) == 0)
> 	{
> 		apropos_cmd_helper(gdb_stdout,cmdlist,&pattern);
> 	}
> 	free(newstr);
> }
> 
1689a1739
>   add_com ("apropos", class_support, apropos_command, "Search for commands by a regex");




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