/* ON.amirx
\\ $VER: ON.amirx 2.2 (20.02.00)
// Written by Donald T. Becker (dtbecker@prolog.net) IRC: StarDustr
\\ Please mail any bug reports/comments to the above address with a subject
// header of ON.amirx.
\\
// ** What to do with this file?
\\ Put this script in AmIRC/Rexx
//  The following variables will be replaced with the portions of data
\\   returned from the  GETLINE  command.
//
\\   %a       Replaced with variable LINE         (all data)
//   %p       Replaced with variable LINE.PREFIX  (usually source of data line)
\\   %c       Replaced with variable LINE.COMMAND (usually the server command)
//   %d       Replaced with variable LINE.DEST    (usually destination of data line)
\\   %r       Replaced with variable LINE.REST    (usually the text from the user)
//   %w1-%w?? Replaced with word 1 thru 99 of variable LINE.REST
\\
*/
;parse arg oncmd docmd;oncmd=upper(oncmd);options results;Cenv=address();if left(Cenv,6) ~='AMIRC.' then exit 1;if oncmd="ABOUT" then call About();if docmd="" then exit 2;cmds="";OnPort='ON.'||right(Cenv,1);if show('p',OnPort) then;do;'say /ISON @@@@@@@@@';interpret "address" OnPort "ADD oncmd docmd";exit;end;ONVer="$VER: ON 2.2 (20.02.00)";if ~show('c',"ONOFF_Title") then;do;call setclip("ONOFF_Title","ON");call setclip("ONOFF_Version",ONVer);call setclip("ONOFF_Copyright","December 1999  by StarDustr");call setclip("ONOFF_Author","StarDustr  @Dal.net on #AmIRC");call setclip("ONOFF_Description","An EVENT Handler for use with AmIRC");end;if ~show('L',"rexxsupport.library") then;do;if ~addlib("rexxsupport.library",0,-30,0) then;do;interpret Ecmd '"rexxsupport.library Open Failure.  EOJ."';exit;end;end;xx=openport(OnPort);if ~xx then;do;'Echo' '"OnPort OpenPort failure.  EOJ."';exit;end;max=0;getversion;AVer=result;call AddON();signal DoWaits;AddON:;max=max+1;onc.max=oncmd;doc.max=strip(docmd);dspcmd= doc.max;if AVer<2 then;do;xl=pos('%', dspcmd);do while xl>0;le=left(dspcmd,xl-1);ri=substr(dspcmd,xl+1);dspcmd=le||'%%'||ri;xl=pos('%', dspcmd,xl+2);end;end;cmds=cmds onc.max;'echo p='d2c(27)'««ON»' "Active for command" onc.max "executing command" dspcmd;return;DelON:;if oncmd=0 then;do;'echo p='d2c(27)'««ON»' "Immediate Exit Complete.  ON Deactivated!";call EOJ();end;if datatype(oncmd) ~="NUM" then return;if oncmd>max then;do;'echo p='d2c(27)'««ON»' "No ON Function Active for #"oncmd;return;end;'echo p='d2c(27)'««ON»' "Exiting ON #"oncmd "for" onc.oncmd;if max=1 then;do;'echo p='d2c(27)'««ON»' "Last ON Function Removed.  ON Deactived";call EOJ();end;onc.oncmd=onc.max;doc.oncmd= doc.max;max=max-1;cmds="";do xct=1 to max;cmds=cmds onc.xct;end xct;return;ListON:;do ant=1 to max;dspcmd= doc.ant;if AVer<2 then;do;xl=pos('%', dspcmd);do while xl>0;le=left(dspcmd,xl-1);ri=substr(dspcmd,xl+1);dspcmd=le||'%%'||ri;xl=pos('%', dspcmd,xl+2);end;end;'echo p='d2c(27)'««ON»' "Command #"ant "ON" onc.ant "executing command" dspcmd;end ant;return;EOJ:;call closeport(OnPort);xx=' '||show('p');if 0=pos(' ON.',xx) then;do;call setclip("ONOFF_Title","");call setclip("ONOFF_Version","");call setclip("ONOFF_Copyright","");call setclip("ONOFF_Author","");call setclip("ONOFF_Description","");end;exit;DoWaits:;do forever;getline;if ~show('p',Cenv) then call EOJ();if 0 ~=pos(upper(line.command),cmds) then;do;lcmd=upper(line.command);do cnt=1 to max;if lcmd=onc.cnt then call doit();end cnt;end;xx=getpkt(OnPort);if xx='00000000'x then iterate;UCmd=getarg(xx);call reply(xx);parse value UCmd with UFunc oncmd docmd;if UFunc='ADD' then call AddON();if UFunc='DEL' then call DelON();if UFunc='LIST' then call ListON();end;doit:;xcmd= doc.cnt;xl=pos('%',upper(xcmd));if xl>0 then;do;zine=line;x1=pos('`',zine);do while x1>0;zine=left(zine,x1-1)||substr(zine,x1+1);x1=pos('`',zine);end;x2=pos("'",zine);do while x2>0;zine=left(zine,x2-1)||substr(zine,x2+1);x2=pos("'",zine);end;x3=pos('"',zine);do while x3>0;zine=left(zine,x3-1)||substr(zine,x3+1);x3=pos('"',zine);end;parseline zine;end;xl=pos('%A',upper(xcmd));do while xl>0;xcmd=left(xcmd,xl-1)||translate(line,'7f'x,'%')||substr(xcmd,xl+2);xl=pos('%A',upper(xcmd));end;xl=pos('%P',upper(xcmd));do while xl>0;xcmd=left(xcmd,xl-1)||translate(line.prefix,'7f'x,'%')||substr(xcmd,xl+2);xl=pos('%P',upper(xcmd));end;xl=pos('%C',upper(xcmd));do while xl>0;xcmd=left(xcmd,xl-1)||translate(line.command,'7f'x,'%')||substr(xcmd,xl+2);xl=pos('%C',upper(xcmd));end;xl=pos('%D',upper(xcmd));do while xl>0;xcmd=left(xcmd,xl-1)||translate(line.dest,'7f'x,'%')||substr(xcmd,xl+2);xl=pos('%D',upper(xcmd));end;xl=pos('%R',upper(xcmd));do while xl>0;xcmd=left(xcmd,xl-1)||translate(line.rest,'7f'x,'%')||substr(xcmd,xl+2);xl=pos('%R',upper(xcmd));end;mwc=words(line.rest);xl=pos('%W',upper(xcmd));do while xl>0;le=left(xcmd,xl-1);ri=substr(xcmd,xl+2);wrd=left(ri,1);xwd="";if datatype(wrd)="NUM" then;do;xl=1;wrd=substr(ri,2,1);if datatype(wrd)="NUM" then xl=2;wrd=left(ri,xl);ri=substr(ri,xl+1);if wrd ~>mwc then;xwd=word(line.rest,wrd);end;xcmd=le||translate(xwd,'7f'x,'%')||ri;xl=pos('%W',upper(xcmd));end;'say' translate(xcmd,'%','7f'x);return;About:;MCmd="";MRexx=showlist('A',MuiRexx)+showlist('V',MuiRexx);if MRexx then MRexx=exists("MuiRexx:MuiRexx");if exists("SYS:RexxC/MuiRexx") then MCmd="SYS:RexxC/MuiRexx";if MRexx then MCmd="MuiRexx:MuiRexx";if exists("SYS:Utilities/MuiRexx") then MCmd="SYS:Utilities/MuiRexx";if MCmd="" then;do;'Echo "MuiRexx not found.  EOJ."';exit;end;address command;'run >nil:' MCmd port 'ONOFF';'waitforport' 'ONOFF';interpret "address" Cenv;'say' '/rx mcf_about ONOFF QUIT';exit