1stMUD/corefiles/
1stMUD/gods/
1stMUD/player/
1stMUD/win32/
1stMUD/win32/ROM/
/**************************************************************************
*  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
*  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
*                                                                         *
*  Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael         *
*  Chastain, Michael Quan, and Mitchell Tse.                              *
*                                                                         *
*  In order to use any part of this Merc Diku Mud, you must comply with   *
*  both the original Diku license in 'license.doc' as well the Merc       *
*  license in 'license.txt'.  In particular, you may not remove either of *
*  these copyright notices.                                               *
*                                                                         *
*  Much time and thought has gone into this software and you are          *
*  benefiting.  We hope that you share your changes too.  What goes       *
*  around, comes around.                                                  *
***************************************************************************
*       ROM 2.4 is copyright 1993-1998 Russ Taylor                        *
*       ROM has been brought to you by the ROM consortium                 *
*           Russ Taylor (rtaylor@hypercube.org)                           *
*           Gabrielle Taylor (gtaylor@hypercube.org)                      *
*           Brian Moore (zump@rom.org)                                    *
*       By using this code, you have agreed to follow the terms of the    *
*       ROM license, in the file Rom24/doc/rom.license                    *
***************************************************************************
*       1stMUD ROM Derivative (c) 2001-2002 by Ryan Jennings              *
*            http://1stmud.dlmud.com/  <r-jenn@shaw.ca>                   *
***************************************************************************/
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "olc.h"
#include "tables.h"

const char *do_fun_name args ((DO_FUN * fun));
DO_FUN *do_fun_lookup args ((const char *name));

#define CMDEDIT(fun)    bool fun (CHAR_DATA *ch, const char *argument)

CH_CMD (do_cmdcheck)
{
	int i;
	DO_FUN *fun;
	bool found = FALSE;

	if (IS_NULLSTR (argument))
		chprintln (ch, "Syntax: cmdcheck null|missing|<do_fun_name>");
	else if (!str_prefix (argument, "null"))
	{
		chprintln (ch, "NULL commands:");
		for (i = 0; i < maxCommands; i++)
		{
			if (cmd_table[i].do_fun == do_null)
			{
				found = TRUE;
				chprintlnf (ch, "%s", cmd_table[i].name);
			}
		}
		if (!found)
			chprintln (ch, "None.");
	}
	else if (!str_prefix (argument, "missing"))
	{
		int cmd, pos = 0;
		bool any = FALSE;

		chprintln (ch, "Functions missing command entries:");
		for (i = 0; dofun_table[i].fun != NULL; i++)
		{
			found = FALSE;
			for (cmd = 0; cmd < maxCommands; cmd++)
			{
				if (dofun_table[i].fun == cmd_table[cmd].do_fun)
				{
					found = TRUE;
					break;
				}
			}
			if (!found)
			{
				any = TRUE;
				chprintf (ch, "%15s ", dofun_table[i].name);
				if (++pos % 4 == 0)
					chprintln (ch, "");
			}
		}
		if (pos % 4 != 0)
			chprintln (ch, "");
		if (!any)
			chprintln (ch, "None.");
	}
	else if ((fun = do_fun_lookup (argument)) != NULL)
	{
		chprintlnf (ch, "%s commands:", argument);
		for (i = 0; i < maxCommands; i++)
		{
			if (cmd_table[i].do_fun == fun)
			{
				found = TRUE;
				chprintlnf (ch, "%s", cmd_table[i].name);
			}
		}
		if (!found)
			chprintln (ch, "None.");
	}
	return;
}

CMDEDIT (cmdedit_show)
{
	CMD_DATA *pCmd;

	EDIT_CMD (ch, pCmd);

	chprintln (ch, draw_line (NULL, 0));
	chprintlnf (ch, "Name      : %s", pCmd->name);
	chprintlnf (ch, "DoFun     : %s", do_fun_name (pCmd->do_fun));
	chprintlnf (ch, "Position  : %s",
				flag_string (position_flags, pCmd->position));
	chprintlnf (ch, "Level     : %d", pCmd->level);
	chprintlnf (ch, "Log       : %s", flag_string (log_flags, pCmd->log));
	chprintlnf (ch, "fShow     : %s", !pCmd->show ? "FALSE" : "TRUE");
	chprintln (ch, draw_line (NULL, 0));
	return TRUE;
}

CMDEDIT (cmdedit_create)
{
	int j, i = maxCommands;
	CMD_DATA *pCmd;
	struct cmd_type *new_table;
	char buf[MIL];

	if (!IS_NULLSTR (argument) && command_lookup (argument) == -1)
		sprintf (buf, argument);
	else
		sprintf (buf, "New Command%d", maxCommands + 1);

	maxCommands++;

	alloc_mem (new_table, struct cmd_type, maxCommands + 1);

	if (!new_table)
	{
		chprintln (ch,
				   "Memory Allocation Failed!!! Unable to create command.");
		return FALSE;
	}

	for (j = 0; j < i; j++)
		new_table[j] = cmd_table[j];

	free_mem (cmd_table);
	cmd_table = new_table;

	cmd_table[i].name = str_dup (buf);
	cmd_table[i].do_fun = do_null;
	cmd_table[i].level = 0;
	cmd_table[i].position = POS_DEAD;
	cmd_table[i].show = 0;
	cmd_table[i].log = LOG_NORMAL;

	cmd_table[i + 1].name = str_dup ("");

	pCmd = &cmd_table[i];
	edit_start (ch, pCmd, ED_CMD);
	chprintln (ch, "Command created.");
	return TRUE;
}

CMDEDIT (cmdedit_dofun)
{
	CMD_DATA *pCmd;
	DO_FUN *fun;

	EDIT_CMD (ch, pCmd);

	if (IS_NULLSTR (argument))
	{
		chprintln (ch, "Syntax: dofun <function>");
		return FALSE;
	}

	if (is_name (argument, "none clear reset"))
	{
		pCmd->do_fun = do_null;
		chprintln (ch, "Function entry reset.");
		return TRUE;
	}

	if ((fun = do_fun_lookup (argument)) == do_null)
	{
		chprintln
			(ch, "That is not a valid function (probably not coded in yet)");
		return FALSE;
	}

	pCmd->do_fun = fun;
	chprintlnf (ch, "%s now points to the %s function.", pCmd->name,
				argument);
	return TRUE;
}

CMDEDIT (cmdedit_delete)
{
	CMD_DATA *pCmd;

	EDIT_CMD (ch, pCmd);

	if (str_cmp (argument, "confirm"))
	{
		chprintln
			(ch,
			 "Typing 'delete confirm' again will permanetely remove this command!");
		return FALSE;
	}
	else

	{
		int i, j = 0, c;
		struct cmd_type *new_table;

		alloc_mem (new_table, struct cmd_type, maxCommands + 1);

		if (!new_table)
		{
			chprintln
				(ch, "Memory Allocation error!!! Unable to delete command.");
			return FALSE;
		}

		c = command_lookup (pCmd->name);

		for (i = 0; i < maxCommands; i++)
			if (i != c)
				new_table[j++] = cmd_table[i];

		free_mem (cmd_table);
		cmd_table = new_table;
		maxCommands--;

		pCmd = &cmd_table[0];
		edit_start (ch, pCmd, ED_CMD);
		chprintln (ch, "Command deleted.");
	}

	return TRUE;
}