diff --git a/applications/Template2Keywords/Template2Keywords.cs b/applications/Template2Keywords/Template2Keywords.cs new file mode 100644 index 00000000..4dbeccdb --- /dev/null +++ b/applications/Template2Keywords/Template2Keywords.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace Template2Keywords +{ + class Template2Keywords + { + static List keywords; + static Dictionary table; + + static void Main(string[] args) + { + table = new Dictionary(); + keywords = new List(); + + //Read the keywords from message_template in the order they appear. + //This is kinda sloppy because I just wanted to see if it worked. + StreamReader freader = File.OpenText("message_template.msg"); + char[] sep = new char[2]; + sep[0] = ' '; + sep[1] = '\t'; + while (!freader.EndOfStream) + { + string line = freader.ReadLine(); + int pos = line.IndexOf("//"); + if (pos != -1) + line = line.Substring(0, pos); + + string[] words = line.Split(sep); + foreach (string s in words) + if (s.Length > 0 && char.IsUpper(s[0])) + { + keywords.Add(s); + break; + } + } + + //Hash the keywords + foreach (string s in keywords) + { + hash(s); + } + + //Write the output, should be identical to keywords.txt + StreamWriter fwriter = File.CreateText("output.txt"); + for (uint i = 0; i < 0x1FFF; i++) + { + if (table.ContainsKey(i)) + { + fwriter.WriteLine(table[i]); + } + } + fwriter.Close(); + } + + static uint hash(string s) + { + uint b = 0; + for (int k = 1; k < s.Length; k++) + { + b = (b + (uint)(s[k])) * 2; + } + b *= 2; + b &= 0x1FFF; + + while (table.ContainsKey(b)) + { + if (table[b] == s) + return b; + + b++; + if (b > 0x1FFF) + return 0; //Give up looking, went past the end. (Shouldn't happen) + } + + table[b] = s; + return b; + } + } +} diff --git a/applications/Template2Keywords/Template2Keywords.csproj b/applications/Template2Keywords/Template2Keywords.csproj new file mode 100644 index 00000000..4a370f43 --- /dev/null +++ b/applications/Template2Keywords/Template2Keywords.csproj @@ -0,0 +1,49 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {279047FE-3264-403A-88D7-CF7F7609803E} + Exe + Properties + Template2Keywords + Template2Keywords + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applications/Template2Keywords/Template2Keywords.sln b/applications/Template2Keywords/Template2Keywords.sln new file mode 100644 index 00000000..81aac021 --- /dev/null +++ b/applications/Template2Keywords/Template2Keywords.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Template2Keywords", "Template2Keywords.csproj", "{279047FE-3264-403A-88D7-CF7F7609803E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {279047FE-3264-403A-88D7-CF7F7609803E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {279047FE-3264-403A-88D7-CF7F7609803E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {279047FE-3264-403A-88D7-CF7F7609803E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {279047FE-3264-403A-88D7-CF7F7609803E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal