home *** CD-ROM | disk | FTP | other *** search
- /* Search Altavista thru Amirc or CLI. © 2001 by Purp|eT. */
- /* $VER V2.0 Bug reports? suggestions? Mailto: purplet@dingoblue.net.au */
-
- /* P R E F S A R E A */
-
-
- MaxHits = 5
-
- SeparateOutput = "N" /* [ Y/N ] */
- DeleteTempAfter = "Y" /* [ Y/N ] */
-
-
- /* E N D P R E F S */
-
-
-
-
- /* Don't Edit Anything Below This Point!! */
-
- Options results
- parse arg SearchString;NL='0a'x;ES= d2c(27);Bold = d2c(2);TC = 1
-
- if searchstring = "/FORCE" then do;setclip(AVSearch,"");exit;end
-
-
- amirc_bold='02'x
- amirc_uline='1F'x
- AV_Plus = '%2B'
- cr=''x
-
- Tags ="<B> </B> <U> </U> <BR>"
- NewTags ="amirc_bold amirc_bold amirc_uline amirc_uline cr"
-
- Tags2 = "+"
- NewTags2 = "AV_Plus"
-
- CheckIt = getclip(AVSearch)
-
- If CheckIt = "RUN" then DO
- techo("Search already in progress. Wait for current search to finish.")
- Exit
- End
-
- Setclip(AVSearch,"RUN")
-
- If SearchString = "" then DO
- Techo("Usage: /RX AVSearch <Search Keywords>")
- Call EndProg
- End
-
- If MaxHits > 10 then MaxHits = 10
- If MaxHits < 1 then MaxHits = 1
-
- Techo("Searching for "bold""SearchString""Bold" on AltaVista, MaxHits = "bold""MaxHits""bold", Please wait...")
-
- SearchString2 = SearchString
-
- desc = SearchString2
-
- DO UNTIL Tags2=''
- PARSE VAR Tags2 Tag Tags2
- PARSE VAR NewTags2 NewTag NewTags2
- CALL TagCleanup(UPPER(Tag),NewTag)
- END
-
- SearchString2 = desc
-
- SearchString2 = Translate(SearchString2,"+"," ")
-
- If Open(File1,'TCP:www.altavista.com/80','RW') = 0 then DO
- Techo("Error: TCP: Error")
- Call EndProg
- End
-
- Call writeln(file1,'GET /cgi-bin/query?pg=q&sc=on&hl=on&act=2006&par=0&q='SearchString2'&search.x=21&search.y=6&kl=XX&stype=stext HTTP/1.0')
- Call writeln(file1,'User-Agent: MSIE/6.0')
- Call writeln(file1,'Accept: */*;q=1')
- Call writeln(file1,'Host: www.altavista.com')
- Call writeln(file1,'Referer: http://www.altavista.com/')
- Call writeln(file1,'')
-
- call time(R)
-
- Do i = 1 to MaxHits
- HLine = readln(file1)
- Do until pos(">"i".</",HLine) ~=0|time(E) >20
- HLine = ReadLn(File1)
- If Find(HLine,"found no document matching your") ~=0 then DO
- Techo("No matches found for "Bold""SearchString)
- Call EndProg
- End
- If pos("</HTML>",upper(HLine)) ~=0 then DO
- Call EndProg
- End
- End
- NextLine = Readln(File1)
- ULine = substr(NextLine, Pos(upper("http://"),upper(NextLine)) , Pos('"',NextLine,Pos(upper("http://"),upper(NextLine)))-pos(upper("http://"),upper(NextLine)) )
- techo(bold""i". "Bold""ULine)
-
- /* Begin Snorslex's Sheer Coding Brilliance ;-) */
-
- DO UNTIL Tags=''
- PARSE VAR Tags Tag Tags
- PARSE VAR NewTags NewTag NewTags
- CALL TagCleanup(UPPER(Tag),NewTag)
- END
-
- /* End Snorslex's Sheer Coding Brilliance ;-) */
-
- If Upper(SeparateOutput) = "Y" then Techo(Bold""Bold)
- End
- Call EndProg
- Exit
-
- EndProg:
- Close(File1)
- Techo(Bold"Search Complete")
- SetClip(AVSearch,"")
- If Upper(DeleteTempAfter) = "Y" then DO
- address command 'C:Delete >nil: 'AVSTempFile
- End
- Exit
- Return
-
- Techo:
- parse arg EchoString
- "ECHO P="d2c(27)"b«AVSearch» C="TC" "EchoString
- say EchoString
- Return 0
-
- /* Begin Snorslex's Sheer Coding Brilliance (Part II) :) */
-
- TagCleanup:
- curr_tag=ARG(1)
- curr_newtag=ARG(2)
- DO FOREVER
- posi=POS(curr_tag,UPPER(desc))
- IF posi>0 THEN DO
- desc=LEFT(desc,posi-1)||VALUE(curr_newtag)||SUBSTR(desc,posi+LENGTH(curr_tag),LENGTH(desc)-posi)
- END
- ELSE LEAVE
- END
- RETURN
-
- /* End Snor... you get the picture :) */
-