home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma52.dms / ma52.adf / AWebAminet.lha / awebaminet.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1996-03-30  |  9.7 KB  |  287 lines

  1. /* AminetFind script for AWeb (1.0)
  2.  * $VER: AWebAminet.rexx 1.0 (30.3.96) by Sami Itkonen
  3.  * 
  4.  * Usage: 
  5.  *    from CLI:    run >NIL: rx awebaminet.rexx
  6.  *    from AWeb:    Select 'Start ARexx Macro' from the menu (Amiga-!)
  7.  * 
  8.  * Read the documentation for more information.
  9. */
  10.  
  11. /* START OF CONFIGURATION VARIABLES */
  12.  
  13. def_site = 'ftp.germany.aminet.org'         /* Your default Aminet site */
  14. def_findsite = 'haegar2.uni-paderborn.de'     /* Your default findserver  */
  15. def_maxhits = 20                /* Your default number of maximum hits */
  16. use_http = "ON"                    /* Use http:// instead of ftp:// with
  17.                            certain sites */
  18.  
  19. /* END OF CONFIGURATION VARIABLES */
  20.  
  21. options results
  22.  
  23. host = address()
  24.  
  25. if host = "REXX" then host = "AWEB.1"
  26. else 
  27.     if upper(left(host,4)) ~= "AWEB" then exit
  28.  
  29. address value host
  30.  
  31. call Initialize
  32.  
  33. parse arg args
  34. call ParseCmds
  35.  
  36. action = upper(action)
  37. select
  38.     when action = "FIND" then call FindWord
  39.     when action = "CREATE" then call CreateForm
  40.     when action = "ABOUT" then call About
  41.     otherwise
  42.         call CreateForm
  43. end
  44. exit
  45.  
  46. FindWord:
  47. if keyword ~= "" then do
  48.     if ~showlist(H,'TCP') then address command 'mount TCP: from amitcp:devs/inet-mountlist'
  49.     if ~showlist(H,'TCP') then address command 'mount TCP:'
  50.     if showlist(H,'TCP') then do
  51.         if open(2,'tcp:'||findsite||'/1848',w) then do
  52.             address command 'delete t:awebfind#?.html >NIL:'
  53.             fname='t:awebfind'time(S)'.html'
  54.             call open(1,fname,w)
  55.             call writeln(1,'<html><head><title>AminetFind results</title></head><body>')
  56.             call writeln(1,'<H1>AminetFind Results - using site 'aminetsite'</H1>')
  57.  
  58.             if upper(use_http) = "ON" & aminetsite = "ftp.wustl.edu" then preurl = "http://"
  59.  
  60.             findstr=keyword
  61.             if upper(exact)="ON" then findstr='"'||findstr||'"'
  62.             if upper(case)="ON" then findstr='ADTFind 'findstr
  63.             else 
  64.                 findstr = 'ADTfind 'findstr
  65. /*            call writeln(1, args findstr host'<BR>')*/
  66.             call writeln(1, '<H3> Results of the search <I>"'keyword'"</I>')
  67.             if exact = "ON" then call writeln(1,' (Exact)')
  68.             if case = "ON" then call writeln(1,' (Case Sensitive)')
  69.             call writeln(1,'</H3>')
  70.             call writeln(2,'max 'maxhits)
  71.             call writeln(2,'width 'width)
  72.             call writeln(2,findstr)
  73.             call writeln(2,'quit')
  74.             do until eof(2)
  75.                 text=readln(2)
  76.                 select 
  77.                     when left(text,9)='#error=no' then call writeln( 1, '<B>No matches found.</B><BR>')
  78.                     when left(text,9)='#error=ma' then call writeln( 1, '<B>Additional Matches Omitted.</B><P>')
  79.                     when left(text,1)='#' then foo = 1
  80.                     when text = '' then foo = 1
  81.                     when text = 'Unknown command (? for help).' then foo = 1
  82.                     otherwise
  83.                             call WriteLine
  84.                 end
  85.             end
  86.             if found then call writeln(1,'</UL></PRE>')
  87.             call writeln(1,'<HR><FORM ACTION="x-aweb:rexx/awebaminet.rexx">')
  88.             call writeln(1,'<INPUT TYPE="HIDDEN" NAME="action" VALUE="FIND">')
  89.             call writeln(1,'<B>New search:</B> <INPUT SIZE=15 MAXLENGTH=15 NAME="keyword" VALUE="">')
  90.             call writeln(1,'<INPUT TYPE="HIDDEN" NAME="aminetsite" VALUE="'aminetsite'">')
  91.             call writeln(1,'<INPUT TYPE="HIDDEN" NAME="findsite" VALUE="'findsite'">')
  92.             call writeln(1,'<INPUT TYPE="SUBMIT" VALUE="Find"> <INPUT TYPE="RESET" VALUE="Reset"></FORM>')
  93.             call writeln(1,'<EM><A href="x-aweb:rexx/awebaminet.rexx?action=create">Full Form</A></EM>')
  94.             call writeln(1,'<HR>Created by 'version'</body></html>')
  95.             call close(1)
  96.             'OPEN file://localhost/'fname
  97.         end
  98.         else FindError('Error opening TCP:')
  99.     end
  100.         else FindError('You need AmiTCP installed in the proper directories, or mount TCP:')
  101. end
  102. return
  103.  
  104. Writeline:
  105.     parse var text file.age '@' file.dir '@' file.name '@' file.size '@' a '@' b '@' file.ldesc '@' file.desc
  106.     file.age = (date(i) + 2920 - file.age % 86400) % 7
  107.     file.size = trunc(file.size/1024,0)
  108.     if length(file.size) > 3 then file.size = trunc(file.size/1024,1)||'M'
  109.     else
  110.         file.size = file.size||'K'
  111.     dot = lastpos(".", file.name)
  112.         if ~found then do
  113.                 found = 1
  114.                 call writeln( 1, "<P><PRE><UL><B>FILE                   DIR        SIZE  AGE  DESCRIPTION</B>" )
  115.         end
  116.     if (dot > 0) then
  117.             file.readme = left(file.name, dot) || 'readme'
  118.     else
  119.             file.readme = file.name'.readme'
  120. /*    file.desc = translate(file.desc,'''','"')*/
  121.     file.desc = replace(file.desc,'<','<')
  122.     file.desc = replace(file.desc,'>','>')
  123.     if file.name ~= "" then do
  124.         lin = '<LI><a href="'preurl||aminetsite'/pub/aminet/'file.dir'/'file.name'">'file.name'</A>'
  125.         lin = lin copies(' ', 19 - length(file.name)) file.dir
  126.         lin = lin copies(' ', 10 - length(file.dir)) 
  127.         lin = lin copies(' ',  4 - length(file.size)) file.size
  128.         lin = lin copies(' ',  3 - length(file.age)) file.age 
  129.         lin = lin ' <a href="ftp://'aminetsite'/pub/aminet/'file.dir'/'file.readme'">'file.desc'</A>'
  130.         call writeln( 1, lin)
  131.     end
  132. return
  133.  
  134. FindError: 
  135.     parse arg text
  136.     address command 'delete t:awebfind#?.html >NIL:'
  137.     fname='t:awebfind'time(S)'.html'
  138.     call open(1,fname,w)
  139.     call writeln(1,'<html><head><title>AminetFind Error</title></head><body>')
  140.     call writeln(1,'<H1>AminetFind Error</H1>')
  141.     call writeln(1,'<EM>'text'</EM>')
  142.     call writeln(1,'<HR>Created by 'version'</body></html>')
  143.     call close(1)
  144.     'OPEN file://localhost/'fname
  145. return
  146.  
  147. ParseCmds:
  148.     parse var args part1 "action=" '"' action '"' part2
  149.         rest = part1 part2
  150.     parse var rest part1 "keyword=" '"' keyword '"' part2
  151.         rest = part1 part2
  152.     parse var rest part1 "exact=" '"' exact '"' part2
  153.         rest = part1 part2
  154.     parse var rest part1 "case=" '"' case '"' part2
  155.         rest = part1 part2
  156.     parse var rest part1 "aminetsite=" '"' aminetsite '"' part2
  157.         rest = part1 part2
  158.     parse var rest part1 "findsite=" '"' findsite '"' part2
  159.         rest = part1 part2
  160.     parse var rest part1 "maxhits=" '"' maxhits '"' part2
  161.         rest = part1 part2
  162.     if exact = "" then exact = "OFF"
  163.     if case = "" then case = "OFF"
  164.     if aminetsite = "" then do
  165.         if def_site ~= "" then aminetsite = def_site
  166.         else
  167.             aminetsite = "ftp.wustl.edu"
  168.     end
  169.     if findsite = "" then do
  170.         if def_findsite ~= "" then findsite = def_findsite
  171.         else
  172.             findsite = "ftp.wustl.edu"
  173.     end
  174.     if maxhits = "" then do    
  175.     if def_maxhits ~= "" then maxhits = def_maxhits
  176.         else
  177.             maxhits = 20
  178.     end
  179.     if rest ~= '' & right(keyword,1) = '*' then do
  180.         rest = strip(rest)
  181.         rest = replace(rest,'*"','"')
  182.         rest = compress(rest,'"')
  183.         keyword=left(keyword,length(keyword)-1)
  184.         keyword = keyword||rest
  185.     end
  186. return
  187.  
  188. Initialize:
  189.         if ~show(l, 'rexxsupport.library') then
  190.                 if ~addlib('rexxsupport.library', 0, -30, 0) then exit 50
  191. /*        if ~show(l, 'rexxdossupport.library') then
  192.                 if ~addlib('rexxdossupport.library', 0, -30, 0) then exit 50*/
  193.     keyword = ""
  194.     found = 0
  195.     preurl = "ftp://"
  196.     width=100
  197.     version = '<EM><A HREF="x-aweb:rexx/awebaminet.rexx?action=about">AWebAminet.rexx 1.0</A></EM> by <A HREF="mailto:Sami.Itkonen@hut.fi"><CITE>Sami Itkonen</CITE></A>'
  198.     sversion = '<EM>AWebAminet.rexx 1.0</EM> by <CITE>Sami Itkonen</CITE>'
  199. return
  200.  
  201. CreateForm:
  202.     address command 'delete t:awebfind#?.html >NIL:'
  203.     form='t:awebfind'time(S)'.html'
  204.  
  205.     call open(5,form,w)
  206.     call writeln(5,'<html><head><title>AminetFind Form</title></head><body><h1>AminetFind Form for AWeb</H1>')
  207.     call writeln(5,'<FORM ACTION="x-aweb:rexx/awebaminet.rexx"><B>')
  208.     call writeln(5,'<INPUT TYPE="HIDDEN" NAME="action" VALUE="FIND">')
  209.     call writeln(5,'Search for: <INPUT SIZE=15 MAXLENGTH=15 NAME="keyword" VALUE="">')
  210.     call writeln(5,'Exact Match ? <INPUT TYPE="CHECKBOX" NAME="exact" VALUE="ON">')
  211.     call writeln(5,'Case Sensitive ? <INPUT TYPE="CHECKBOX" NAME="case" VALUE="ON">')
  212.     call writeln(5,'Maximum Number of Hits: <SELECT NAME="maxhits">')
  213.     do i = 1 to 5
  214.         if maxhits % 20 = i then call writeln(5,'<OPTION SELECTED>'20*i)
  215.         else
  216.             call writeln(5,'<OPTION>'20*i)
  217.     end
  218.     call writeln(5,'</SELECT><P>Aminet site: <SELECT NAME="aminetsite">')
  219.  
  220.     datal = AminetSites()
  221.     do i = 0 until data.i = 'ENDAMINET */'
  222.             parse value sourceline(i+datal) with data.i
  223.         if data.i ~= 'ENDAMINET */' & data.i ~= "" then do
  224.             if data.i = def_site then call writeln(5,'<OPTION SELECTED>'data.i)
  225.             else
  226.                 call writeln(5,'<OPTION>'data.i)
  227.         end
  228.     end
  229.     call writeln(5,'</SELECT><P>Findserver: </B><SELECT NAME="findsite">')
  230.     fsite.1 = 'ftp.wustl.edu'
  231.     fsite.2 = 'haegar2.uni-paderborn.de'
  232.     fsite.3 = 'amiga.icu.net.ch'
  233.     do i = 1 to 3
  234.         if fsite.i = def_findsite then call writeln(5,'<OPTION SELECTED>'fsite.i)
  235.         else
  236.             call writeln(5,'<OPTION>'fsite.i)
  237.     end
  238.     call writeln(5,'</SELECT><HR><INPUT TYPE="SUBMIT" VALUE="Find"> <INPUT TYPE="RESET" VALUE="Reset"></FORM>')
  239.     call writeln(5,'<HR>Created by 'version'</body></html>')
  240.     call close(5)
  241.     'OPEN file://localhost/'form
  242. return    
  243.  
  244. About:
  245.     address command 'delete t:awebfind#?.html >NIL:'
  246.     about='t:awebfind'time(S)'.html'
  247.     call open(5,about,w)
  248.     call writeln(5,'<html><head><title>About AWebAminet</title></head><body>')
  249.     call writeln(5,'<H1>AWebAminet.rexx - AminetFind script for AWeb</H1>')
  250.     call writeln(5,'<H3>Contacting the Author:</H3>')
  251.     call writeln(5,'<DL><DT><EM>Email</EM><DD><a href="mailto:Sami.Itkonen@hut.fi">Sami.Itkonen@hut.fi</a>')
  252.     call writeln(5,'<DT><EM>WWW</EM><DD><a href="http://www.hut.fi/~samzait/">http://www.hut.fi/~samzait/</A></DL>')
  253.     call writeln(5,'<H3>What''s there more about AWeb ?</H3>')
  254.     call writeln(5,'<UL><LI>Read the <a href="file://localhost/awebaminet.doc">documentation</a> for this script')
  255.     call writeln(5,'<LI>Search Aminet for <a href="x-aweb:rexx/awebaminet.rexx?action=find&keyword=aweb comm"><CITE>aweb comm</CITE></A>')
  256.     call writeln(5,'<LI><a href="http://www.xs4all.nl/~yrozijn/aweb/">AWeb Home Page</A></UL>')
  257.     call writeln(5,'<HR>Created by 'sversion'</body></html>')
  258.     call close(5)
  259.     'OPEN file://localhost/'about
  260. return
  261.  
  262. REPLACE: procedure
  263. parse arg a,b,c
  264. d=index(a,b)
  265. do while d~=0
  266.         a=insert(c,delstr(a,d,length(b)),d-1)
  267.         d=index(a,b)
  268. end
  269. return a
  270.  
  271.  
  272. SendASite:
  273.     return SIGL + 3
  274. AminetSites:
  275.     signal SendASite
  276.  
  277. /* AMINET
  278.  
  279. ftp.wustl.edu
  280. ftp.aminet.org
  281. ftp.amigalib.com
  282. ftp.germany.aminet.org
  283. ftp.luth.se
  284. ftp.doc.ic.ac.uk
  285.  
  286. ENDAMINET */
  287.