/* $VER: AmIRSay.amirx 2.3 (24/02/00) */
/* Program Written By Bruce Steers <bsteers@btinternet.com> */
/* Using Clipper By Bruce Steers <bsteers@btinternet.com> */

OPTIONS RESULTS
debug=0
LF='0A'X
ver='2.3'
myecho='p='d2c(27)'b«AmIRSay» '
myintro=d2c(2)'«AmIRSay 'ver'»'d2c(2)
go=0
nicknum=1
amirc=0


SIGNAL ON BREAK_C

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

ibase=showlist(l,'intuition.library',,a)
call forbid; scrA=next(ibase,56)
scrW=c2d(IMPORT(offset(scrA,12),2))
scrH=c2d(IMPORT(offset(scrA,14),2))
screen=word(IMPORT(next(scrA,26)),1)
call permit

parse source . . . prog .
lp=max(lastpos('/',prog),lastpos(':',prog))-1
parse var prog progpath +lp +1 progname
progname=strip(progname)

lp=max(lastpos('/',progpath),lastpos(':',progpath))
parse var progpath amircpath +lp .
progpath=progpath'/'


call makemuicodes()

IF ~getsay() THEN do;call sayme('Error finding ''Say'' Command !'); exit(1); end

call loadprefs()
IF index(address(),'AMIRC.')~=0 then amirc=1
 else do;
 p=show(p)
 parse var p 'AMIRC.' pn .
   if pn~="" then do
   address value 'AMIRC.'pn
   amirc=1;
   end
   else do
   amirc=0
   end
 end

if amirc then do; 'getmynick'; mynick=RESULT;end; else; mynick='UnKnown'
call sayChan(myintro mynick' Is now in Speech Mode :^)')

 DO until go~=0
 drop comm; drop dest; drop prefix; drop rest

 call getvars()

 if debug then call sayme('"'rest'"')
 parse var prefix nick '!' user '@' host .

   if comm=="PRIVMSG" then do
     if nick==mynick | nick=='UnKnown' then do
     w1=upper(word(rest,1))
       select
       when w1==":SAYG" then call irsgui()
       when w1==":SAYU" then do; call loadprefs ; call sayme('prefs Reloaded'); end
       when w1==":SAY?" | w1==":SAYH" | w1==":SAYHELP" then call sayhelp();
       when upper(rest)==":SAYQ" | rest==":" then go=1
       otherwise nop
       end
     end
     else; call saytext()

   end
 end

call sayChan(mynick'''s AmIRSay 'ver' has Exited')
Exit

loadprefs:
if ~exists('s:AmIRSay.cfg') then do
if req('AmIRSay Error',' Did not find Prefs file *n*n s:AmIRSAY.cfg *n*n Shall i create a new one ? ','_YES','_NO')==2 then do; say 'AmIRSAY is Quitting'; exit; end
call open(ph,'s:AmIRSAY.cfg','W')
call writeln(ph,'-l0 -m1 -d1 -p1 -u1'LF'Hello, this is just a test')
call writeln(ph,'oic¿oh i see'LF'lol¿laughs outloud'LF'brb¿b right bak'LF'ic¿i see'LF'm8¿mate'LF'[¿]')
call writeln(ph,'8*7<}1:4O)1'LF'*<}:O)'LF'[¿]')
call writeln(ph,'Default¿-r -p100 -s200'LF'Girl¿-f -p270 -s200'LF'Man¿-m -p120 -s200')
call close(ph)
end

call open(ph, 's:AmIRSAY.cfg' )
ln = readln(ph)

 IF index(ln,'-')=0 then do  /* THEN IT's OLD Style Prefs */
 saynick =readln(ph)
 nomui =readln(ph)
 readln(ph); readln(ph); readln(ph)
 end
 else do
 parse var ln '-l' saynick ' -m' nomui .
 end

drop text.
drop blank.
drop uvoice.
text0=0
text.0=0
blank0=0
blank.0=0
uvoice0=0
uvoice.0=0
doing=0

  do c=1 while ~eof(ph)
  ln=readln(ph)
  if ln=="" then leave
    select
    when doing==0 then; if ln=='[¿]' then doing=doing+1; else; call addtext()
    when doing==1 then if ln=='[¿]' then doing=doing+1; else; call addblank()
    when doing==2 then call adduv()
    otherwise nop
    end
  end
call close(ph)

return

addtext:
text0=text0+1
text.0 = text0
parse var ln text.text0.t_repl '¿' text.text0.t_with
text.text0.t_with = strip(text.text0.t_with)
return

addblank:
blank0=blank0+1
blank.0 = blank0
blank.blank0 = ln
return

adduv:
uvoice0=uvoice0 + 1
uvoice.0 = uvoice0
parse var ln uvoice.uvoice0.uv_nick '¿' uvoice.uvoice0.uv_mode
uvoice.uvoice0.uv_mode = strip(uvoice.uvoice0.uv_mode)
return


saytext:

if saynick then rest=nick'.' rest

 if nomui==1 then do
   do c=1 to nom.0
   orest=rest
   rest=reptag(rest,nom.c,"")
   if orest~=rest then c=c-1
   end
 end

 if 0 < text.0 then do
  do c=1 to text.0
  orest=rest
  rest=reptag(rest,text.c.t_repl,text.c.t_with,1)
  if orest~=rest then c=c-1
  end
 end

 if 0 < blank.0 then do
  do c=1 to blank.0
  orest=rest
  rest=reptag(rest,blank.c,"")
  if orest~=rest then c=c-1
  end
 end

if nick ~= lastnick then call checkvoice()

ADDRESS command sayc' <>nil: 'uvoice.nicknum.uv_mode' 'substr(rest,2)
drop rest
return

reptag: PROCEDURE  /* replaces text for text */
parse arg ln , tag , rep , word1; word1=strip(word1)
p=1

ln=substr(ln,2)

 if word1=="" then do
	do until p<1
	p=index(upper(ln),upper(tag),p)
		if p~=0 then do
      ln=delstr(ln,p,length(tag))
      ln=insert(rep,ln,p-1)
      p=p+1
		end
	end
 end
 else do
	do c=1 to words(ln)
		if upper(word(ln,c))==upper(tag) then do
		ps=wordindex(ln,c)
      ln=delstr(ln,ps,length(tag))
      ln=insert(rep,ln,ps-1)
      p=p+1
		end
	end
 end
return ':'ln

checkvoice:
if uvoice.0 == 0 then return
lastnick = nick
nicknum=1
 do c=1 to uvoice.0
 if nick == uvoice.c.uv_nick then nicknum = c
 end
return

getvars:
 if Amirc then do
 'getline'
 comm=line.command
 dest=line.dest
 rest=translate(line.rest,"'","`")
 prefix=line.prefix
 parse var prefix nick '!' host .
 getmynick
 mynick=result
 return
 end
writech(STDOUT, 'enter line: ')
rest=':'readln(STDIN)
comm='PRIVMSG'
dest='#Amiga'
prefix='Test!~id@domain.com'
parse var prefix nick '!' host .
if word(rest,1)=':mn' then do
mynick='Test'; rest=':'substr(rest,5)
end
else; mynick='UnKnown'
return

SayChan:
if amirc then; 'say 'myintro arg(1)
else; say 'CHAN: 'arg(1)
return

SayMe:
if amirc then; 'echo 'myecho arg(1)
else; say 'PRIV: 'arg(1)
return

sayhelp:
call sayme('AmIRSAY By Bruce.  ( commands are case insensitive)')
call sayme('')
call sayme(' /msg yourself to run the following commands ....')
call sayme('SAYG   = Load the AmIRSAYPrefs GUI')
call sayme('SAYU   = Update settings')
call sayme('SAYQ   = Quit AmIRSAY')
call sayme(' SAY? SAYHELP or SAYH = Calls this help text')
call sayme('')
return

req:
 parse arg rbar,rtxt,rg1,rg2,rg3,rg4,rg5,rg6,rg7,rg8 .; if rf~=0 then call close(rf); call open(rf,'awnpipe:ClipperReq/xc'); call writeln(rf,'"'rbar'" v it "Clipper" sw dg db a ps "'screen'"');
call writeln(rf,'space');; call writeln(rf,'layout b 5'); call writeln(rf,'space'); call writeln(rf,'label so weih 5 weiw 10 gt "*n*n'rtxt'"'); call writeln(rf,'space'); call writeln(rf,'le'); call writeln(rf,'layout b 0 si so');
if rg1~="" then call writeln(rf,'button gt "'rg1'" close');if rg2~="" then call writeln(rf,'button gt "'rg2'" close');if rg3~="" then call writeln(rf,'button gt "'rg3'" close'); if rg4~="" then call writeln(rf,'button gt "'rg4'" close');
if rg5~="" then call writeln(rf,'button gt "'rg5'" close');if rg6~="" then call writeln(rf,'button gt "'rg6'" close');if rg7~="" then call writeln(rf,'button gt "'rg7'" close');if rg8~="" then call writeln(rf,'button gt "'rg8'" close');
call writeln(rf,'le'); call writeln(rf,'open');call readln(rf); do while ~eof(rf); rn=readln(rf); parse var rn rn1 rn2 rn3 rn4 rn5 .; if rn1=='gadget' then return(rn2-2); end; return(0)

irsgui:
if ~show('p','IRSPREFS') then
 address command 'run >nil: 'amircpath'AmIRSayPrefs'
else
 address IRSPREFS 'show'
return

makemuicodes:
nom.1='0';   nom.2='1';   nom.3='2';   nom.4='3'
nom.5='4';   nom.6='5';   nom.7='6';   nom.8='7'
nom.9='8';   nom.10='9';  nom.11='10'; nom.12='11'
nom.13='12'; nom.14='13'; nom.15='14'; nom.16='15'
nom.17='';   nom.18='';   nom.19='';   nom.20=''
nom.21='';   nom.0=21
return

BREAK_C: call saychan(myintro' has Quit (Ctrl_C Detected)'); exit(0)

getsay:
sayc='sys:utilities/say' ; if exists(sayc) THEN return(1)
sayc='C:say' ; if exists(sayc) THEN return(1)
sayc='sys:system/say' ; if exists(sayc) THEN return(1)
sayc='say' ; if exists(sayc) THEN return(1)
return (0)
