key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/*
**               j###t  ########## ####   ####
**              j###t   ########## ####   ####
**             j###T               "###L J###"
**          ######P'    ##########  #########
**          ######k,    ##########   T######T
**          ####~###L   ####
**          #### q###L  ##########   .#####
**          ####  \###L ##########   #####"
*/

package key;

import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Enumeration;
import java.io.IOException;

public abstract class CommandCategory extends Command implements CategoryCommand
{
	public void runCommand( Commandable c, Player p, StringTokenizer args, String fullLine, InteractiveConnection ic, Flags flags ) throws IOException
	{
		c.run( p, args, fullLine, this, ic, flags );
	}

	/**
	  * should put the player into this mode
	 */
	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
			//  this will only be called if none of the sub-commands
			//  were validated.
		
		fullLine = fullLine.trim().toLowerCase();
		
		StringTokenizer st = new StringTokenizer( fullLine );
		Vector v = new Vector( 25, 50 );
		
		for( Enumeration e = p.getCategoryCommandsMatching( st ); e.hasMoreElements(); )
		{
			Object[] o = (Object[]) e.nextElement();
			
			CommandList cl;
			
			if( o[0] != null )
				cl = ((CommandContainer) o[0]).getCommandList();
			else
				cl = (CommandList) o[1];
				
			for( Enumeration f = cl.elements(); f.hasMoreElements(); )
			{
				String s = ((Command)f.nextElement()).getName();
				
				if( !v.contains( s ) )
					v.addElement( s );
			}
		}
		
		if( v.size() > 0 )
		{
			ic.send( "'" + fullLine +
				"' is not a command, it is a category that contains other commands.  For instance, you might type '" +
				fullLine + " " + ((String) v.elementAt( 0 )) +
				"'.  The full list of available commands is: ^h" +
				Grammar.commaSeperate( v.elements() ) + "^-" );
		}
		else
			ic.send( "There are no available sub-commands in this category." );
	}
	
	public String getPrompt( Player p )
	{
		return( getName() + ": " );
	}
	
	public String getEnd()
	{
		return( "end" );
	}
}