CGI and find

J. Landman Gay jacque at hyperactivesw.com
Tue Sep 2 17:59:01 EDT 2003


On 9/2/03 5:25 PM, Dar Scott wrote:

> Where is your find script? In the library stack?

My setup (OS X) is:

  MC Darwin engine in /Library/WebServer/CGI-Executables/
  A text file called "search.mt" containing the script in the same folder
  A stack called "searchStack.mc" in the same folder

Elsewhere on disk, I have an html form where I can enter the search 
terms. Its contents are sent with a "get" directive in the action 
statement. I load the html form from disk into my browser, fill out the 
search terms, and hit the Send button.

The script in the search.mt text file looks like this (watch for line wrap):

on startup
   put "Content-Type: text/html" & cr & cr
   put the ticks into theStart
   put urlDecode($QUERY_STRING) into theTerm
   if $REQUEST_METHOD is "GET" then delete char 1 to offset("=",theTerm) 
of theTerm
   put "" into buffer
   put "searchStack.mc" into theStack
   if theTerm = "" then
     put "No query submitted." after buffer
   else if there is no stack theStack then
     put "Data stack cannot be found." after buffer
   else
     start using stack theStack
     set the defaultstack to "fictionwise" -- not sure if you need this
     put 0 into theCt
     mark cds by finding theTerm
     repeat with x = 1 to the number of marked cds
       put "<b>" & fld "title" of marked cd x & "</b><p>" & cr after buffer
       -- other stuff here
       add 1 to theCt
     end repeat
     stop using stack theStack
   end if

   put the ticks - theStart && "ticks" into theETime
   put theNumHits && "found" into theNumHits
   put url ("file:header.txt") & "<h3>Results for " &quote& theTerm 
&quote& colon \
       & "</h3>"& theCt && "found" && "<p> <p>" before buffer
   put cr&cr& "<p> <p>Execution time: " & theETime & "</body> 
</html>" after buffer
   put buffer
end startup


This works and is pretty fast. All "put" statments that don't go into 
variables get automatically written to stdout; you don't need "write" 
statements.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list