/*
$VER: Console.quickfile 1.4 (12 Jun 2000  00:03:41) by M Andre Z Eckenrode

Opens a console window in which ARexx and other macro commands may be typed and
executed. The current address port is indicated by the prompt. The size and
position of the window may optionally be customized by providing the following
arguments:

  <left edge> <upper edge> <width> <height>

The following default values are used for any missing arguments:

  120 85 400 100

*/

options results
options failat 100

arg win.x win.y win.w win.h .
if win.h = '' then win.h = 100
if win.w = '' then win.w = 400
if win.y = '' then win.y = 85
if win.x = '' then win.x = 120

call close('STDOUT')
call open('STDOUT',"CON:"win.x"/"win.y"/"win.w"/"win.h"/QuickFile ARexx Console - Type 'Q' to quit/wait",'rw')

mainloop:

	signal on halt
	signal on ioerr
	signal on syntax

	do forever
		writech('STDOUT','[33m'address()'> [31m')
		cmd = readln('STDOUT')

		select
			when upper(cmd) = 'Q' then call halt
			when cmd = '' then nop
			otherwise do
				cmd = cmd'; qfrc = rc; qfresult = result'
				call checkinst
				interpret cmd
				if qfrc < 20 then do
					if qfresult ~= 'RESULT' then do
						say 'QFResult =' qfresult
						result = 'RESULT'
					end
				end
				if qfrc ~= 0 then do
					/* For some reason, the SAY and ECHO instructions cause RC to be set to 12 here */
					if qfrc ~= 12 & pos('SAY ',upper(cmd)) = 0 & pos('ECHO ',upper(cmd)) = 0 then do
						say 'QFRC =' qfrc
						say '*** QuickFile Error ***'
					end
				end
			end
		end
	end

halt:
	say '   Halted...press CTRL+\ to close'
exit

syntax:
	say 'Oops....   'errortext(qfrc)
signal mainloop

ioerr:
	say 'IO error.'
signal mainloop

checkinst: procedure expose cmd
	inst.1 = 'UPDREC'
	inst.2 = 'NEXT'
	inst.3 = 'DOSEARCH'
	inst.4 = 'GOTO'
	inst.5 = 'SHOWALL'
	inst.6 = 'INSREC'
	inst.7 = 'DELREC'
	
	do i = 1 to 7
		if pos(inst.i,upper(cmd)) > 0 then do
			cmd = cmd'; refresh'
			leave
		end
	end
return
