<commit_before>#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include <tag.h>

#include <ln.h>
#include <util.h>

/* sorry */
#define foreach_node(N, L)	  \
	for (struct frag *_n, **_l=&(L); \
	     (_n = (N) = *_l) \
	     && (*_l = untag(_n->link[0]), true);)

static struct frag *nodes_from_lines(char *buffer, size_t length);
static struct frag *link_node(struct frag *node, struct frag *list);

int
ln_insert(struct frag **f, size_t x, char *s, size_t n)
{
	struct frag *Q, *q;

	Q = nodes_from_lines(s, n);
	if (!Q) return ENOMEM;

	*f = frag_query(*f, x);

	foreach_node (q, Q) {
		frag_insert(*f, *f ? f[0]->len : 0, q);
		*f = q;
	}

	return 0;
}

struct frag *
link_node(struct frag *q, struct frag *Q)
{
	q->link[0] = tag0(Q);
	return q;
}

struct frag *
nodes_from_lines(char *s, size_t n)
{
	struct frag *Q=0x0;
	struct frag *q=0;
	size_t z=0;

	while (n) {
		z = next_line(s, n);

		q = calloc(1, sizeof *q);
		if (!q) goto fail;

		q->len = z;
		Q = link_node(q, Q);

		s += z, n -= z;
	}

	return Q;

 fail:
	foreach_node(q, Q) free(q);
	return 0x0;
}

void<commit_msg>Style.<commit_after>#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include <tag.h>

#include <ln.h>
#include <util.h>

/* sorry */
#define foreach_node(N, L)	  \
	for (struct frag *_n, **_l=&(L); \
	     (_n = (N) = *_l) \
	     && (*_l = untag(_n->link[0]), true);)

static struct frag *nodes_from_lines(char *s, size_t n);
static struct frag *link_node(struct frag *q, struct frag *Q);

int
ln_insert(struct frag **f, size_t x, char *s, size_t n)
{
	struct frag *Q, *q;

	Q = nodes_from_lines(s, n);
	if (!Q) return ENOMEM;

	*f = frag_query(*f, x);

	foreach_node (q, Q) {
		frag_insert(*f, *f ? f[0]->len : 0, q);
		*f = q;
	}

	return 0;
}

struct frag *
link_node(struct frag *q, struct frag *Q)
{
	q->link[0] = tag0(Q);
	return q;
}

struct frag *
nodes_from_lines(char *s, size_t n)
{
	struct frag *Q=0x0;
	struct frag *q=0x0;
	size_t y=0;

	while (n) {
		y = next_line(s, n);
		s += y, n -= y;

		q = calloc(1, sizeof *q);
		if (!q) goto fail;

		q->len = y;
		Q = link_node(q, Q);
	}

	return Q;

 fail:
	foreach_node(q, Q) free(q);
	return 0x0;
}

void
{'fraction_non_alphanumeric': 0.19359205776173286, 'fraction_numerical': 0.012184115523465704, 'mean_word_length': 3.355599214145383, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '3530087', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1004, 'n_words': 275}