// from www.javascriptkit.com/script/cut154.shtml
@tools.dpuser

output = stringarray(0)

output += "title = new Object();"
output += "desc = new Object();"
output += "links= new Object();"
output += "matched= new Object();"
output += "keywords= new Object();"
output += "found= new Object();"
output += "var temp=0;"
// actual location or the item to be searched // description of he location
// actual link
// percentage match found
// keywords as parsed from the input 
//no of keywords after parsing
output += "keywords[0]=0"
//no of  matches found.
output += "found[0]=0"

database = stringarray(0)
n = 1

text = importdoc("../functions_doc.h", /text)
while (nelements(text) > 0) {
 i = 1
 while(text[i] != "" && i < nelements(text)) i++
 function = text[1:i]
 print function[1]
 if (i < nelements(text)) {
  text = text[i+1:nelements(text)]
 } else {
  text = stringarray(0)
 }
 database += "desc[" + n + "] = \"" + function[1] + " function\""
 line = function[1] + " " + function[2]
 replace line, "\"", ""
 replace line, "\"", ""
 line = unify(line)
 database += "title[" + n + "] = \"" + line + "\""
aga=function[1]
replace aga, " \(obsolete\)", ""
 database += "links[" + n + "] = \"function_" + aga + ".html\""
 database += "matched[" + n + "] = 0"
 n++
}
text = importdoc("../procedures_doc.h", /text)
while (nelements(text) > 0) {
 i = 1
 while(text[i] != "" && i < nelements(text)) i++
 function = text[1:i]
 print function[1]
 if (i < nelements(text)) {
  text = text[i+1:nelements(text)]
 } else {
  text = stringarray(0)
 }
 database += "desc[" + n + "] = \"" + function[1] + " procedure\""
 line = function[1] + " " + function[2]
 replace line, "\"", " "
 replace line, "\"", " "
 line = unify(line)
 database += "title[" + n + "] = \"" + line + "\""
aga=function[1]
replace aga, " \(obsolete\)", ""
 database += "links[" + n + "] = \"procedure_" + aga + ".html\""
 database += "matched[" + n + "] = 0"
 n++
}

files = ["index.html","installing.html","syntax.html","operators.html","ifandloop.html","variables.html","plotting.html","fitsfiles.html","examples.html","bridges.html"]
for i=1, nelements(files) {
 print files[i]
 text = import("../" + files[i], /text)
 text = nohtml(text)
 line = ""
 for j=1, nelements(text) line += text[j] + " "
 while (strpos(line, "&nbsp;") != -1) replace line, "&nbsp;", " "
 while (strpos(line, "\"") != -1) replace line, "\"", " "
 line = simplifywhitespace(line)
 line = unify(line)
 database += "desc[" + n + "] = \"" + files[i] + "\""
 database += "title[" + n + "] = \"" + line + "\""
 database += "links[" + n + "] = \"" + files[i] + "\""
 database += "matched[" + n + "] = 0"
 n++
}

output += "title[0] = " + (n-1)
output += database

output += import("searchend.html", /text)

export "index.js", output
