* Added a sample program that generates the keyword order using the hash function that SL uses
git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@425 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
82
applications/Template2Keywords/Template2Keywords.cs
Normal file
82
applications/Template2Keywords/Template2Keywords.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Template2Keywords
|
||||
{
|
||||
class Template2Keywords
|
||||
{
|
||||
static List<string> keywords;
|
||||
static Dictionary<uint, string> table;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
table = new Dictionary<uint, string>();
|
||||
keywords = new List<string>();
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
applications/Template2Keywords/Template2Keywords.csproj
Normal file
49
applications/Template2Keywords/Template2Keywords.csproj
Normal file
@@ -0,0 +1,49 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{279047FE-3264-403A-88D7-CF7F7609803E}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Template2Keywords</RootNamespace>
|
||||
<AssemblyName>Template2Keywords</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Template2Keywords.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
20
applications/Template2Keywords/Template2Keywords.sln
Normal file
20
applications/Template2Keywords/Template2Keywords.sln
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user