Commit c510042b authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

do more int ->bool conversions, change the order of the parameters in

findnextstr(), and make findnextstr() maintain the value of current_y
too


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1918 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 50c7f2de
Showing with 65 additions and 39 deletions
+65 -39
...@@ -16,13 +16,19 @@ CVS code - ...@@ -16,13 +16,19 @@ CVS code -
- Remove redundant NANO_SMALL #ifdef. (DLR) - Remove redundant NANO_SMALL #ifdef. (DLR)
- nano.c: - nano.c:
do_para_begin(), do_para_end() do_para_begin(), do_para_end()
- Maintain current_y as do_justify() does, for consistency with - Maintain current_y's value when moving up or down lines so
it. (DLR) that smooth scrolling works correctly. (DLR)
- rcfile.c: - rcfile.c:
parse_rcfile() parse_rcfile()
- Add missing brackets around an if statement block so that - Add missing brackets around an if statement block so that
parsing the numeric argument after "tabsize" works properly parsing the numeric argument after "tabsize" works properly
again. (DLR, found by Mike Frysinger) again. (DLR, found by Mike Frysinger)
- search.c:
findnextstr()
- Take the no_sameline parameter after can_display_wrap and
wholewords, not after all other parameters. (DLR)
- Maintain current_y's value when moving up or down lines so
that smooth scrolling works correctly. (DLR)
- winio.c: - winio.c:
unget_kbinput() unget_kbinput()
- New function used as a wrapper for ungetch(). (DLR) - New function used as a wrapper for ungetch(). (DLR)
......
...@@ -1431,7 +1431,7 @@ bool do_int_spell_fix(const char *word) ...@@ -1431,7 +1431,7 @@ bool do_int_spell_fix(const char *word)
search_last_line = FALSE; search_last_line = FALSE;
/* Find the first whole-word occurrence of word. */ /* Find the first whole-word occurrence of word. */
while (findnextstr(TRUE, TRUE, fileage, 0, word, FALSE) != 0) while (findnextstr(TRUE, TRUE, FALSE, fileage, 0, word))
if (is_whole_word(current_x, current->data, word)) { if (is_whole_word(current_x, current->data, word)) {
edit_refresh(); edit_refresh();
......
...@@ -392,21 +392,22 @@ void not_found_msg(const char *str); ...@@ -392,21 +392,22 @@ void not_found_msg(const char *str);
void search_abort(void); void search_abort(void);
void search_init_globals(void); void search_init_globals(void);
int search_init(bool replacing); int search_init(bool replacing);
int is_whole_word(int curr_pos, const char *datastr, const char bool is_whole_word(int curr_pos, const char *datastr, const char
*searchword); *searchword);
int findnextstr(int can_display_wrap, int wholeword, const filestruct bool findnextstr(bool can_display_wrap, bool wholeword, bool
*begin, size_t beginx, const char *needle, int no_sameline); no_sameline, const filestruct *begin, size_t beginx, const char
*needle);
void do_search(void); void do_search(void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
void do_research(void); void do_research(void);
#endif #endif
void replace_abort(void); void replace_abort(void);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
int replace_regexp(char *string, int create_flag); int replace_regexp(char *string, bool create_flag);
#endif #endif
char *replace_line(const char *needle); char *replace_line(const char *needle);
int do_replace_loop(const char *needle, const filestruct *real_current, int do_replace_loop(const char *needle, const filestruct *real_current,
size_t *real_current_x, int wholewords); size_t *real_current_x, bool wholewords);
void do_replace(void); void do_replace(void);
void do_gotoline(int line, bool save_pos); void do_gotoline(int line, bool save_pos);
void do_gotoline_void(void); void do_gotoline_void(void);
......
...@@ -249,7 +249,7 @@ int search_init(bool replacing) ...@@ -249,7 +249,7 @@ int search_init(bool replacing)
return 0; return 0;
} }
int is_whole_word(int curr_pos, const char *datastr, const char bool is_whole_word(int curr_pos, const char *datastr, const char
*searchword) *searchword)
{ {
size_t sln = curr_pos + strlen(searchword); size_t sln = curr_pos + strlen(searchword);
...@@ -266,13 +266,15 @@ int is_whole_word(int curr_pos, const char *datastr, const char ...@@ -266,13 +266,15 @@ int is_whole_word(int curr_pos, const char *datastr, const char
* If can_display_wrap is nonzero, we put messages on the statusbar, and * If can_display_wrap is nonzero, we put messages on the statusbar, and
* wrap around the file boundaries. The return value specifies whether * wrap around the file boundaries. The return value specifies whether
* we found anything. */ * we found anything. */
int findnextstr(int can_display_wrap, int wholeword, const filestruct bool findnextstr(bool can_display_wrap, bool wholeword, bool
*begin, size_t beginx, const char *needle, int no_sameline) no_sameline, const filestruct *begin, size_t beginx, const char
*needle)
{ {
filestruct *fileptr = current; filestruct *fileptr = current;
const char *rev_start = NULL, *found = NULL; const char *rev_start = NULL, *found = NULL;
size_t current_x_find = 0; size_t current_x_find = 0;
/* Where needle was found. */ /* Where needle was found. */
int current_y_find = current_y;
/* rev_start might end up 1 character before the start or after the /* rev_start might end up 1 character before the start or after the
* end of the line. This won't be a problem because strstrwrapper() * end of the line. This won't be a problem because strstrwrapper()
...@@ -302,21 +304,36 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct ...@@ -302,21 +304,36 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct
not_found_msg(needle); not_found_msg(needle);
return 0; return 0;
} }
fileptr =
#ifndef NANO_SMALL
if (ISSET(REVERSE_SEARCH)) {
fileptr = fileptr->prev;
current_y_find--;
} else {
#endif
fileptr = fileptr->next;
current_y_find++;
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(REVERSE_SEARCH) ? fileptr->prev : }
#endif #endif
fileptr->next;
/* Start or end of buffer reached; wrap around. */ /* Start or end of buffer reached; wrap around. */
if (fileptr == NULL) { if (fileptr == NULL) {
if (!can_display_wrap) if (!can_display_wrap)
return 0; return 0;
fileptr =
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(REVERSE_SEARCH) ? filebot : if (ISSET(REVERSE_SEARCH)) {
fileptr = filebot;
current_y_find = editwinrows - 1;
} else {
#endif #endif
fileage; fileptr = fileage;
current_y_find = 0;
#ifndef NANO_SMALL
}
#endif
if (can_display_wrap) if (can_display_wrap)
statusbar(_("Search Wrapped")); statusbar(_("Search Wrapped"));
} }
...@@ -352,6 +369,7 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct ...@@ -352,6 +369,7 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct
/* Set globals now that we are sure we found something. */ /* Set globals now that we are sure we found something. */
current = fileptr; current = fileptr;
current_x = current_x_find; current_x = current_x_find;
current_y = current_y_find;
return 1; return 1;
} }
...@@ -360,7 +378,8 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct ...@@ -360,7 +378,8 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct
void do_search(void) void do_search(void)
{ {
size_t old_pww = placewewant, fileptr_x = current_x; size_t old_pww = placewewant, fileptr_x = current_x;
int i, didfind; int i;
bool didfind;
filestruct *fileptr = current; filestruct *fileptr = current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
...@@ -395,7 +414,7 @@ void do_search(void) ...@@ -395,7 +414,7 @@ void do_search(void)
#endif #endif
search_last_line = FALSE; search_last_line = FALSE;
didfind = findnextstr(TRUE, FALSE, current, current_x, answer, FALSE); didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x, answer);
/* Check to see if there's only one occurrence of the string and /* Check to see if there's only one occurrence of the string and
* we're on it now. */ * we're on it now. */
...@@ -408,8 +427,8 @@ void do_search(void) ...@@ -408,8 +427,8 @@ void do_search(void)
* which case it's the only occurrence. */ * which case it's the only occurrence. */
if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
last_search)) { last_search)) {
didfind = findnextstr(TRUE, FALSE, current, current_x, didfind = findnextstr(TRUE, FALSE, TRUE, current, current_x,
answer, TRUE); answer);
if (fileptr == current && fileptr_x == current_x && !didfind) if (fileptr == current && fileptr_x == current_x && !didfind)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
} else { } else {
...@@ -430,7 +449,7 @@ void do_search(void) ...@@ -430,7 +449,7 @@ void do_search(void)
void do_research(void) void do_research(void)
{ {
size_t old_pww = placewewant, fileptr_x = current_x; size_t old_pww = placewewant, fileptr_x = current_x;
int didfind; bool didfind;
filestruct *fileptr = current; filestruct *fileptr = current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
...@@ -447,8 +466,8 @@ void do_research(void) ...@@ -447,8 +466,8 @@ void do_research(void)
#endif #endif
search_last_line = FALSE; search_last_line = FALSE;
didfind = findnextstr(TRUE, FALSE, current, current_x, didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x,
last_search, FALSE); last_search);
/* Check to see if there's only one occurrence of the string and /* Check to see if there's only one occurrence of the string and
* we're on it now. */ * we're on it now. */
...@@ -461,8 +480,8 @@ void do_research(void) ...@@ -461,8 +480,8 @@ void do_research(void)
* found again, in which case it's the only occurrence. */ * found again, in which case it's the only occurrence. */
if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
last_search)) { last_search)) {
didfind = findnextstr(TRUE, FALSE, current, current_x, didfind = findnextstr(TRUE, FALSE, TRUE, current,
answer, TRUE); current_x, answer);
if (fileptr == current && fileptr_x == current_x && !didfind) if (fileptr == current && fileptr_x == current_x && !didfind)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
} else { } else {
...@@ -491,9 +510,9 @@ void replace_abort(void) ...@@ -491,9 +510,9 @@ void replace_abort(void)
} }
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
int replace_regexp(char *string, int create_flag) int replace_regexp(char *string, bool create_flag)
{ {
/* Split personality here - if create_flag is zero, just calculate /* Split personality here - if create_flag is FALSE, just calculate
* the size of the replacement line (necessary because of * the size of the replacement line (necessary because of
* subexpressions \1 to \9 in the replaced text). */ * subexpressions \1 to \9 in the replaced text). */
...@@ -520,7 +539,7 @@ int replace_regexp(char *string, int create_flag) ...@@ -520,7 +539,7 @@ int replace_regexp(char *string, int create_flag)
/* But add the length of the subexpression to new_size. */ /* But add the length of the subexpression to new_size. */
new_size += i; new_size += i;
/* And if create_flag is nonzero, append the result of the /* And if create_flag is TRUE, append the result of the
* subexpression match to the new line. */ * subexpression match to the new line. */
if (create_flag) { if (create_flag) {
strncpy(string, current->data + current_x + strncpy(string, current->data + current_x +
...@@ -586,24 +605,24 @@ char *replace_line(const char *needle) ...@@ -586,24 +605,24 @@ char *replace_line(const char *needle)
* needle is the string to seek. We replace it with answer. Return -1 * needle is the string to seek. We replace it with answer. Return -1
* if needle isn't found, else the number of replacements performed. */ * if needle isn't found, else the number of replacements performed. */
int do_replace_loop(const char *needle, const filestruct *real_current, int do_replace_loop(const char *needle, const filestruct *real_current,
size_t *real_current_x, int wholewords) size_t *real_current_x, bool wholewords)
{ {
int replaceall = FALSE, numreplaced = -1; int numreplaced = -1;
size_t old_pww = placewewant, current_x_save = current_x; size_t old_pww = placewewant, current_x_save = current_x;
const filestruct *current_save = current; const filestruct *current_save = current;
bool replaceall = FALSE;
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* The starting-line match and bol/eol regex flags. */ /* The starting-line match and bol/eol regex flags. */
int begin_line = FALSE, bol_or_eol = FALSE; bool begin_line = FALSE, bol_or_eol = FALSE;
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
int mark_set = ISSET(MARK_ISSET); bool old_mark_isset = ISSET(MARK_ISSET);
UNSET(MARK_ISSET); UNSET(MARK_ISSET);
edit_refresh(); edit_refresh();
#endif #endif
while (findnextstr(TRUE, wholewords, current_save, current_x_save, while (findnextstr(TRUE, wholewords,
needle,
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* We should find a bol and/or eol regex only once per line. If /* We should find a bol and/or eol regex only once per line. If
* the bol_or_eol flag is set, it means that the last search * the bol_or_eol flag is set, it means that the last search
...@@ -613,7 +632,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, ...@@ -613,7 +632,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
#else #else
FALSE FALSE
#endif #endif
) != 0) { , current_save, current_x_save, needle)) {
int i = 0; int i = 0;
size_t match_len; size_t match_len;
...@@ -739,7 +758,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, ...@@ -739,7 +758,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
new_magicline(); new_magicline();
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (mark_set) if (old_mark_isset)
SET(MARK_ISSET); SET(MARK_ISSET);
#endif #endif
...@@ -956,8 +975,8 @@ void do_find_bracket(void) ...@@ -956,8 +975,8 @@ void do_find_bracket(void)
search_last_line = FALSE; search_last_line = FALSE;
while (TRUE) { while (TRUE) {
if (findnextstr(FALSE, FALSE, current, current_x, regexp_pat, if (findnextstr(FALSE, FALSE, FALSE, current, current_x,
FALSE) != 0) { regexp_pat)) {
/* Found identical bracket. */ /* Found identical bracket. */
if (current->data[current_x] == ch_under_cursor) if (current->data[current_x] == ch_under_cursor)
count++; count++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment