KeywordLookupGenerator.py should take an output file as an argument
https://bugs.webkit.org/show_bug.cgi?id=84292

Patch by Don Olmstead <don.olmstead@am.sony.com> on 2012-04-19
Reviewed by Eric Seidel.

Extended KeywordLookupGenerator to accept an additional argument specifying an output file. If this argument is found stdout is redirected to a file for the duration of the script.

* KeywordLookupGenerator.py:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114684 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/KeywordLookupGenerator.py b/Source/JavaScriptCore/KeywordLookupGenerator.py
index 29f50df..748acf9 100644
--- a/Source/JavaScriptCore/KeywordLookupGenerator.py
+++ b/Source/JavaScriptCore/KeywordLookupGenerator.py
@@ -1,4 +1,5 @@
 # Copyright (C) 2011 Apple Inc. All rights reserved.
+# Copyright (C) 2012 Sony Network Entertainment. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -27,6 +28,15 @@
 
 keywordsText = open(sys.argv[1]).read()
 
+# A second argument signifies that the output
+# should be redirected to a file
+redirect_to_file = len(sys.argv) > 2
+
+# Change stdout to point to the file if requested
+if redirect_to_file:
+    file_output = open(sys.argv[-1], "w")
+    sys.stdout = file_output
+
 # Observed weights of the most common keywords, rounded to 2.s.d
 keyWordWeights = {
     "catch": 0.01,
@@ -288,3 +298,8 @@
 """)
 
 trie.printAsC()
+
+# Close the redirected file if requested
+if (redirect_to_file):
+    file_output.close()
+    sys.stdout = sys.__stdout__