<commit_before>/* (C) 2015 <NAME>. */

#include <assert.h>
#include <ctype.h>
#include <curses.h>
#include <stdbool.h>

#include "draw.h"
#include "buffer.h"
#include "yank.h"

int lwe_scroll;

struct {
	char *start;
	char *end;
} bounds;

static void pc(char c);
static void ptarg(int count);
static void refresh_bounds(void);
static void nextline(char **p);
static void advcursor(char c);

void present(void)
{
	refresh();
}

void clrscreen(void)
{
	erase();
}

int scroll_line()
{
	return lwe_scroll;
}

void set_scroll(int n)
{
	lwe_scroll = n;
	if (lwe_scroll < 0)
		lwe_scroll = 0;
}

void adjust_scroll(int delta)
{
	set_scroll(scroll_line() + delta);
}

char *winstart()
{
	refresh_bounds();
	return bounds.start;
}

char *winend()
{
	refresh_bounds();
	return bounds.end;
}

static void refresh_bounds()
{
	bounds.start = skipscreenlines(getbufptr(), scroll_line());
	int r = 0, c = 0;
	bounds.end = bounds.start;
	while (bounds.end != getbufend() && r < LINES - 1) {
		c++;
		if (*bounds.end == '\n')
			c = 0;
		c %= COLS;
		if (c == 0)
			r++;
		bounds.end++;
	}
	if (bounds.end >= getbufend())
		bounds.end = getbufend() - 1;
	else if (bounds.end > bounds.start && *bounds.end == '\n')
		bounds.end--;
	assert(inbuf(bounds.start) && inbuf(bounds.end));
}

char *skipscreenlines(char *start, int lines)
{
	assert(inbuf(start));
	while (lines > 0 && start < getbufend()) {
		lines -= screenlines(start);
		start = endofline(start) + 1;
	}
	start = start > getbufend() ? getbufend() : start;
	return start;
}

int screenlines(char *start)
{
	char *end = endofline(start);
	if (start == NULL || end == NULL)
		return 1;
	int len = end - start;
	return (len / COLS) + 1;
}
<commit_msg>Remove problematic winbounds adjustment code<commit_after>/* (C) 2015 <NAME>. */

#include <assert.h>
#include <ctype.h>
#include <curses.h>
#include <stdbool.h>

#include "draw.h"
#include "buffer.h"
#include "yank.h"

int lwe_scroll;

struct {
	char *start;
	char *end;
} bounds;

static void pc(char c);
static void ptarg(int count);
static void refresh_bounds(void);
static void nextline(char **p);
static void advcursor(char c);

void present(void)
{
	refresh();
}

void clrscreen(void)
{
	erase();
}

int scroll_line()
{
	return lwe_scroll;
}

void set_scroll(int n)
{
	lwe_scroll = n;
	if (lwe_scroll < 0)
		lwe_scroll = 0;
}

void adjust_scroll(int delta)
{
	set_scroll(scroll_line() + delta);
}

char *winstart()
{
	refresh_bounds();
	return bounds.start;
}

char *winend()
{
	refresh_bounds();
	return bounds.end;
}

static void refresh_bounds()
{
	bounds.start = skipscreenlines(getbufptr(), scroll_line());
	int r = 0, c = 0;
	bounds.end = bounds.start;
	while (bounds.end != getbufend() && r < LINES - 1) {
		c++;
		if (*bounds.end == '\n')
			c = 0;
		c %= COLS;
		if (c == 0)
			r++;
		bounds.end++;
	}
	assert(inbuf(bounds.start) && inbuf(bounds.end));
}

char *skipscreenlines(char *start, int lines)
{
	assert(inbuf(start));
	while (lines > 0 && start < getbufend()) {
		lines -= screenlines(start);
		start = endofline(start) + 1;
	}
	start = start > getbufend() ? getbufend() : start;
	return start;
}

int screenlines(char *start)
{
	char *end = endofline(start);
	if (start == NULL || end == NULL)
		return 1;
	int len = end - start;
	return (len / COLS) + 1;
}

{'fraction_non_alphanumeric': 0.1730241074153189, 'fraction_numerical': 0.009459871833994507, 'mean_word_length': 3.9516616314199395, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6130839', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1301, 'n_words': 333}