Help viewer suggestions (was Re: Wheeled Mouse)



Bruce Stephens wrote:

> I find the help viewer, convenient thought it is, much less
> comfortable than Netscape, mostly because it doesn't support scrolling
> with the wheel.  Its manpage viewing is just horrible compared to
> tkman, but even so it would be improved by wheel scrolling.

Speaking of the help viewer, in the version I have (0.20 RPMS), the help
viewer doesn't even have a search function to search for text in a page.
This is the most important feature for man page searching for me, cause
90% of the time, I do a "man xxx" and then immediately hit "/" (search
in
less) and search for "RETURN".  This will immediately take me to the
RETURN VALUE section of the manpage, and then I'm done, cause I've
looked
at the prototype, and I've looked at the return value.

So if the search function isn't in the current CVS version of gnome, it
should be put in.  An easy way to do it is to us POSIX regexps...

Here's some code that could do it since I don't know anything about CVS.
This code uses a GtkText Widget, since I don't know anything about the
Gnome html widget.  So obviously it would need to be adapted, but it
shouldn't be too hard.

There's no excuse for every app not to have regular expression searching
when you're dealing with a unix system.  Especially if our goal is to
have a friendly, yet powerful GUI.

Later,
Ben Boule


/********************CODE STARTS HERE
************************************/

/* Posix says sys/types.h must be included before regex.h */
#include <sys/types.h>
#include <regex.h>

/* Finds the first match for a regular expression in a text widget 
   w - pointer to the text widget
   expression - the pattern to search for
   index - pointer to an integer to store the location of the match in
   RETURNS:
	 1 - Value found
	 0 - Value not found
	-1 - Error
   SIDE EFFECTS: 
	If the search is successful, the current entry point of the
	text widget is moved to the first character of the matching string
   
	If the search is not successful, client should pop up a messagebox
	stating that the search was unsuccessful.

*/
int find_regex(GtkText *w, char *expression, guint *index) {

	regex_t compiled_expression;
	int retval = 0;
	int nmatches = 0;
	regmatch_t *matches = NULL;

	/* Check arguments */
	if((!GTK_IS_TEXT(w))||(regexp==NULL)||(index==NULL))
	  return -1;

	/* Compile expression */
	retval = regcomp(&compiled_expression,expression,REG_EXTENDED);
	if(retval<0)
	 return -1;

	/* Allocate structs */
	nmatches = compiled_expresssion.re_nsub;
	matches = (regmatch_t *) malloc(sizeof(regmatch_t)*(nmatches+1));		

	/* Make comparison */
	retval = regexec(&compiled_expression,
			GTK_TEXT(w)->text,nmatches+1,matches,0);
		
	/* Check for an error */
	if(retval<0) {
	 regfree(&compiled_expression);	 
	 free(matches);
	 return -1;
	}
	/* Check for a failure to match */	
	if(retval==REG_NOMATCH) {
	 regfree(&compiled_expression);
	 free(matches);
	 return 0;
	}
	/* Change insertion position and return 1 */
	gtk_text_set_point(GTK_TEXT(w),matches[0].rm_so);
	regfree(&compiled_expression);
	free(matches);
	return 1;	
}

P.S. If anybody needs help with regular expressions in C, give me a
buzz.
I've done more of it than I care to admit.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]