home *** CD-ROM | disk | FTP | other *** search
/ Dream 46 / Amiga_Dream_46.iso / Amiga / Internet / Irc / ChatBox1_164.lha / Rexx / aminetfind4.cb < prev    next >
Text File  |  1997-10-24  |  3KB  |  96 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. length=10  /* Default number of max hits */
  16. absmax=20  /* Absolute maximum hits to show */
  17. width=80   /* Default maximum width of result text */
  18.  
  19. output='/echo'
  20.  
  21. do while left(keywords,1)='-'
  22.     opt=word(keywords,1)
  23.     opt=upper(right(opt,length(opt)-1))
  24.     select
  25.         when opt='SAY' then do
  26.             output='/m' chan
  27.             CMD '/echo Saying results to channel.'
  28.         end
  29.         when opt='MAX' then do
  30.             if datatype(word(keywords,2),n) then do
  31.                 length=word(keywords,2)
  32.             end
  33.             else do
  34.                 CMD '/echo 'word(keywords,2)' needs to be a numerical option'
  35.             end
  36.             parse var keywords .' 'keywords
  37.         end
  38.         when opt='TO' then do
  39.             output='/m' word(keywords,2)
  40.             parse var keywords .' 'keywords        
  41.         end
  42.         otherwise do
  43.             CMD '/echo Unrecognized Option: 'word(keywords,1)
  44.         end
  45.     end
  46.  
  47.     parse var keywords .' 'keywords
  48. end
  49.  
  50. if keywords='' then do
  51.     CMD '/echo Usage: /find [-opts] keywords'
  52.     CMD '/echo Opts:'
  53.     CMD '/echo -SAY        Says to current channel'
  54.     CMD '/echo -MAX <hits> Limits hits to <hits>'
  55.     CMD '/echo -TO <whom>  Sends results to <whom>'
  56.     exit
  57. end
  58.  
  59. if ~showlist(H,'TCP') then address command 'mount TCP: from amitcp:devs/inet-mountlist'
  60. if ~showlist(H,'TCP') then address command 'mount TCP:'
  61. if showlist(H,'TCP') then do
  62.     if open(1,'TCP:find.germany.aminet.org/1848',w) then do
  63.         call writeln(1,'find 'keywords)
  64.         call writeln(1,'quit')
  65.         linecnt=0
  66.         do until eof(1)
  67.             text=left(readln(1),width)
  68.             linecnt=linecnt+1
  69.             if linecnt<=length then do
  70.                 if (text~='') then do
  71.                     if left(text,3)='***' then linecnt=linecnt-1
  72.                     if linecnt=1 then do
  73.                         CMD output 'Searching for keywords: 'keywords', maxhits: 'length
  74.                         CMD output 'File                 Dir        Size Description'
  75.                     end
  76.                     if left(text,3)='***' then CMD '/echo' text
  77.                     else CMD output text
  78.                     if output~='/echo' then do
  79.                         if linecnt//5=0 then call delay(250)
  80.                         if linecnt>=absmax then do
  81.                             CMD '/echo Absolute maximum hits reached (Flood Protection) Ending search.'
  82.                             exit
  83.                         end
  84.                     end
  85.                 end
  86.                 else linecnt=linecnt-1
  87.             end
  88.         end
  89.         if linecnt=1 then CMD output linecnt' match found.'
  90.         else CMD output linecnt' matches found.'
  91.     end
  92.     else CMD '/echo Could not open connection.'
  93. end
  94. else CMD '/echo Could not mount TCP:'
  95.  
  96.