home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / gscr20.zip / gcmd.cmd < prev    next >
OS/2 REXX Batch file  |  1997-06-17  |  14KB  |  536 lines

  1. /* All outgoing commands */
  2.  
  3. Parse Upper Arg Win winname Us Verb Parm1 Parms
  4. Parse Arg xWin xwinname xUs xVerb xParm1 xParms
  5. Parse Arg ywin ywinname yUs yVerb nickname hostmask actions
  6. Parse Arg zwin zwinname zus zVerb var1 var2 var3
  7. Parse Arg awin awinname aus alltext
  8. Parse Arg bwin bwinname bus bverb allvars
  9.  
  10. Pool = 'OS2ENVIRONMENT'
  11.  
  12. /* stuff='WIN '||win||' WINNAME '||winname||' US '||us||' VERB '||verb||' PARM1 '||parm1||' PARMS '||parms
  13. ircrexxdisplay(stuff, '')
  14. */
  15.  
  16.  
  17. /* Log all of my private outgoing messages */
  18.  
  19. msglog = value('logme',,Pool)
  20. if (msglog = 'on') then do
  21.  
  22. tome=0
  23. if Verb = "/MSG" then do
  24.     tome = 1
  25.     alltext = '#'subword(alltext, 2)
  26. end
  27. if left(winname, 1) \= "#" & winname \= "!" & left(verb, 1) \= '/' then do
  28.     tome=1
  29.     alltext = '#'winname' 'alltext
  30. end
  31.  
  32. if tome then do
  33.     n = Value('nummsgs',,Pool) + 1
  34.     Value('nummsgs',n,Pool)
  35.     message = Time()'] 'alltext
  36.     Value('msgbuf.'n,message,Pool)
  37.  
  38.     
  39.     if(n > value('buffer',,Pool)) then do
  40.         roll=value('rollbuffer',,pool)
  41.         if roll = 'on' then do
  42.             do i = 1 to n
  43.                 nextmsg = value('msgbuf.'i+1,,Pool)
  44.                 value('msgbuf.'i,nextmsg,Pool)
  45.             end
  46.             value('nummsgs',n-1,Pool)
  47.         end
  48.         else do
  49.             ircrexxdisplay(' ', win)
  50.             ircrexxdisplay('YOUR MESSAGE BUFFER IS FULL', win)
  51.             ircrexxdisplay('TYPE /set nummsgs 0 TO RESET', win)
  52.             value('nummsgs',n-1,Pool)
  53.         end
  54.     end
  55. return "OK"
  56. end
  57. end
  58.  
  59. /* Speed up Processing */
  60. slash = left(verb, 1)
  61. if slash \= '/' then return "OK"
  62.  
  63.  
  64.  
  65. /* who am I logged on as? */
  66. if (Verb = '/WHOAMI') then do
  67.     ircrexxdisplay('You are Currently Logged In as '||US, win)
  68.     return ''
  69. end
  70.  
  71.  
  72.  
  73. /* Add action item */
  74. if (Verb = '/ADD') then do
  75.     if (parm1 = '') then return ''
  76.     joinactions=value('joinactions',,pool)
  77.     do i = 1 to joinactions
  78.         nick=value(nick.i,,pool)
  79.         if nick=parm1 then do
  80.             value(nick.i, parm1, pool)
  81.             value(host.i, hostmask, pool)
  82.             value(action.i, actions, pool)
  83.             ircrexxdisplay('', win)
  84.             ircrexxdisplay(''nickname' changed.', win)
  85.             return ''
  86.         end
  87.  
  88.     end
  89.  
  90.     i=joinactions+1
  91.     value('joinactions', i, pool)
  92.     value(nick.i, parm1, pool)
  93.     value(host.i, hostmask, pool)
  94.     value(action.i, actions, pool)
  95.     ircrexxdisplay('', win)
  96.     ircrexxdisplay(''parm1' added.', win)
  97.  
  98. return ''
  99. end
  100.  
  101.  
  102. /* Change actions on existing action item */
  103. if (Verb = '/CHANGE') then do
  104.     if (parm1 = '') then return ''
  105.     joinactions=value('joinactions',,pool)
  106.     do i = 1 to joinactions
  107.         nick=value(nick.i,,pool)
  108.         if nick=parm1 then do
  109.             value(action.i, xparms, pool)
  110.             ircrexxdisplay(' ', win)
  111.             ircrexxdisplay(''parm1' changed.', win)
  112.             return ''
  113.         end
  114.     end
  115. ircrexxdisplay(' ', win)
  116. ircrexxdisplay(''parm1' does not exist.', win)
  117. return ''
  118. end
  119.  
  120.  
  121. /* Remove an action item */
  122. if (Verb = '/REMOVE') then do 
  123.     if (parm1 = '') then return ''
  124.     joinactions=value('joinactions',,pool)
  125.     next = joinactions + 1
  126.     value(nick.next, '', pool)
  127.     value(host.next, '', pool)
  128.     value(action.next, '', pool)
  129.     do i = 1 to joinactions
  130.         nick=value(nick.i,,pool)
  131.         if nick=parm1 then do
  132.             do j = i + 1 to joinactions
  133.                 k = j-1
  134.                 nextnick = value(nick.j,,pool)
  135.                 nextaction = value(action.j,,pool)
  136.                 nextmask = value(host.j,,pool)
  137.                 value(nick.k, nextnick, pool)
  138.                 value(host.k, nextmask, pool)
  139.                 value(action.k, nextaction, pool)
  140.             end
  141.             joinactions = joinactions - 1
  142.             value('joinactions', joinactions, pool)
  143.             ircrexxdisplay(''parm1' removed.', win)
  144.             return ''
  145.         end
  146.     end
  147. ircrexxdisplay(' ', win)
  148. ircrexxdisplay(''parm1' does not exist.', win)
  149. return ''
  150. end
  151.     
  152.     
  153.  
  154.  
  155. /* List Joinactions */
  156. if (Verb = '/JOINLIST') then do
  157.     joins = value(joinactions,,Pool)
  158.     ircrexxdisplay(' ', win)
  159.     ircrexxdisplay('Join Action List', win)
  160.     ircrexxdisplay('-----------------', win)
  161.     do i = 1 to joins
  162.         output = value(nick.i,,pool)' 'value(host.i,,pool)' 'value(action.i,,Pool)
  163.         ircrexxdisplay(output, win)
  164.     end
  165. return ''
  166. end
  167.  
  168.  
  169.  
  170. /* Set Alias */
  171. if (Verb = '/ALIAS') then do
  172.     aliascount=value(aliases,,Pool)
  173.     if parm1 = '' then do
  174.         ircrexxdisplay(' ', win)
  175.         ircrexxdisplay('Current Alias List:', win)
  176.         ircrexxdisplay('-------------------', win)
  177.         do i=1 to aliascount
  178.             alias = value(alias.i,,Pool)
  179.             command = value(command.i,,Pool)
  180.             ircrexxdisplay(alias' = 'command, win)
  181.         end
  182.     return ''
  183.     end
  184.  
  185.     do i=1 to aliascount
  186.         alias = value(alias.i,,Pool)
  187.         if alias = parm1 then do
  188.             value(alias.i, parm1, Pool)
  189.             value(command.i, xparms, Pool)
  190.             ircrexxdisplay('Alias for 'xparms' set to 'parm1, win)
  191.             return ''
  192.         end
  193.     end
  194.  
  195.  
  196.     Aliascount = Aliascount + 1
  197.     value(aliases, aliascount, Pool)
  198.     value(alias.aliascount, parm1, Pool)
  199.     value(command.aliascount, xparms, Pool)
  200.     ircrexxdisplay('Alias for 'xparms' set to 'parm1, win) 
  201.     return ''
  202. end
  203.  
  204.  
  205.  
  206. /* Remove an Alias */
  207. if (Verb = '/REMOVEALIAS') then do 
  208.     if (parm1 = '') then return ''
  209.     aliascount=value('aliases',,pool)
  210.     next = aliascount+1
  211.     value(alias.next,'',pool)
  212.     value(command.next,'',pool)
  213.     do i=1 to aliascount
  214.         alias = value(alias.i,,Pool)
  215.         if alias = parm1 then do
  216.             do j=i+1 to aliascount
  217.                 k = j-1
  218.                 nextalias = value(alias.j,,pool)
  219.                 nextcommand = value(command.j,,pool)
  220.                 value(alias.k, nextalias, Pool)
  221.                 value(command.k, nextcommand, Pool)
  222.             end
  223.             ircrexxdisplay(''parm1' removed.', win)
  224.             aliascount = aliascount - 1
  225.             value('aliases', aliascount, Pool)
  226.             return ''
  227.         end
  228.     end
  229.     
  230.     ircrexxdisplay(' ', win)
  231.     ircrexxdisplay(''parm1' does not exist.', win)
  232.     return ''
  233. end
  234.  
  235.  
  236.  
  237.  
  238. /* Poll for aliases for any command */
  239. aliases=value(aliases,,Pool)
  240. if (aliases > 0) then do
  241.     do i=1 to aliases
  242.         alias=value(alias.i,,Pool)
  243.         if Verb = alias then do
  244.             command=value(command.i,,Pool)
  245.             lines = 1
  246.             output.lines=''
  247.             do j = 1 to words(command)
  248.                 piece = subword(command, j, 1)
  249.                 if piece = '$0' then piece = allvars
  250.                 if piece = '$1' then piece = var1
  251.                 if piece = '$2' then piece = var2
  252.                 if piece = '$3' then piece = var3
  253.                 if piece = '$me' then piece = xUs
  254.                 if piece = '$ch' then piece = xwinname
  255.                 if piece = '+' then do
  256.                     lines=lines + 1
  257.                     piece=''
  258.                     output.lines=''
  259.                 end
  260.                 output.lines = output.lines||' '||piece
  261.             end
  262.             
  263.             do j=1 to lines
  264.                 l = length(output.j)
  265.                 if j = 1 then
  266.                     output.j = right(output.j, l-1)
  267.                 else output.j = right(output.j, l-2)
  268.                 ircrexxcommand(output.j, win)
  269.             end
  270.             return ''
  271.         end
  272.     end
  273. end
  274.         
  275.  
  276.  
  277. /* Set or View the current Environment */
  278. if (Verb = '/SET') then do
  279.      if (Parm1 \= '') then do
  280.         if (Parms <> '') then do
  281.             VALUE(xParm1,xParms,Pool)
  282.             ircrexxdisplay(Parm1 'Set to: ' || xParms || '.', win)
  283.             Return ''
  284.         end
  285.         else do
  286.             TempStr = Value(Parm1,,Pool)
  287.             IrcRexxDisplay(Parm1 'Is currently: ' || TempStr || '.', win)
  288.             Return ''
  289.         end
  290.     end
  291.     else do
  292.         ircrexxdisplay(' ', win)
  293.         ircrexxdisplay('CURRENT ENVIRONMENT:', win)
  294.         ircrexxdisplay('--------------------', win)
  295.         configfile = value('configfile',,pool)
  296.         buffer = value('buffer',,pool)
  297.         rollbuffer = value('rollbuffer',, pool)
  298.         msglog = value('log',,pool)
  299.         msgs = value('nummsgs',,pool)
  300.         logme = value('logme',,pool)
  301.         Aliases = value('aliases',,pool)
  302.         joinactions = value('joinactions',,Pool)
  303.         greet = value('greet',,Pool)
  304.         greetmsg = value('greetmsg',,pool)
  305.         autorun = value('autorun',,pool)
  306.         join = value('join',,pool)
  307.         greetscr = value('greetscr',,pool)
  308.         onjoin = value('onjoin',,pool)
  309.         onleave = value('onleave',,pool)
  310.         kickmirc = value('kickmirc',,pool)
  311.         ircrexxdisplay('configfile:   '||configfile, win)
  312.         ircrexxdisplay('autorun:      '||autorun, win)
  313.         ircrexxdisplay('========================', win)
  314.         ircrexxdisplay('buffer:       '||buffer, win)
  315.         ircrexxdisplay('rollbuffer:   '||rollbuffer, win)
  316.         ircrexxdisplay('log:          '||msglog, win)
  317.         ircrexxdisplay('logme:        '||logme, win)
  318.         ircrexxdisplay('nummsgs:      '||msgs, win)
  319.         ircrexxdisplay('========================', win)
  320.         ircrexxdisplay('join:         '||join, win)
  321.         ircrexxdisplay('greet:        '||greet, win)
  322.         ircrexxdisplay('greetscr:     '||greetscr, win)
  323.         ircrexxdisplay('kickmirc:     '||kickmirc, win)
  324.         ircrexxdisplay('========================', win)
  325.         ircrexxdisplay('onjoin:       '||onjoin, win)
  326.         ircrexxdisplay('onleave:      '||onleave, win)
  327.         ircrexxdisplay('========================', win)
  328.         ircrexxdisplay('joinactions:  '||joinactions, win)
  329.         ircrexxdisplay('aliases:      '||aliases, win)
  330.         ircrexxdisplay('========================', win)
  331.         ircrexxdisplay('greetmsg:     '||greetmsg, win)
  332.         ircrexxdisplay(' ', win)
  333.         return ''
  334.     end
  335.  
  336. end
  337.  
  338.  
  339. /* Reset an item in the current environment */
  340. if (Verb = '/RESET') then do
  341.     if parm1 = '' then return ''
  342.     value(parm1,'',pool)
  343.     ircrexxdisplay(' ', win)
  344.     ircrexxdisplay(''||parm1||' Has been reset.', win)
  345.     return ''
  346. end
  347.     
  348.  
  349. /* View the Message Queue */
  350. if (Verb = '/LAST') then do
  351.     msglog = value('log',,Pool)
  352.     msgnum = value('nummsgs',,Pool)
  353.  
  354.     ircrexxdisplay(" ",win)
  355.     if (msglog \= 'on') then ircrexxdisplay("Message Log DISABLED", Win)    
  356.  
  357.     if (msgnum = 0) then do 
  358.         ircrexxdisplay("No new Messages",win)
  359.         Return ""
  360.     end
  361.  
  362.         
  363.     if (Parm1 = "" | Parm1 > msgnum) then msgdisp = msgnum
  364.             else msgdisp = Parm1
  365.     ircrexxdisplay('Displaying last' msgdisp 'Messages to you:',win)
  366.  
  367.     do i = msgnum - msgdisp + 1 to msgnum
  368.         text = i':  'value('msgbuf.'i,,Pool)
  369.         ircrexxdisplay(text, win)
  370.     end
  371.     Return ""
  372. end
  373.  
  374.  
  375. /* Save the message Buffer */
  376.  
  377. if (Verb = '/SAVEMSGS') then do
  378.     msglog = value('msglog',,Pool)
  379.     msgnum = value('nummsgs',,Pool)
  380.     if (msgnum = 0) then do 
  381.         ircrexxdisplay("No Messages to be saved.",win)
  382.         Return ""
  383.     end
  384.     else do
  385.         if (Parm1 <> '') then do
  386.             ircrexxdisplay('Writing msgs to log file:' Parm1,win)
  387.             LineOut(Parm1, titlline, 1)
  388.             do i = 1 to msgnum
  389.                 text = i || ': ' value('msgbuf.'i,,Pool)
  390.                 LineOut(Parm1, text)
  391.             end
  392.             LineOut(Parm1)
  393.             IrcRexxDisplay(Parm1 "written.",Win)
  394.             Return ""
  395.         end
  396.         else do
  397.             Parm1 = "msgsave.txt"
  398.             ircrexxdisplay('Writing msgs to log file: msgssave.txt',win)
  399.             LineOut(Parm1, titlline, 1)
  400.             do i = 1 to msgnum
  401.                 text = i || ': ' value('msgbuf.'i,,Pool)
  402.                 LineOut(Parm1, text)
  403.             end
  404.             LineOut(Parm1)
  405.             IrcRexxDisplay(Parm1 "written.",Win)
  406.             Return ""
  407.         end
  408.     end
  409. end
  410.  
  411. /* Show output of External OS/2 text program in current window */
  412. if (Verb = '/EXEC') then do
  413.     CMD = "C:\OS2\CMD.EXE"
  414.     if (Parm1 <> '') then do
  415.         ADDRESS CMD xParm1 xParms '| rxqueue'
  416.         nr = queued()
  417.         do i=1 to nr
  418.             Parse pull line
  419.             if line <> ' ' Then IrcRexxDisplay(line,Win)
  420.         end
  421.     end
  422.     else do
  423.         IrcRexxDisplay(ErStr1 "You must provide a command and any appropriate",Win)
  424.         IrcRexxDisplay(ErStr2 "parameters that you wish to run.",Win)
  425.     end
  426.     Return ""
  427. end
  428.  
  429.  
  430. /* Pipe output of External OS/2 text program to current channel or query */
  431. if (Verb = '/PIPE') then do
  432.     CMD = "C:\OS2\CMD.EXE"
  433.     if (Parm1 <> '') then do
  434.         ADDRESS CMD xParm1 xParms '| rxqueue'
  435.         nr = queued()
  436.         do i=1 to nr
  437.             Parse pull line
  438.             if line <> ' ' Then IrcRexxCommand(line, Win)
  439.         end
  440.     end
  441.     else do
  442.         IrcRexxDisplay(ErStr1 "You must provide a command and any appropriate",Win)
  443.         IrcRexxDisplay(ErStr2 "parameters that you wish to run.",Win)
  444.     end
  445.     Return ""
  446. end
  447.  
  448.  
  449. /* Start an OS/2 Program */
  450. if (Verb = '/START') then do
  451.     CMD = "C:\OS2\CMD.EXE"
  452.     address CMD 'start /n ' allvars 
  453.     ircrexxdisplay(' ', win)
  454.     ircrexxdisplay('Command Routed to Shell', win)
  455.     return ''
  456. end
  457.  
  458.  
  459. /* Save the Current Environment */
  460. if (Verb = '/SAVE') then do
  461.     configfile=value('configfile',,pool)
  462.     aliases=value('aliases',,pool)
  463.     joinactions=value('joinactions',,pool)
  464.     buffer=value('buffer',,pool)
  465.     rollbuffer=value('rollbuffer',,pool)
  466.     log=value('log',,pool)
  467.     logme=value('logme',,pool)
  468.     greet=value('greet',,pool)
  469.     greetmsg=value('greetmsg',,pool)
  470.     autorun=value('autorun',,pool)
  471.     greetscr=value('greetscr',,pool)
  472.     join=value('join',,pool)
  473.     onjoin=value('onjoin',,pool)
  474.     onleave=value('onleave',,pool)
  475.     kickmirc=value('kickmirc',,pool)
  476.     
  477.  
  478.     ircrexxcommand('/exec erase '||configfile, win)
  479.     
  480.     lineout(configfile,,1)
  481.     lineout(configfile,"/set configfile "||configfile)
  482.     lineout(configfile,"/set autorun "||autorun)
  483.     lineout(configfile,"/set nummsgs 0")
  484.     lineout(configfile,"/set aliases 0")
  485.     lineout(configfile,"/set joinactions 0")
  486.     lineout(configfile,"/set buffer "||buffer)
  487.     lineout(configfile,"/set rollbuffer "||rollbuffer)
  488.     lineout(configfile,"/set log "||log)
  489.     lineout(configfile,"/set logme "||logme)
  490.     lineout(configfile,"/set greetmsg "||greetmsg)
  491.     lineout(configfile,"/set greet "||greet)
  492.     lineout(configfile,"/set greetscr "||greetscr)
  493.     lineout(configfile,"/set join "||join)
  494.     lineout(configfile,"/set onjoin "||onjoin)
  495.     lineout(configfile,"/set onleave "||onleave)
  496.     lineout(configfile,"/set kickmirc "||kickmirc)
  497.  
  498.     do i = 1 to aliases
  499.         alias = value(alias.i,,pool)
  500.         command = value(command.i,,pool)
  501.         lineout(configfile,"/alias "||alias||" "||command)
  502.  
  503.     end
  504.     IrcRexxDisplay('Aliases written', win)
  505.  
  506.     lineout(configfile, "/run "||autorun)
  507.     IrcRexxDisplay('Autorun written', win)
  508.     
  509.     do i = 1 to joinactions
  510.         nick = value(nick.i,,pool)
  511.         host = value(host.i,,pool)
  512.         action = value(action.i,,pool)
  513.         lineout(configfile,"/add "||nick||" "||host||" "||action)
  514.     end    
  515.      ircrexxdisplay('Join Actions Written', win)
  516.     
  517.     lineout(configfile)
  518.  
  519.     IrcRexxDisplay('Environment Saved to '||configfile,Win)
  520.     Return ""
  521. end
  522.  
  523. /* Re-Initialize the Environment */
  524. if Verb='/INIT' then do
  525.     configfile=value('configfile',,pool)
  526.     ircrexxcommand("/run "||configfile, win)
  527.     
  528.     call rxfuncadd 'rexxlibregister', 'rexxlib', 'rexxlibregister'
  529.     call rexxlibregister
  530.     ircrexxdisplay('REXX External Library Registered', win)
  531.  
  532.     return ""
  533. end
  534.  
  535. /* Everything Else */
  536. Return "OK"