/********************************************************

	EG2100_Web.c
	2001, Z-World

	Example of a target board creating a web page while
	connected to a EG2100 RabbitLink board.

	This program demonstrates the ability of a Rabbit-
	based target board to update files on the web
	server of the RabbitLink board it is connected to.
	
 ********************************************************/

int get_cons_response(char buf, int bufsize)
{
	int	len, done;

	len = 0;
	done = 0;
	while (!done && (len < bufsize)) {
		if (kbhit()) {
			buf[len] = getchar();
			len++;
		}

		if ((len > 0) && ConsoleFinish(0))
			buf[len] = '\0';
			done = 1;
	}

	return(len);
}

/********************************************************/
 
#define	CTRL_D	0x04
 
main()
{
	struct tm	t;
	
	// enable all STDIO to go to the RabbitLink console
	PrintToConsole(1);

	// make sure we are not in the middle of a command
	printf("\n");

	// turn off local echo
	printf("echo off\n");

	// get RabbitLink response
	get_cons_response(s, 255);
	printf("RabbitLink returned:  %s\n", s);
			
	// delete web page if it exists
	printf("delete demo.html\n");

	// get RabbitLink response
	get_cons_response(s, 255);
	printf("RabbitLink returned:  %s\n", s);
	
	// create the web page
	printf("put demo.html\n");
	printf("<H2>A demonstration web page</H2>\n");
	
	// get the current time	
	tm_rd(&t);
	printf("Created on %02d/%02d/%04d at %02d:%02d:%02d\n",
				t.tm_mon, t.tm_mday, t.tm_year+1900,
				t.tm_hour, t.tm_min, t.tm_sec);
	
	// end web page
	printf("%c", CTRL_D);
	
	// get RabbitLink response
	get_cons_response(s, 255);
	printf("RabbitLink returned:  %s\n", s);

	// stop all STDIO from going to RabbitLink console
	PrintToConsole(0);
}
