
#include <stdio.h>
#include <stdlib.h>
#include <proto/exec.h>
#include <proto/dos.h>

#define	USE_DOORLIB

#include <proto/pipeline.h>

struct 	Library		*PipelineBase;
long						 LineNumber;
ULONG						 WriteFlags;

void main( int argc, char **argv )
{
	struct	Line		*le;
	struct	List		 hist;
	UBYTE					 buff[80];

	if( argc != 2 )
	{
		Printf( "Don't run this door in a CLI!!  Start as a ZDOOR only!\n\n" );
		Printf( "Usage: %s <Line Number>\n\n", argv[0] );
		return;
	}

	if( PipelineBase = OpenLibrary( "zeus.library", NULL ) )
	{
		LineNumber = atol( argv[1] );
		le = GetLine( LineNumber );

		if( !le )
		{
			Printf( "Illegal line number!\n\n" );
			CloseLibrary( PipelineBase );
			return;
		}

		WriteFlags = NULL;

		LPuts( "\x0c" );
		LPuts( "\n[32mThis door demonstrates various input options that are available.\n" );
		LPuts( "   to Zeus door programmers.\n\n" );

		LPuts( "[36mFirst, a simple 'no-frills' input.  All the standard Zeus command line\n" );
		LPuts( "   editing keys will work here.  See documentation for details.\n\n" );

		LPuts( "[32mType something! : [37m" );
		ReadLineTags( LineNumber, buff, TAG_DONE );

		LPuts( "\n[36mNow a hot key (or 'raw') input!\n\n" );
		LPuts( "[32mPress any key : [37m" );
		ReadLineTags( LineNumber, buff, RLT_Raw, TRUE, TAG_DONE );

		LPuts( "\n[36mZeus gives you the option to filter the incoming characters like so:\n\n" );
		LPuts( "[32mUpper case input : [37m" );
		ReadLineTags( LineNumber, buff, RLT_MakeUpper, TRUE, TAG_DONE );

		LPuts( "[32mLower case input : [37m" );
		ReadLineTags( LineNumber, buff, RLT_MakeLower, TRUE, TAG_DONE );

		LPuts( "[32mOnly numbers     : [37m" );
		ReadLineTags( LineNumber, buff, RLT_OnlyNums, TRUE, TAG_DONE );

		LPuts( "[32m'Secret' input   : [37m" );
		ReadLineTags( LineNumber, buff, RLT_Secret, TRUE, TAG_DONE );

		LPuts( "\n[36mYou can also limit the input to a set of characters using the ONLYOPTS\n" );
		LPuts( "   flag.  In this input you can only type 'A' 'B' and 'C' (and return)\n\n" );
		LPuts( "[32mTry it : [37m" );
		ReadLineTags( LineNumber, buff, RLT_MakeUpper, TRUE, RLT_Opts, "ABC\r", TAG_DONE );

		LPuts( "\n[36mYou can also specify characters that cannot be entered.  For example\n" );
		LPuts( "   in this input you can enter all numbers apart from '6'.\n\n" );
		LPuts( "[32mTry it : [37m" );
		ReadLineTags( LineNumber, buff, RLT_OnlyNums, TRUE, RLT_XOpts, "6", TAG_DONE );

		LPuts( "\n[36mWith 'raw' input you can set a timeout value.\n\n" );
		LPuts( "[32mYou have five seconds to press a key! : [37m" );

		if( ReadLineTags( LineNumber, buff, RLT_Raw, TRUE, RLT_TimeOut, 5000000, TAG_DONE ) )
			LPuts( "\n[36mGot a key!\n" );
		else
			LPuts( "\n\n[36mDidn't get a key!\n" );

		LPuts( "\n[36mZeus' input functions also feature a history buffer which works\n" );
		LPuts( "   much like a normal shell one.  In this example, each line of text you\n" );
		LPuts( "   enter will be stored in the history buffer and can be recalled using the\n" );
		LPuts( "   standard Zeus command history keys (see docs).  Enter a blank line to end.\n\n" );

		NewList( &hist );

		AddHistList( LineNumber, &hist );

		while( 1 )
		{
			LPuts( "[36m> [37m" );

			buff[0] = 0x00;

			ReadLineTags( LineNumber, buff, RLT_Flags, IR_HISTORY | IR_ADDHIST, TAG_DONE );

			if( !buff[0] ) break;
		}

		RemHistList( LineNumber );
		ClearHistList( &hist );

		LPuts( "\n[36mThats the end of this short reading mode demo.  See the source code,\n" );
		LPuts( "   library docs and header files to discover the entire range of input options\n" );
		LPuts( "   available to Zeus door programmers.\n\n" );

		LPuts( "Press any key to exit: " );
		ReadLineTags( LineNumber, buff, RLT_Raw, TRUE, RLT_NoShow, TRUE, TAG_DONE );

		CloseLibrary( PipelineBase );
	}
}
