summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2005-12-01 13:26:11 +0000
committerpixel <pixel>2005-12-01 13:26:11 +0000
commit1e42ac8e3b3c3c770bd2796537379a57fac7b21d (patch)
treee6498057188a1552b9cf5eaa532e8c862de9dfcd
parente87814e9caf9d34cbd402b87d90e5cecdee3de0d (diff)
Adding the elf hasing algorithm for huh... quite no reason.
-rw-r--r--cd-tool.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/cd-tool.cpp b/cd-tool.cpp
index fbebf8e..fb17871 100644
--- a/cd-tool.cpp
+++ b/cd-tool.cpp
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: cd-tool.cpp,v 1.46 2005-11-13 13:43:21 pixel Exp $ */
+/* $Id: cd-tool.cpp,v 1.47 2005-12-01 13:26:11 pixel Exp $ */
#define WIP
@@ -362,6 +362,28 @@ struct option long_options[] = {
{0, 0, NULL, 0 }
};
+static Uint32 elf_hash(const unsigned char * name) {
+ Uint32 h = 0, g;
+
+ while (*name) {
+ h = (h << 4) + *name++;
+ if ((g = h & 0xf0000000))
+ h ^= g >> 24;
+ h &= ~g;
+ }
+
+ return h;
+}
+
+static int lua_elf_hash(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+ String t = L->tostring();
+
+ L->push((lua_Number) elf_hash((unsigned char *) t.to_charp()));
+
+ return 1;
+}
+
CODE_BEGINS
/* That's the basic lua starter for non interactive mode */
@@ -389,6 +411,10 @@ Lua * start_basic_lua(void) {
L->push(myprint);
L->setvar();
+ L->push("hash");
+ L->push(lua_elf_hash);
+ L->setvar();
+
Luabasecdtool::pushstatics(L);
return L;