/* Sort Events Date-Time-Alpha */

	VER				= 'EZCron v3.00ß15 by Jim Hines'
	LF				= '0a'x
	defevent	 	= 'rx,ezcron:rexx/TalkingClock.rexx,hourly,daily,--/--/--,--/--/--,--:--,--:--,-,-,0,Talking Clock Script,'

	SIGNAL ON ERROR
	SIGNAL ON IOERR
	SIGNAL ON SYNTAX
	SIGNAL ON HALT
	SIGNAL ON BREAK_C
	OPTIONS FAILAT 20
	OPTIONS RESULTS

	if ~show('L','rexxsupport.library') then
   		call addlib('rexxsupport.library', 0, -30)
	
	if ~show('L','rexxreqtools.library') then
   		call addlib("rexxreqtools.library", 0, -30, 0)

	a = 1
	A = 1
	b = 2
	B = 2
	c = 3
	C = 3
	d = 4
	D = 4
	e = 5
	E = 5
	f = 6
	F = 6
	g = 7
	G = 7
	h = 8
	H = 8
	i = 9
	I = 9
	j = 10
	J = 10
	k = 11
	K = 11
	l = 12
	L = 12
	m = 13
	M = 13
	n = 14
	N = 14
	o = 15
	O = 15
	p = 16
	P = 16
	q = 17
	Q = 17
	r = 18
	R = 18
	s = 19
	S = 19
	t = 20
	T = 20
	u = 21
	U = 21
	v = 22
	V = 22
	w = 23
	W = 23
	x = 24
	X = 24
	y = 25
	Y = 25
	z = 26
	Z = 26

address EZCRONPREFS
eventparse:
	do forever
		setlist selectevent clear
		event. = 0
		
		if ~open('cronfile', 's:cron.config', 'R') then do
			call message('Config file not found...Exiting')
			call exiting()
		end
		
		errors = 0
		do until eof('cronfile')
			linein = readln('cronfile')
			parse var linein line ';'
			next = event.0 + 1
	
	        parse var line event.next.command','event.next.pargs','event.next.time',',
			event.next.date','event.next.startdate','event.next.enddate',',
			event.next.rng1','event.next.rng2','event.next.sfx','event.next.txt',',
			event.next.run','event.next.desc','

			if event.next.run = '' then event.next.run = N
			if event.next.run = 'N' then event.next.run = '0'
			if event.next.run = 'Y' then event.next.run = '1'
			if event.next.run = 'X' then event.next.run = '2'

			event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',,
							'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
							/* THE ABOVE TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */

			event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',,
							'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
							/* THE ABOVE TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */

			event.next.txt = strip(event.next.txt) /* This Gets rid of the leading & trailing spaces in the LAST variable
													  If new fields are added, the variable must be changed to reflect this */
	
			if line ~= '' then do  /* This keeps the commented out lines from appearing */
				if event.next.desc = '' then event.next.desc = 'No Description Available' /* Check and fix for old config files */
				setlist selectevent '"'event.next.desc'"'
			end
		
			select
				when event.next.command = '' then iterate
				when event.next.command = '' then do
					iterate
				end
				otherwise event.0 = next
			end
		end
		call close('cronfile')
		call waitforpkt()
	end

/* ===== END OF PARSE  */

syntax:
ioerr:
error:
    errorrc = RC
    call rtezrequest('EZCron has exited with an error'||LF||'Line' SIGL ERRORTEXT(errorrc),'Okay!','EZCron FATAL ERROR','rt_reqpos = reqpos_centerscr rtez_flags=ezreqf_centertext',)
	call exiting()

exiting:
break_c:
	hide unload		/* Hide the window and unload the gui */
	call closeport('EZCRONPREFS')
	address command 'sys:rexxc/vxc >nil:'
	address command 'sys:rexxc/vxc >nil:'
	address command 'sys:rexxc/vxc >nil:'
	address command 'sys:rexxc/vxc >nil:'
	address command 'run >nil: avail flush'	
	exit
