From 1e42ac8e3b3c3c770bd2796537379a57fac7b21d Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 1 Dec 2005 13:26:11 +0000 Subject: Adding the elf hasing algorithm for huh... quite no reason. --- cd-tool.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3