Improving a few comments.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5322 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-07-26 17:04:29 +00:00
parent f7e8861770
commit 17ab9a2dba
3 changed files with 15 additions and 17 deletions

View File

@ -6,6 +6,7 @@
new bindable functions, 'findnext' and 'findprevious', which repeat new bindable functions, 'findnext' and 'findprevious', which repeat
the last search command in a fixed direction without prompting. the last search command in a fixed direction without prompting.
* src/global.c (shortcut_init): Tweak a string. * src/global.c (shortcut_init): Tweak a string.
* src/search.c, src/move.c: Improve a few of the comments.
2015-07-25 Benno Schulenberg <bensberg@justemail.net> 2015-07-25 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init, strtosc), src/files.c (savefile), * src/global.c (shortcut_init, strtosc), src/files.c (savefile),

View File

@ -52,9 +52,8 @@ void do_page_up(void)
{ {
int i, skipped = 0; int i, skipped = 0;
/* If there's less than a page of text left on the screen, put the /* If the cursor is less than a page away from the top of the file,
* cursor at the beginning of the first line of the file, and then * put it at the beginning of the first line. */
* update the edit window. */
if (openfile->current->lineno == 1 || ( if (openfile->current->lineno == 1 || (
#ifndef NANO_TINY #ifndef NANO_TINY
!ISSET(SOFTWRAP) && !ISSET(SOFTWRAP) &&
@ -106,9 +105,8 @@ void do_page_down(void)
{ {
int i; int i;
/* If there's less than a page of text left on the screen, put the /* If the cursor is less than a page away from the bottom of the file,
* cursor at the beginning of the last line of the file, and then * put it at the end of the last line. */
* update the edit window. */
if (openfile->current->lineno + maxrows - 2 >= if (openfile->current->lineno + maxrows - 2 >=
openfile->filebot->lineno) { openfile->filebot->lineno) {
do_last_line(); do_last_line();

View File

@ -547,12 +547,11 @@ void do_research(void)
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Calculate the size of the replacement line, taking possible
* subexpressions \1 to \9 into account. Return the replacement
* text in the passed string only when create is TRUE. */
int replace_regexp(char *string, bool create) int replace_regexp(char *string, bool create)
{ {
/* We have a split personality here. If create is FALSE, just
* calculate the size of the replacement line (necessary because of
* subexpressions \1 to \9 in the replaced text). */
const char *c = last_replace; const char *c = last_replace;
size_t search_match_count = regmatches[0].rm_eo - size_t search_match_count = regmatches[0].rm_eo -
regmatches[0].rm_so; regmatches[0].rm_so;
@ -596,12 +595,13 @@ int replace_regexp(char *string, bool create)
} }
#endif /* HAVE_REGEX_H */ #endif /* HAVE_REGEX_H */
/* Return a copy of the current line with one needle replaced. */
char *replace_line(const char *needle) char *replace_line(const char *needle)
{ {
char *copy; char *copy;
size_t new_line_size, search_match_count; size_t new_line_size, search_match_count;
/* Calculate the size of the new line. */ /* First calculate the size of the new line. */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) { if (ISSET(USE_REGEXP)) {
search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so; search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so;
@ -618,10 +618,10 @@ char *replace_line(const char *needle)
/* Create the buffer. */ /* Create the buffer. */
copy = charalloc(new_line_size); copy = charalloc(new_line_size);
/* The head of the original line. */ /* Copy the head of the original line. */
strncpy(copy, openfile->current->data, openfile->current_x); strncpy(copy, openfile->current->data, openfile->current_x);
/* The replacement text. */ /* Add the replacement text. */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
replace_regexp(copy + openfile->current_x, TRUE); replace_regexp(copy + openfile->current_x, TRUE);
@ -629,9 +629,9 @@ char *replace_line(const char *needle)
#endif #endif
strcpy(copy + openfile->current_x, answer); strcpy(copy + openfile->current_x, answer);
/* The tail of the original line. */
assert(openfile->current_x + search_match_count <= strlen(openfile->current->data)); assert(openfile->current_x + search_match_count <= strlen(openfile->current->data));
/* Copy the tail of the original line. */
strcat(copy, openfile->current->data + openfile->current_x + strcat(copy, openfile->current->data + openfile->current_x +
search_match_count); search_match_count);
@ -797,9 +797,8 @@ ssize_t do_replace_loop(
#endif #endif
openfile->current_x += match_len + length_change - 1; openfile->current_x += match_len + length_change - 1;
/* Clean up. */ /* Update the file size, and put the changed line into place. */
openfile->totsize += mbstrlen(copy) - openfile->totsize += mbstrlen(copy) - mbstrlen(openfile->current->data);
mbstrlen(openfile->current->data);
free(openfile->current->data); free(openfile->current->data);
openfile->current->data = copy; openfile->current->data = copy;