From 01ec64945c4325ec88e1fffeec4764da8209f3c0 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Tue, 23 Oct 2018 22:11:38 +0100 Subject: [PATCH] Removed generator - Too many edge cases to handle. --- Generator/App.config | 6 - Generator/Generator.cs | 193 --------------------------- Generator/Generator.csproj | 99 -------------- Generator/Program.cs | 60 --------- Generator/Properties/AssemblyInfo.cs | 36 ----- Generator/raylib-cs.ico | Bin 142667 -> 0 bytes 6 files changed, 394 deletions(-) delete mode 100644 Generator/App.config delete mode 100644 Generator/Generator.cs delete mode 100644 Generator/Generator.csproj delete mode 100644 Generator/Program.cs delete mode 100644 Generator/Properties/AssemblyInfo.cs delete mode 100644 Generator/raylib-cs.ico diff --git a/Generator/App.config b/Generator/App.config deleted file mode 100644 index 731f6de..0000000 --- a/Generator/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Generator/Generator.cs b/Generator/Generator.cs deleted file mode 100644 index 4a5893b..0000000 --- a/Generator/Generator.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Text.RegularExpressions; - -namespace Generator -{ - static class Generator - { - public static string RaylibDirectory = "C:\\raylib\\raylib\\"; - public static string RaylibDirectory2 = "C:\\Users\\Chris\\Documents\\projects\\raylib\\"; - - // string extensions - private static string CapitalizeFirstCharacter(string format) - { - if (string.IsNullOrEmpty(format)) - return string.Empty; - else - return char.ToUpper(format[0]) + format.ToLower().Substring(1); - } - - public static string Indent(this string value, int size) - { - var strArray = value.Split('\n'); - var sb = new StringBuilder(); - foreach (var s in strArray) - sb.Append(new string(' ', size)).Append(s); - return sb.ToString(); - } - - // testing regex - public static string ReplaceEx(this string input, string pattern, string replacement) - { - var matches = Regex.Matches(input, pattern); - foreach (Match match in matches) - { - //Console.WriteLine(match.Value); - } - return Regex.Replace(input, pattern, replacement); - } - - // Create binding code - public static void Process(string filePath, string api) - { - var lines = File.ReadAllLines(RaylibDirectory + "src//" + filePath); - var output = ""; - - output += "using Raylib;\n"; - output += "using static Raylib.Raylib;\n\n"; - output += "public partial class Examples\n{\n"; - - // convert functions to c# - foreach (string line in lines) - { - if (line.StartsWith(api)) - { - output += "\t\t[DllImport(nativeLibName)]\n"; - string newLine = line.Clone().ToString(); - newLine = newLine.Replace(api, "public static extern"); - - // add converted function - output += "\t\t" + newLine + "\n\n"; - } - } - output += "\t\t#endregion\n"; - - //output += text; - output += "\n}"; - - output = output.Replace("(void)", "()"); - output = output.Replace("const char *", "string "); - output = output.Replace("const char * ", "string"); - output = output.Replace("const char*", "string"); - output = output.Replace("unsigned int", "uint"); - output = output.Replace("unsigned char", "byte"); - output = output.Replace("const void *", "byte[] "); - output = output.Replace("const float *", "float[] "); - output = output.Replace("const int *", "int[] "); - output = output.Replace("...", "params object[] args"); - output = output.Replace("Music ", "IntPtr "); - - Console.WriteLine(output); - - filePath = Path.GetFileNameWithoutExtension(filePath); - filePath = CapitalizeFirstCharacter(filePath); - - Directory.CreateDirectory("Raylib-cs"); - File.WriteAllText("Raylib-cs/ " + filePath + ".cs", output); - } - - // Convert c style to c# - // Design is close to raylib so only a few changes needed - public static void ProcessExample(string file, string folder, string path) - { - // load and setup - var fileName = Path.GetFileNameWithoutExtension(file); - var text = File.ReadAllText(file); - var result = ""; - var output = ""; - output += "using Raylib;\n"; - output += "using static Raylib.Raylib;\n\n"; - output += "public partial class " + folder + "\n{\n"; - // text = text.Replace("\r", "\r\n"); - - // rough file conversion - string[] lines = text.Split('\n'); - for (int i = 0; i < lines.Length; i++) - { - string line = lines[i]; - - // ignore certain preprocess symbols - if (line.Contains("#include")) - continue; - else if (line.Contains("#if")) - continue; - else if (line.Contains("#else")) - continue; - else if (line.Contains("#endif")) - continue; - - else if (line.Contains("#define")) - { - var str = line.Replace("#define", ""); - var arr = str.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - if (arr.Length < 2) - continue; - - bool isNumeric = int.TryParse(arr[1], out var n); - if (isNumeric) - result += "public const int " + arr[0] + " = " + arr[1] + ";\r\n"; - else - result += "public const string " + arr[0] + " = " + arr[1] + ";\r\n"; - } - - // change main signature - else if (line.StartsWith("int main")) - result += "public static void Main()\r\n"; - - // remove typedef and mark members as public - else if (line.StartsWith("typedef struct")) - { - var members = ""; - while (!line.StartsWith("}")) - { - i++; - line = lines[i]; - members += "public " + line + "\n"; - } - - line = line.Replace(" ", ""); - line = line.Replace("}", ""); - line = line.Replace(";", ""); - result += "struct " + line + "{\n\n"; - result += members; - } - - // copy line by default - else - result += line + "\n"; - } - - // regex - - // (Type){...} -> new Type(...) - // e.g (Vector2){ 100, 100 } -> new Vector2( 100, 100 ); - result = result.ReplaceEx(@"\((\w+)\){(.*)}", @"new $1($2);"); - result = result.ReplaceEx(@"\((\w+)\) \w+ = {(.*)}", @"new $1($2);"); - - // Type name[size] -> Type[] name = new Type[size]; - // e.g Rectangle buildings[MAX_BUILDINGS]; -> Rectangle[] buildings = new Rectangle[MAX_BUILDINGS]; - result = result.ReplaceEx(@"(\w+) (\w+)\[(.*)\];", "$1[] $2 = new $1[$3];"); - - result = result.Replace("Music ", "IntPtr "); - result = result.Replace("(void)", "()"); - - // defines to enums(might use defines as variables aswell not sure) - result = result.ReplaceEx(@"KEY_(\w+)", @"(int)Key.$1"); - result = result.ReplaceEx(@"MOUSE_(\w+)", @"(int)Mouse.$1"); - result = result.ReplaceEx(@"FLAG_(\w+)", @"(int)Flag.$1"); - // result = result.ReplaceEx(@"FLAG_(\w+)", @"(int)Flag.$1"); - - // add result - result = result.Indent(4); - output += result; - output += "\n}\n"; - - // saves relative to executable location - var loc = path + "//" + fileName + ".cs"; - File.WriteAllText(loc, output); - Console.WriteLine("Generated " + fileName + ".cs"); - } - } -} diff --git a/Generator/Generator.csproj b/Generator/Generator.csproj deleted file mode 100644 index 5f57c3f..0000000 --- a/Generator/Generator.csproj +++ /dev/null @@ -1,99 +0,0 @@ - - - - - Debug - AnyCPU - {063F21F1-12D3-41C6-B598-125C725955B1} - Exe - Generator - Generator - v4.6.1 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - raylib-cs.ico - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - true - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - true - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Generator/Program.cs b/Generator/Program.cs deleted file mode 100644 index b63f38a..0000000 --- a/Generator/Program.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.IO; - -namespace Generator -{ - /// - /// Rough generator for creating bindings and ports for raylib - /// Not a full parser so generated code is not perfect - /// - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Raylib-cs generator"); - GenerateBindings(); - // GeneratePort("Examples"); - // GeneratePort("Templates"); - // GeneratePort("Games"); - Console.WriteLine("Finished generating. Enjoy! :)"); - Console.WriteLine("Press enter to exit"); - Console.Read(); - } - - /// - /// Requires raylib headers - /// - static void GenerateBindings() - { - Console.WriteLine("Generating bindings"); - Generator.Process("raylib.h", "RLAPI"); - Generator.Process("raymath.h", "RMDEF"); - Generator.Process("physac.h", "PDEF"); - Generator.Process("rlgl.h", "RLGL"); - } - - /// - /// Porting C to C# - /// - static void GeneratePort(string folder) - { - Console.WriteLine("Generating examples"); - - // output folder - Directory.CreateDirectory(folder); - var path = Generator.RaylibDirectory + folder.ToLower(); - var dirs = Directory.GetDirectories(path); - - var files = Directory.GetFiles(path, "*.c", SearchOption.AllDirectories); - foreach (var file in files) - { - // create sub folder in output - var dirName = Path.GetDirectoryName(file); - var name = new DirectoryInfo(dirName).Name; - if (!Directory.Exists(folder + name)) - Directory.CreateDirectory(folder + "//" + name); - Generator.ProcessExample(file, folder, folder + "//" + name); - } - } - } -} diff --git a/Generator/Properties/AssemblyInfo.cs b/Generator/Properties/AssemblyInfo.cs deleted file mode 100644 index 171731b..0000000 --- a/Generator/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Generator")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Generator")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("063f21f1-12d3-41c6-b598-125c725955b1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Generator/raylib-cs.ico b/Generator/raylib-cs.ico deleted file mode 100644 index 296d5dd59c742944d814a44152a05b1d2a8018f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142667 zcmZQzU}WH600Bk@1%_Tu28K2U28Mba$WMGJvXJQZ#fbcU|7#JRF zFfnun___0PNpUeSFz|YMxCDV@L70P$fq@~WXhj+W0|R4mkh>GZx^prw85kH?(j9#r z85lP9bN@+XWnf_7EbxddW?QDIHuS+|R<*AKXaP7?h8^M3vRpW+qjtPJ|g7#G|IwG5FYipgl%J!);PWWV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