/* $VER: EditLogin.rexx 1.0 (4/25/95 by Spike Dethman)
*/
/* allow users to edit their own individual sys.welcome series */

options results ; signal on SYNTAX ; signal on ERROR ; signal on IOERR

changewhere 'Editing login'
getuser 39 ; uucp=result ; userwelcome='Mail:users/'uucp'/sys.welcome'
getuser 27 ; width=result ; getuser 28 ; term=result
editwelcome='Pfiles:EditLogin.welcome'
defwelcome='systext:tt'term'.welcome.default'
if ~exists(defwelcome) then defwelcome='systext:sys.welcome.default'

Start:
if ~exists(editwelcome) then do ;
	transmit editwelcome' not found- Please inform Sysop.' ;
	exit ;
end

LoadLogin:
	totoptions=0
	call open('i',editwelcome,'r')
	do while ~eof('i') ;
		i=totoptions+1 ;
		opttext.i=readln('i') ; if eof('i') then iterate ;
		optdesc.i=readln('i') ; if eof('i') then iterate ;
		optcmd.i=readln('i') ; if eof('i') then iterate ;
		totoptions=totoptions+1 ;
	end
	call close('i')

	do i=1 to totoptions ;
		optflag.i=0 ;
	end i

	file=userwelcome ; call LoadUser

Menu:
	transmit 'n1Here are your current login options:n1'
	otxt='Test This Login' ; onum=1 ; ostat=-1 ; call ListOpt
	otxt='Reset to system defaults' ; onum=2 ; ostat=-1 ; call ListOpt
	do i=1 to totoptions ;
		otxt=opttext.i ; onum=i+2 ; ostat=optflag.i ; call ListOpt ;
	end i

	if totoptions%2~=totoptions/2 then sendstring 'n1'

	sendstring 'n1Enter the # of the item to change, or press ENTER to continue.n1:i64 3}'
	getuser 70 ; choice=result

	if choice='' then signal SaveExit 

	if choice<1 | choice>totoptions+2 then signal Menu

	if choice=1 then do ;
		 call LoginTest ; signal MENU ;
	end

	if choice=2 then do ;
		file=defwelcome ; call LoadUser ; signal Menu ;
	end

	i=choice-2
	transmit 'n1'optdesc.i
	sendstring 'n1Do you want to enable the "'opttext.i'" option [Yes] ?1}'
	getuser 70 ; optflag.i=result

	signal Menu

SaveExit:
	call open('o',userwelcome,'w')
	do i=1 to totoptions ;
		if optflag.i=1 then call writeln('o',optcmd.i) ;
	end i
	call close('o')

	exit




LoginTest:
	transmit 'Testing Login...n1'
	do i=1 to totoptions ;
		if optflag.i=1 then do ;
			transmit optcmd.i ;
		end ;
	end i

	return

LoadUser:
	if ~exists(file) then file=defwelcome
	call open(f1,file,'r')
	do while ~eof(f1) ;
		cmdline=readln(f1) ; if eof(f1) then iterate ;
		do i=1 to totoptions ;
			if cmdline=optcmd.i then optflag.i=1 ;
		end i ;
	end
	call close(f1)

	return

ListOpt:
	sendstring right(' 'onum') ',4)left(otxt||copies(' ',28),28)
	if ostat>-1 then do ;
		if ostat=0 then otxt=': No  ' ;
		else otxt=': Yes ' ;
		sendstring otxt ;
	end
	else sendstring '      '

	if width<80 | onum%2=onum/2 then sendstring 'n1'

	return

SYNTAX:
ERROR:
IOERR:
transmit errortext(RC)" error in l "sigl"n1>>"sourceline(sigl)"<< in EditLogin.rexx"
bufferflush
exit 10
