<commit_before>/**
 * @file
 *
 * @date 02.02.2009
 * @author <NAME>
 */

#include <embox/unit.h>

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include <util/array.h>
#include <cmd/framework.h>

#include <shell_utils.h>
#include "console/console.h"

// XXX just for now -- Eldar
EMBOX_UNIT(shell_start, shell_stop);

#include <shell_command.h>

static void deprecated_exec_callback(CONSOLE_CALLBACK *cb, CONSOLE *console, char *cmdline) {
	int words_counter = 0;

	SHELL_COMMAND_DESCRIPTOR *c_desc;
	char *words[CMDLINE_MAX_LENGTH + 1];

	if (0 == (words_counter = parse_str(cmdline, words))) {
		/* Only spaces were entered */
		return;
	}
	if (NULL == (c_desc = shell_command_descriptor_find_first(words[0], -1))) {
		return;
	}
	if (NULL == c_desc->exec) {
		return;
	}

	printf("%s: Executing command using deprecated API.\n\n", words[0]);
	shell_command_exec(c_desc, words_counter, words);
}

static void exec_callback(CONSOLE_CALLBACK *cb, CONSOLE *console, char *cmdline) {
	const struct cmd *cmd;
	int code;
	/* In the worst case cmdline looks like "x x x x x x". */
	char *argv[(CMDLINE_MAX_LENGTH + 1) / 2];
	int argc = 0;

	if (0 == (argc = parse_str(cmdline, argv))) {
		/* Only spaces were entered */
		return;
	}

	if (NULL == (cmd = cmd_lookup(argv[0]))) {
#if 0
		printf("%s: Command not found\n", argv[0]);
#else
		deprecated_exec_callback(cb, console, cmdline);
#endif
		return;
	}

	if (0 != (code = cmd_exec(cmd, argc, argv))) {
		printf("%s: Command returned with code %d: %s\n", cmd_name(cmd), code,
				strerror(-code));
	}
}

/**
 * Guesses command using its beginning
 *
 * -- Eldar
 */
static void guess_callback(CONSOLE_CALLBACK *cb, CONSOLE *console,
		const char* line, const int max_proposals, int *proposals_len,
		const char *proposals[], int *offset, int *common) {
	const struct cmd *cmd;<commit_msg>Fix backward compatibility with old shell commands<commit_after>/**
 * @file
 *
 * @date 02.02.2009
 * @author <NAME>
 */

#include <embox/unit.h>

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include <util/array.h>
#include <cmd/framework.h>

#include <shell_utils.h>
#include "console/console.h"

// XXX just for now -- Eldar
EMBOX_UNIT(shell_start, shell_stop);

#include <shell_command.h>

static void deprecated_exec_callback(int argc, char **argv) {
	SHELL_COMMAND_DESCRIPTOR *c_desc;

	if (NULL == (c_desc = shell_command_descriptor_find_first(argv[0], -1))) {
		return;
	}
	if (NULL == c_desc->exec) {
		return;
	}

	printf("%s: Executing command using deprecated API.\n\n", argv[0]);
	shell_command_exec(c_desc, argc, argv);
}

static void exec_callback(CONSOLE_CALLBACK *cb, CONSOLE *console, char *cmdline) {
	const struct cmd *cmd;
	int code;
	/* In the worst case cmdline looks like "x x x x x x". */
	char *argv[(CMDLINE_MAX_LENGTH + 1) / 2];
	int argc = 0;

	if (0 == (argc = parse_str(cmdline, argv))) {
		/* Only spaces were entered */
		return;
	}

	if (NULL == (cmd = cmd_lookup(argv[0]))) {
#if 0
		printf("%s: Command not found\n", argv[0]);
#else
		deprecated_exec_callback(argc, argv);
#endif
		return;
	}

	if (0 != (code = cmd_exec(cmd, argc, argv))) {
		printf("%s: Command returned with code %d: %s\n", cmd_name(cmd), code,
				strerror(-code));
	}
}

/**
 * Guesses command using its beginning
 *
 * -- Eldar
 */
static void guess_callback(CONSOLE_CALLBACK *cb, CONSOLE *console,
		const char* line, const int max_proposals, int *proposals_len,
		const char *proposals[], int *offset, int *common) {
	const struct cmd *cmd;
{'fraction_non_alphanumeric': 0.15561877667140825, 'fraction_numerical': 0.01166429587482219, 'mean_word_length': 4.224368499257058, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '2061921', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1315, 'n_words': 356}