mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All 
................................................ contributions are welcome. 
....Copyright(C).1995.Melvin.Smith.............. Enjoy. 
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@hom.net
MUD++ development mailing list    mudpp@van.ml.org
------------------------------------------------------------------------------
edithelp.cc
*/

#include "config.h"
#include "string.h"
#include "edit.h"
#include "help.h"
#include "pc.h"

void HelpEditor::command( const String & arg )
{

	String str;
	String arg1;
	String arg2;
	int val1;

	arg.startArgs();
	arg1 = arg.getArg();
	arg2 = arg.getArgRest();

	if ( text )
	{
		text->command( arg );
		if ( text->done() )
		{
			if ( text->getState() != ED_CANCEL )
			{
				OutputFile outf(savefile.chars());
				if ( !outf )
				{
					pc->out("Error creating file.\n\r");
				}
				else
				{
					outf << text->asStr();
					outf.close();
					savefile.clr();
				}
			}
			delete text;
			text = 0;
			state = ED_NONE;
			help->unlock();
			return;
		}
		return;
	}
	else if ( filename )
	{
		state = ED_NONE;
		remove( savefile.chars() );
		rename( filename.chars(), savefile.chars() );
		remove( filename.chars() );
		help->unlock();
		filename.clr();
		savefile.clr();
		return;
	}

	if ( !help )
	{
		pc->out("No help.\n\r");
		return;
	}

	if ( !(bool)arg || (arg == "\n") )
	{
		str << "Keywords: " << help->getName() <<endl;
		str << "Filename: " << help->getFileName() <<endl;
		str << "Level:    " << help->getLevel() <<endl;
		str << "Spec bits:   " << listBits(help_bit_list, help->help_bits) << endl;
		str << "Priv needed: " << listBits(priv_bit_list, &(help->priv_needed)) << endl;
		pc->out(str);
		return;
	}

	if ( arg1 == "view" )
	{
		str << HELP_DIR << "/" << help->getFileName();
		pc->view(str);
		return;
	}
	else if ( arg1 == "level" )
	{
		if ( !arg2.isNumber() )
			return;

		help->setLevel(arg2.asInt() );
		pc->out("Level set.\n\r");
		return;
	}
	else if ( (arg1 == "keywords") || (arg1 == "name") )
	{
		Help::remove(help);
		help->setName(arg2);
		Help::add(help);
		pc->out("Keywords set.\n\r");
		return;
	}
	else if ( arg1 == "text" )
	{
		if ( !(bool)(help->getFileName()) )
		{
			pc->out("First set filename.\n\r");
			return;
		}
		if ( help->isLocked() )
		{
			pc->out("Somebody else is editing it now.\n\r");
			return;
		}
		str << HELP_DIR << "/" << help->getFileName();
		editFile( str );
		state = ED_DESC;
		help->lock();
		return;
	}
	else if ( arg1 == "filename" )
	{
		if ( !(bool)arg2 || !arg2.legalFilename() )
		{
			pc->out("Illegal filename.\n\r");
			return;
		}
		str << HELP_DIR << "/" << arg2;
		InputFile inf(str);
		if (inf)
		{
			pc->out("This filename is used now. Try another one.\n\r");
			return;
		}
		help->setFileName(arg2);
		return;
	}
	else if ( arg1 == "claim" )
	{
		if ( !(bool)arg2 || !arg2.legalFilename() )
		{
			pc->out("Illegal filename.\n\r");
			return;
		}
		str << HELP_DIR << "/" << arg2;
		InputFile inf(str);
		if (!inf)
		{
			pc->out("No such filename. Check and type it again or use 'filename'"
			" to create a new one\n\r");
			return;
		}
		help->setFileName(arg2);
		return;
	}
	else if ( arg1 == "all" )
	{
		TOGGLE_BIT( help->help_bits, ALL_CAN_READ );
		pc->out("'All can read' bit toggled.\n\r");
		return;
	}
	else if ( arg1 == "no-title" )
	{
		TOGGLE_BIT( help->help_bits, NO_TITLE );
		pc->out( "'No title' bit toggled.\n\r");
		return;
	}
	else if ( arg1 == "priv" )
	{
		// change priv bits
		if (!(val1 = lookupBit ( priv_bit_list, arg2 )))
		{
			pc->out("No such privilage bit. See help privilages.\n\r");
			return;
		}
		TOGGLE_BIT( &(help->priv_needed), val1 );
		pc->out("Changed access rights to help.\n\r");
		return;
	}
	else if ( arg1 == "help" )
	{
		pc->view("../help/hedit.hlp");
		pc->page("");
		return;
	}

}