<commit_before>#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tinyrl.h"
#include "complete.h"

static char **complete(tinyrl_t * t, const char *text,
		       unsigned len)
{
	char **matches = NULL;

	if (!len || text[0] == 'h') {
		matches = tinyrl_add_match(matches, "hello");
		matches = tinyrl_add_match(matches, "help");
	}

	return matches;
}

static bool complete_key(tinyrl_t * t, int key)
{
	tinyrl_match_e status;
	const char *text;
	unsigned start;
	unsigned len;
	char **matches;
	bool ret = false;

	/* find the start of the current word */
	text = tinyrl__get_line(t);
	start = len = tinyrl__get_point(t);
	while (start && !isspace(text[start - 1])) {
		start--;
	}
	text += start;
	len -= start;

	/* try and complete the word */
	matches = complete(t, text, len);
	if (!matches)
		return false;

	status = tinyrl_complete(t, start, matches);
	switch (status) {
	case TINYRL_MATCH:
	case TINYRL_COMPLETED_MATCH:
		ret = tinyrl_insert_text(t, " ");
		break;
	case TINYRL_AMBIGUOUS:
	case TINYRL_COMPLETED_AMBIGUOUS:
	case TINYRL_MATCH_WITH_EXTENSIONS:
		tinyrl_crlf(t);
		tinyrl_display_matches(t, matches);
		tinyrl_reset_line_state(t);
		break;
	case TINYRL_NO_MATCH:
		break;
	}

	tinyrl_delete_matches(matches);

	return ret;
}

int main(int argc, char *argv[])
{
	tinyrl_t *t;
	char *line;

	t = tinyrl_new(stdin, stdout, 0);
	tinyrl_bind_key(t, '\t', complete_key);

	for (;;) {
		line = tinyrl_readline(t, "> ", NULL);
		if (!line)
			break;

		if (strcmp(line, "exit") == 0) {
			free(line);
			break;
		}

		printf("echo: %s\n", line);

		tinyrl_history_add(tinyrl__get_history(t), line);
		free(line);
	}

	tinyrl_delete(t);
	return 0;
}

<commit_msg>example: complete() doesn't need tinyrl_t<commit_after>#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tinyrl.h"
#include "complete.h"

static char **complete(const char *text, unsigned len)
{
	char **matches = NULL;

	if (!len || text[0] == 'h') {
		matches = tinyrl_add_match(matches, "hello");
		matches = tinyrl_add_match(matches, "help");
	}

	return matches;
}

static bool complete_key(tinyrl_t * t, int key)
{
	tinyrl_match_e status;
	const char *text;
	unsigned start;
	unsigned len;
	char **matches;
	bool ret = false;

	/* find the start of the current word */
	text = tinyrl__get_line(t);
	start = len = tinyrl__get_point(t);
	while (start && !isspace(text[start - 1])) {
		start--;
	}
	text += start;
	len -= start;

	/* try and complete the word */
	matches = complete(text, len);
	if (!matches)
		return false;

	status = tinyrl_complete(t, start, matches);
	switch (status) {
	case TINYRL_MATCH:
	case TINYRL_COMPLETED_MATCH:
		ret = tinyrl_insert_text(t, " ");
		break;
	case TINYRL_AMBIGUOUS:
	case TINYRL_COMPLETED_AMBIGUOUS:
	case TINYRL_MATCH_WITH_EXTENSIONS:
		tinyrl_crlf(t);
		tinyrl_display_matches(t, matches);
		tinyrl_reset_line_state(t);
		break;
	case TINYRL_NO_MATCH:
		break;
	}

	tinyrl_delete_matches(matches);

	return ret;
}

int main(int argc, char *argv[])
{
	tinyrl_t *t;
	char *line;

	t = tinyrl_new(stdin, stdout, 0);
	tinyrl_bind_key(t, '\t', complete_key);

	for (;;) {
		line = tinyrl_readline(t, "> ", NULL);
		if (!line)
			break;

		if (strcmp(line, "exit") == 0) {
			free(line);
			break;
		}

		printf("echo: %s\n", line);

		tinyrl_history_add(tinyrl__get_history(t), line);
		free(line);
	}

	tinyrl_delete(t);
	return 0;
}


{'fraction_non_alphanumeric': 0.14811542991755006, 'fraction_numerical': 0.002944640753828033, 'mean_word_length': 4.258513931888545, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '552418', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1366, 'n_words': 313}