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
Этот коммит содержится в:
родитель
cb04b56c92
Коммит
0ec34ac28a
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
28
src/search.c
28
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
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user