Commit 78f95e3b authored by Mart Lubbers's avatar Mart Lubbers

add hash search, so you can share links

parent c0b85ce0
...@@ -7,3 +7,4 @@ MersenneTwister ...@@ -7,3 +7,4 @@ MersenneTwister
StdEnv StdEnv
StdLib StdLib
TCPIP TCPIP
clean-platform
...@@ -58,18 +58,18 @@ function highlight(type) { ...@@ -58,18 +58,18 @@ function highlight(type) {
} }
} }
sform.onsubmit = function(){ function formsubmit(){
if(form_str.value === ''){ if(form_str.value === ''){
sresults.innerHTML = 'Can\'t search for the empty string'; sresults.innerHTML = 'Can\'t search for the empty string';
} else { } else {
sresults.innerHTML = 'Proccessing...'; sresults.innerHTML = 'Proccessing...';
var url = 'api.php?str=' + var str = encodeURIComponent(form_str.value);
encodeURIComponent(form_str.value); var url = 'api.php?str=' + str;
console.log('Async: ' + url); console.log('Apicall: ' + url);
var xmlHttp = new XMLHttpRequest(); var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){ if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
console.log(xmlHttp.responseText); console.log('Response: ' + xmlHttp.responseText);
var responsedata = JSON.parse(xmlHttp.responseText); var responsedata = JSON.parse(xmlHttp.responseText);
sresults.innerHTML = sresults.innerHTML =
'<p>Return code: ' + responsedata['return'] + '</p>' + '<p>Return code: ' + responsedata['return'] + '</p>' +
...@@ -90,6 +90,18 @@ sform.onsubmit = function(){ ...@@ -90,6 +90,18 @@ sform.onsubmit = function(){
}; };
xmlHttp.open('GET', url, true); // true for asynchronous xmlHttp.open('GET', url, true); // true for asynchronous
xmlHttp.send(null); xmlHttp.send(null);
document.location.hash = "#" + str;
} }
return false; return false;
}; };
window.onload = function(){
sform.onsubmit = formsubmit;
var str = document.location.hash;
if(str !== ''){
str = str.substring(1);
console.log('Detected hash, setting searchstring to ' + str);
form_str.value = str;
formsubmit();
}
}
...@@ -4,7 +4,7 @@ ini_set('display_errors', '1'); ...@@ -4,7 +4,7 @@ ini_set('display_errors', '1');
define('PRE_IDENT', '[\w~@#$%^?!+\-*<>\/|&=:`]+'); define('PRE_IDENT', '[\w~@#$%^?!+\-*<>\/|&=:`]+');
define('PRE_MODULE', define('PRE_MODULE',
"/\s*(?:definition\s*|system\s*|implementation\s*)module\s+(\S+)\s*[\n;]/"); "/\s*(?:definition\s*|system\s*|implementation\s*)module\s+([\w.]+)\s*[\n;]/");
define('PRE_FUNC', define('PRE_FUNC',
'/^(?:\\/\\/)?\s*(?:instance|class)?\s*\(?(' . PRE_IDENT . ')\)?\s*(?:infix[lr]?\s+\d\s*(?:\\/\\/)?)?(?:\s+a\s+)?::.*$/mi'); '/^(?:\\/\\/)?\s*(?:instance|class)?\s*\(?(' . PRE_IDENT . ')\)?\s*(?:infix[lr]?\s+\d\s*(?:\\/\\/)?)?(?:\s+a\s+)?::.*$/mi');
...@@ -25,12 +25,11 @@ function search_doc(&$r, $name, $libraries){ ...@@ -25,12 +25,11 @@ function search_doc(&$r, $name, $libraries){
$lowername = strtolower($name); $lowername = strtolower($name);
$lowerfuncname = strtolower($funcname); $lowerfuncname = strtolower($funcname);
if(strstr($lowerfuncname, $lowername) !== FALSE){ if(strstr($lowerfuncname, $lowername) !== FALSE){
$score = -1*strlen($funcname)+ $score = -100+levenshtein($lowername, $lowerfuncname);
levenshtein($lowername, $lowerfuncname);
} else { } else {
$score = levenshtein($lowername, $lowerfuncname); $score = levenshtein($lowername, $lowerfuncname);
} }
if($score < strlen($name)/2){ if($score < 3){
array_push($r, array( array_push($r, array(
"library" => $library, "library" => $library,
"filename" => $filename, "filename" => $filename,
...@@ -69,7 +68,65 @@ if($_SERVER['REQUEST_METHOD'] !== 'GET'){ ...@@ -69,7 +68,65 @@ if($_SERVER['REQUEST_METHOD'] !== 'GET'){
'MersenneTwister' => './MersenneTwister/', 'MersenneTwister' => './MersenneTwister/',
'StdEnv' => './StdEnv/', 'StdEnv' => './StdEnv/',
'StdLib' => './StdLib/', 'StdLib' => './StdLib/',
'TCPIP' => './TCPIP/'); 'TCPIP' => './TCPIP/',
'cleanplatform:OS-Linux-64' =>'./clean-platform/OS-Linux-64/',
'cleanplatform:OS-Linux-64/System' =>'./clean-platform/OS-Linux-64/System/',
'cleanplatform:OS-Linux-64/Database' =>'./clean-platform/OS-Linux-64/Database/',
'cleanplatform:OS-Linux-64/Database/SQL' =>'./clean-platform/OS-Linux-64/Database/SQL/',
'cleanplatform:OS-Mac' =>'./clean-platform/OS-Mac/',
'cleanplatform:OS-Mac/System' =>'./clean-platform/OS-Mac/System/',
'cleanplatform:OS-Mac/Database' =>'./clean-platform/OS-Mac/Database/',
'cleanplatform:OS-Mac/Database/SQL' =>'./clean-platform/OS-Mac/Database/SQL/',
'cleanplatform:OS-Mac/Network' =>'./clean-platform/OS-Mac/Network/',
'cleanplatform:OS-Linux-32' =>'./clean-platform/OS-Linux-32/',
'cleanplatform:OS-Linux-32/System' =>'./clean-platform/OS-Linux-32/System/',
'cleanplatform:OS-Windows-64' =>'./clean-platform/OS-Windows-64/',
'cleanplatform:OS-Windows-64/System' =>'./clean-platform/OS-Windows-64/System/',
'cleanplatform:OS-Linux' =>'./clean-platform/OS-Linux/',
'cleanplatform:OS-Linux/System' =>'./clean-platform/OS-Linux/System/',
'cleanplatform:OS-Linux/Network' =>'./clean-platform/OS-Linux/Network/',
'cleanplatform:OS-Posix' =>'./clean-platform/OS-Posix/',
'cleanplatform:OS-Posix/System' =>'./clean-platform/OS-Posix/System/',
'cleanplatform:OS-Posix/Network' =>'./clean-platform/OS-Posix/Network/',
'cleanplatform:OS-Posix/DataSources' =>'./clean-platform/OS-Posix/DataSources/',
'cleanplatform:OS-Windows-32' =>'./clean-platform/OS-Windows-32/',
'cleanplatform:OS-Windows-32/System' =>'./clean-platform/OS-Windows-32/System/',
'cleanplatform:OS-Windows' =>'./clean-platform/OS-Windows/',
'cleanplatform:OS-Windows/System' =>'./clean-platform/OS-Windows/System/',
'cleanplatform:OS-Windows/Database' =>'./clean-platform/OS-Windows/Database/',
'cleanplatform:OS-Windows/Database/SQL' =>'./clean-platform/OS-Windows/Database/SQL/',
'cleanplatform:OS-Windows/Network' =>'./clean-platform/OS-Windows/Network/',
'cleanplatform:OS-Windows/DataSources' =>'./clean-platform/OS-Windows/DataSources/',
'cleanplatform:OS-Windows/Data' =>'./clean-platform/OS-Windows/Data/',
'cleanplatform:OS-Independent' =>'./clean-platform/OS-Independent/',
'cleanplatform:OS-Independent/Math' =>'./clean-platform/OS-Independent/Math/',
'cleanplatform:OS-Independent/System' =>'./clean-platform/OS-Independent/System/',
'cleanplatform:OS-Independent/Crypto' =>'./clean-platform/OS-Independent/Crypto/',
'cleanplatform:OS-Independent/Crypto/Hash' =>'./clean-platform/OS-Independent/Crypto/Hash/',
'cleanplatform:OS-Independent/Control' =>'./clean-platform/OS-Independent/Control/',
'cleanplatform:OS-Independent/Control/Monad' =>'./clean-platform/OS-Independent/Control/Monad/',
'cleanplatform:OS-Independent/GUI' =>'./clean-platform/OS-Independent/GUI/',
'cleanplatform:OS-Independent/Deprecated' =>'./clean-platform/OS-Independent/Deprecated/',
'cleanplatform:OS-Independent/Deprecated/StdLib' =>'./clean-platform/OS-Independent/Deprecated/StdLib/',
'cleanplatform:OS-Independent/Database' =>'./clean-platform/OS-Independent/Database/',
'cleanplatform:OS-Independent/Database/SQL' =>'./clean-platform/OS-Independent/Database/SQL/',
'cleanplatform:OS-Independent/Text' =>'./clean-platform/OS-Independent/Text/',
'cleanplatform:OS-Independent/Text/Unicode' =>'./clean-platform/OS-Independent/Text/Unicode/',
'cleanplatform:OS-Independent/Text/Unicode/Encodings' =>'./clean-platform/OS-Independent/Text/Unicode/Encodings/',
'cleanplatform:OS-Independent/Text/Encodings' =>'./clean-platform/OS-Independent/Text/Encodings/',
'cleanplatform:OS-Independent/Text/Parsers' =>'./clean-platform/OS-Independent/Text/Parsers/',
'cleanplatform:OS-Independent/Text/Parsers/Test' =>'./clean-platform/OS-Independent/Text/Parsers/Test/',
'cleanplatform:OS-Independent/Text/Parsers/MetarDemo' =>'./clean-platform/OS-Independent/Text/Parsers/MetarDemo/',
'cleanplatform:OS-Independent/Internet' =>'./clean-platform/OS-Independent/Internet/',
'cleanplatform:OS-Independent/Internet/HTTP' =>'./clean-platform/OS-Independent/Internet/HTTP/',
'cleanplatform:OS-Independent/Network' =>'./clean-platform/OS-Independent/Network/',
'cleanplatform:OS-Independent/Test' =>'./clean-platform/OS-Independent/Test/',
'cleanplatform:OS-Independent/Data' =>'./clean-platform/OS-Independent/Data/',
'cleanplatform:OS-Independent/Data/Functor' =>'./clean-platform/OS-Independent/Data/Functor/',
'cleanplatform:OS-Independent/Data/IntMap' =>'./clean-platform/OS-Independent/Data/IntMap/',
'cleanplatform:OS-Independent/Data/Encoding' =>'./clean-platform/OS-Independent/Data/Encoding/',
'cleanplatform:OS-Independent/Graphics' =>'./clean-platform/OS-Independent/Graphics/',
'cleanplatform:OS-Independent/Graphics/Scalable' =>'./clean-platform/OS-Independent/Graphics/Scalable/');
$res = array(); $res = array();
$msg = search_doc($res, $_GET['str'], $libraries); $msg = search_doc($res, $_GET['str'], $libraries);
......
...@@ -5,28 +5,31 @@ ...@@ -5,28 +5,31 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="api.js" type="text/javascript" defer="defer"></script> <script src="api.js" type="text/javascript" defer="defer"></script>
<style type="text/css"> <style type="text/css">
.comment { color: #aaaaaa; } .comment { color: #aaaaaa; }
.funcname { color: #5998c2; font-weight: bold; } .funcname { color: #5998c2; font-weight: bold; }
.classname { color: #5998c2; } .classname { color: #5998c2; }
.typevar { color: #59c28a; font-weight: bold; } .typevar { color: #59c28a; font-weight: bold; }
.type { color: #e3890b; font-weight: bold; } .type { color: #e3890b; font-weight: bold; }
.punctuation { color: #777777; } .punctuation { color: #777777; }
</style> </style>
</head> </head>
<body> <body>
<form id="search_form" action="#"> <a href="https://github.com/dopefishh/cloogle">
<table> <img src="logo.jpg" alt="follow link for the sourcecode" />
<tr> </a>
<td colspan="3"> <form id="search_form" action="#">
<input type="text" id="search_str" /> <table>
</td> <tr>
</tr> <td colspan="3">
<tr> <input type="text" id="search_str" />
<td><input type="submit" value="Search" onchange="js_sub()" /></td> </td>
</tr> </tr>
</table> <tr>
</form> <td><input type="submit" value="Search" /></td>
<div id='search_results'></div> </tr>
</table>
</form>
<div id='search_results'></div>
</body> </body>
</html> </html>
logo.jpg

5.52 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment