From 89f7445f332661dfc66761b341860025055be5e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= <agateau@kde.org>
Date: Wed, 23 Oct 2013 13:00:31 +0200
Subject: [PATCH 1/3] Install all kjs headers

---
 tier1/kjs/src/kjs/CMakeLists.txt | 65 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 3 deletions(-)

diff --git a/tier1/kjs/src/kjs/CMakeLists.txt b/tier1/kjs/src/kjs/CMakeLists.txt
index 9523e89..234962c 100644
--- a/tier1/kjs/src/kjs/CMakeLists.txt
+++ b/tier1/kjs/src/kjs/CMakeLists.txt
@@ -251,6 +251,65 @@ add_subdirectory(api)
 #     ${CMAKE_CURRENT_BINARY_DIR}/global.h
 #
 #     DESTINATION  ${INCLUDE_INSTALL_DIR}/kjs COMPONENT Devel )
-
-
-
+install(FILES
+  array_instance.h
+  array_object.h
+  bool_object.h
+  collector.h
+  CommonIdentifiers.h
+  commonunicode.h
+  CompileState.h
+  completion.h
+  context.h
+  date_object.h
+  debugger.h
+  dtoa.h
+  error_object.h
+  ExecState.h
+  function.h
+  function_object.h
+  grammar.h
+  identifier.h
+  internal.h
+  interpreter.h
+  JSImmediate.h
+  JSLock.h
+  jsonlexer.h
+  json_object.h
+  jsonstringify.h
+  JSType.h
+  JSVariableObject.h
+  JSWrapperObject.h
+  lexer.h
+  list.h
+  LocalStorage.h
+  lookup.h
+  makenodes.h
+  math_object.h
+  nodes2bytecode.h
+  nodes.h
+  number_object.h
+  object.h
+  object_object.h
+  operations.h
+  package.h
+  Parser.h
+  propertydescriptor.h
+  property_map.h
+  PropertyNameArray.h
+  property_slot.h
+  protect.h
+  regexp.h
+  regexp_object.h
+  SavedBuiltins.h
+  scope_chain.h
+  scriptfunction.h
+  string_object.h
+  SymbolTable.h
+  types.h
+  ustring.h
+  value.h
+  ${CMAKE_CURRENT_BINARY_DIR}/global.h
+  DESTINATION ${INCLUDE_INSTALL_DIR}/kjs
+  COMPONENT Devel
+)
-- 
1.8.1.2


From 60cb0c38e7a9ea4acd3abfebb57ffdeaeb035b2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= <agateau@kde.org>
Date: Wed, 23 Oct 2013 15:47:36 +0200
Subject: [PATCH 2/3] Install wtf headers, using wtf/ and kjs/ in include
 directives

---
 tier1/kjs/src/CMakeLists.txt       |  3 +--
 tier1/kjs/src/wtf/CMakeLists.txt   | 38 ++++++++++++++++++++++++++++++++------
 tier1/kjs/src/wtf/FastMalloc.h     |  2 +-
 tier1/kjs/src/wtf/HashCountedSet.h |  6 +++---
 tier1/kjs/src/wtf/HashFunctions.h  |  2 +-
 tier1/kjs/src/wtf/HashMap.h        |  4 ++--
 tier1/kjs/src/wtf/HashSet.h        |  4 ++--
 tier1/kjs/src/wtf/HashTable.cpp    |  2 +-
 tier1/kjs/src/wtf/HashTable.h      |  6 +++---
 tier1/kjs/src/wtf/HashTraits.h     |  4 ++--
 tier1/kjs/src/wtf/ListRefPtr.h     |  2 +-
 tier1/kjs/src/wtf/OwnArrayPtr.h    |  4 ++--
 tier1/kjs/src/wtf/OwnPtr.h         |  4 ++--
 tier1/kjs/src/wtf/PassRefPtr.h     |  2 +-
 tier1/kjs/src/wtf/RefPtr.h         |  4 ++--
 tier1/kjs/src/wtf/Vector.h         |  8 ++++----
 tier1/kjs/src/wtf/VectorTraits.h   |  2 +-
 17 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/tier1/kjs/src/CMakeLists.txt b/tier1/kjs/src/CMakeLists.txt
index 8629716..de1d59f 100644
--- a/tier1/kjs/src/CMakeLists.txt
+++ b/tier1/kjs/src/CMakeLists.txt
@@ -1,4 +1,3 @@
 add_subdirectory(kjs)
 
-# nothing to compile there
-#add_subdirectory(wtf)
+add_subdirectory(wtf)
diff --git a/tier1/kjs/src/wtf/CMakeLists.txt b/tier1/kjs/src/wtf/CMakeLists.txt
index 83b4417..dd80388 100644
--- a/tier1/kjs/src/wtf/CMakeLists.txt
+++ b/tier1/kjs/src/wtf/CMakeLists.txt
@@ -9,9 +9,35 @@
 #set_target_properties(wtf PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
 #install(TARGETS wtf ${INSTALL_TARGETS_DEFAULT_ARGS} )
 
-########### install files ###############
-# FIXME: Actually, most of these should NOT be installed. The only
-# ones that need be are those needed from instaled KJS headers
-# KJS headers are no longer installed, so don't install WTF headers either
-#install( FILES AlwaysInline.h Assertions.h FastMalloc.h HashCountedSet.h HashMap.h HashSet.h HashFunctions.h HashTable.h HashTraits.h Noncopyable.h OwnArrayPtr.h OwnPtr.h PassRefPtr.h Platform.h RefPtr.h SharedPtr.h Vector.h VectorTraits.h DESTINATION  ${INCLUDE_INSTALL_DIR}/wtf )
-
+install(FILES
+  AlwaysInline.h
+  ASCIICType.h
+  Assertions.h
+  DisallowCType.h
+  FastMalloc.h
+  Forward.h
+  GetPtr.h
+  HashCountedSet.h
+  HashFunctions.h
+  HashIterators.h
+  HashMap.h
+  HashSet.h
+  HashTable.h
+  HashTraits.h
+  ListRefPtr.h
+  MathExtras.h
+  Noncopyable.h
+  OwnArrayPtr.h
+  OwnPtr.h
+  PassRefPtr.h
+  Platform.h
+  RefCounted.h
+  RefPtr.h
+  RefPtrHashMap.h
+  SharedPtr.h
+  UnusedParam.h
+  Vector.h
+  VectorTraits.h
+  DESTINATION ${INCLUDE_INSTALL_DIR}/wtf
+  COMPONENT Devel
+)
diff --git a/tier1/kjs/src/wtf/FastMalloc.h b/tier1/kjs/src/wtf/FastMalloc.h
index 29a72a5..d1abb48 100644
--- a/tier1/kjs/src/wtf/FastMalloc.h
+++ b/tier1/kjs/src/wtf/FastMalloc.h
@@ -23,7 +23,7 @@
 #ifndef WTF_FastMalloc_h
 #define WTF_FastMalloc_h
 
-#include "Platform.h"
+#include <wtf/Platform.h>
 #if USE(MULTIPLE_THREADS)
 #include <pthread.h>
 #endif
diff --git a/tier1/kjs/src/wtf/HashCountedSet.h b/tier1/kjs/src/wtf/HashCountedSet.h
index be3c387..1edd5bb 100644
--- a/tier1/kjs/src/wtf/HashCountedSet.h
+++ b/tier1/kjs/src/wtf/HashCountedSet.h
@@ -23,9 +23,9 @@
 #ifndef WTF_HashCountedSet_h
 #define WTF_HashCountedSet_h
 
-#include "Assertions.h"
-#include "HashMap.h"
-#include "Vector.h"
+#include <wtf/Assertions.h>
+#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/HashFunctions.h b/tier1/kjs/src/wtf/HashFunctions.h
index f665447..0bb6538 100644
--- a/tier1/kjs/src/wtf/HashFunctions.h
+++ b/tier1/kjs/src/wtf/HashFunctions.h
@@ -22,7 +22,7 @@
 #ifndef WTF_HashFunctions_h
 #define WTF_HashFunctions_h
 
-#include "RefPtr.h"
+#include <wtf/RefPtr.h>
 #include <kjs/global.h>
 #if HAVE_STDINT_H
 #include <stdint.h>
diff --git a/tier1/kjs/src/wtf/HashMap.h b/tier1/kjs/src/wtf/HashMap.h
index ba2971c..e8889d9 100644
--- a/tier1/kjs/src/wtf/HashMap.h
+++ b/tier1/kjs/src/wtf/HashMap.h
@@ -22,7 +22,7 @@
 #ifndef WTF_HashMap_h
 #define WTF_HashMap_h
 
-#include "HashTable.h"
+#include <wtf/HashTable.h>
 
 namespace WTF {
 
@@ -330,6 +330,6 @@ namespace WTF {
 
 using WTF::HashMap;
 
-#include "RefPtrHashMap.h"
+#include <wtf/RefPtrHashMap.h>
 
 #endif /* WTF_HashMap_h */
diff --git a/tier1/kjs/src/wtf/HashSet.h b/tier1/kjs/src/wtf/HashSet.h
index e84b349..c0491b1 100644
--- a/tier1/kjs/src/wtf/HashSet.h
+++ b/tier1/kjs/src/wtf/HashSet.h
@@ -22,8 +22,8 @@
 #ifndef WTF_HashSet_h
 #define WTF_HashSet_h
 
-#include "HashTable.h"
-#include <CommonIdentifiers.h>
+#include <wtf/HashTable.h>
+#include <kjs/CommonIdentifiers.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/HashTable.cpp b/tier1/kjs/src/wtf/HashTable.cpp
index e08d09a..9e63f71 100644
--- a/tier1/kjs/src/wtf/HashTable.cpp
+++ b/tier1/kjs/src/wtf/HashTable.cpp
@@ -17,7 +17,7 @@
     Boston, MA 02110-1301, USA.
 */
 
-#include "HashTable.h"
+#include <wtf/HashTable.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/HashTable.h b/tier1/kjs/src/wtf/HashTable.h
index 0b2c22c..f33d687 100644
--- a/tier1/kjs/src/wtf/HashTable.h
+++ b/tier1/kjs/src/wtf/HashTable.h
@@ -22,8 +22,8 @@
 #ifndef WTF_HashTable_h
 #define WTF_HashTable_h
 
-#include "FastMalloc.h"
-#include "HashTraits.h"
+#include <wtf/FastMalloc.h>
+#include <wtf/HashTraits.h>
 #include <wtf/Assertions.h>
 
 namespace WTF {
@@ -1135,6 +1135,6 @@ namespace WTF {
 
 } // namespace WTF
 
-#include "HashIterators.h"
+#include <wtf/HashIterators.h>
 
 #endif // WTF_HashTable_h
diff --git a/tier1/kjs/src/wtf/HashTraits.h b/tier1/kjs/src/wtf/HashTraits.h
index 4d01726..6b521e9 100644
--- a/tier1/kjs/src/wtf/HashTraits.h
+++ b/tier1/kjs/src/wtf/HashTraits.h
@@ -22,8 +22,8 @@
 #ifndef WTF_HashTraits_h
 #define WTF_HashTraits_h
 
-#include "Assertions.h"
-#include "HashFunctions.h"
+#include <wtf/Assertions.h>
+#include <wtf/HashFunctions.h>
 #include <utility>
 #include <limits>
 
diff --git a/tier1/kjs/src/wtf/ListRefPtr.h b/tier1/kjs/src/wtf/ListRefPtr.h
index 0a704d8..2ca17c3 100644
--- a/tier1/kjs/src/wtf/ListRefPtr.h
+++ b/tier1/kjs/src/wtf/ListRefPtr.h
@@ -23,7 +23,7 @@
 #ifndef WTF_ListRefPtr_h
 #define WTF_ListRefPtr_h
 
-#include "RefPtr.h"
+#include <wtf/RefPtr.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/OwnArrayPtr.h b/tier1/kjs/src/wtf/OwnArrayPtr.h
index 3b77871..ba792b0 100644
--- a/tier1/kjs/src/wtf/OwnArrayPtr.h
+++ b/tier1/kjs/src/wtf/OwnArrayPtr.h
@@ -23,8 +23,8 @@
 #define WTF_OwnArrayPtr_h
 
 #include <algorithm>
-#include "Assertions.h"
-#include "Noncopyable.h"
+#include <wtf/Assertions.h>
+#include <wtf/Noncopyable.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/OwnPtr.h b/tier1/kjs/src/wtf/OwnPtr.h
index 188a1dc..99564bb 100644
--- a/tier1/kjs/src/wtf/OwnPtr.h
+++ b/tier1/kjs/src/wtf/OwnPtr.h
@@ -23,8 +23,8 @@
 #define WTF_OwnPtr_h
 
 #include <algorithm>
-#include "Assertions.h"
-#include "Noncopyable.h"
+#include <wtf/Assertions.h>
+#include <wtf/Noncopyable.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/PassRefPtr.h b/tier1/kjs/src/wtf/PassRefPtr.h
index 25b9906..8b7ba6d 100644
--- a/tier1/kjs/src/wtf/PassRefPtr.h
+++ b/tier1/kjs/src/wtf/PassRefPtr.h
@@ -22,7 +22,7 @@
 #ifndef WTF_PassRefPtr_h
 #define WTF_PassRefPtr_h
 
-#include "AlwaysInline.h"
+#include <wtf/AlwaysInline.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/RefPtr.h b/tier1/kjs/src/wtf/RefPtr.h
index 493ab05..128e8db 100644
--- a/tier1/kjs/src/wtf/RefPtr.h
+++ b/tier1/kjs/src/wtf/RefPtr.h
@@ -23,8 +23,8 @@
 #define WTF_RefPtr_h
 
 #include <algorithm>
-#include "AlwaysInline.h"
-#include "PassRefPtr.h"
+#include <wtf/AlwaysInline.h>
+#include <wtf/PassRefPtr.h>
 
 namespace WTF {
 
diff --git a/tier1/kjs/src/wtf/Vector.h b/tier1/kjs/src/wtf/Vector.h
index 9b0f38a..c45e17d 100644
--- a/tier1/kjs/src/wtf/Vector.h
+++ b/tier1/kjs/src/wtf/Vector.h
@@ -23,10 +23,10 @@
 #ifndef WTF_Vector_h
 #define WTF_Vector_h
 
-#include "Assertions.h"
-#include "FastMalloc.h"
-#include "Noncopyable.h"
-#include "VectorTraits.h"
+#include <wtf/Assertions.h>
+#include <wtf/FastMalloc.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/VectorTraits.h>
 #include <limits>
 #include <stdlib.h>
 #include <cstring>
diff --git a/tier1/kjs/src/wtf/VectorTraits.h b/tier1/kjs/src/wtf/VectorTraits.h
index 31ae028..7a7a134 100644
--- a/tier1/kjs/src/wtf/VectorTraits.h
+++ b/tier1/kjs/src/wtf/VectorTraits.h
@@ -23,7 +23,7 @@
 #ifndef WTF_VectorTraits_h
 #define WTF_VectorTraits_h
 
-#include "RefPtr.h"
+#include <wtf/RefPtr.h>
 #include <utility>
 
 using std::pair;
-- 
1.8.1.2


From 474f167f9516a1cae5694da7f30b3d526d894f8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= <agateau@kde.org>
Date: Wed, 23 Oct 2013 15:56:13 +0200
Subject: [PATCH 3/3] Fix KI18n standalone build

- Format according to CMake template
- Duplicate KJS create_hash_table script
- Add call to find_package(KJS)
---
 superbuild/CMakeLists.txt         |   1 +
 tier2/ki18n/CMakeLists.txt        |  22 ++-
 tier2/ki18n/src/CMakeLists.txt    |   7 +-
 tier2/ki18n/src/create_hash_table | 274 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 297 insertions(+), 7 deletions(-)
 create mode 100755 tier2/ki18n/src/create_hash_table

diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt
index 5cdec94..ed4d078 100644
--- a/superbuild/CMakeLists.txt
+++ b/superbuild/CMakeLists.txt
@@ -25,6 +25,7 @@ sb_add_project(tier1/threadweaver )
 
 sb_add_project(tier2/kauth DEPENDS kcoreaddons)
 sb_add_project(tier2/kcrash DEPENDS kcoreaddons kwindowsystem)
+sb_add_project(tier2/ki18n DEPENDS kjs)
 
 # sb_add_project(tier3/kconfigwidgets DEPENDS kauth kcoreaddons kcodecs kconfig kguiaddons ki18n kwidgetsaddons)
 
diff --git a/tier2/ki18n/CMakeLists.txt b/tier2/ki18n/CMakeLists.txt
index 4cc8e30..f18fdd1 100644
--- a/tier2/ki18n/CMakeLists.txt
+++ b/tier2/ki18n/CMakeLists.txt
@@ -2,24 +2,36 @@ cmake_minimum_required(VERSION 2.8.12)
 
 project(KI18n)
 
+# ECM setup
 find_package(ECM 0.0.9 REQUIRED NO_MODULE)
-
 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
 include(FeatureSummary)
 include(CMakePackageConfigHelpers)
 include(ECMSetupVersion)
 
-find_package(KF5 5.0.0 REQUIRED MODULE COMPONENTS CMake Compiler InstallDirs)
+set(KF5_VERSION "5.0.0")
+
+ecm_setup_version(
+  ${KF5_VERSION}
+  VARIABLE_PREFIX KI18N
+  VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/ki18n_version.h"
+  PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KI18nConfigVersion.cmake"
+)
+
+# Dependencies
 set(REQUIRED_QT_VERSION "5.2.0")
+
 find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS Core Test Concurrent)
 
+find_package(KF5 5.0.0 REQUIRED MODULE COMPONENTS CMake Compiler InstallDirs)
+
 find_package(Perl)
 set_package_properties(Perl PROPERTIES URL "http://www.perl.org" TYPE REQUIRED PURPOSE "Needed for building kdelibs")
 
-ecm_setup_version(5.0.0 VARIABLE_PREFIX KI18N
-                        VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/ki18n_version.h"
-                        PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KI18nConfigVersion.cmake")
+if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
+  find_package(KJS ${KF5_VERSION} REQUIRED)
+endif()
 
 remove_definitions(-DQT_NO_KEYWORDS)
 remove_definitions(-DQT_NO_CAST_FROM_ASCII)
diff --git a/tier2/ki18n/src/CMakeLists.txt b/tier2/ki18n/src/CMakeLists.txt
index 7f8259b4..9de8b5e 100644
--- a/tier2/ki18n/src/CMakeLists.txt
+++ b/tier2/ki18n/src/CMakeLists.txt
@@ -28,7 +28,7 @@ install(FILES
 ### ktranscript plugin
 
 # kjs hash stuff for transcript plugin
-set(CREATE_HASH_TABLE ${KJS_SOURCE_DIR}/src/kjs/create_hash_table)
+set(CREATE_HASH_TABLE ${CMAKE_CURRENT_SOURCE_DIR}/create_hash_table)
 
 add_custom_command(
     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
@@ -37,7 +37,10 @@ add_custom_command(
             > ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ktranscript.cpp
 )
-macro_add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/ktranscript.cpp ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h)
+set_property(
+    SOURCE ktranscript.cpp
+    APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
+)
 
 set(ktranscript_LIB_SRCS
     ktranscript.cpp
diff --git a/tier2/ki18n/src/create_hash_table b/tier2/ki18n/src/create_hash_table
new file mode 100755
index 0000000..94f3e43
--- /dev/null
+++ b/tier2/ki18n/src/create_hash_table
@@ -0,0 +1,274 @@
+#! /usr/bin/perl -w
+#
+# Static Hashtable Generator
+#
+# (c) 2000-2002 by Harri Porten <porten@kde.org> and
+#                  David Faure <faure@kde.org>
+# Modified (c) 2004 by Nikolas Zimmermann <wildfox@kde.org>
+#
+# Part of the KJS library.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+use strict;
+
+my $file = $ARGV[0];
+shift;
+my $findSize = 0;
+my $includelookup = 0;
+my $useNameSpace;
+
+# Use -s as second argument to make it try many hash sizes
+if (defined($ARGV[0]) && $ARGV[0] eq "-s") { $findSize = 1; shift; }
+
+# Use -i as second argument to make it include "lookup.h"
+if (defined($ARGV[0]) && $ARGV[0] eq "-i") { $includelookup = 1; shift; }
+
+# Use -n as second argument to make it use the third argument as namespace parameter ie. -n KDOM
+if (defined($ARGV[0]) && $ARGV[0] eq "-n") { $useNameSpace = $ARGV[1]; shift; shift; }
+
+open(IN, $file) or die "No such file $file";
+
+my @keys = ();
+my @values = ();
+my @attrs = ();
+my @params = ();
+my @hashes = ();
+my @table = ();
+my @links = ();
+
+my $inside = 0;
+my $name;
+my $size;
+my $hashsize;
+my $banner = 0;
+sub calcTable();
+sub output();
+sub hashValue($);
+
+while (<IN>) {
+  chop;
+  s/^\s*//g;
+  if (/^\#|^$/) {
+      # comment. do nothing
+    } elsif (/^\@begin/ && !$inside) {
+      if (/^\@begin\s*([:_\w]+)\s*(\d+)\s*$/) {
+        $inside = 1;
+        $name = $1;
+        $hashsize = $2;
+      } else {
+         printf STDERR "WARNING: \@begin without table name and hashsize, skipping $_\n";
+      }
+    } elsif (/^\@end\s*$/ && $inside) {
+
+      if($findSize) {
+	my $entriesnum=@keys;
+        print STDERR "Table: $name   $entriesnum entries\n";
+	for( my $i=3 ; $i<79 ; ++$i) { $hashsize=$i ; calcTable(); }
+      } else {
+        calcTable();
+      }
+
+      output();
+      @keys = ();
+      @values = ();
+      @attrs = ();
+      @params = ();
+      @table = ();
+      @links = ();
+      @hashes = ();
+      $inside = 0;
+    } elsif (/^(\S+)\s*(\S+)\s*([\w\|]*)\s*(\w*)\s*$/ && $inside) {
+      my $key = $1;
+      my $val = $2;
+      my $att = $3;
+      my $param = $4;
+      push(@keys, $key);
+      push(@values, $val);
+      push(@hashes, hashValue($key));
+      printf STDERR "WARNING: Number of arguments missing for $key/$val\n"
+        if ( $att =~ m/Function/ && length($param) == 0);
+      push(@attrs, length($att) > 0 ? $att : "0");
+      push(@params, length($param) > 0 ? $param : "0");
+    } elsif ($inside) {
+      die "invalid data {" . $_ . "}";
+    }
+}
+
+die "missing closing \@end" if ($inside);
+
+sub calcTable() {
+  $size = $hashsize;
+  my $collisions = 0;
+  my $maxdepth = 0;
+  my $i = 0;
+  foreach my $key (@keys) {
+    my $depth = 0;
+    my $h = hashValue($key) % $hashsize;
+    while (defined($table[$h])) {
+      if (defined($links[$h])) {
+	$h = $links[$h];
+	$depth++;
+      } else {
+	$collisions++;
+	$links[$h] = $size;
+	$h = $size;
+	$size++;
+      }
+    }
+    #print STDERR "table[$h] = $i\n";
+    $table[$h] = $i;
+    $i++;
+    $maxdepth = $depth if ( $depth > $maxdepth);
+  }
+
+  # Ensure table is big enough (in case of undef entries at the end)
+  if ( $#table+1 < $size ) {
+    $#table = $size-1;
+  }
+  #print STDERR "After loop: size=$size table=".($#table+1)."\n";
+
+  if ($findSize) {
+    my $emptycount = 0;
+    foreach my $entry (@table) {
+      $emptycount++ if (!defined($entry));
+    }
+    print STDERR "Hashsize: $hashsize  Total Size: $size Empty: $emptycount MaxDepth: $maxdepth Collisions: $collisions\n";
+  }
+#  my $debugtable = 0;
+#  foreach my $entry (@table) {
+#    print STDERR "$debugtable " . (defined $entry ? $entry : '<undefined>');
+#    print STDERR " -> " . $links[$debugtable] if (defined($links[$debugtable]));
+#    print STDERR "\n";
+#    $debugtable++;
+#  }
+}
+
+sub leftShift($$) {
+    my ($value, $distance) = @_;
+    return (($value << $distance) & 0xFFFFFFFF);
+}
+
+# Paul Hsieh's SuperFastHash
+# http://www.azillionmonkeys.com/qed/hash.html
+# Ported from UString..
+sub hashValue($) {
+  my @chars = split(/ */, $_[0]);
+
+  # This hash is designed to work on 16-bit chunks at a time. But since the normal case
+  # (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
+  # were 16-bit chunks, which should give matching results
+
+  my $EXP2_32 = 4294967296;
+
+  my $hash = 0x9e3779b9;
+  my $l    = scalar @chars; #I wish this was in Ruby --- Maks
+  my $rem  = $l & 1;
+  $l = $l >> 1;
+
+  my $s = 0;
+
+  # Main loop
+  for (; $l > 0; $l--) {
+    $hash   += ord($chars[$s]);
+    my $tmp = leftShift(ord($chars[$s+1]), 11) ^ $hash;
+    $hash   = (leftShift($hash, 16)% $EXP2_32) ^ $tmp;
+    $s += 2;
+    $hash += $hash >> 11;
+    $hash %= $EXP2_32;
+  }
+
+  # Handle end case
+  if ($rem !=0) {
+    $hash += ord($chars[$s]);
+    $hash ^= (leftShift($hash, 11)% $EXP2_32);
+    $hash += $hash >> 17;
+  }
+
+  # Force "avalanching" of final 127 bits
+  $hash ^= leftShift($hash, 3);
+  $hash += ($hash >> 5);
+  $hash = ($hash% $EXP2_32);
+  $hash ^= (leftShift($hash, 2)% $EXP2_32);
+  $hash += ($hash >> 15);
+  $hash = $hash% $EXP2_32;
+  $hash ^= (leftShift($hash, 10)% $EXP2_32);
+
+  # this avoids ever returning a hash code of 0, since that is used to
+  # signal "hash not computed yet", using a value that is likely to be
+  # effectively the same as 0 when the low bits are masked
+  $hash = 0x80000000  if ($hash == 0);
+
+  return $hash;
+}
+
+sub output() {
+  if (!$banner) {
+    $banner = 1;
+    print "/* Automatically generated from $file using $0. DO NOT EDIT ! */\n";
+  }
+
+  my $nameEntries = "${name}Entries";
+  $nameEntries =~ s/:/_/g;
+
+  print "\n#include \"lookup.h\"\n" if ($includelookup);
+  if ($useNameSpace) {
+    print "\nnamespace ${useNameSpace}\n{\n";
+  } else {
+    print "\nnamespace KJS {\n";
+  }
+  print "\nstatic const struct KJS::HashEntry ".$nameEntries."[] = {\n";
+  my $i = 0;
+  #print STDERR "writing out table with ".($#table+1)." entries\n";
+
+  if ($hashsize eq 0) {
+    # To make the hash table lookup code fast, we don't allow tables of size 0.
+    # That way it can do a modulo by the size without a special case to avoid division by 0.
+    print "   \{ 0, 0, 0, 0, 0 \}\n";
+    $hashsize = 1;
+    $size = 1;
+  } else {
+    foreach my $entry (@table) {
+      if (defined($entry)) {
+        my $key = $keys[$entry];
+        print "   \{ \"" . $key . "\"";
+        print ", " . $values[$entry];
+        my $kjsattrs = $attrs[$entry];
+        if ($kjsattrs ne "0") {
+         $kjsattrs =~ s/([^|]+)/KJS::$1/g; # DontDelete|Function -> KJS::DontDelete|KJS::Function
+        }
+        print ", " . $kjsattrs;
+        print ", " . $params[$entry];
+        print ", ";
+        if (defined($links[$i])) {
+          print "&" . $nameEntries . "[" . $links[$i] . "]" . " \}";
+        } else {
+          print "0 \}"
+        }
+        print "/* " . $hashes[$entry] . " */ ";
+      } else {
+        print "   \{ 0, 0, 0, 0, 0 \}";
+      }
+      print "," unless ($i == $size - 1);
+      print "\n";
+      $i++;
+    }
+  }
+  print "};\n\n";
+  print "const struct KJS::HashTable $name = ";
+  print "\{ 2, $size, ".$nameEntries.", $hashsize \};\n\n";
+  print "} // namespace\n";
+}
-- 
1.8.1.2

