home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / on-line / amirsay / rexx / amirsay.amirx < prev   
Encoding:
Text File  |  2000-04-20  |  12.2 KB  |  538 lines

  1. /* Program Written By Bruce Steers <bsteers@btinternet.com> */
  2. /* Using Clipper By Bruce Steers <bsteers@btinternet.com> */
  3.  
  4. OPTIONS RESULTS
  5.  
  6. debug=0
  7.  
  8. amirc=0
  9. go=0
  10. nicknum=1
  11.  
  12. SIGNAL ON BREAK_C
  13. /*SIGNAL ON ERROR*/
  14.  
  15. LF='0A'X
  16. vers='$VER: AmIRSay.amirx 4.5 (09/04/00)'
  17. ver=word(vers,3)
  18.  
  19. myecho='p='d2c(27)'b«AmIRSay» '
  20. myintro='«AmIRSay»'
  21.  
  22. adr=address()
  23.  IF index(adr,'AMIRC.')~=0 then do
  24.  amircport=adr
  25.  parse var adr 'AMIRC.' portnum .
  26.  amirc=1
  27.  end
  28.  else do;
  29.  p=show('p')
  30.  parse var p 'AMIRC.' portnum .
  31.    if portnum~="" then do
  32.    address value 'AMIRC.'portnum
  33.    amirc=1 ;
  34.    end
  35.    else do
  36.    amirc=0
  37.    end
  38.  end
  39.  
  40. call addlib('rexxsupport.library',0,-30,0)
  41. call addlib('rexxdossupport.library',0,-30,0)
  42.  
  43. parse source . . . prog .
  44. lp=max(lastpos('/',prog),lastpos(':',prog))-1
  45. parse var prog progpath +lp +1 progname
  46. progname=strip(progname)
  47.  
  48. lp=max(lastpos('/',progpath),lastpos(':',progpath))
  49. parse var progpath amircpath +lp .
  50. progpath=progpath'/'
  51.  
  52. ownp='AMIRSAYRX.'portnum
  53. overalert=""
  54. parse arg args
  55. ag=upper(word(args,1))
  56.  
  57.  if ag~="" then do
  58.    select
  59.    when index(ag,'-A')==1 then parse var ag '-A' overalert .
  60.    when ag=='SAYN' then do; call irsgui(); address AMIRSAY 'COM GETNEW'; exit; end
  61.    when ag=='SAYV' then do; sayme(vers); exit; end
  62.    when ag=='SAYG' then do; call irsgui(); exit; end
  63.    when ag=='SAYR' then do; 'say /ping'; call reload(); go=1; end;
  64.    when ag=='SAYU' then do; 'say /ping'; address value 'AMIRSAYRX.'portnum; 'SAYU'; exit; end
  65.    when ag=="SAY?" | ag=="SAYH" | ag=="SAYHELP" then do; call sayhelp();exit; end
  66.     otherwise do;
  67.     'say /ping'
  68.     address value ownp
  69.     interpret(args)
  70.     exit
  71.     end
  72.    end
  73.  end
  74.  
  75. call loadprefs()
  76.  
  77. if show('p',ownp) then do
  78. if dstart==0 then call sayme('Error! AmIRSay already running at port AMIRC.'portnum)
  79. else; call irsgui()
  80. exit
  81. end
  82. else
  83. op=openport(ownp)
  84.  
  85.  
  86. ibase=showlist(l,'intuition.library',,a)
  87. call forbid; scrA=next(ibase,56)
  88. scrW=c2d(IMPORT(offset(scrA,12),2))
  89. scrH=c2d(IMPORT(offset(scrA,14),2))
  90. screen=word(IMPORT(next(scrA,26)),1)
  91. call permit
  92.  
  93.  
  94. call makemuicodes()
  95.  
  96. IF ~getsay() THEN do;call sayme('Error finding ''Say'' Command !'); exit(1); end
  97.  
  98. if amirc then do; 'getmynick'; mynick=RESULT;end; else; mynick='Brucey'
  99.  
  100. if overalert~="" then do; oa=alertchan; alertchan=overalert; end
  101. if alertchan | overalert==1 then; call sayChan('V'ver' (^: 'mynick' is now in Speech Mode :^)')
  102. else; call sayme('V'ver' (^: 'mynick' you are now in Speech Mode :^)')
  103. if overalert~="" then alertchan=oa
  104.  
  105.  DO until go~=0
  106.  drop comm; drop dest; drop prefix; drop rest
  107.  
  108.  call getvars()
  109. call getrx()
  110.  
  111.  if debug then call sayme('"'rest'"')
  112. /* parse var prefix nick '!' user '@' host .*/
  113.  
  114.    if comm=="PRIVMSG" then do
  115.  
  116.      if nick==mynick then do
  117.      w1=upper(word(rest,1))
  118.        select
  119.        when w1==":SAY#" then call chanfunc(substr(rest,7))
  120.        when w1==":SAYG" then call irsgui()
  121.        when w1==":SAYV" then call sayme(vers)
  122.        when w1==":SAYU" then do; call loadprefs ; call sayme('prefs Reloaded'); end
  123.        when w1==":SAY?" | w1==":SAYH" | w1==":SAYHELP" then call sayhelp();
  124.        when w1==":SAYQ" | (rest==":" & amirc==0) then go=1
  125.        when w1==":SAYR" then call reload()
  126.        otherwise nop
  127.        end
  128.      end
  129.  
  130. if index(rest,"ACTION ")==3 then do; rest=delstr(rest,1,9); rest=':'nick rest; end
  131.  
  132.    call dosay()
  133.    end
  134.  end
  135.  
  136. IF go~=0 THEN do
  137. if alertchan then; call sayChan(mynick'''s AmIRSay 'ver' has Exited')
  138. else; call sayme(mynick' your AmIRSay 'ver' has Exited')
  139. end
  140. call closeport ownp
  141. Exit
  142.  
  143. chanfunc:
  144.  
  145. parse arg chan; chan=make#(word(chan,1))
  146. select
  147.  when upper(chan)=='#S' then do;
  148. call open(th,'s:amirsay.cfg')
  149. call open(nh,'T:AmIRSay.cfg','W')
  150. at=0
  151. do while at<5
  152. ln=readln(th)
  153. if at~=5 then call writeln(nh,ln)
  154. if ln=='[¿]' then at=at+1
  155. end
  156. call close(th)
  157. sme='Saved New Channel Ignore List, , '
  158. do c=1 to nochan0
  159. call writeln(nh,nochan.c)
  160. sme=sme', 'nochan.c
  161. end
  162. call close(nh)
  163. address command 'copy <>nil: clone T:AmIRSay.cfg s: QUIET'
  164. call delete('T:AmIRSay.cfg')
  165. call sayme(sme)
  166. return;
  167. end
  168.  
  169.  when upper(chan)=='#L' then do
  170.   if nochan0>0 then do
  171.    sme='Channel Ignore List , '
  172.    do c=1 to nochan.0; sme=sme', 'nochan.c; end
  173.   end
  174.   else; sme='Not Ignoring Any Channels'
  175.  call sayme(sme)
  176.  return
  177.  end
  178. otherwise do
  179. sme='';   do c=1 to nochan.0; sme=sme nochan.c; end
  180.  
  181. if chan=='#' then do; "getchannel" ; chan=result; end
  182.  
  183.  if index(upper(sme),upper(chan))~=0 then; call subnochan();
  184.  else; call addnochan(1);
  185. end
  186. return
  187.  
  188. addnochan:
  189.  if arg(1)==1 then do
  190.  ln=chan
  191.   do cc=1 to nochan0
  192.   if upper(ln)==upper(nochan.cc) then do; call sayme('Channel 'nochan.cc' is already being Ignored in AmIRC.'portnum); return; end
  193.   end
  194.  call sayme('Adding 'chan' to the Ignore List')
  195.  end
  196. nochan0=nochan0+1
  197. nochan.0 = nochan0
  198. nochan.nochan0 = ln
  199. return
  200.  
  201. make#: PROCEDURE; new=arg(1); if index(new,'#')~=1 then new='#'new; return new
  202.  
  203. subnochan:
  204. if nochan0==0 then do; call sayme('There are no channels being ignored..'); return; end
  205.  do cc=1 to nochan0
  206.   if upper(chan)==upper(nochan.cc) then do;
  207.   call sayme('Removing Ignore for Channel 'nochan.cc);
  208.    do mc=cc to nochan0
  209.    p1=mc+1
  210.    nochan.mc=nochan.p1
  211.    end
  212.   nochan0=nochan0-1
  213.   nochan.0 = nochan0
  214.   return;
  215.   end
  216.  end
  217.  
  218. call sayme('Error . Channel 'chan' is not set to be ignored')
  219. return
  220.  
  221. reload:
  222. call open(h,'T:tmp','W')
  223. call writeln(h,'/**/')
  224. if show('p','AMIRSAY') then call writeln(h,'address ''AMIRSAY''; QUIT; address command ''run >nil: 'amircpath'AmIRSayPrefs PORT AMIRC.'portnum''' ; address command ''waitforport AMIRSAY''')
  225. call writeln(h,'do while show(''p'','''ownp'''); call delay(30); end')
  226. if ~amirc then call writeln(h,'address command ''rx <>con://///CLOSE 'prog'''')
  227. else; call writeln(h,'address AMIRC.'portnum' ''say /rx amirsay''')
  228. call close(h); address command 'run <>nil: rx t:tmp'
  229. go=1;
  230. return
  231.  
  232. dosay:
  233. parse var rest ':' lin
  234.  IF 0 < (privt.0) then do
  235.   do c=1 to privt.0
  236.   if index(lin,privt.c)==2 then return
  237.   end
  238.  end
  239.  
  240. call saytext()
  241. return
  242.  
  243. loadprefs:
  244. if ~exists('s:AmIRSay.cfg') then do
  245. call open(ph,'s:AmIRSAY.cfg','W')
  246. call writeln(ph,'-l0 -d1 -p1 -a1 -s0'LF'Hello, this is just a test')
  247. call writeln(ph,'oic¿oh i see'LF'lol¿laughs outloud'LF'brb¿b right bak'LF'ic¿i see'LF'm8¿mate'LF'[¿]')
  248. call writeln(ph,'*'LF'<'LF'>'LF'@'LF'^'LF'[¿]')
  249. call writeln(ph,'Default¿-r -p100 -s200'LF'Girl¿-f -p270 -s200'LF'Man¿-m -p120 -s200[¿]')
  250. call writeln(ph,'PING 'LF'SOUND 'LF'DCC 'LF'USERINFO 'LF'VERSION ')
  251. call writeln(ph,'st bernard¿saint bernard[¿]')
  252. call close(ph)
  253. end
  254.  
  255. call open(ph, 's:AmIRSAY.cfg' )
  256. ln = readln(ph)
  257.  
  258.  IF index(ln,'-')==0 then do  /* THEN IT's OLD Style Prefs */
  259.  saynick =readln(ph)
  260.  readln(ph) /* no mui obsolete */
  261.  alertchan=1
  262.  readln(ph); readln(ph); readln(ph)
  263.  end
  264.  else do
  265.  parse var ln '-l' saynick . 0 '-a' alertchan . 0 '-s' dstart . 0 '-r' regnum .
  266.  end
  267. if alertchan=="" then alertchan=1
  268. if dstart=="" then dstart=0
  269. drop text.
  270. drop mwd.
  271. drop blank.
  272. drop uvoice.
  273. drop privt.
  274. drop nochan.
  275. text0=0
  276. text.0=0
  277. mwd0=0
  278. mwd.0=0
  279. blank0=0
  280. blank.0=0
  281. uvoice0=0
  282. uvoice.0=0
  283. privt0=0
  284. privt.0=0
  285. nochan0=0
  286. nochan.0=0
  287. doing=0
  288.  
  289.   do c=1 while ~eof(ph)
  290.   ln=readln(ph)
  291.   if ln=="" then leave
  292.     select
  293.     when doing==0 then; if ln=='[¿]' then; doing=doing+1; else; call addtext()
  294.     when doing==1 then; if ln=='[¿]' then; doing=doing+1; else; call addblank()
  295.     when doing==2 then; if ln=='[¿]' then; doing=doing+1; else; call adduv()
  296.     when doing==3 then; if ln=='[¿]' then; doing=doing+1; else; call addprivt()
  297.     when doing==4 then; if ln=='[¿]' then; doing=doing+1; else; call addmwords()
  298.     when doing==5 then; if ln=='[¿]' then; doing=doing+1; else do; ln=make#(ln); call addnochan(); end
  299.     otherwise nop
  300.     end
  301.   end
  302. call close(ph)
  303.  
  304. return
  305.  
  306. addtext:
  307. text0=text0+1
  308. text.0 = text0
  309. parse var ln text.text0.t_repl '¿' text.text0.t_with
  310. text.text0.t_with = strip(text.text0.t_with)
  311. return
  312.  
  313. addmwords:
  314. mwd0=mwd0+1
  315. mwd.0 = mwd0
  316. parse var ln mwd.mwd0.t_repl '¿' mwd.mwd0.t_with
  317. mwd.mwd0.t_with = strip(mwd.mwd0.t_with)
  318. return
  319.  
  320. addblank:
  321. blank0=blank0+1
  322. blank.0 = blank0
  323. blank.blank0 = ln
  324. return
  325.  
  326. adduv:
  327. uvoice0=uvoice0 + 1
  328. uvoice.0 = uvoice0
  329. parse var ln uvoice.uvoice0.uv_nick '¿' uvoice.uvoice0.uv_mode
  330. uvoice.uvoice0.uv_mode = strip(uvoice.uvoice0.uv_mode)
  331. return
  332.  
  333. addprivt:
  334. privt0=privt0 + 1
  335. privt.0 = privt0
  336. privt.privt0 = ln
  337. return
  338.  
  339. saytext:
  340. if delstr(rest,1,1)=='AMIRSAY VERSION CHECK' then do; 'echo Sending AmIRSay Version Info to 'nick; 'RAW NOTICE 'nick' :<-- Using AmIRSay 'ver word(vers,4); end
  341. if saynick then rest=':'nick'.' strip(rest,,':')
  342. if nick ~= lastnick then call checkvoice()
  343.  
  344. if index(uvoice.nicknum.uv_mode,'-0')==1 THEN return
  345. if nochan0>0 then do
  346. do c=1 to nochan.0
  347. if upper(dest)==upper(nochan.c) then return
  348. end
  349. end
  350.  
  351. cp=1
  352.  do while cp~=0
  353.  cp=index(rest,'')
  354.    if cp~=0 then do
  355.    cc=1
  356.      do while cc>0
  357.      nc=substr(rest,cp+cc,1)
  358.      if datatype(nc)=='NUM' | nc==',' then do; ec=cc; cc=cc+1; end
  359.      else; cc=-1
  360.      end
  361.    rest=delstr(rest,cp,ec+1)
  362.    end
  363.  end
  364.  
  365.    do c=1 to nom.0
  366.    orest=rest
  367.    rest=reptag(rest,nom.c,"")
  368.    if orest~=rest then c=c-1
  369.    end
  370.  
  371.  if 0 < text.0 then do
  372.   do c=1 to text.0
  373.   orest=rest
  374.   rest=reptag(rest,text.c.t_repl,text.c.t_with,1)
  375.   if orest~=rest then c=c-1
  376.   end
  377.  end
  378.  
  379.  if 0 < mwd.0 then do
  380.   do c=1 to mwd.0
  381.   orest=rest
  382.   rest=reptag(rest,mwd.c.t_repl,mwd.c.t_with)
  383.   if orest~=rest then c=c-1
  384.   end
  385.  end
  386.  
  387.  if 0 < blank.0 then do
  388.   do c=1 to blank.0
  389.   orest=rest
  390.   rest=reptag(rest,blank.c," ")
  391.   if orest~=rest then c=c-1
  392.   end
  393.  end
  394.  
  395. rest=reptag(rest,';',"")
  396.  
  397. /*say sayc' <>nil: 'uvoice.nicknum.uv_mode' 'substr(rest,2)*/
  398.  
  399.  
  400. ADDRESS COMMAND sayc' <>nil: 'uvoice.nicknum.uv_mode' 'substr(rest,2)
  401.  
  402. rest=''
  403. return
  404.  
  405. reptag: PROCEDURE  /* replaces text for text */
  406. parse arg ln , tag , rep , word1; word1=strip(word1)
  407. p=1
  408.  
  409. ln=substr(ln,2)
  410.  
  411.  
  412.  if word1=="" then do
  413.     do until p<1
  414.     p=index(upper(ln),upper(tag),p)
  415.         if p~=0 then do
  416.       ln=delstr(ln,p,length(tag))
  417.       ln=insert(rep,ln,p-1)
  418.       /*p=p+1*/
  419.         end
  420.     end
  421.  end
  422.  else do
  423.     do c=1 to words(ln)
  424.         if upper(word(ln,c))==upper(tag) then do
  425.         ps=wordindex(ln,c)
  426.       ln=delstr(ln,ps,length(tag))
  427.       ln=insert(rep,ln,ps-1)
  428.       /*p=p+1*/
  429.         end
  430.     end
  431.  end
  432. return ':'ln
  433.  
  434. checkvoice:
  435. if uvoice.0 == 0 then return
  436. lastnick = nick
  437. nicknum=1
  438.  do c=1 to uvoice.0
  439.  if nick == uvoice.c.uv_nick then nicknum = c
  440.  end
  441. return
  442.  
  443. getvars:
  444.  if Amirc then do
  445.  'getline'
  446.  comm=line.command
  447.  dest=line.dest
  448.  rest=translate(line.rest,"'","`")
  449.  prefix=line.prefix
  450.  parse var prefix nick '!' host .
  451.  getmynick
  452.  mynick=result
  453.  return
  454.  end
  455.  
  456. call writech(STDOUT, 'enter line: ')
  457. rest=':'readln(STDIN)
  458. comm='PRIVMSG'
  459. dest='#Amiga'
  460. prefix='Brucey!~id@domain.com'
  461. parse var prefix nick '!' host .
  462. mynick='Brucey'
  463. return
  464.  
  465. SayChan:
  466. if amirc then; 'say 'myintro arg(1)
  467. else; say 'CHAN: 'arg(1)
  468. return
  469.  
  470. SayMe:
  471. if amirc then; 'echo 'myecho arg(1)
  472. else; say 'PRIV: 'arg(1)
  473. return
  474.  
  475. sayhelp:
  476. call sayme('AmIRSAY By Bruce.  ( commands are case insensitive)')
  477. call sayme('')
  478. call sayme(' AmIRSay has the following commands ....')
  479. call sayme('either /msg yourself or use /rx amirsay <command>')
  480. call sayme('or send the relevant AMIRC Port the commands')
  481. call sayme('SAYV   = Get AmIRSay''s Version')
  482. call sayme('SAYG   = Load the AmIRSAYPrefs GUI')
  483. call sayme('SAYU   = Update settings')
  484. call sayme('SAYQ   = Quit AmIRSAY')
  485. call sayme(' SAY? SAYHELP or SAYH = Calls this help text')
  486. call sayme('')
  487. return
  488.  
  489. irsgui:
  490. if ~show('p','AMIRSAY') then do
  491.  address command 'run >nil: 'amircpath'AmIRSayPrefs PORT 'address()
  492.  address command 'waitforport AMIRSAY'
  493. end
  494. else do
  495.  address AMIRSAY 'show'
  496.  address AMIRSAY 'COM ToFront'
  497.  end
  498. return
  499.  
  500. makemuicodes:
  501. nom.1=''; nom.2=''; nom.3=''; nom.4=''; nom.5=''; nom.0=5
  502. return
  503.  
  504. BREAK_C:
  505. IF alertchan THEN; call saychan(myintro' V'ver' has Quit (Ctrl_C Detected)');
  506. else; call sayme(myintro' V'ver' has Quit (Ctrl_C Detected)');
  507. exit(0);
  508. return
  509.  
  510. getsay:
  511. sayc='sys:utilities/say' ; if exists(sayc) THEN return(1)
  512. sayc='C:say' ; if exists(sayc) THEN return(1)
  513. sayc='sys:system/say' ; if exists(sayc) THEN return(1)
  514. sayc='say' ; if exists(sayc) THEN return(1)
  515. return (0)
  516.  
  517. getrx:
  518. rt=0
  519. pkt=getpkt(ownp)
  520. if pkt~=null() then do
  521. rxa=getarg(pkt)
  522. parse var rxa rxarg rxparam ; rxparam=strip(rxparam)
  523. rxarg=upper(rxarg)
  524.  
  525. select
  526. when rxarg=='SAYV' then call sayme(vers)
  527. when rxarg=='SAYG' then call irsgui()
  528. when rxarg=='SAY#' then call chanfunc(rxparam)
  529. when rxarg=='SAYQ' then do;call sayme('Quitting..'); exit(0) ; end
  530. when rxarg=='SAYU' then do; call loadprefs ; call sayme('prefs Reloaded'); end
  531. otherwise rt=5
  532. end
  533. call reply(pkt,rt)
  534. end
  535. return
  536.  
  537. ERROR: 'echo line 'SIGL; exit
  538.