/* Adds /ALIAS's to Amirc prefs */

parse arg cfg

parse source sr

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

call open(ih,cfg)
call open(oh,'T:Default.AmIRCfg',W)
at=0
alias0=0
dones=""

  do while ~eof(ih)
  ln = readln(ih);

    if at=="a" then do
       if ln=="" then do;
       at="e" ; call checkalias()
       end
       else do
       alias0=alias0+1
       alias.alias0=ln
       end
    end

     if at==0 then do
     if ln=="# Alias list" then at="a"
     call writeln(oh,ln)
     end

  if at=="e" then call writeln(oh,ln)

  end

call close(ih)
call close(oh)

done = (g==0) + (q==0) + (h==0) + (u==0)

if done==0 then do
call req( 'AmIRSay install', 'All items were there allready :^)' || '0A'X || '' || '0A'X || 'No Changes have been made','_OK')
call deleteit()
end
rq=0
call req('AmIRSay install','I found 'done' Item'ps(done)' that want adding' || '0A'X || '' || '0A'X || ''dones'' || '0A'X || '' || '0A'X || 'Backup Default.AmIRCfg as' || '0A'X || 'Default.AmIRCfg.bak ?' '_YES|_NO|_Abort')
if rq == 0 then call deteteit()
if rq == 1 then address command 'copy clone "'cfg'" "'cfg'.bak"'
address command 'copy clone T:Default.AmIRCfg "'cfg'"'

deleteit:
address command 'delete <>nil: T:Default.AmIRCfg'
exit(0)


checkalias:
g=0; q=0; h=0; u=0

do c=1 to alias0
if upper(word(alias.c,2))=="SAYG" then g=c
if upper(word(alias.c,2))=="SAYQ" then q=c
wd=upper(word(alias.c,2))
if wd=="SAY?" | wd=="SAYH" | wd=="SAYHELP" then h=c
if upper(word(alias.c,2))=="SAYU" then u=c
call writeln(oh,alias.c)
end

if g==0 then do; dones=dones'/SAYG' || '0A'X || ''
call writeln(oh,'ALIAS SAYG /rx "options results; ''getmynick''; ''say /msg ''result'' sayg''"')
end
if q==0 then do; dones=dones'/SAYQ' || '0A'X || ''
call writeln(oh,'ALIAS SAYQ /rx "options results; ''getmynick''; ''say /msg ''result'' sayq''"')
end
if h==0 then do; dones=dones'/SAY?' || '0A'X || ''
call writeln(oh,'ALIAS SAY? /rx "options results; ''getmynick''; ''say /msg ''result'' sayh''"')
end
if u==0 then do; dones=dones'/SAYU' || '0A'X || ''
call writeln(oh,'ALIAS SAYU /rx "options results; ''getmynick''; ''say /msg ''result'' sayu''"')
end
return

req:
 rq = rtezrequest(arg(2),arg(3),arg(1),'rt_reqpos = reqpos_centerscr   rt_leftoffset = 120')
return
