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
master
David Lawrence Ramsey 2007-01-09 23:35:02 +00:00
parent cb04b56c92
commit 0ec34ac28a
4 changed files with 20 additions and 18 deletions

View File

@ -1,6 +1,7 @@
CVS code - CVS code -
- General: - General:
- Miscellaneous comment fixes. (DLR) - Miscellaneous comment fixes. (DLR)
- More int -> bool conversions. (DLR)
- Don't install the nanorc manpages or generate their HTML - Don't install the nanorc manpages or generate their HTML
versions if nano is built without nanorc support. Changes to versions if nano is built without nanorc support. Changes to
configure.ac, doc/man/Makefile.am, and doc/man/fr/Makefile.am. configure.ac, doc/man/Makefile.am, and doc/man/fr/Makefile.am.

View File

@ -844,9 +844,8 @@ int filesearch_init(void)
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Use last_search if answer is an empty string, or /* Use last_search if answer is an empty string, or
* answer if it isn't. */ * answer if it isn't. */
if (ISSET(USE_REGEXP) && if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ?
regexp_init((i == -2) ? last_search : last_search : answer))
answer) == 0)
return -1; return -1;
#endif #endif
break; break;
@ -1030,7 +1029,7 @@ void do_fileresearch(void)
if (last_search[0] != '\0') { if (last_search[0] != '\0') {
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Since answer is "", use last_search! */ /* Since answer is "", use last_search! */
if (ISSET(USE_REGEXP) && regexp_init(last_search) == 0) if (ISSET(USE_REGEXP) && !regexp_init(last_search))
return; return;
#endif #endif

View File

@ -568,7 +568,7 @@ void do_rcfile(void);
/* All functions in search.c. */ /* All functions in search.c. */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
int regexp_init(const char *regexp); bool regexp_init(const char *regexp);
void regexp_cleanup(void); void regexp_cleanup(void);
#endif #endif
void not_found_msg(const char *str); void not_found_msg(const char *str);

View File

@ -41,19 +41,20 @@ static bool regexp_compiled = FALSE;
/* Regular expression helper functions. */ /* Regular expression helper functions. */
/* Compile the given regular expression. Return value 0 means the /* Compile the regular expression regexp to see if it's valid. Return
* expression was invalid, and we wrote an error message on the status * TRUE if it is, or FALSE otherwise. */
* bar. Return value 1 means success. */ bool regex_init(const char *regexp)
int regexp_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 #ifndef NANO_TINY
| (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE) | (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE)
#endif #endif
); );
assert(!regexp_compiled);
if (rc != 0) { if (rc != 0) {
size_t len = regerror(rc, &search_regexp, NULL, 0); size_t len = regerror(rc, &search_regexp, NULL, 0);
char *str = charalloc(len); char *str = charalloc(len);
@ -61,11 +62,13 @@ int regexp_init(const char *regexp)
regerror(rc, &search_regexp, str, len); regerror(rc, &search_regexp, str, len);
statusbar(_("Bad regex \"%s\": %s"), regexp, str); statusbar(_("Bad regex \"%s\": %s"), regexp, str);
free(str); free(str);
return 0;
return FALSE;
} }
regexp_compiled = TRUE; regexp_compiled = TRUE;
return 1;
return TRUE;
} }
/* Decompile the compiled regular expression we used in the last /* 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 #ifdef HAVE_REGEX_H
/* Use last_search if answer is an empty string, or /* Use last_search if answer is an empty string, or
* answer if it isn't. */ * answer if it isn't. */
if (ISSET(USE_REGEXP) && if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ?
regexp_init((i == -2) ? last_search : last_search : answer))
answer) == 0)
return -1; return -1;
#endif #endif
break; break;
@ -511,7 +513,7 @@ void do_research(void)
if (last_search[0] != '\0') { if (last_search[0] != '\0') {
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Since answer is "", use last_search! */ /* Since answer is "", use last_search! */
if (ISSET(USE_REGEXP) && regexp_init(last_search) == 0) if (ISSET(USE_REGEXP) && !regexp_init(last_search))
return; return;
#endif #endif