Op  4-09-2017 om 18:37 schreef Andreas Grünbacher:
2017-09-04 18:04 GMT+02:00 Benno Schulenberg <bensb...@telfort.nl>:
The original testor.c has this:
$ wc testor.c
   95  388 2719 testor.c

Not in my testing:

$ wc testor.c
  103  415 2983 testor.c

Ouch.  Attached a wrong testor.c?  I could have sworn I attached
the correct, unpatched file.  :|  Now then.

$ file testor.c
testor.c: ASCII text, with CRLF line terminators

It shouldn't have CRs.  That must be an artifact of email.

Benno
/* Try to move up nrows softwrapped chunks from the given line and the
 * given column (leftedge).  After moving, leftedge will be set to the
 * starting column of the current chunk.  Return the number of chunks we
 * couldn't move up, which will be zero if we completely succeeded. */
int go_back_chunks(int nrows, filestruct **line, size_t *leftedge)
{
    int i;

#ifndef NANO_TINY
    if (ISSET(SOFTWRAP)) {
	/* Recede through the requested number of chunks. */
	for (i = nrows; i > 0; i--) {
	    size_t chunk = chunk_for(*leftedge, *line);

	    *leftedge = 0;

	    if (chunk >= i)
		return go_forward_chunks(chunk - i, line, leftedge);

	    if (*line == openfile->fileage)
		break;

	    i -= chunk;
	    *line = (*line)->prev;
	    *leftedge = HIGHEST_POSITIVE;
	}

	if (*leftedge == HIGHEST_POSITIVE)
	    *leftedge = leftedge_for(*leftedge, *line);
    } else
#endif
	for (i = nrows; i > 0 && (*line)->prev != NULL; i--)
	    *line = (*line)->prev;

    return i;
}

/* Try to move down nrows softwrapped chunks from the given line and the
 * given column (leftedge).  After moving, leftedge will be set to the
 * starting column of the current chunk.  Return the number of chunks we
 * couldn't move down, which will be zero if we completely succeeded. */
int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge)
{
    int i;

#ifndef NANO_TINY
    if (ISSET(SOFTWRAP)) {
	size_t current_leftedge = *leftedge;

	/* Advance through the requested number of chunks. */
	for (i = nrows; i > 0; i--) {
	    bool end_of_line = FALSE;

	    current_leftedge = get_softwrap_breakpoint((*line)->data,
					current_leftedge, &end_of_line);

	    if (!end_of_line)
		continue;

	    if (*line == openfile->filebot)
		break;

	    *line = (*line)->next;
	    current_leftedge = 0;
	}

	/* Only change leftedge when we actually could move. */
	if (i < nrows)
	    *leftedge = current_leftedge;
    } else
#endif
	for (i = nrows; i > 0 && (*line)->next != NULL; i--)
	    *line = (*line)->next;

    return i;
}

/* Return TRUE if there are fewer than a screen's worth of lines between
 * the line at line number was_lineno (and column was_leftedge, if we're
 * in softwrap mode) and the line at current[current_x]. */
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge)
{
#ifndef NANO_TINY
    if (ISSET(SOFTWRAP)) {
	filestruct *line = openfile->current;
	size_t leftedge = leftedge_for(xplustabs(), openfile->current);
	int rows_left = go_back_chunks(editwinrows - 1, &line, &leftedge);

	return (rows_left > 0 || line->lineno < was_lineno ||
		(line->lineno == was_lineno && leftedge <= was_leftedge));
    } else
#endif
	return (openfile->current->lineno - was_lineno < editwinrows);
}

Reply via email to