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>
#if !defined(WIN32)
#include <sys/time.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "merc.h"
#include "tables.h"
#include "olc.h"
#include "lookup.h"
#include "recycle.h"
#include "interp.h"

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

HEDIT(hedit_show)
{
	HELP_DATA *help;

	EDIT_HELP(ch, help);

	chprintlnf(ch,
			   "Keyword : [%s]\n\r" "Level   : [%d]\n\r" "Texto   :\n\r"
			   "%s-FIN-", help->keyword, help->level, help->text);

	return FALSE;
}

HEDIT(hedit_level)
{
	HELP_DATA *help;
	int lev;

	EDIT_HELP(ch, help);

	if (IS_NULLSTR(argument) || !is_number(argument))
	{
		chprintln(ch, "Sintaxis : nivel [-1..MAX_LEVEL]");
		return FALSE;
	}

	lev = atoi(argument);

	if (lev < -1 || lev > MAX_LEVEL)
	{
		chprintf(ch, "HEdit : niveles entre -1 y %d solamente.\n\r", MAX_LEVEL);
		return FALSE;
	}

	help->level = lev;
	chprintln(ch, "Ok.");
	return TRUE;
}

HEDIT(hedit_keyword)
{
	HELP_DATA *help;

	EDIT_HELP(ch, help);

	if (IS_NULLSTR(argument))
	{
		chprintln(ch, "Sintaxis : keyword [keywords]");
		return FALSE;
	}

	free_string(help->keyword);
	help->keyword = str_dup(argument);

	chprintln(ch, "Ok.");
	return TRUE;
}

HEDIT(hedit_new)
{
	char arg[MIL], fullarg[MIL];
	HELP_DATA *help;

	if (IS_NULLSTR(argument))
	{
		chprintln(ch, "Sintaxis : new [nombre]");
		chprintln(ch, "           new [area] [nombre]");
		return FALSE;
	}

	strcpy(fullarg, argument);
	argument = one_argument(argument, arg);

	if (help_lookup(argument))
	{
		chprintln(ch, "HEdit : help ya existe.");
		return FALSE;
	}

	help = new_help();
	help->level = 0;
	help->keyword = str_dup(argument);
	help->text = str_dup("");

	LINK(help, help_first, help_last, next, prev);

	edit_start(ch, help, ED_HELP);
	chprintln(ch, "Ok.");
	return FALSE;
}

HEDIT(hedit_text)
{
	HELP_DATA *help;

	EDIT_HELP(ch, help);

	if (!IS_NULLSTR(argument))
	{
		chprintln(ch, "Sintaxis : texto");
		return FALSE;
	}

	string_append(ch, &help->text);

	return TRUE;
}

void hedit(CHAR_DATA * ch, char *argument)
{
	if (ch->pcdata->security < 9)
	{
		chprintln(ch, "HEdit: Insufficient security to modify code.");
		edit_done(ch);
	}

	if (!str_cmp(argument, "done"))
	{
		edit_done(ch);
		return;
	}

	if (emptystring(argument))
	{
		hedit_show(ch, argument);
		return;
	}

	if (!process_olc_command(ch, argument, help_olc_comm_table))
		interpret(ch, argument);
	return;
}

CH_CMD(do_hedit)
{
	HELP_DATA *pHelp;
	char arg[MIL];

	if (IS_NPC(ch))
		return;

	argument = one_argument(argument, arg);

	if (is_name(arg, "create new make"))
	{
		hedit_new(ch, argument);
		return;
	}

	strcat(arg, " ");
	strcat(arg, argument);

	if ((pHelp = help_lookup(arg)) == NULL)
	{
		chprintln(ch, "HEdit : Help inexistente.");
		return;
	}

	edit_start(ch, pHelp, ED_HELP);
	return;
}

HEDIT(hedit_delete)
{
	HELP_DATA *pHelp;
	DESCRIPTOR_DATA *d;

	EDIT_HELP(ch, pHelp);

	for (d = descriptor_first; d; d = d->next)
		if (d->editor == ED_HELP && pHelp == (HELP_DATA *) d->pEdit)
			edit_done(d->character);

	UNLINK(pHelp, help_first, help_last, next, prev);

	free_help(pHelp);

	chprintln(ch, "Ok.");
	return TRUE;
}

HEDIT(hedit_list)
{
	char buf[MIL];
	int cnt = 0;
	HELP_DATA *pHelp;
	BUFFER *buffer;

	EDIT_HELP(ch, pHelp);

	if (!str_cmp(argument, "all"))
	{
		buffer = new_buf();

		for (pHelp = help_first; pHelp; pHelp = pHelp->next)
		{
			sprintf(buf, "%3d. %-14.14s%s", cnt, pHelp->keyword,
					cnt % 4 == 3 ? "\n\r" : " ");
			add_buf(buffer, buf);
			cnt++;
		}

		if (cnt % 4)
			add_buf(buffer, "\n\r");

		page_to_char(buf_string(buffer), ch);
		return FALSE;
	}

	if (IS_NULLSTR(argument))
	{
		chprintln(ch, "Sintaxis : list all");
		return FALSE;
	}

	return FALSE;
}