Actually apply Rocco's spell check fix to the 1.0 tree :-)

git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_0_branch/nano@996 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2002-01-11 13:42:49 +00:00
parent 04c3c425ac
commit 2c7d2c4e50
3 changed files with 40 additions and 29 deletions

37
nano.c
View File

@ -1297,27 +1297,36 @@ int do_int_spell_fix(char *word)
edit_update(fileage, TOP); edit_update(fileage, TOP);
/* make sure word is still mis-spelt (i.e. when multi-errors) */ while (1) {
if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL)
{
do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */ /* make sure word is still mis-spelt (i.e. when multi-errors) */
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace, if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL) {
/* find wholewords only */
if (!is_whole_word(current_x, current, prevanswer))
continue;
do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace,
_("Edit a replacement")); _("Edit a replacement"));
do_replace_highlight(FALSE, prevanswer); do_replace_highlight(FALSE, prevanswer);
/* start from the start of this line again */ /* start from the start of this line again */
current = fileage; current = fileage;
current_x = beginx_top; current_x = beginx_top;
search_last_line = FALSE; search_last_line = FALSE;
if (strcmp(prevanswer,answer) != 0) { if (strcmp(prevanswer,answer) != 0) {
j = i; j = i;
do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j); do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j);
}
} }
break;
} }
/* restore the search/replace strings */ /* restore the search/replace strings */

View File

@ -83,6 +83,7 @@ int renumber_all(void);
int open_file(char *filename, int insert, int quiet); int open_file(char *filename, int insert, int quiet);
int do_writeout(char *path, int exiting); int do_writeout(char *path, int exiting);
int do_gotoline(long defline); int do_gotoline(long defline);
int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i); int wholewords, int *i);
/* Now in move.c */ /* Now in move.c */

View File

@ -212,6 +212,20 @@ void not_found_msg(char *str)
} }
} }
int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword)
{
/* start of line or previous character not a letter */
if ((curr_pos < 1) || (!isalpha((int) fileptr->data[curr_pos-1])))
/* end of line or next character not a letter */
if (((curr_pos + strlen(searchword)) == strlen(fileptr->data))
|| (!isalpha((int) fileptr->data[curr_pos + strlen(searchword)])))
return TRUE;
return FALSE;
}
filestruct *findnextstr(int quiet, filestruct * begin, int beginx, filestruct *findnextstr(int quiet, filestruct * begin, int beginx,
char *needle) char *needle)
{ {
@ -523,21 +537,8 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
break; break;
/* Make sure only whole words are found */ /* Make sure only whole words are found */
if (wholewords) if ((wholewords) && (!is_whole_word(current_x, fileptr, prevanswer)))
{ continue;
/* start of line or previous character not a letter */
if ((current_x == 0) || (!isalpha((int) fileptr->data[current_x-1])))
{
/* end of line or next character not a letter */
if (((current_x + strlen(prevanswer)) == strlen(fileptr->data))
|| (!isalpha((int) fileptr->data[current_x + strlen(prevanswer)])))
;
else
continue;
}
else
continue;
}
/* If we're here, we've found the search string */ /* If we're here, we've found the search string */
if (!replaceall) { if (!replaceall) {