From 0ec34ac28aa9b977d3a45849fa7ff1ab165effd9 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 9 Jan 2007 23:35:02 +0000 Subject: [PATCH] make regexp_init() return a bool instead of an int git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4023 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 1 + src/browser.c | 7 +++---- src/proto.h | 2 +- src/search.c | 28 +++++++++++++++------------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04fe2368..878094b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ CVS code - - General: - Miscellaneous comment fixes. (DLR) + - More int -> bool conversions. (DLR) - Don't install the nanorc manpages or generate their HTML versions if nano is built without nanorc support. Changes to configure.ac, doc/man/Makefile.am, and doc/man/fr/Makefile.am. diff --git a/src/browser.c b/src/browser.c index a1393fb6..a7d7622e 100644 --- a/src/browser.c +++ b/src/browser.c @@ -844,9 +844,8 @@ int filesearch_init(void) #ifdef HAVE_REGEX_H /* Use last_search if answer is an empty string, or * answer if it isn't. */ - if (ISSET(USE_REGEXP) && - regexp_init((i == -2) ? last_search : - answer) == 0) + if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ? + last_search : answer)) return -1; #endif break; @@ -1030,7 +1029,7 @@ void do_fileresearch(void) if (last_search[0] != '\0') { #ifdef HAVE_REGEX_H /* Since answer is "", use last_search! */ - if (ISSET(USE_REGEXP) && regexp_init(last_search) == 0) + if (ISSET(USE_REGEXP) && !regexp_init(last_search)) return; #endif diff --git a/src/proto.h b/src/proto.h index db397d71..37bf5822 100644 --- a/src/proto.h +++ b/src/proto.h @@ -568,7 +568,7 @@ void do_rcfile(void); /* All functions in search.c. */ #ifdef HAVE_REGEX_H -int regexp_init(const char *regexp); +bool regexp_init(const char *regexp); void regexp_cleanup(void); #endif void not_found_msg(const char *str); diff --git a/src/search.c b/src/search.c index 89b31cf2..eed26de2 100644 --- a/src/search.c +++ b/src/search.c @@ -41,19 +41,20 @@ static bool regexp_compiled = FALSE; /* Regular expression helper functions. */ -/* Compile the given regular expression. Return value 0 means the - * expression was invalid, and we wrote an error message on the status - * bar. Return value 1 means success. */ -int regexp_init(const char *regexp) +/* Compile the regular expression regexp to see if it's valid. Return + * TRUE if it is, or FALSE otherwise. */ +bool regex_init(const char *regexp) { - int rc = regcomp(&search_regexp, regexp, REG_EXTENDED + int rc; + + assert(!regexp_compiled); + + rc = regcomp(&search_regexp, regexp, REG_EXTENDED #ifndef NANO_TINY | (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE) #endif ); - assert(!regexp_compiled); - if (rc != 0) { size_t len = regerror(rc, &search_regexp, NULL, 0); char *str = charalloc(len); @@ -61,11 +62,13 @@ int regexp_init(const char *regexp) regerror(rc, &search_regexp, str, len); statusbar(_("Bad regex \"%s\": %s"), regexp, str); free(str); - return 0; + + return FALSE; } regexp_compiled = TRUE; - return 1; + + return TRUE; } /* Decompile the compiled regular expression we used in the last @@ -218,9 +221,8 @@ int search_init(bool replacing, bool use_answer) #ifdef HAVE_REGEX_H /* Use last_search if answer is an empty string, or * answer if it isn't. */ - if (ISSET(USE_REGEXP) && - regexp_init((i == -2) ? last_search : - answer) == 0) + if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ? + last_search : answer)) return -1; #endif break; @@ -511,7 +513,7 @@ void do_research(void) if (last_search[0] != '\0') { #ifdef HAVE_REGEX_H /* Since answer is "", use last_search! */ - if (ISSET(USE_REGEXP) && regexp_init(last_search) == 0) + if (ISSET(USE_REGEXP) && !regexp_init(last_search)) return; #endif -- 2.39.5