Fixed the path separators so that they work on Unix.
Improved the output for the doc processor: MathML equations are replaced by their textual representation and whitespace better matches function declarations. Added new configuration settings for the doc processor and the license. Removed stale debugging code. License.txt is now a file, not a resource.
This commit is contained in:
parent
875263e46a
commit
a7849e8dd9
8 changed files with 90 additions and 37 deletions
|
@ -11,7 +11,6 @@ namespace Bind
|
|||
{
|
||||
class DocProcessor
|
||||
{
|
||||
static readonly Regex remove_doctype = new Regex("<!DOCTYPE.*/>", RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
static readonly Regex remove_mathml = new Regex(@"<(mml:math)[^>]*?>(?:.|\n)*?</\s*\1\s*>",
|
||||
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
|
||||
static readonly StreamWriter output_stream = new StreamWriter(new MemoryStream());
|
||||
|
@ -26,6 +25,10 @@ namespace Bind
|
|||
settings.XmlResolver = null;
|
||||
}
|
||||
|
||||
// Strips MathML tags from the source and replaces the equations with the content
|
||||
// found in the <!-- eqn: :--> comments in the docs.
|
||||
// Todo: Some simple MathML tags do not include comments, find a solution.
|
||||
// Todo: Some files include more than 1 function - find a way to map these extra functions.
|
||||
public string ProcessFile(string file)
|
||||
{
|
||||
string text = File.ReadAllText(file);
|
||||
|
@ -33,19 +36,37 @@ namespace Bind
|
|||
Match m = remove_mathml.Match(text);
|
||||
while (m.Length > 0)
|
||||
{
|
||||
string removed = text.Substring(m.Index, m.Length);
|
||||
text = text.Remove(m.Index, m.Length);
|
||||
int equation = removed.IndexOf("eqn");
|
||||
if (equation > 0)
|
||||
{
|
||||
text = text.Insert(m.Index,
|
||||
"<![CDATA[" +
|
||||
removed.Substring(equation + 4, removed.IndexOf(":-->") - equation - 4) +
|
||||
"]]>");
|
||||
}
|
||||
m = remove_mathml.Match(text);
|
||||
}
|
||||
//text = remove_doctype.Replace(sb.ToString(), String.Empty, 1), String.Empty);
|
||||
|
||||
// The pure XmlReader is ~20x faster than the XmlTextReader.
|
||||
var doc = XmlReader.Create(new StringReader(text), settings);
|
||||
//var doc = new XmlTextReader(new StringReader(text));
|
||||
|
||||
using (StringWriter sw = new StringWriter())
|
||||
XmlReader doc = null;
|
||||
try
|
||||
{
|
||||
xslt.Transform(doc, null, sw);
|
||||
return sw.ToString();
|
||||
// The pure XmlReader is ~20x faster than the XmlTextReader.
|
||||
doc = XmlReader.Create(new StringReader(text), settings);
|
||||
//doc = new XmlTextReader(new StringReader(text));
|
||||
|
||||
using (StringWriter sw = new StringWriter())
|
||||
{
|
||||
xslt.Transform(doc, null, sw);
|
||||
return sw.ToString();
|
||||
}
|
||||
}
|
||||
catch (XmlException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
Console.WriteLine(doc.ToString());
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ namespace Bind.GL2
|
|||
{
|
||||
#region --- Fields ---
|
||||
|
||||
protected static string glTypemap = "GL2\\gl.tm";
|
||||
protected static string glTypemap = "GL2/gl.tm";
|
||||
protected static string csTypemap = "csharp.tm";
|
||||
protected static string enumSpec = "GL2\\enum.spec";
|
||||
protected static string enumSpecExt = "GL2\\enumext.spec";
|
||||
protected static string glSpec = "GL2\\gl.spec";
|
||||
protected static string enumSpec = "GL2/enum.spec";
|
||||
protected static string enumSpecExt = "GL2/enumext.spec";
|
||||
protected static string glSpec = "GL2/gl.spec";
|
||||
protected static string glSpecExt = "";
|
||||
|
||||
protected static string importsFile = "GLCore.cs";
|
||||
|
@ -455,13 +455,14 @@ namespace Bind.GL2
|
|||
|
||||
public void WriteBindings(DelegateCollection delegates, FunctionCollection functions, EnumCollection enums)
|
||||
{
|
||||
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
|
||||
if (!Directory.Exists(Settings.OutputPath))
|
||||
Directory.CreateDirectory(Settings.OutputPath);
|
||||
|
||||
// Enums
|
||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, enumsFile)))
|
||||
{
|
||||
WriteLicense(sw, Resources.License);
|
||||
WriteLicense(sw);
|
||||
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
|
||||
{
|
||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||
|
@ -490,7 +491,7 @@ namespace Bind.GL2
|
|||
// Delegates
|
||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, delegatesFile)))
|
||||
{
|
||||
WriteLicense(sw, Resources.License);
|
||||
WriteLicense(sw);
|
||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||
sw.WriteLine("{");
|
||||
sw.Indent();
|
||||
|
@ -508,7 +509,7 @@ namespace Bind.GL2
|
|||
// Core
|
||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, importsFile)))
|
||||
{
|
||||
WriteLicense(sw, Resources.License);
|
||||
WriteLicense(sw);
|
||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||
sw.WriteLine("{");
|
||||
sw.Indent();
|
||||
|
@ -525,7 +526,7 @@ namespace Bind.GL2
|
|||
// Wrappers
|
||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, wrappersFile)))
|
||||
{
|
||||
WriteLicense(sw, Resources.License);
|
||||
WriteLicense(sw);
|
||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||
sw.WriteLine("{");
|
||||
sw.Indent();
|
||||
|
@ -770,9 +771,9 @@ namespace Bind.GL2
|
|||
|
||||
#region void WriteLicense
|
||||
|
||||
public void WriteLicense(BindStreamWriter sw, string license)
|
||||
public void WriteLicense(BindStreamWriter sw)
|
||||
{
|
||||
sw.WriteLine(Resources.License);
|
||||
sw.WriteLine(File.ReadAllText(Path.Combine(Settings.InputPath, Settings.LicenseFile)));
|
||||
sw.WriteLine();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,6 @@ namespace Bind
|
|||
void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes);
|
||||
void WriteEnums(BindStreamWriter sw, EnumCollection enums);
|
||||
void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes);
|
||||
void WriteLicense(BindStreamWriter sw, string license);
|
||||
void WriteLicense(BindStreamWriter sw);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,19 @@ namespace Bind
|
|||
// Disable BeforeFieldInit.
|
||||
static Settings() { }
|
||||
|
||||
public const string DefaultInputPath = "..\\..\\..\\Source\\Bind\\Specifications";
|
||||
public const string DefaultOutputPath = "..\\..\\..\\Source\\OpenTK\\OpenGL\\Bindings";
|
||||
public const string DefaultInputPath = "../../../Source/Bind/Specifications";
|
||||
public const string DefaultOutputPath = "../../../Source/OpenTK/OpenGL/Bindings";
|
||||
public const string DefaultOutputNamespace = "OpenTK.Graphics";
|
||||
public static string DefaultDocPath = "..\\..\\..\\Source\\Bind\\Specifications\\Docs";
|
||||
public static string DefaultDocFile = "ToInlineDocs.xslt";
|
||||
public const string DefaultDocPath = "../../../Source/Bind/Specifications/Docs";
|
||||
public const string DefaultDocFile = "ToInlineDocs.xslt";
|
||||
public const string DefaultLicenseFile = "License.txt";
|
||||
|
||||
public static string InputPath = DefaultInputPath;
|
||||
public static string OutputPath = DefaultOutputPath;
|
||||
public static string OutputNamespace = DefaultOutputNamespace;
|
||||
public static string DocPath = DefaultDocPath;
|
||||
public static string DocFile = DefaultDocFile;
|
||||
public static string LicenseFile = DefaultLicenseFile;
|
||||
|
||||
public static string GLClass = "GL"; // Needed by Glu for the AuxEnumsClass. Can be set through -gl:"xxx".
|
||||
public static string OutputClass = "GL"; // The real output class. Can be set through -class:"xxx".
|
||||
|
|
|
@ -13,22 +13,22 @@
|
|||
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
||||
|
||||
<xsl:template name ="summary" match="refentry">
|
||||
/// <summary>
|
||||
/// <xsl:value-of select="concat(translate(
|
||||
/// <summary>
|
||||
/// <xsl:value-of select="concat(translate(
|
||||
substring(refnamediv/refpurpose, 1, 1), $lowercase, $uppercase),
|
||||
substring(refnamediv/refpurpose, 2, string-length(refnamediv/refpurpose) - 1))"/>
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
|
||||
<xsl:for-each select="refsect1/variablelist/varlistentry">
|
||||
<xsl:choose>
|
||||
<xsl:when test="../../@id = 'parameters'">
|
||||
/// <param name="{term/parameter}">
|
||||
/// <param name="{term/parameter}">
|
||||
<xsl:for-each select="listitem/para">
|
||||
/// <para>
|
||||
/// <xsl:value-of select="normalize-space(.)"/>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <xsl:value-of select="normalize-space(.)"/>
|
||||
/// </para>
|
||||
</xsl:for-each>
|
||||
/// </param>
|
||||
/// </param>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
|
|
26
Source/Bind/Specifications/License.txt
Normal file
26
Source/Bind/Specifications/License.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
|
@ -76,7 +76,10 @@ namespace Bind
|
|||
|
||||
internal static StreamReader OpenSpecFile(string folder, string file)
|
||||
{
|
||||
Console.WriteLine(folder);
|
||||
Console.WriteLine(file);
|
||||
string path = Path.Combine(folder, file);
|
||||
Console.WriteLine(path);
|
||||
return new StreamReader(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ namespace Bind.Wgl
|
|||
public Generator()
|
||||
: base()
|
||||
{
|
||||
glTypemap = "Wgl\\wgl.tm";
|
||||
glTypemap = "Wgl/wgl.tm";
|
||||
csTypemap = "csharp.tm";
|
||||
enumSpec = "Wgl\\wglenum.spec";
|
||||
enumSpecExt = "Wgl\\wglenumext.spec";
|
||||
glSpec = "Wgl\\wgl.spec";
|
||||
glSpecExt = "Wgl\\wglext.spec";
|
||||
enumSpec = "Wgl/wglenum.spec";
|
||||
enumSpecExt = "Wgl/wglenumext.spec";
|
||||
glSpec = "Wgl/wgl.spec";
|
||||
glSpecExt = "Wgl/wglext.spec";
|
||||
|
||||
importsFile = "WglCore.cs";
|
||||
delegatesFile = "WglDelegates.cs";
|
||||
|
|
Loading…
Reference in a new issue