<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>

int fd = -1;

void usage(int argc, char *argv[]){
	char *name = NULL;
	name = strrchr(argv[0], '/');
	printf("usage : %s [PORT]\n",(name ? name + 1: argv[0]));
}

void set_speed (struct termios *config, speed_t speed)
{
	cfsetispeed(config, speed);
	cfsetospeed(config, speed);
}

void INThandler(int sig)
{
	char yn;
	signal(sig, SIG_IGN);
	printf("quit term ? [Y/n]\n");
	yn = getchar();

	if (yn == 'y' || yn == 'Y')
	{
		close(fd);
		exit(EXIT_SUCCESS);
	}

	exit(0);
}

int main(int argc, char *argv [])
{
	struct termios conf;
	struct termios save;

	char buffer[1024];
	int reads;

	if (argc != 2) {
		usage(argc, argv);
		return 0;
	}

	if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
	{
		usage(argc, argv);
		return 0;
	}

	const char *port = argv[1];

	signal(SIGINT, INThandler);

	/*No block opening to switch to non-local mode*/
	fd = open(port, O_RDWR | O_NONBLOCK);
	if (fd < 0) {
		printf("[ERROR] %s : %s\n",port, strerror(errno));
		exit(EXIT_FAILURE);
	}

	if (tcgetattr(fd, &conf) != 0) {
		printf("%s", strerror(errno));
		exit(EXIT_FAILURE);
	}

	conf.c_cflag   &= ~ CLOCAL;
	tcsetattr(fd, TCSANOW, &conf);

	// We manipulate fd to block it
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) &  ~O_NONBLOCK);

	printf("[INFO] %s : opened\n", port);
	tcgetattr(fd, &conf);

	memcpy(&save, &conf, sizeof(struct termios));
	cfmakeraw(&conf);
	set_speed(&conf, B9600);

	conf.c_cflag &= ~PARENB;
	conf.c_cflag &= ~CSIZE;
	conf.c_cflag |= CS8;
	conf.c_cflag &= ~CSTOPB;
	conf.c_cflag |= CRTSCTS;
	conf.c_cc[VMIN] = 1;
	conf.c_cc[VTIME] = 0;
	conf.c_cflag &= ~CLOCAL;
	conf.c_cflag |= HUPCL;

	if (tcsetattr(fd, TCSANOW, &conf) < 0) {
		printf("%s", strerror(errno));
		exit(EXIT_FAILURE);
	}

	printf("[INFO] %s : configured\n", port);

	printf("[INFO] Data reception started\n");

	while (1) {
		reads = read(fd, buffer, 1024);
		if (reads < 0)  {
			printf("%s", strerror(errno));
			exit(EXIT_FAILURE);<commit_msg>Fixed Baud Rate.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>

int fd = -1;

void usage(int argc, char *argv[]){
	char *name = NULL;
	name = strrchr(argv[0], '/');
	printf("usage : %s [PORT]\n",(name ? name + 1: argv[0]));
}

void set_speed (struct termios *config, speed_t speed)
{
	cfsetispeed(config, speed);
	cfsetospeed(config, speed);
}

void INThandler(int sig)
{
	char yn;
	signal(sig, SIG_IGN);
	printf("quit term ? [Y/n]\n");
	yn = getchar();

	if (yn == 'y' || yn == 'Y')
	{
		close(fd);
		exit(EXIT_SUCCESS);
	}

	exit(0);
}

int main(int argc, char *argv [])
{
	struct termios conf;
	struct termios save;

	char buffer[1024];
	int reads;

	if (argc != 2) {
		usage(argc, argv);
		return 0;
	}

	if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
	{
		usage(argc, argv);
		return 0;
	}

	const char *port = argv[1];

	signal(SIGINT, INThandler);

	/*No block opening to switch to non-local mode*/
	fd = open(port, O_RDWR | O_NONBLOCK);
	if (fd < 0) {
		printf("[ERROR] %s : %s\n",port, strerror(errno));
		exit(EXIT_FAILURE);
	}

	if (tcgetattr(fd, &conf) != 0) {
		printf("%s", strerror(errno));
		exit(EXIT_FAILURE);
	}

	conf.c_cflag   &= ~ CLOCAL;
	tcsetattr(fd, TCSANOW, &conf);

	// We manipulate fd to block it
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) &  ~O_NONBLOCK);

	printf("[INFO] %s : opened\n", port);
	tcgetattr(fd, &conf);

	memcpy(&save, &conf, sizeof(struct termios));
	cfmakeraw(&conf);
	set_speed(&conf, B115200);

	conf.c_cflag &= ~PARENB;
	conf.c_cflag &= ~CSIZE;
	conf.c_cflag |= CS8;
	conf.c_cflag &= ~CSTOPB;
	conf.c_cflag |= CRTSCTS;
	conf.c_cc[VMIN] = 1;
	conf.c_cc[VTIME] = 0;
	conf.c_cflag &= ~CLOCAL;
	conf.c_cflag |= HUPCL;

	if (tcsetattr(fd, TCSANOW, &conf) < 0) {
		printf("%s", strerror(errno));
		exit(EXIT_FAILURE);
	}

	printf("[INFO] %s : configured\n", port);

	printf("[INFO] Data reception started\n");

	while (1) {
		reads = read(fd, buffer, 1024);
		if (reads < 0)  {
			printf("%s", strerror(errno));
			exit(EXIT_FAILURE);
{'fraction_non_alphanumeric': 0.1998103816070159, 'fraction_numerical': 0.015169471438729557, 'mean_word_length': 4.096618357487923, 'pattern_counts': {'":': 0, '<': 25, '<?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': '1926151', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1843, 'n_words': 411}