Пример #1
0
int register_command(struct command *cmd)
{
	/*
	 * We do not check if the command already exists.
	 * This allows us to overwrite a builtin command
	 * with a module.
	 */

	debug("register command %s\n", cmd->name);

	list_add_sort(&cmd->list, &command_list, compare);

	if (cmd->aliases) {
		char **aliases = (char**)cmd->aliases;
		while(*aliases) {
			char *usage = "alias for ";
			struct command *c = xzalloc(sizeof(struct command));

			memcpy(c, cmd, sizeof(struct command));

			c->name = *aliases;
			c->usage = xmalloc(strlen(usage) + strlen(cmd->name) + 1);
			sprintf((char*)c->usage, "%s%s", usage, cmd->name);

			c->aliases = NULL;

			register_command(c);

			aliases++;
		}
	}

	return 0;
}
Пример #2
0
int register_command(struct command *cmd)
{
	/*
	 * We do not check if the command already exists.
	 * This allows us to overwrite a builtin command
	 * with a module.
	 */

	debug("register command %s\n", cmd->name);

	list_add_sort(&cmd->list, &command_list, compare);

	if (cmd->aliases) {
		const char * const *aliases = cmd->aliases;
		while(*aliases) {
			struct command *c = xzalloc(sizeof(struct command));

			memcpy(c, cmd, sizeof(struct command));

			c->name = *aliases;
			c->desc = cmd->desc;
			c->opts = cmd->opts;

			c->aliases = NULL;

			register_command(c);

			aliases++;
		}
	}

	return 0;
}