#!D:/Python/python.exe import os import sys import string import win32pipe def main(): #if main returns 0 the user will get an error message theQuery=os.environ['QUERY_STRING'] #Build an exec string to pass to the OS execString="c:\opt\www\cgi-bin\htsearch.exe " execString=execString + '"' execString=execString + theQuery execString=execString + '" ' #Do the search; put the result page into a temporary file resultsFile=win32pipe.popen(execString, 'r') if (resultsFile): resultsOut=resultsFile.read() resultsTestLine=string.split(resultsOut, "\n") resultsFile.close() if (string.find(resultsTestLine[2], "No match for")!=-1): mispell1=string.replace(resultsTestLine[2], "<html><head><title>No match for '", "") mispell2=string.replace(mispell1, "'", "") ispellString="echo " + mispell2 + " | c:\dos\ispell -a -d //c/dos/english | c:\dos\sed '/^&./!d'" spellFile=win32pipe.popen(ispellString, 'r') if (spellFile): spellOut=spellFile.readlines() spellFile.close() replaceString="Check the spelling of the search word(s) you used.

" if (len(spellOut)): for Line in spellOut: replaceString=replaceString + "" replaceString=replaceString+ "
Search Word
 
Suggested Spelling(s)
Click on a suggestion to search for that word
" fragment=string.split(Line, ":") origWordList=string.split(fragment[0]) origWord=origWordList[1] replaceString=replaceString + origWord + "" suggestList=string.split(fragment[1], ", ") newQuery=string.lower(theQuery) for suggestWord in suggestList: suggestWord1=string.strip(suggestWord) newQuery1=string.replace(newQuery, origWord, suggestWord1) replaceString=replaceString + "" + suggestWord1 + " " replaceString=replaceString +"

" resultsOut2=string.replace(resultsOut, "Check the spelling of the search word(s) you used.", replaceString) else: resultsOut2=resultsOut print resultsOut2 return 1 resultsOut2=string.replace(resultsOut, "Description

Excerpt", "Excerpt") resultsOut3=string.replace(resultsOut2, "Excerpt", "
Excerpt") resultsOut4=string.replace(resultsOut3, "Excerpt

", "") print resultsOut4 else: return 0 return 1 if (main()): pass else: print "Content-type: text/html\n\n" print "\n\n" print "\n\n

There was some sort of error.

\n" print "\n\n"