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