<commit_before>/**
 * @file
 * @brief
 *
 * @author  <NAME>
 * @date    30.10.2013
 */

#include <stdio.h>
#include <unistd.h>
#include <drivers/input/input_dev.h>
#include <embox/cmd.h>

EMBOX_CMD(input_test_main);

static void usage(char *argv0) {
	printf("Usage: %s -i INPUT_DEV\n", argv0);
}

static char *dev_type_map(enum input_dev_type type) {
	switch (type) {
	case INPUT_DEV_KBD:
		return "KEYBOARD";
	case INPUT_DEV_MOUSE:
		return "MOUSE";
	case INPUT_DEV_APB:
		return "APB";
	}

	/* NOTREACHED */
	return "";
}

static int indev_cb(struct input_dev *indev) {
	struct input_event ev;

	while (0 == input_dev_event(indev, &ev)) {
		printf("input event: dev_type=%s, type=%08x, value=%08x\n",
			dev_type_map(ev.devtype), ev.type, ev.value);
	}

	return 0;
}

static int input_test_main(int argc, char **argv) {
	int opt;
	char *indev_name = NULL;
	struct input_dev *indev;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "i:"))) {
		switch(opt) {
		case 'i':
			indev_name = optarg;
			break;
		default:
			usage(argv[0]);
			return 1;
		}
	}

	if (!indev_name) {
		usage(argv[0]);
		return 1;
	}

	indev = input_dev_lookup(indev_name);
	if (NULL == indev) {
		printf("Cannot find such input dev");
		return 1;
	}

	if (0 != input_dev_open(indev, indev_cb)) {
		return 1;
	}

	while (1) {
		sleep(1);
	}<commit_msg>cmd input_test isn't endless, some fixes<commit_after>/**
 * @file
 * @brief
 *
 * @author  <NAME>
 * @date    30.10.2013
 */

#include <stdio.h>
#include <unistd.h>
#include <drivers/input/input_dev.h>
#include <embox/cmd.h>

EMBOX_CMD(input_test_main);

static void usage(char *argv0) {
	printf("Usage: %s -i INPUT_DEV\n", argv0);
}

static char *dev_type_map(enum input_dev_type type) {
	switch (type) {
	case INPUT_DEV_KBD:
		return "KEYBOARD";
	case INPUT_DEV_MOUSE:
		return "MOUSE";
	case INPUT_DEV_APB:
		return "APB";
	}

	/* NOTREACHED */
	return "";
}

static int indev_cb(struct input_dev *indev) {
	struct input_event ev;

	while (0 == input_dev_event(indev, &ev)) {
		printf("input event: dev_type=%s, type=%08x, value=%08x\n",
			dev_type_map(ev.devtype), ev.type, ev.value);
	}

	return 0;
}

static int input_test_main(int argc, char **argv) {
	int opt;
	char *indev_name = NULL;
	struct input_dev *indev;
	int res;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "i:"))) {
		switch(opt) {
		case 'i':
			indev_name = optarg;
			break;
		default:
			usage(argv[0]);
			return 1;
		}
	}

	if (!indev_name) {
		usage(argv[0]);
		return 1;
	}

	indev = input_dev_lookup(indev_name);
	if (NULL == indev) {
		printf("Cannot find such input dev\n");
		return -ENOENT;
	}

	if (0 != (res = input_dev_open(indev, indev_cb))) {
		printf("Troubles with open\n");
		return res;
	}

	getchar();

	input_dev_close(indev);
{'fraction_non_alphanumeric': 0.16287468400144456, 'fraction_numerical': 0.01733477789815818, 'mean_word_length': 3.851138353765324, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1660881', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1174, 'n_words': 260}