add DB's overhaul of regexp_init() and a few other regex-related bits,
and convert REGEXP_COMPILED to a static int in search.c, since it's only used there git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1724 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
d893fa946d
commit
4b741b9c7b
17
ChangeLog
17
ChangeLog
|
@ -52,6 +52,9 @@ CVS code -
|
||||||
- Use size_t's instead of ints for the get_verbatim_kbinput()
|
- Use size_t's instead of ints for the get_verbatim_kbinput()
|
||||||
call and the loop that ungetch()es its returned int*,
|
call and the loop that ungetch()es its returned int*,
|
||||||
respectively. (DLR)
|
respectively. (DLR)
|
||||||
|
- nano.h:
|
||||||
|
- Since REGEXP_COMPILED is only used in search.c, convert it
|
||||||
|
from a flag to a static int there. (DLR)
|
||||||
- proto.h:
|
- proto.h:
|
||||||
- Remove unused xpt() and add_marked_sameline() prototypes.
|
- Remove unused xpt() and add_marked_sameline() prototypes.
|
||||||
(DLR)
|
(DLR)
|
||||||
|
@ -59,6 +62,15 @@ CVS code -
|
||||||
- Move "rebinddelete" up in the list of options so that the list
|
- Move "rebinddelete" up in the list of options so that the list
|
||||||
is in alphabetical order. (DLR)
|
is in alphabetical order. (DLR)
|
||||||
- search.c:
|
- search.c:
|
||||||
|
regexp_init()
|
||||||
|
- Overhaul for efficiency. Also check if regcomp() failed, and
|
||||||
|
if so, display "Bad regex" message on the statusbar, so that
|
||||||
|
we don't have to display it separately after every call to
|
||||||
|
this function. (David Benbennick)
|
||||||
|
search_init()
|
||||||
|
- Only check whether USE_REGEXP is set, and hence whether or not
|
||||||
|
to display "[Regexp]" on the search prompt, if HAVE_REGEX_H is
|
||||||
|
defined. (DLR)
|
||||||
not_found_msg()
|
not_found_msg()
|
||||||
- Convert to properly handle strings generated by
|
- Convert to properly handle strings generated by
|
||||||
display_string() that have been used in the search prompt
|
display_string() that have been used in the search prompt
|
||||||
|
@ -96,6 +108,11 @@ CVS code -
|
||||||
searched_later_lines. (DLR)
|
searched_later_lines. (DLR)
|
||||||
edit_refresh()
|
edit_refresh()
|
||||||
- Remove apparently unneeded leaveok() calls. (David Benbennick)
|
- Remove apparently unneeded leaveok() calls. (David Benbennick)
|
||||||
|
statusbar()
|
||||||
|
- Call reset_cursor() just before refreshing the edit window, so
|
||||||
|
that slang and other non-ncurses versions of curses will
|
||||||
|
properly place the cursor back in the edit window instead of
|
||||||
|
leaving it at the end of the statusbar. (DLR)
|
||||||
do_credits()
|
do_credits()
|
||||||
- Use napms() instead of nanosleep(), as it does the same thing
|
- Use napms() instead of nanosleep(), as it does the same thing
|
||||||
(aside from taking an argument in milliseconds instead of
|
(aside from taking an argument in milliseconds instead of
|
||||||
|
|
35
src/nano.h
35
src/nano.h
|
@ -251,24 +251,23 @@ typedef struct historyheadtype {
|
||||||
#define VIEW_MODE (1<<10)
|
#define VIEW_MODE (1<<10)
|
||||||
#define USE_MOUSE (1<<11)
|
#define USE_MOUSE (1<<11)
|
||||||
#define USE_REGEXP (1<<12)
|
#define USE_REGEXP (1<<12)
|
||||||
#define REGEXP_COMPILED (1<<13)
|
#define TEMP_OPT (1<<13)
|
||||||
#define TEMP_OPT (1<<14)
|
#define CUT_TO_END (1<<14)
|
||||||
#define CUT_TO_END (1<<15)
|
#define REVERSE_SEARCH (1<<15)
|
||||||
#define REVERSE_SEARCH (1<<16)
|
#define MULTIBUFFER (1<<16)
|
||||||
#define MULTIBUFFER (1<<17)
|
#define DOS_FILE (1<<17)
|
||||||
#define DOS_FILE (1<<18)
|
#define MAC_FILE (1<<18)
|
||||||
#define MAC_FILE (1<<19)
|
#define SMOOTHSCROLL (1<<19)
|
||||||
#define SMOOTHSCROLL (1<<20)
|
#define DISABLE_CURPOS (1<<20) /* Damn, we still need it. */
|
||||||
#define DISABLE_CURPOS (1<<21) /* Damn, we still need it. */
|
#define REBIND_DELETE (1<<21)
|
||||||
#define REBIND_DELETE (1<<22)
|
#define NO_CONVERT (1<<22)
|
||||||
#define NO_CONVERT (1<<23)
|
#define BACKUP_FILE (1<<23)
|
||||||
#define BACKUP_FILE (1<<24)
|
#define NO_RCFILE (1<<24)
|
||||||
#define NO_RCFILE (1<<25)
|
#define COLOR_SYNTAX (1<<25)
|
||||||
#define COLOR_SYNTAX (1<<26)
|
#define PRESERVE (1<<26)
|
||||||
#define PRESERVE (1<<27)
|
#define HISTORY_CHANGED (1<<27)
|
||||||
#define HISTORY_CHANGED (1<<28)
|
#define HISTORYLOG (1<<28)
|
||||||
#define HISTORYLOG (1<<29)
|
#define RESTRICTED (1<<29)
|
||||||
#define RESTRICTED (1<<30)
|
|
||||||
|
|
||||||
/* Control key sequences, changing these would be very very bad. */
|
/* Control key sequences, changing these would be very very bad. */
|
||||||
#define NANO_CONTROL_SPACE 0
|
#define NANO_CONTROL_SPACE 0
|
||||||
|
|
56
src/search.c
56
src/search.c
|
@ -31,24 +31,39 @@
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "nano.h"
|
#include "nano.h"
|
||||||
|
|
||||||
/* Regular expression helper functions */
|
|
||||||
|
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
|
static int 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)
|
int regexp_init(const char *regexp)
|
||||||
{
|
{
|
||||||
/* Hmm, perhaps we should check for whether regcomp returns successfully */
|
int rc = regcomp(&search_regexp, regexp, REG_EXTENDED |
|
||||||
if (regcomp(&search_regexp, regexp, (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE)
|
(ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE));
|
||||||
| REG_EXTENDED) != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
SET(REGEXP_COMPILED);
|
assert(!regexp_compiled);
|
||||||
|
if (rc != 0) {
|
||||||
|
size_t len = regerror(rc, &search_regexp, NULL, 0);
|
||||||
|
char *str = charalloc(len);
|
||||||
|
|
||||||
|
regerror(rc, &search_regexp, str, len);
|
||||||
|
statusbar(_("Bad regex \"%s\": %s"), regexp, str);
|
||||||
|
free(str);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
regexp_compiled = TRUE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void regexp_cleanup(void)
|
void regexp_cleanup(void)
|
||||||
{
|
{
|
||||||
if (ISSET(REGEXP_COMPILED)) {
|
if (regexp_compiled) {
|
||||||
UNSET(REGEXP_COMPILED);
|
regexp_compiled = FALSE;
|
||||||
regfree(&search_regexp);
|
regfree(&search_regexp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,9 +161,12 @@ int search_init(int replacing)
|
||||||
#endif
|
#endif
|
||||||
"",
|
"",
|
||||||
|
|
||||||
|
#ifdef HAVE_REGEX_H
|
||||||
/* This string is just a modifier for the search prompt; no
|
/* This string is just a modifier for the search prompt; no
|
||||||
* grammar is implied. */
|
* grammar is implied. */
|
||||||
ISSET(USE_REGEXP) ? _(" [Regexp]") : "",
|
ISSET(USE_REGEXP) ? _(" [Regexp]") :
|
||||||
|
#endif
|
||||||
|
"",
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* This string is just a modifier for the search prompt; no
|
/* This string is just a modifier for the search prompt; no
|
||||||
|
@ -170,7 +188,6 @@ int search_init(int replacing)
|
||||||
if (i == -1 || (i < 0 && last_search[0] == '\0') ||
|
if (i == -1 || (i < 0 && last_search[0] == '\0') ||
|
||||||
(!replacing && i == 0 && answer[0] == '\0')) {
|
(!replacing && i == 0 && answer[0] == '\0')) {
|
||||||
statusbar(_("Search Cancelled"));
|
statusbar(_("Search Cancelled"));
|
||||||
reset_cursor();
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
search_history.current = search_history.next;
|
search_history.current = search_history.next;
|
||||||
#endif
|
#endif
|
||||||
|
@ -180,21 +197,15 @@ int search_init(int replacing)
|
||||||
case -2: /* It's the same string. */
|
case -2: /* It's the same string. */
|
||||||
#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) == 0)
|
||||||
statusbar(_("Invalid regex \"%s\""), last_search);
|
|
||||||
reset_cursor();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 0: /* They entered something new. */
|
case 0: /* They entered something new. */
|
||||||
last_replace[0] = '\0';
|
last_replace[0] = '\0';
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
if (ISSET(USE_REGEXP) && regexp_init(answer) == 0) {
|
if (ISSET(USE_REGEXP) && regexp_init(answer) == 0)
|
||||||
statusbar(_("Invalid regex \"%s\""), answer);
|
|
||||||
reset_cursor();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
|
@ -424,11 +435,8 @@ int do_research(void)
|
||||||
|
|
||||||
#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) == 0)
|
||||||
statusbar(_("Invalid regex \"%s\""), last_search);
|
return -1;
|
||||||
reset_cursor();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
search_last_line = 0;
|
search_last_line = 0;
|
||||||
|
@ -914,7 +922,7 @@ int do_find_bracket(void)
|
||||||
|
|
||||||
regexp_init(regexp_pat);
|
regexp_init(regexp_pat);
|
||||||
/* We constructed regexp_pat to be a valid expression. */
|
/* We constructed regexp_pat to be a valid expression. */
|
||||||
assert(ISSET(REGEXP_COMPILED));
|
assert(regexp_compiled);
|
||||||
|
|
||||||
search_last_line = 0;
|
search_last_line = 0;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
|
|
@ -2380,6 +2380,7 @@ void statusbar(const char *msg, ...)
|
||||||
waddstr(bottomwin, " ]");
|
waddstr(bottomwin, " ]");
|
||||||
wattroff(bottomwin, A_REVERSE);
|
wattroff(bottomwin, A_REVERSE);
|
||||||
wnoutrefresh(bottomwin);
|
wnoutrefresh(bottomwin);
|
||||||
|
reset_cursor();
|
||||||
wrefresh(edit);
|
wrefresh(edit);
|
||||||
/* Leave the cursor at its position in the edit window, not
|
/* Leave the cursor at its position in the edit window, not
|
||||||
* in the statusbar. */
|
* in the statusbar. */
|
||||||
|
|
Loading…
Reference in New Issue