soc.2009.penguin.visualstudio: 1bb16d5b: ========================================...

wade at soc.pidgin.im wade at soc.pidgin.im
Thu Jun 25 11:20:33 EDT 2009


-----------------------------------------------------------------
Revision: 1bb16d5b8cb6dd66fb84a1ef592124eccf83ec49
Ancestor: d67100357ff7bd33d18402600550bef7624fea1d
Author: wade at soc.pidgin.im
Date: 2009-06-25T15:15:39
Branch: im.pidgin.soc.2009.penguin.visualstudio
URL: http://d.pidgin.im/viewmtn/revision/info/1bb16d5b8cb6dd66fb84a1ef592124eccf83ec49

Added files:
        libpurple/wrapper/generator/CArgument.cs
        libpurple/wrapper/generator/CEnum.cs
        libpurple/wrapper/generator/CFile.cs
        libpurple/wrapper/generator/CFunction.cs
        libpurple/wrapper/generator/CStruct.cs
        libpurple/wrapper/generator/CTyped.cs
        libpurple/wrapper/generator/Program.cs
        libpurple/wrapper/generator/WrapperGenerator.cs
Added directories:
        libpurple/wrapper/generator

ChangeLog: 



-------------- next part --------------
============================================================
--- libpurple/wrapper/generator/CArgument.cs	30f31b9dd20af4c989a22b566d1189d118eff3c0
+++ libpurple/wrapper/generator/CArgument.cs	30f31b9dd20af4c989a22b566d1189d118eff3c0
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+
+namespace Scripts
+{
+    class CArgument : CTyped
+    {
+        private String name;
+        public bool isEllipsis = false;
+        public bool isFunctionPointer = false;
+        public List<CArgument> functionPointerArguments = new List<CArgument>();
+
+        public CArgument()
+        {
+        }
+
+        public CArgument(String type, String name)
+        {
+            this.Type = type;
+            this.name = name;
+        }
+
+        public String Name
+        {
+            get { return name; }
+            set { name = value; }
+        }
+
+        public bool IsEllipsis
+        {
+            get { return isEllipsis; }
+            set { isEllipsis = value; }
+        }
+
+        public bool IsFunctionPointer
+        {
+            get { return isFunctionPointer; }
+            set { isFunctionPointer = value; }
+        }
+
+        public List<CArgument> FunctionPointerArguments
+        {
+            get { return functionPointerArguments; }
+        }
+
+        public void AddFunctionPointerArgument(CArgument argument)
+        {
+            functionPointerArguments.Add(argument);
+        }
+
+        public override string ToString()
+        {
+            if (this.IsEllipsis)
+                return "...";
+            else if (this.IsFunctionPointer)
+            {
+                String str = this.Type + " (*" + this.Name + ")(";
+
+                for (int i = 0; i < this.FunctionPointerArguments.Count; i++)
+                {
+                    if (i != 0)
+                        str += ", ";
+
+                    str += this.FunctionPointerArguments[i].ToString();
+                }
+                str += ")";
+
+                return str;
+            }
+            else
+                return this.Type + " " + this.Name;
+        }
+
+        public string GetCSharpPrivateFunction()
+        {
+            if (this.IsEllipsis)
+                return "...";
+            else
+                return this.CSharpPrivateType + " " + this.Name;
+        }
+
+        public string GetCSharpPublicFunction()
+        {
+            if (this.IsEllipsis)
+                return "...";
+            else
+            {
+                return this.CSharpPublicType + " " + this.Name;
+            }
+        }
+    }
+}
============================================================
--- libpurple/wrapper/generator/CEnum.cs	9048e38a96ce92f4868ccb7c1c3f955c1031e129
+++ libpurple/wrapper/generator/CEnum.cs	9048e38a96ce92f4868ccb7c1c3f955c1031e129
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Scripts
+{
+    class CEnum
+    {
+    }
+}
============================================================
--- libpurple/wrapper/generator/CFile.cs	1fc931786a135ac4887cd0dfa0c5eb5576c60838
+++ libpurple/wrapper/generator/CFile.cs	1fc931786a135ac4887cd0dfa0c5eb5576c60838
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Scripts
+{
+    class CFile
+    {
+        private String fileName;
+        private List<CStruct> structs = new List<CStruct>();
+        private List<CFunction> functions = new List<CFunction>();
+
+        public CFile(String fileName)
+        {
+            this.fileName = fileName;
+        }
+
+        public String FileName
+        {
+            get { return fileName; }
+            set { fileName = value; }
+        }
+
+        public String FileNameAsClassName
+        {
+            get
+            {
+                String name;
+                if (this.FileName.Contains("."))
+                    name = this.FileName.Substring(0, this.FileName.IndexOf("."));
+                else
+                    name = this.FileName;
+                name = name.ToLower();
+
+
+                String finalName = "";
+                finalName += Char.ToUpper(name[0]);
+
+                for (int i = 1; i < name.Length; i++)
+                {
+                    if ( (name[i] == '_' || name[i] == '-') && i != name.Length - 1)
+                    {
+                        finalName += Char.ToUpper(name[i + 1]);
+                        i++;
+                    }
+                    else
+                        finalName += name[i];
+                }
+
+                return finalName;
+            }
+        }
+
+        public List<CStruct> Structs
+        {
+            get { return structs; }
+        }
+
+        public List<CFunction> Functions
+        {
+            get { return functions; }
+        }
+
+        public void addStruct(CStruct structToAdd)
+        {
+            structs.Add(structToAdd);
+        }
+
+        public void addFunction(CFunction function)
+        {
+            functions.Add(function);
+        }
+    }
+}
============================================================
--- libpurple/wrapper/generator/CFunction.cs	bfc9611e35852d6b8281d8c3cc91a795456dff21
+++ libpurple/wrapper/generator/CFunction.cs	bfc9611e35852d6b8281d8c3cc91a795456dff21
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+
+namespace Scripts
+{
+    class CFunction : CTyped
+    {
+        private String name;
+        private List<CArgument> arguments = new List<CArgument>();
+
+        public CFunction(String returnType, String name)
+        {
+            this.name = name;
+            this.Type = returnType;
+        }
+
+        public String Name
+        {
+            get { return name; }
+            set { name = value; }
+        }
+
+
+
+
+        public void AddArgument(CArgument argument)
+        {
+            arguments.Add(argument);
+        }
+
+        public List<CArgument> Arguments
+        {
+            get
+            {
+                return arguments;
+            }
+        }
+
+        public override string ToString()
+        {
+            String str = this.Type + " " + this.Name + "(";
+
+            for (int i = 0; i < this.Arguments.Count; i++)
+            {
+                if (i != 0)
+                    str += ", ";
+                
+                str += this.Arguments[i].ToString();
+            }
+
+            str += ")";
+            return str;
+        }
+
+        public string GetCSharpPrivateFunction()
+        {
+            String str = "";
+            str += this.CSharpPrivateType + " " + this.Name + "(";
+
+            for (int i = 0; i < this.Arguments.Count; i++)
+            {
+                if (i != 0)
+                    str += ", ";
+
+                str += this.Arguments[i].GetCSharpPrivateFunction();
+            }
+
+            str += ")";
+            return str;
+        }
+
+        public string GetCSharpPublicFunction(String className)
+        {
+            String str = "";
+
+            String modifiedName = this.Name.ToLower();
+            if (modifiedName.StartsWith("purple_"))
+                modifiedName = modifiedName.Substring(7);
+            if (modifiedName.StartsWith(className.ToLower() + "_"))
+                modifiedName = modifiedName.Substring(className.Length + 1);
+
+            String finalName = "";
+            finalName += Char.ToUpper(modifiedName[0]);
+            for (int i = 1; i < modifiedName.Length; i++)
+            {
+                if (modifiedName[i] == '_' && i != modifiedName.Length - 1)
+                {
+                    finalName += Char.ToUpper(modifiedName[i + 1]);
+                    i++;
+                }
+                else
+                {
+                    finalName += modifiedName[i];
+                }
+            }
+
+
+
+            str += this.CSharpPublicType + " " + finalName + "(";
+
+            for (int i = 0; i < this.Arguments.Count; i++)
+            {
+                if (i != 0)
+                    str += ", ";
+
+                str += this.Arguments[i].GetCSharpPublicFunction();
+            }
+
+            str += ")";
+            return str;
+        }
+    }
+}
============================================================
--- libpurple/wrapper/generator/CStruct.cs	9ae6da17259101affc79f2c3a54eb82ebb8f525d
+++ libpurple/wrapper/generator/CStruct.cs	9ae6da17259101affc79f2c3a54eb82ebb8f525d
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+
+namespace Scripts
+{
+    class CStruct
+    {
+        private String name;
+        private List<CArgument> fields = new List<CArgument>();
+
+        public CStruct(String name)
+        {
+            this.name = name;
+        }
+
+        public String Name
+        {
+            get { return name; }
+            set { name = value; }
+        }
+
+        public List<CArgument> Fields
+        {
+            get { return fields; }
+        }
+
+        public void AddField(CArgument argument)
+        {
+            fields.Add(argument);
+        }
+
+        public override string ToString()
+        {
+            String str = "struct " + this.Name + " { ";
+
+            foreach (CArgument argument in this.Fields)
+                str += argument.ToString() + "; ";
+
+            str += "};";
+
+            return str;
+        }
+    }
+}
============================================================
--- libpurple/wrapper/generator/CTyped.cs	24695cf8982ac835c63776e355cc6f87f15225e1
+++ libpurple/wrapper/generator/CTyped.cs	24695cf8982ac835c63776e355cc6f87f15225e1
@@ -0,0 +1,175 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Scripts
+{
+    class CTyped
+    {
+        private string type;
+
+        public String Type
+        {
+            get { return type; }
+            set { type = value; }
+        }
+
+        public String RawType
+        {
+            get
+            {
+                if (this.Type.Contains(" "))
+                    return this.Type.Substring(0, type.IndexOf(" "));
+                else
+                    return this.Type;
+            }
+        }
+
+        public bool IsTypePointer
+        {
+            get
+            {
+                if (this.Type != null && (this.Type.EndsWith("*") || this.Type == "gpointer"))
+                    return true;
+                else
+                    return false;
+            }
+        }
+
+        public bool IsTypeString
+        {
+            get
+            {
+                if (this.NativeType == "string")
+                    return true;
+                else
+                    return false;
+            }
+        }
+
+        public bool IsTypeNative
+        {
+            get
+            {
+                if (this.NativeType == null)
+                    return false;
+                else
+                    return true;
+            }
+        }
+
+        public bool IsTypeVoid
+        {
+            get
+            {
+                if (this.Type == "void")
+                    return true;
+                else
+                    return false;
+            }
+        }
+
+        public String CSharpPrivateType
+        {
+            get
+            {
+                String str = "";
+
+                if (this.IsTypeNative)
+                    str += this.NativeType;
+                else if (this.IsTypePointer)
+                    str += "IntPtr";
+                else if (this.IsTypeVoid)
+                    str += "void";
+                else
+                    str += "UNKNOWN";
+
+                return str;
+            }
+        }
+
+        public String CSharpPublicType
+        {
+            get
+            {
+                String str = "";
+
+                if (this.IsTypeNative)
+                    str += this.NativeType;
+                else if (this.Type == "void *" || this.Type == "gpointer")
+                    str += "IntPtr";
+                else
+                    str += this.RawType;
+
+                return str;
+            }
+        }
+
+        public String NativeType
+        {
+            get
+            {
+                switch (this.Type)
+                {
+                    case "gboolean":
+                        return "bool";
+
+                    case "gchar":
+                    case "char":
+                    case "int8":
+                        return "char";
+
+                    case "uint8":
+                    case "unsigned char":
+                        return "byte";
+
+                    case "gchar *":
+                    case "char *":
+                        return "string";
+
+                    case "gint":
+                    case "int":
+                    case "gint32":
+                        return "int";
+
+                    case "guint":
+                    case "unsigned int":
+                    case "guint32":
+                        return "uint";
+
+                    case "gshort":
+                    case "short":
+                    case "gint16":
+                        return "short";
+
+                    case "gushort":
+                    case "unsigned short":
+                    case "guint16":
+                        return "ushort";
+
+                    case "glong":
+                    case "long":
+                    case "gint64":
+                        return "long";
+
+                    case "gulong":
+                    case "unsigned long":
+                    case "guint64":
+                        return "ulong";
+
+                    case "gfloat":
+                    case "float":
+                        return "float";
+
+                    case "gdouble":
+                    case "double":
+                        return "double";
+                }
+
+                return null;
+            }
+        }
+
+    }
+}
============================================================
--- libpurple/wrapper/generator/Program.cs	805ab943d4786b1c4380d8e8d8e025cfed29b282
+++ libpurple/wrapper/generator/Program.cs	805ab943d4786b1c4380d8e8d8e025cfed29b282
@@ -0,0 +1,21 @@
+using System;
+
+namespace Scripts
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            WrapperGenerator wrapperGen = new WrapperGenerator();
+
+            Console.WriteLine("Parsing .h files...");
+            wrapperGen.ParseHFilesInDirectory(@"C:\Users\Wade\Desktop\fullOA\OABuild\libpurple");
+
+            Console.WriteLine("Writing struct data...");
+            wrapperGen.GenerateStructFiles();
+
+            Console.WriteLine("Writing function data...");
+            wrapperGen.GenerateFunctionWrappers();
+        }
+    }
+}
============================================================
--- libpurple/wrapper/generator/WrapperGenerator.cs	77ace5e9a3c915964add3db40edf462ba15888e9
+++ libpurple/wrapper/generator/WrapperGenerator.cs	77ace5e9a3c915964add3db40edf462ba15888e9
@@ -0,0 +1,324 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text.RegularExpressions;
+
+namespace Scripts
+{
+    class WrapperGenerator
+    {
+        private List<CFile> files = new List<CFile>();
+        private String path = @"C:\Users\Wade\Desktop\gen-test\";
+
+        public void ParseHFilesInDirectory(String path)
+        {
+            DirectoryInfo directionryInfo = new DirectoryInfo(path);
+            FileInfo[] fileInfos = directionryInfo.GetFiles("*.h");
+
+            
+            Regex structRegex = new Regex(@"struct \s+ (?<StructName>\w+?) \s* \{ (?<StructInternal>.*?) \} \s* ;", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
+            Regex structInternalRegex = new Regex(@"(?<VariableType> ( \w+ \s+ [\*]+ ) | ( \w+ \s+) )" +
+                                                  @"(  ( \( \* (?<Name> \w+ ) \) \s* \( (?<FunctionPointerArguments> .*?) \) )" +
+                                                  @"    |  (?<Name> .*? ) ) ;", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
+
+            Regex functionRegEx = new Regex(@"(?<ReturnType> ( \w+ \s+ [\*]+ ) | ( \w+ \s+)  ) (?<Name>\w+?) \s* \( (?<ParameterList> [^\)]*) \)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
+            Regex functionArgumentsRegEx = new Regex(@"(?<VariableType> ( \w+ \s+ [\*]+ ) | ( \w+ \s+)  ) (?<VariableName>\w+)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
+
+            Regex commentRegex = new Regex(@"(?<Comment> /\* .*? \*/)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
+
+            foreach (FileInfo fileInfo in fileInfos)
+            {
+                if (fileInfo.Name == "internal.h" || fileInfo.Name == "dbus.h" || fileInfo.Name == "dbus-bindings.h" ||
+                    fileInfo.Name == "dbus-maybe.h" || fileInfo.Name == "dbus-define-api.h" || fileInfo.Name == "dbus-purple.h" ||
+                    fileInfo.Name == "dbus-server.h" || fileInfo.Name == "dbus-useful.h" || fileInfo.Name == "gaim-compat.h" ||
+                    fileInfo.Name == "media-gst.h")
+                    continue;
+
+
+                StreamReader reader = new StreamReader(fileInfo.FullName);
+                String fullFile = reader.ReadToEnd();
+                reader.Close();
+
+
+                CFile currentFile = new CFile(fileInfo.Name);
+
+                foreach (Match commentMatch in commentRegex.Matches(fullFile))
+                {
+                    fullFile = fullFile.Remove(
+                        fullFile.IndexOf(commentMatch.Groups["Comment"].Value),
+                        commentMatch.Groups["Comment"].Length);
+                }
+
+                foreach (Match match in structRegex.Matches(fullFile))
+                {
+                    CStruct structObject = new CStruct(match.Groups["StructName"].Value);
+                    if (structObject.Name.Length > 0 && structObject.Name[0] == '_')
+                        structObject.Name = structObject.Name.Substring(1);
+
+                    String internalStructData = match.Groups["StructInternal"].Value;
+
+                    if (internalStructData != null)
+                    {
+                        foreach (Match internalStructMatch in structInternalRegex.Matches(internalStructData))
+                        {
+                            string elementType = internalStructMatch.Groups["VariableType"].Value.Trim();
+                            string name = internalStructMatch.Groups["Name"].Value;
+
+                            CArgument argument = new CArgument(elementType, name);
+
+                            string functionPointerArguments = internalStructMatch.Groups["FunctionPointerArguments"].Value;
+                            if (functionPointerArguments != "")
+                            {
+                                argument.IsFunctionPointer = true;
+
+                                String[] functionPointerArgumentsList = functionPointerArguments.Split(',');
+                                foreach (String functionPointerArgument in functionPointerArgumentsList)
+                                {
+                                    String currentArgument = functionPointerArgument.Replace("const ", "").Trim();
+
+                                    CArgument functionPointerArgumentObject = new CArgument();
+                                    if (currentArgument == "void")
+                                        continue;
+                                    else
+                                    {
+                                        Match parameterMatch = functionArgumentsRegEx.Match(currentArgument);
+                                        functionPointerArgumentObject.Type = parameterMatch.Groups["VariableType"].Value.Trim();
+                                        functionPointerArgumentObject.Name = parameterMatch.Groups["VariableName"].Value;
+                                    }
+
+                                    argument.AddFunctionPointerArgument(functionPointerArgumentObject);
+                                }
+                            }
+
+                            structObject.AddField(argument);
+                        }
+                    }
+
+                    //Console.WriteLine(structObject.ToString());
+                    currentFile.addStruct(structObject);
+                }
+
+                foreach (Match match in functionRegEx.Matches(fullFile))
+                {
+                    String functionReturnType = match.Groups["ReturnType"].Value.Trim();
+                    String functionName = match.Groups["Name"].Value;
+                    String parameterList = match.Groups["ParameterList"].Value;
+
+                    if (functionReturnType == "typedef" || functionReturnType == "define")
+                        continue;
+
+
+                    CFunction function = new CFunction(functionReturnType, functionName);
+
+                    String[] functionParameters = parameterList.Split(',');
+                    foreach (String functionParameterInList in functionParameters)
+                    {
+                        String functionParameter = functionParameterInList.Replace("const ", "").Trim();
+
+                        CArgument argument = new CArgument();
+                        if (functionParameter == "...")
+                        {
+                            argument.IsEllipsis = true;
+                        }
+                        else if (functionParameter == "void")
+                            continue;
+                        else
+                        {
+                            Match parameterMatch = functionArgumentsRegEx.Match(functionParameter);
+                            argument.Type = parameterMatch.Groups["VariableType"].Value.Trim();
+                            argument.Name = parameterMatch.Groups["VariableName"].Value;
+                        }
+
+                        function.AddArgument(argument);
+                    }
+
+                    currentFile.addFunction(function);
+                    //Console.WriteLine(function.ToString());
+                    //Console.WriteLine(function.GetCSharpPrivateFunction());
+                    //Console.WriteLine(function.GetCSharpPublicFunction());
+                    //Console.WriteLine();
+                }
+
+                files.Add(currentFile);
+            }
+        }
+
+        private void WriteCommentHeader(StreamWriter writer)
+        {
+            writer.WriteLine("/* purple");
+            writer.WriteLine(" *");
+            writer.WriteLine(" * Purple is the legal property of its developers, whose names are too numerous");
+            writer.WriteLine(" * to list here.  Please refer to the COPYRIGHT file distributed with this");
+            writer.WriteLine(" * source distribution.");
+            writer.WriteLine(" *");
+            writer.WriteLine(" * This program is free software; you can redistribute it and/or modify");
+            writer.WriteLine(" * it under the terms of the GNU General Public License as published by");
+            writer.WriteLine(" * the Free Software Foundation; either version 2 of the License, or");
+            writer.WriteLine(" * (at your option) any later version.");
+            writer.WriteLine(" *");
+            writer.WriteLine(" * This program is distributed in the hope that it will be useful,");
+            writer.WriteLine(" * but WITHOUT ANY WARRANTY; without even the implied warranty of");
+            writer.WriteLine(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the");
+            writer.WriteLine(" * GNU General Public License for more details.");
+            writer.WriteLine(" *");
+            writer.WriteLine(" * You should have received a copy of the GNU General Public License");
+            writer.WriteLine(" * along with this program; if not, write to the Free Software");
+            writer.WriteLine(" * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA");
+            writer.WriteLine(" */");
+            writer.WriteLine();
+            writer.WriteLine("/*");
+            writer.WriteLine(" * This file was auto-generated from the libpurple header files to provide a");
+            writer.WriteLine(" * clean interface between .NET/CLR and the unmanaged C library, libpurple.");
+            writer.WriteLine(" *");
+            writer.WriteLine(" * This code isn't complete, but completely a work in progress. :)");
+            writer.WriteLine(" * Three major things left:");
+            writer.WriteLine(" *  - Resolve the remaining UNKNOWN types.");
+            writer.WriteLine(" *  - Handle translation between delegate and function pointers.");
+            writer.WriteLine(" *  - Fill in the translation between public .NET class calls and private DllImport[] calls.");
+            writer.WriteLine(" */");
+            writer.WriteLine();
+
+
+
+        }
+
+        public void GenerateStructFiles()
+        {
+            StreamWriter writer;
+            foreach (CFile file in files)
+            {
+                foreach (CStruct structure in file.Structs)
+                {
+                    writer = new StreamWriter(path + structure.Name + ".cs");
+                    WriteCommentHeader(writer);
+
+                    writer.WriteLine("using System;");
+                    writer.WriteLine("using System.Collections.Generic;");
+                    writer.WriteLine("using System.Runtime.InteropServices;");
+                    writer.WriteLine();
+                    writer.WriteLine("namespace PurpleWrapper");
+                    writer.WriteLine("{");
+                    writer.WriteLine("\tpublic class " + structure.Name + " : UnmanagedWrapper<_" + structure.Name + ">");
+                    writer.WriteLine("\t{");
+
+                    writer.WriteLine("\t\tpublic " + structure.Name + "()");
+                    writer.WriteLine("\t\t{");
+                    writer.WriteLine("\t\t}");
+                    writer.WriteLine();
+
+                    writer.WriteLine("\t\tpublic " + structure.Name + "(IntPtr refernece)");
+                    writer.WriteLine("\t\t{");
+                    writer.WriteLine("\t\t\tthis.Reference = reference;");
+                    writer.WriteLine("\t\t\tthis.Data = (_" + structure.Name + ")Marshal.PtrToStructure(this.Reference, typeof(_" + structure.Name + "));");
+                    writer.WriteLine("\t\t}");
+                    writer.WriteLine();
+
+
+
+                    foreach (CArgument argument in structure.Fields)
+                    {
+                        writer.WriteLine("\t\tpublic " + argument.GetCSharpPublicFunction());
+                        writer.WriteLine("\t\t{");
+
+
+                        /* get */
+                        writer.WriteLine("\t\t\tget");
+                        writer.WriteLine("\t\t\t{");
+                        if (argument.IsTypeNative)
+                            writer.WriteLine("\t\t\t\treturn this.Data." + argument.Name + ";");
+                        else
+                            writer.WriteLine("\t\t\t\tthrow new NotImplementedException(); /* Non-native type. */");
+                        writer.WriteLine("\t\t\t}");
+
+
+                        /* set */
+                        writer.WriteLine("\t\t\tset");
+                        writer.WriteLine("\t\t\t{");
+                        writer.WriteLine("\t\t\t\tif (this.Reference != IntPtr.Zero)");
+                        writer.WriteLine("\t\t\t\t\tthis.Reference = IntPtr.Zero;");
+                        writer.WriteLine();
+
+                        if (argument.IsTypeNative)
+                            writer.WriteLine("\t\t\t\tthis.Data." + argument.Name + " = value;");
+                        else
+                            writer.WriteLine("\t\t\t\tthrow new NotImplementedException(); /* Non-native type. */");
+
+                        writer.WriteLine("\t\t\t}");
+                        writer.WriteLine("\t\t}");
+                        writer.WriteLine();
+                    }
+
+                    writer.WriteLine("\t}");
+                    writer.WriteLine();
+                    writer.WriteLine();
+
+
+                    writer.WriteLine("\t[StructLayout(LayoutKind.Sequential)]");
+                    writer.WriteLine("\tclass _" + structure.Name);
+                    writer.WriteLine("\t{");
+
+                    foreach (CArgument argument in structure.Fields)
+                    {
+                        writer.WriteLine("\t\t/*");
+                        writer.WriteLine("\t\t * " + argument.ToString());
+                        writer.WriteLine("\t\t */");
+                        writer.WriteLine("\t\t" + argument.GetCSharpPrivateFunction() + ";");
+                        writer.WriteLine();
+                    }
+
+                    writer.WriteLine("\t}");
+
+
+                    writer.WriteLine("}");
+                    writer.WriteLine();
+
+                    writer.Close();
+
+
+                }
+
+            }
+
+        }
+
+        public void GenerateFunctionWrappers()
+        {
+            foreach (CFile file in files)
+            {
+                StreamWriter writer = new StreamWriter(path + file.FileNameAsClassName + ".cs");
+                WriteCommentHeader(writer);
+
+                writer.WriteLine("using System;");
+                writer.WriteLine("using System.Collections.Generic;");
+                writer.WriteLine("using System.Runtime.InteropServices;");
+                writer.WriteLine();
+                writer.WriteLine("namespace PurpleWrapper");
+                writer.WriteLine("{");
+
+                writer.WriteLine("\tpublic class " + file.FileNameAsClassName);
+                writer.WriteLine("\t{");
+
+                foreach (CFunction function in file.Functions)
+                {
+                    writer.WriteLine("\t\t/*");
+                    writer.WriteLine("\t\t * " + function.ToString());
+                    writer.WriteLine("\t\t */");
+                    writer.WriteLine("\t\t[DllImport(\"libpurple.dll\")]");
+                    writer.WriteLine("\t\tprivate static extern " + function.GetCSharpPrivateFunction() + ";");
+                    writer.WriteLine();
+                    writer.WriteLine("\t\tpublic static " + function.GetCSharpPublicFunction(file.FileNameAsClassName));
+                    writer.WriteLine("\t\t{");
+                    writer.WriteLine("\t\t\tthrow new NotImplementedException();");
+                    writer.WriteLine("\t\t}");
+                    writer.WriteLine();
+                }
+
+                writer.WriteLine("\t}");
+                writer.WriteLine("}");
+                writer.WriteLine();
+
+                writer.Close();
+            }
+        }
+    }
+}


More information about the Commits mailing list