Apply the same regexp_init checks to using last|search in search_init()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1418 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2003-02-03 07:07:40 +00:00
parent c45335782a
commit d89eb91e77
2 changed files with 13 additions and 3 deletions

View File

@ -20,7 +20,8 @@ CVS Code -
- Fix nano crashing when searching/replacing an invalid - Fix nano crashing when searching/replacing an invalid
regex (try "^*"). Changed regexp_init() to return regex (try "^*"). Changed regexp_init() to return
1 or 0 based on regcomp()'s return value and search_init 1 or 0 based on regcomp()'s return value and search_init
to exit with an error message (sorry Jordi!) to exit with an error message (sorry Jordi!). Added
another check when using last_search instead of answer.
- Move regcomp into rcfile.c rather than each display refresh - Move regcomp into rcfile.c rather than each display refresh
of winio.c. New function rcfile.c:nregcomp(). of winio.c. New function rcfile.c:nregcomp().
This fixes much of nano's resource hogging behavior This fixes much of nano's resource hogging behavior

View File

@ -102,6 +102,9 @@ int search_init(int replacing)
int i = 0; int i = 0;
char *buf; char *buf;
static char *backupstring = NULL; static char *backupstring = NULL;
#ifdef HAVE_REGEX_H
const char *regex_error = _("Invalid regex \"%s\"");
#endif /* HAVE_REGEX_H */
search_init_globals(); search_init_globals();
@ -164,14 +167,20 @@ int search_init(int replacing)
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
/* If answer is "", use last_search! */ /* If answer is "", use last_search! */
regexp_init(last_search); if (regexp_init(last_search) == 0) {
statusbar(regex_error, last_search);
reset_cursor();
free(backupstring);
backupstring = NULL;
return -3;
}
#endif #endif
break; break;
case 0: /* They entered something new */ case 0: /* They entered something new */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
if (regexp_init(answer) == 0) { if (regexp_init(answer) == 0) {
statusbar(_("Invalid regex!")); statusbar(regex_error, answer);
reset_cursor(); reset_cursor();
free(backupstring); free(backupstring);
backupstring = NULL; backupstring = NULL;