home *** CD-ROM | disk | FTP | other *** search
/ Dream 46 / Amiga_Dream_46.iso / Amiga / Internet / Irc / ChatBox1_164.lha / Rexx / aminetfind3.cb < prev    next >
Text File  |  1997-10-24  |  3KB  |  94 lines

  1. /* AminetFind Arexx script for ChatBox
  2.     Written by Josef Faulkner (panther@gate.net) IRC: Josef
  3.  
  4.     This script will connect to an ADT search port on an Aminet findserver
  5.     and use the port to do a very fast search of the complete aminet index
  6.     for some keywords.
  7. */
  8.  
  9. if ~show('L','rexxsupport.library') then if ~addlib('rexxsupport.library',0,-30,0) then exit 20
  10.  
  11. indexfile='dh2:net/index'
  12.  
  13. parse arg chan' 'keywords
  14.  
  15. if keywords='' then do
  16.     CMD '/echo Usage: /find [-opts] keywords'
  17.     CMD '/echo Opts:'
  18.     CMD '/echo -SAY        Says to current channel'
  19.     CMD '/echo -MAX <hits> Limits hits to <hits>'
  20.     CMD '/echo -TO <whom>  Sends results to <whom>'
  21.     exit
  22. end
  23.  
  24. length=10  /* Default number of max hits */
  25. absmax=20  /* Absolute maximum hits to show */
  26. width=80   /* Default maximum width of result text */
  27.  
  28. output='/echo'
  29.  
  30. do while left(keywords,1)='-'
  31.     CMD '/echo keyword found'
  32.     opt=word(keywords,1)
  33.     opt=upper(right(opt,length(opt)-1))
  34.     select
  35.         when opt='SAY' then do
  36.             output='/m' chan
  37.             CMD '/echo Saying results to channel.'
  38.         end
  39.         when opt='MAX' then do
  40.             if datatype(word(keywords,2),n) then do
  41.                 length=word(keywords,2)
  42.             end
  43.             else do
  44.                 CMD '/echo 'word(keywords,2)' needs to be a numerical option'
  45.             end
  46.             parse var keywords .' 'keywords
  47.         end
  48.         when opt='TO' then do
  49.             output='/m' word(keywords,2)
  50.             parse var keywords .' 'keywords        
  51.         end
  52.         otherwise do
  53.             CMD '/echo Unrecognized Option: 'word(keywords,1)
  54.         end
  55.     end
  56.     
  57.     parse var keywords .' 'keywords
  58. end
  59.  
  60. if ~showlist(H,'TCP') then address command 'mount TCP: from amitcp:devs/inet-mountlist'
  61. if ~showlist(H,'TCP') then address command 'mount TCP:'
  62. if showlist(H,'TCP') then do
  63.     if open(1,'TCP:find.germany.aminet.org/1848',w) then do
  64.         call writeln(1,'find 'keywords)
  65.         call writeln(1,'quit')
  66.         linecnt=0
  67.         do until eof(1)
  68.             text=left(readln(1),width)
  69.             linecnt=linecnt+1
  70.             if linecnt<=length then do
  71.                 if (text~='') then do
  72.                     if left(text,3)='***' then linecnt=linecnt-1
  73.                     if linecnt=1 then do
  74.                         CMD output 'Searching for keywords: 'keywords', maxhits: 'length
  75.                         CMD output 'File                 Dir        Size Description'
  76.                     end
  77.                     if left(text,3)='***' then CMD '/echo' text
  78.                     else CMD output text
  79.                     if output~='/echo' then do
  80.                         if linecnt//5=0 then call delay(250)
  81.                         if linecnt>=absmax then do
  82.                             CMD '/echo Absolute maximum hits reached (Flood Protection) Ending search.'
  83.                             exit
  84.                         end
  85.                     end
  86.                 end
  87.                 else linecnt=linecnt-1
  88.             end
  89.         end
  90.         if linecnt=1 then CMD output linecnt' matche found.'
  91.         else CMD output linecnt' matches found.'
  92.     end
  93. end
  94.