/* 
 * datentime.c
 * (C)1995 NHSW, Torge Hjorth.
 *
 * Prints a date and time string to standard output.
 * Eks: 1995.07.06 20:00:03
 */

#define __USE_SYSBASE 1

#include <stdlib.h>

#include <exec/types.h>
#include <devices/timer.h>
#include <proto/utility.h>
#include <proto/exec.h>
#include <proto/timer.h>
#include <proto/dos.h>

char __ver[] = "$VER: datentime 1.0 (06.07.95)\n";

LONG __saveds Jalla_main(char *jalla)
{
	struct ClockData cd;
	struct Library *TimerBase;
	struct Library *DOSBase; 
	struct Library *UtilityBase;
	struct ExecBase *SysBase = *((struct ExecBase **)4);
	struct timerequest tr;
	struct timeval tv;

	LONG retval = 20;
	
	if (DOSBase = OpenLibrary("dos.library",37))
	{
		if (UtilityBase = OpenLibrary("utility.library",37))
		{
			if (!(OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest *)&tr,0)))
			{
				TimerBase = (struct Library *)tr.tr_node.io_Device;
				GetSysTime(&tv);
				Amiga2Date(tv.tv_secs,&cd);
				Printf("%04ld.%02ld.%02ld %02ld:%02ld:%02ld\n",cd.year,cd.month,cd.mday,cd.hour,cd.min,cd.sec);
				retval = 0;
				CloseDevice((struct IORequest *)&tr);
			}
			CloseLibrary(UtilityBase);
		}
		CloseLibrary(DOSBase);
	}
	return(retval);
}

