/*
 *
 *  MCDReqMan v1.02 © David Huckett..
 *  Checks loaded CD's for pending requests from
 *  when they were offline..
 *   By David Huckett  16-Sep-95 3:640/800 Fidonet
 *
 * CLI USAGE ONLY..
 *
*/

/*
 *  Short instructions and doc..
 *
 *  Simply use RX MCDReqMan from the CLI once you are in the current
 *  directory that this prog is in, or if you have it in your REXX:
 *  assign, you can use RX MCDReqMan from any CLI window..
 *
 *  Alternativly just double click on the MCDReqMan Icon..
 *
 *  This program is best set up in a Cron Even to be executed nightly
 *  and it will automatically check whatever CD('s) you have loaded and
 *  fulfill any requests...
 *
 *  By Using NODISPLAY as an argument, you can suppress any text display
 *  to the CLI window..  Used mainly if run fro a Cron..
 *
*/

/*
 *  16-Sep-95   Complete rewrite of all the OFFLINE request functions.
 *
 *              Everything was too slow and was to many separate things
 *              for a user to remember...
 *
 * Been away with work and thought up new ideas..  Good to be back home.
 *
*/

REQPATH       = 'Doors:MegaCD/Requests/'
BUFFERDIR     = 'Doors:MegaCD/BUFFER/' 
CDCFG         = 'Doors:MegaCD/CD.cfg'
FILEDIR       = 'Doors:MegaCD/'

/*** NO FURTHER USER ADJUSTABLE VALUES BELOW HERE ***/

arg DISPLAY

	if strip(Upper(DISPLAY)) = 'NODISPLAY' then DISPLAY = 'N'
	else DISPLAY = 'Y'

signal on error;signal on syntax;signal on IOERR;signal on BREAK_C
 if ~show('L','rexxsupport.library') then do
  if ~addlib('rexxsupport.library',0,-30,0) then do
    if DISPLAY = 'Y' then say 'Support library not available.'
     call error
    signal Quit
   end
end

CALL PRAGMA('W','N')

START:

	IF DISPLAY = 'Y' then do
		say '		'
		tit1 = '                  +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+'
		tit2 = '                  +  MegaCD Xenolink1.97 CD-Rom Door  +'
		tit3 = '                  +      Offline Request Manager      +'
		tit4 = '                  +          version 1.02             +'
		tit5 = '                  +    by David Huckett 16-Sep-95..   +'
		tit6 = '                  +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+'
		say tit1;say tit2;say tit3;say tit4;say tit5;say tit6;say ''
	end

if ~exists(CDcfg) then do
	if DISPLAY = 'Y' then say ' You do not have a config file!'
	call ERROR
	end
else do
	Call open(cfg,CDcfg,'R')
		numcd=readln(cfg)
		do i=1 to numcd
			lock.i=readln(cfg)
			title.i=readln(cfg)
			config.i=readln(cfg)
			desc.i=readln(cfg)
			junk=readln(cfg)
			junk=readln(cfg)
		if  ~Exists(lock.i) then do
			title.i='Not Online'
			iterate i
			end
if DISPLAY = 'Y' then do
		say left(title.i,15)||left('LOADED',8)||left(desc.i,45)
		say 'Checking for requests for 'title.i
END

	CDNAME = SPACE(title.i,1,'_')
	If ~EXISTS(REQPATH||CDNAME'.req') then iterate i
 
	else Call Open(cfile,REQPATH||CDNAME'.req',R)
			do while ~EOF(cfile)
			Junk = readln(cfile)
			if Junk = '' then leave
			FULLNAME = word(Junk,1)
                        FULLPATH = word(Junk,2)
                        FILENAME = word(Junk,3)
	CopyToBuffer = 'Copy FROM 'FULLPATH||FILENAME' TO 'BUFFERDIR||FILENAME' QUIET'
			Address command CopytoBuffer 
	if exists(REQPATH||FULLNAME'.fnd') then call open(user,REQPATH||FULLNAME'.fnd',A)
	else call open(user,REQPATH||FULLNAME'.fnd',W)
	Call writeln(user,FILENAME)
	CALL CLOSE(user)
	end
	CALL CLOSE(cfile)
	Address command 'Delete 'REQPATH||CDNAME'.req QUIET'
	end
	call close(cfg)
END
if DISPLAY = 'Y' then do
say ''
say 'Finished...'
say ''
end
call quit

BREAK_C:
call close(cfg)
call close(cfile)
call close(user)

QUIT:
Exit 0

error:
a = SIGL;If DISPLAY = 'Y' then say 'Error!!!  Line # 'a;call delay 200
EXIT 10

syntax:
a = SIGL;If DISPLAY = 'Y' then say 'Syntax Error!!!  Line # 'a;call delay 200
EXIT 10

ioerr:
If DISPLAY = 'Y' then say 'I/O Error!!!';call delay 200
EXIT 10
