<commit_before>/*
 *  tslib/tests/ts_conf.c
 *
 *  Copyright (C) 2018 <NAME>
 *
 * This file is part of tslib.
 *
 * ts_print_mt is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * ts_print_mt is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ts_print_mt.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 *
 * Test the ts_config_filter API. Change filters at runtime.
 */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include <getopt.h>
#include <errno.h>
#include <unistd.h>

#include "tslib.h"
#include "testutils.h"

static void usage(char **argv)
{
	ts_print_ascii_logo(16);
	printf("%s", tslib_version());
	printf("\n");
	printf("ts_conf tests changing filters and their parameters at runtime\n");
	printf("Usage: %s [--version] [--help] [--idev <input_dev>]\n",
		argv[0]);
}

static void print_module_line(struct ts_module_conf *conf)
{
	if (conf->raw)
		printf("module_raw %s " YELLOW "%s" RESET "\n",
			conf->name, conf->params);
	else
		printf("%d: module %s " YELLOW "%s" RESET "\n",
			conf->nr, conf->name, conf->params);
}

static struct ts_module_conf *get_first(struct ts_module_conf *conf)
{
	struct ts_module_conf *conf_first = NULL;

	while (conf) {
		if (!conf->prev)
			conf_first = conf;

		conf = conf->prev;
	}
	conf = conf_first;

	return conf;
}

static void print_conf(struct ts_module_conf *conf)
{
	conf = get_first(conf);

	while (conf) {
		print_module_line(conf);
		conf = conf->next;
	}
}

static void edit_params(struct ts_module_conf *conf)
{
	int choice;
	char buf[1024] = { '\0' };
	int ret;
	char c;

	print_conf(conf);
	printf("Write parameters for module Nr.: ");
	ret = scanf("%d", &choice);
	if (ret <= 0) {
		perror("scanf");
		return;
	}

	conf = get_first(conf);

	while (conf) {
		if (conf->nr == choice) {
			printf("%s\n", conf->params);
			while ((c = getchar()) != '\n' && c != EOF) { }
			ret = scanf("%[^\n]s", buf);
			if (ret < 0)
				return;
			sprintf(conf->params, "%s", buf);
		}
		conf = conf->next;
	}
}

static int add_line_after(struct ts_module_conf *conf)
{
	struct ts_module_conf *new_filter;
	struct ts_module_conf *conf_last = NULL;
	int nr;
	int found = 0;
	int ret;
	char c;

	printf("add module after nr: ");
	ret = scanf("%d", &nr);
	if (ret <= 0) {
		perror("scanf");
		return -1;
	}

	conf = get_first(conf);

	while (conf) {
		if (conf->nr == nr) {
			found = 1;
			break;
		}
		if (!conf->next)<commit_msg>ts_conf: use int as result for getchar()<commit_after>/*
 *  tslib/tests/ts_conf.c
 *
 *  Copyright (C) 2018 <NAME>
 *
 * This file is part of tslib.
 *
 * ts_print_mt is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * ts_print_mt is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ts_print_mt.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 *
 * Test the ts_config_filter API. Change filters at runtime.
 */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include <getopt.h>
#include <errno.h>
#include <unistd.h>

#include "tslib.h"
#include "testutils.h"

static void usage(char **argv)
{
	ts_print_ascii_logo(16);
	printf("%s", tslib_version());
	printf("\n");
	printf("ts_conf tests changing filters and their parameters at runtime\n");
	printf("Usage: %s [--version] [--help] [--idev <input_dev>]\n",
		argv[0]);
}

static void print_module_line(struct ts_module_conf *conf)
{
	if (conf->raw)
		printf("module_raw %s " YELLOW "%s" RESET "\n",
			conf->name, conf->params);
	else
		printf("%d: module %s " YELLOW "%s" RESET "\n",
			conf->nr, conf->name, conf->params);
}

static struct ts_module_conf *get_first(struct ts_module_conf *conf)
{
	struct ts_module_conf *conf_first = NULL;

	while (conf) {
		if (!conf->prev)
			conf_first = conf;

		conf = conf->prev;
	}
	conf = conf_first;

	return conf;
}

static void print_conf(struct ts_module_conf *conf)
{
	conf = get_first(conf);

	while (conf) {
		print_module_line(conf);
		conf = conf->next;
	}
}

static void edit_params(struct ts_module_conf *conf)
{
	int choice;
	char buf[1024] = { '\0' };
	int ret;
	int c;

	print_conf(conf);
	printf("Write parameters for module Nr.: ");
	ret = scanf("%d", &choice);
	if (ret <= 0) {
		perror("scanf");
		return;
	}

	conf = get_first(conf);

	while (conf) {
		if (conf->nr == choice) {
			printf("%s\n", conf->params);
			while ((c = getchar()) != '\n' && c != EOF) { }
			ret = scanf("%[^\n]s", buf);
			if (ret < 0)
				return;
			sprintf(conf->params, "%s", buf);
		}
		conf = conf->next;
	}
}

static int add_line_after(struct ts_module_conf *conf)
{
	struct ts_module_conf *new_filter;
	struct ts_module_conf *conf_last = NULL;
	int nr;
	int found = 0;
	int ret;
	int c;

	printf("add module after nr: ");
	ret = scanf("%d", &nr);
	if (ret <= 0) {
		perror("scanf");
		return -1;
	}

	conf = get_first(conf);

	while (conf) {
		if (conf->nr == nr) {
			found = 1;
			break;
		}
		if (!conf->next)
{'fraction_non_alphanumeric': 0.15294517059921914, 'fraction_numerical': 0.007129519606178917, 'mean_word_length': 3.694820717131474, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4775420', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2148, 'n_words': 651}