/* I t 's ...

   @@@@@@  @@@@@@  @@
   @@        @@
   @@@@@     @@    @@  @@@@@@@@@    @@@@
   @@        @@    @@  @@  @@  @@  @@  @@
   @@        @@    @@  @@  @@  @@  @@@@@@
   @@        @@    @@  @@  @@  @@  @@
   @@@@@@    @@    @@  @@  @@  @@   @@@@

   N o   R i g h t s   R e s e r v e d    ( P u b l i c )

   B Y:
		A N D R Z E J   J A R M O N I U K
     S O F T W A R E    D E V E L O P M E N T

   (b a s e d   o n   t h e   t r u e   Amiga_E v2.1b   a n d ...
	a n   o l d,   g r e a t   K S 1 . 3 ! ! !)

   Mails ( but not E-mails, I'm soooorry :'( ) are warmly received:
        Andrzej Jarmoniuk, ul. Pîocka 30/43, 06400 Ciechanów, POLAND
*/

MODULE 'intuition/intuition', 'exec/ports', 'dos/dos', 'dos/datetime',
'intuition/screens'

ENUM OK,WARNING

PROC main() HANDLE

	CONST MINUTES_PER_HOUR = 60,
	SECONDS_PER_MINUTE = 60,		/* for clearing the source */
	KEEP_OLD = -1

	DEF ds:datestamp,
	wnd:window,msg:intuimessage,port:mp,scr:screen,
	h_str[3]:STRING,m_str[3]:STRING,s_str[3]:STRING,
	time_str[9]:STRING,
	barh=10

	/* here we are:
			I DON'T KNOW, why a lot people complained that they couldn't
			use DateStamp() function.
			So, if you didn't know it, read this source carefully.
	*/

	
	wnd:=NIL; scr:=NIL
	IF KickVersion(36)
		IF (scr:=LockPubScreen(NIL))=NIL
			WriteF('Could not lock the screen!\n')
			Raise(WARNING)
		ENDIF
		barh:=scr.barheight+1
	ENDIF
	IF (wnd:=OpenWindow([0,0,135,barh,0,1,IDCMP_CLOSEWINDOW,
		WFLG_RMBTRAP+WFLG_DRAGBAR+WFLG_DEPTHGADGET+WFLG_CLOSEGADGET+
		WFLG_NOCAREREFRESH,
		NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,NIL,
		WBENCHSCREEN]:nw))=NIL
	
		WriteF('Could not OPEN THE WINDOW!\n')
		Raise(WARNING)
	ENDIF
	port:=wnd.userport
	
	SetWindowTitles(wnd,NIL,'                      '+
		'ETime, © 1995, Andrzej Jarmoniuk Software Development')

	/*******************************************************/
    /** WATCH THIS CAREFULLY! THIS IS THE MAIN COURSE :-) **/
    /*******************************************************/

	REPEAT
		DateStamp(ds)

		StringF( h_str, '\d[2]', ds.minute / MINUTES_PER_HOUR )
		StringF( m_str, '\z\d[2]', Mod( ds.minute, SECONDS_PER_MINUTE ) )
		StringF( s_str, '\z\d[2]', ds.tick / TICKS_PER_SECOND )

		StringF( time_str, '\s:\s:\s', h_str, m_str, s_str )

		SetWindowTitles( wnd, time_str, KEEP_OLD )

        /*	WindowToFront(wnd)	*/

		Delay(25)
	UNTIL msg:=GetMsg(port)
	ReplyMsg(msg)

	/*******************************************************/
	/** AND SO IT WAS...                                  **/
    /*******************************************************/

	Raise(OK)
EXCEPT
	IF wnd THEN CloseWindow(wnd)
	IF scr THEN UnlockPubScreen(NIL, scr)
	IF exception THEN RETURN 5
ENDPROC

CHAR '$VER: ETime, © Andrzej Jarmoniuk Software Development', 0