slightly simplify paragraph searching code

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1539 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2003-09-04 23:22:47 +00:00
parent 8faf305d0c
commit 74ea836fcc
1 changed files with 59 additions and 67 deletions

126
nano.c
View File

@ -2436,24 +2436,24 @@ int do_para_operation(int operation)
} }
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* We no longer need to check quotation, unless we're searching for /* We no longer need to check quotation, unless we're searching for
the beginning of the paragraph. */ * the beginning of the paragraph. */
if (operation != 1) if (operation != 1)
regfree(&qreg); regfree(&qreg);
#endif #endif
/* Now par_len is the number of lines in this paragraph. Should never /* Now par_len is the number of lines in this paragraph. Should never
* call quotes_match() or quote_length() again. */ * call quotes_match() or quote_length() again. */
/* If operation is nonzero, skip the justification, since we're only /* If we're searching for the beginning of the paragraph, skip the
* searching through the paragraph. If operation is 2, move down the * justification. If we're searching for the end of the paragraph,
* number of lines in the paragraph, so that we end up at the * move down the number of lines in the paragraph and skip the
* paragraph's end. */ * justification. */
if (operation != 0) { if (operation == 1)
if (operation == 2) { goto skip_justify;
while (par_len > 0) { else if (operation == 2) {
current = current->next; while (par_len > 0) {
current_y++; current = current->next;
par_len--; current_y++;
} par_len--;
} }
goto skip_justify; goto skip_justify;
} }
@ -2629,64 +2629,56 @@ int do_para_operation(int operation)
} }
skip_justify: skip_justify:
if (operation != 0) { if (operation == 1) {
switch (operation) { /* We're on the same line we started on. Search for the first
case 1: * non-"blank" line before the line we're on (if there is one),
/* We're on the same line we started on. Search for the * continually restart that search from the current position
* first non-"blank" line before the line we're on (if * until we find a line that's part of a paragraph, and then
* there is one), continually restart that search from * search once more from there, so that we end up on the first
* the current position until we find a line that's part * line of that paragraph. In the process, skip over lines
* of a paragraph, and then search once more from there, * consisting only of spacing characters, as searching for the
* so that we end up on the first line of that * end of the paragraph does. Then update the screen. */
* paragraph. In the process, skip over lines if (current != fileage && current == current_save && !no_restart) {
* consisting only of spacing characters, as searching while (current->prev != NULL) {
* for the end of the paragraph does. Then update the int j, j_space = 0;
* screen. */ current = current->prev;
if (current != fileage && current == current_save && current_y--;
!no_restart) { for (j = 0; j < strlen(current->data); j++) {
while (current->prev != NULL) { if (isspace(current->data[j]))
int j, j_space = 0; j_space++;
current = current->prev; else {
current_y--; j = -1;
for (j = 0; j < strlen(current->data); j++) { break;
if (isspace(current->data[j]))
j_space++;
else {
j = -1;
break;
}
}
if (j != j_space && strlen(current->data) >=
(quote_len + indent_len) &&
current->data[quote_len + indent_len] != '\0') {
no_restart = 1;
break;
}
} }
goto restart_bps; }
} else if (j != j_space && strlen(current->data) >=
no_restart = 0; (quote_len + indent_len) &&
current->data[quote_len + indent_len] != '\0') {
no_restart = 1;
break;
}
}
goto restart_bps;
} else
no_restart = 0;
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* We no longer need to check quotation, if we were /* We no longer need to check quotation, if we were
searching for the beginning of the paragraph. */ * searching for the beginning of the paragraph. */
regfree(&qreg); regfree(&qreg);
#endif #endif
if (current_y < 0) if (current_y < 0)
edit_update(current, CENTER); edit_update(current, CENTER);
else else
edit_refresh(); edit_refresh();
break; return 0;
case 2: } else if (operation == 2) {
/* We've already moved to the end of the paragraph. /* We've already moved to the end of the paragraph. Update the
* Update the screen. */ * screen. */
if (current_y > editwinrows - 1) if (current_y > editwinrows - 1)
edit_update(current, CENTER); edit_update(current, CENTER);
else else
edit_refresh(); edit_refresh();
break; return 0;
}
if (operation != 0)
return 0;
} }
if (current_y > editwinrows - 1) if (current_y > editwinrows - 1)