This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
[RFC] Better apropos patch
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [RFC] Better apropos patch
- From: Daniel Berlin <dan at cgsoftware dot com>
- Date: Wed, 22 Mar 2000 12:57:52 -0800 (PST)
Won't double print, works *much* faster, properly displays prefixes.
Let me know what you guys think.
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,426
> void apropos_cmd_helper (stream, commandlist, regex,prefix)
> 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;
> for (c=commandlist;c;c=c->next)
> {
> if (c->name != NULL)
> {
> returnvalue=re_search(regex,c->name,strlen(c->name),0,strlen(c->name),NULL);
> if (returnvalue >= 0)
> {
> 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;
> }
> }
> if (c->doc != NULL && returnvalue != 0)
> {
> if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
> {
> 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);
> }
> }
> if (c->prefixlist != NULL)
> {
> apropos_cmd_helper(stream,*c->prefixlist,regex,c->prefixname);
> }
> }
> }
>
> void apropos_command (char *searchstr, int from_tty)
> {
> extern struct cmd_list_element *cmdlist;
> regex_t pattern;
> char *pattern_fastmap;
> 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);
> }
> free(pattern_fastmap);
> }
>
1695a1750
> add_com ("apropos", class_support, apropos_command, "Search for commands by a regex");