static void Process() { var parameters = new ConversionParameters { InputPath = @"stb_rect_pack.h", Defines = new string[] { "STB_RECT_PACK_IMPLEMENTATION" }, SkipStructs = new string[] { "stbrp_context" }, SkipGlobalVariables = new string[] { }, SkipFunctions = new string[] { }, Classes = new string[] { }, GlobalArrays = new string[] { } }; var cp = new ClangParser(); var result = cp.Process(parameters); // Write output var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace StbRectPackSharp\n{\n\t"); sb.AppendLine("unsafe partial class StbRectPack\n\t{"); Write(result.Constants, sb); Write(result.GlobalVariables, sb); Write(result.Enums, sb); Write(result.Structs, sb); Write(result.Methods, sb); sb.Append("}\n}"); var data = sb.ToString(); // Post processing Logger.Info("Post processing..."); data = PostProcess(data); File.WriteAllText(@"..\..\..\..\..\src\StbRectPack.Generated.cs", data); }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"nanovg\nansovg.c", Output = output, Defines = new string[0], Namespace = "NanoVGSharp", Class = "NanoSVG", SkipStructs = new string[0], SkipGlobalVariables = new string[0], SkipFunctions = new string[0], Classes = new string[] { }, GlobalArrays = new string[0] }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); File.WriteAllText(@"..\..\..\..\..\src\NanoSVG.Generated.cs", data); } }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_dxt.h", Output = output, Defines = new[] { "STB_DXT_IMPLEMENTATION" }, Namespace = "StbSharp", Class = "StbDxt", SkipStructs = new string[] { }, SkipGlobalVariables = new string[] { }, SkipFunctions = new[] { "stb__DitherBlock" }, Classes = new string[] { }, GlobalArrays = new[] { "stb__Expand5", "stb__Expand6", "stb__OMatch5", "stb__OMatch6", "stb__QuantRBTab", "stb__QuantGTab" } }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("byte* minp;", "byte* minp = null;"); data = data.Replace("byte* maxp;", "byte* maxp = null;"); data = data.Replace("public static void stb__PrepareOptTable(byte* Table, byte* expand, int size)", "public static void stb__PrepareOptTable(byte[] Table, byte[] expand, int size)"); File.WriteAllText(@"..\..\..\..\..\StbSharp\StbDxt.Generated.cs", data); } }
static void Process() { var parameters = new ConversionParameters { InputPath = @"stb_image.h", Defines = new[] { "STBI_NO_SIMD", "STBI_NO_PIC", "STBI_NO_PNM", "STBI_NO_STDIO", "STB_IMAGE_IMPLEMENTATION", }, Namespace = "StbImageSharp", Class = "StbImage", SkipStructs = new[] { "stbi_io_callbacks", "stbi__context", "img_comp", "stbi__jpeg", "stbi__resample", "stbi__gif_lzw", "stbi__gif" }, SkipGlobalVariables = new[] { "stbi__g_failure_reason", "stbi__vertically_flip_on_load" }, SkipFunctions = new[] { "stbi__malloc", "stbi_image_free", "stbi_failure_reason", "stbi__err", "stbi_is_hdr_from_memory", "stbi_is_hdr_from_callbacks", "stbi__pnm_isspace", "stbi__pnm_skip_whitespace", "stbi__pic_is4", "stbi__gif_parse_colortable", "stbi__start_mem", "stbi__start_callbacks", "stbi__rewind", "stbi_load_16_from_callbacks", "stbi_load_from_callbacks", "stbi__get8", "stbi__refill_buffer", "stbi__at_eof", "stbi__skip", "stbi__getn", "stbi_load_16_from_memory", "stbi_load_from_memory", "stbi_load_gif_from_memory", "stbi_info_from_memory", "stbi_info_from_callbacks", "stbi_is_16_bit_from_memory", "stbi_is_16_bit_from_callbacks", "stbi__hdr_test_core" }, Classes = new[] { "stbi_io_callbacks", "stbi__jpeg", "stbi__resample", "stbi__gif", "stbi__context", "stbi__huffman", "stbi__png" }, GlobalArrays = new[] { "stbi__bmask", "stbi__jbias", "stbi__jpeg_dezigzag", "stbi__zlength_base", "stbi__zlength_extra", "stbi__zdist_base", "stbi__zdist_extra", "first_row_filter", "stbi__depth_scale_table", "stbi__zdefault_length", "stbi__zdefault_distance", "length_dezigzag", "png_sig" } }; var cp = new ClangParser(); var result = cp.Process(parameters); // Post processing Logger.Info("Post processing..."); var outputFiles = new Dictionary <string, string>(); Write(result.Constants, outputFiles); Write(result.GlobalVariables, outputFiles); Write(result.Enums, outputFiles); Write(result.Structs, outputFiles); Write(result.Methods, outputFiles); foreach (var pair in outputFiles) { var data = PostProcess(pair.Value); var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace StbImageSharp\n{\n\t"); sb.AppendLine("unsafe partial class StbImage\n\t{"); data = sb.ToString() + data; data += "}\n}"; File.WriteAllText(@"..\..\..\..\..\src\StbImage.Generated." + pair.Key + ".cs", data); } }
static void Process() { var data = string.Empty; using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_truetype.h", Output = output, Defines = new[] { "STB_TRUETYPE_IMPLEMENTATION", }, Namespace = "StbSharpSafe", Class = "StbTrueType", SkipStructs = new string[] { "stbtt__hheap_chunk", "stbtt__hheap", }, SkipGlobalVariables = new string[] { }, SkipFunctions = new string[] { "stbtt__find_table", "stbtt_FreeShape", "stbtt__hheap_alloc", "stbtt__hheap_free", "stbtt__hheap_cleanup", }, Classes = new string[] { "stbtt__buf", "stbtt_pack_range", "stbtt_pack_context", "stbtt_fontinfo", "stbtt__bitmap", "stbtt__csctx", "stbtt__hheap_chunk", "stbtt__hheap", "stbtt__active_edge", "stbtt_vertex", "stbtt_fontinfo", }, GlobalArrays = new string[] { }, GenerateSafeCode = true, TreatStructFieldClassPointerAsArray = (structName, fieldName) => { if (fieldName == "pvertices") { return(true); } return(false); }, TreatFunctionArgClassPointerAsArray = (functionName, argName) => { if (argName == "num_points" || argName == "num_contours" || argName == "contour_lengths") { return(FunctionArgumentType.Ref); } if ((functionName == "stbtt_GetCodepointShape" || functionName == "stbtt_GetGlyphShape") && (argName == "vertices" || argName == "pvertices")) { return(FunctionArgumentType.Ref); } if (argName == "vertices" || argName == "pvertices" || argName == "verts" || argName == "ranges") { return(FunctionArgumentType.Pointer); } return(FunctionArgumentType.Default); }, TreatLocalVariableClassPointerAsArray = (functionName, localVarName) => { if (localVarName == "vertices" || localVarName == "verts" || localVarName == "comp_verts") { return(true); } if (functionName == "stbtt__GetGlyphShapeTT" && localVarName == "tmp") { return(true); } if (functionName == "stbtt__run_charstring" && localVarName == "subr_stack") { return(true); } return(false); } }; var cp = new ClangParser(); cp.Process(parameters); data = output.ToString(); } // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("(void *)(0)", "null"); data = data.Replace("stbtt_vertex* vertices = 0;", "stbtt_vertex* vertices = null;"); data = data.Replace("(flags & 16)?dx:-dx", "(flags & 16) != 0?dx:-dx"); data = data.Replace("(flags & 32)?dy:-dy", "(flags & 32) != 0?dy:-dy"); data = data.Replace("(vertices) == (0)", "vertices == null"); data = data.Replace("sizeof((vertices[0]))", "sizeof(stbtt_vertex)"); data = data.Replace("(int)(!(flags & 1))", "((flags & 1) != 0?0:1)"); data = data.Replace("vertices = 0;", "vertices = null;"); data = data.Replace("stbtt_vertex* comp_verts = 0;", "stbtt_vertex* comp_verts = null;"); data = data.Replace("stbtt_vertex* tmp = 0;", "stbtt_vertex* tmp = null;"); data = data.Replace(",)", ")"); data = data.Replace("+ +", "+"); data = data.Replace("(sizeof(stbtt__hheap_chunk) + size * count)", "((ulong)sizeof(stbtt__hheap_chunk)+ size * (ulong)(count))"); data = data.Replace("size * hh->num_remaining_in_head_chunk", "size * (ulong)hh->num_remaining_in_head_chunk"); data = data.Replace("sizeof((*z))", "sizeof(stbtt__active_edge)"); data = data.Replace("_next_ = 0;", "_next_ = null;"); data = data.Replace("sizeof((scanline[0]))", "sizeof(float)"); data = data.Replace("int c = (int)(((a)->y0) < ((b)->y0));", "int c = (int)(a->y0 < b->y0?1:0);"); data = data.Replace("sizeof((*e))", "sizeof(stbtt__edge)"); data = data.Replace("sizeof((**contour_lengths))", "sizeof(int)"); data = data.Replace("sizeof((points[0]))", "sizeof(stbtt__point)"); data = data.Replace("sizeof((*context))", "sizeof(stbrp_context)"); data = data.Replace("sizeof((*nodes))", "sizeof(stbrp_node)"); data = data.Replace("sizeof((*rects))", "sizeof(stbrp_rect)"); data = data.Replace("(int)(((a[0]) == (b[0])) && ((a[1]) == (b[1])));", "(int)(((a[0] == b[0]) && (a[1] == b[1]))?1:0);"); data = data.Replace("(int)(((a).Value.y0) < ((b).Value.y0));", "a.Value.y0 < b.Value.y0?1:0;"); data = data.Replace("CRuntime.malloc((ulong)(m * sizeof(stbtt_vertex)))", "FakePtr<stbtt_vertex>.CreateWithSize(m)"); data = data.Replace("CRuntime.malloc((ulong)((num_vertices + comp_num_verts) * sizeof(stbtt_vertex)))", "FakePtr<stbtt_vertex>.CreateWithSize(num_vertices + comp_num_verts)"); data = data.Replace("CRuntime.malloc((ulong)(count_ctx.num_vertices * sizeof(stbtt_vertex)))", "FakePtr<stbtt_vertex>.CreateWithSize(count_ctx.num_vertices)"); data = data.Replace("CRuntime.malloc((ulong)((result.w * 2 + 1) * sizeof(float)))", "FakePtr<float>.CreateWithSize(result.w * 2 + 1)"); data = data.Replace("CRuntime.malloc((ulong)(sizeof((e.Value)) * (n + 1)))", "FakePtr<stbtt__edge>.CreateWithSize(n + 1)"); data = data.Replace("CRuntime.malloc((ulong)(sizeof((contour_lengths)) * n))", "FakePtr<int>.CreateWithSize(n + 1)"); data = data.Replace("CRuntime.malloc((ulong)(num_points * sizeof(stbtt__point)))", "FakePtr<stbtt__point>.CreateWithSize(num_points)"); data = data.Replace("(ulong)(num_vertices * sizeof(stbtt_vertex))", "num_vertices"); data = data.Replace("(ulong)(comp_num_verts * sizeof(stbtt_vertex))", "comp_num_verts"); data = data.Replace("(ulong)(result.w * sizeof(float))", "result.w"); data = data.Replace("(ulong)((result.w + 1) * sizeof(float))", "result.w + 1"); data = data.Replace("stbtt__hheap hh, ", ""); data = data.Replace("stbtt__active_edge z = stbtt__hheap_alloc(hh, (ulong)(sizeof((z))), userdata);", "stbtt__active_edge z = new stbtt__active_edge();"); data = data.Replace("stbtt__hheap hh = (stbtt__hheap)({ null, null, 0 });", ""); data = data.Replace("stbtt__hheap_free(hh, z);", ""); data = data.Replace("stbtt__hheap_cleanup(hh, userdata);", ""); data = data.Replace("FakePtr<stbtt__edge> a = ref t;", "FakePtr<stbtt__edge> a = new FakePtr<stbtt__edge>(t);"); data = data.Replace("hh, ", ""); File.WriteAllText(SourceFile, data); }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_image_write.h", Output = output, Defines = new[] { "STBI_WRITE_NO_STDIO", "STB_IMAGE_WRITE_IMPLEMENTATION" }, Namespace = "StbSharp", Class = "StbImageWrite", SkipStructs = new[] { "stbi__write_context" }, SkipGlobalVariables = new[] { "stbi_write_tga_with_rle" }, SkipFunctions = new[] { "stbi__start_write_callbacks", "stbiw__writefv", "stbiw__writef", "stbiw__outfile", "stbi_write_bmp_to_func", "stbi_write_tga_to_func", "stbi_write_hdr_to_func", "stbi_write_png_to_func", "stbi_write_hdr_core", }, Classes = new [] { "stbi__write_context" }, GlobalArrays = new[] { "lengthc", "lengtheb", "distc", "disteb", "crc_table", "stbiw__jpg_ZigZag", "std_dc_luminance_nrcodes", "std_dc_luminance_values", "std_ac_luminance_nrcodes", "std_ac_luminance_values", "std_dc_chrominance_nrcodes", "std_dc_chrominance_values", "std_ac_chrominance_nrcodes", "std_ac_chrominance_values", "std_dc_chrominance_nrcodes", "std_dc_chrominance_values", "YDC_HT", "UVDC_HT", "YAC_HT", "UVAC_HT", "YQT", "UVQT", "aasf", "head0", "head2" } }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("int has_alpha = (int)(((comp) == (2)) || ((comp) == (4)));", "int has_alpha = (((comp) == (2)) || ((comp) == (4)))?1:0;"); data = data.Replace("*arr?", "*arr != null?"); data = data.Replace("sizeof(int)* * 2", "sizeof(int) * 2"); data = data.Replace("(int)(sizeof((*(data))))", "sizeof(byte)"); data = data.Replace("(int)(sizeof((*(_out_))))", "sizeof(byte)"); data = data.Replace("(int)(sizeof((*(hash_table[h]))))", "sizeof(byte*)"); data = data.Replace("sizeof((hash_table[h][0]))", "sizeof(byte*)"); data = data.Replace("(byte***)(malloc((ulong)(16384 * sizeof(char**)))))", "(byte***)(malloc((ulong)(16384 * sizeof(byte**))))"); data = data.Replace("(hlist)?", "(hlist != null)?"); data = data.Replace("(hash_table[i])?", "(hash_table[i] != null)?"); File.WriteAllText(@"..\..\..\..\..\StbSharp\StbImageWrite.Generated.cs", data); } }
static void Process() { var parameters = new ConversionParameters { AdditionalIncludeFolders = new string[] { @"C:\Projects\StbSharp\FreeTypeSharp\FreeTypeTest\FreeTypeTest\freetype\include" }, InputPath = @"C:\Projects\StbSharp\FreeTypeSharp\FreeTypeTest\FreeTypeTest\freetype\src\base\ftbase.c", Defines = new string[] { "_LIB", "_CRT_SECURE_NO_WARNINGS", "FT2_BUILD_LIBRARY" }, SkipEnums = new string[] { "FT_Encoding_", "FT_Glyph_Format_", }, SkipStructs = new string[] { "FT_StreamDesc_", "FT_StreamRec_", "TT_Post_NamesRec_names", "TT_Post_NamesRec_", "FT_HashnodeRec_", "FT_HashRec_", "FT_Service_PsCMapsRec_", "T1_Decoder_FuncsRec_", "PS_BlendRec_", "CFF_InternalRec_", "CFF_Decoder_FuncsRec_", }, SkipGlobalVariables = new string[] { }, SkipFunctions = new string[] { "FT_Raccess_Get_DataOffsets" }, Classes = new string[] { "FT_FaceRec_", "FT_Outline_Funcs_", "FT_Renderer_Class_", "FT_RendererRec_", "FT_ModuleRec_", "FT_Module_Class_", "FT_MemoryRec_", "FT_LibraryRec_", "FT_StreamRec_", "ft_raccess_guess_rec_", "FT_CharMapRec_", "FT_Raster_Params_", "FT_GlyphSlotRec_", "FT_Slot_InternalRec_", "FT_SizeRec_", "FT_CharMapRec_", "FT_DriverRec_", "FT_Driver_ClassRec_", "FT_GlyphRec_", "FT_Glyph_Class_", "FT_Raster_Funcs_", "FT_Incremental_FuncsRec_", "FT_CMapRec_", "FT_CMap_ClassRec_", "FT_Face_InternalRec_", "FT_Incremental_InterfaceRec_", "FT_GlyphLoaderRec_", "TT_FaceRec_", "TT_LoaderRec_", "SFNT_Interface_", "FT_HashRec_", "PSH_Globals_FuncsRec_", "PSH_GlobalsRec_", "T1_Hints_FuncsRec_", "T2_Hints_FuncsRec_", "FT_Service_PsCMapsRec_", "PS_UnicodesRec_", "PS_BlendRec_", "CFF_FontRec_", "CFF_SubFontRec_", "PSHinter_Interface_", "PS_Table_FuncsRec_", "PS_TableRec_", "PS_Parser_FuncsRec_", "PS_ParserRec_", "T1_FieldRec_", "PS_Builder_", "CFF_GlyphSlotRec_", "FT_Generic_", "PS_Decoder_", "T1_BuilderRec_", "T1_Decoder_FuncsRec_", "T1_DecoderRec_", "CFF_Builder_", "CFF_SizeRec_", "CFF_Decoder_", "AFM_ParserRec_", "T1_Builder_FuncsRec_", "T1_CMap_ClassesRec_", "AFM_Parser_FuncsRec_", "CFF_Decoder_FuncsRec_", "FT_Service_PropertiesRec_", "FT_Service_SFNT_TableRec_", "FT_Service_PsFontNameRec_", "FT_Service_GlyphDictRec_", "FT_GlyphLoadRec_", }, GlobalArrays = new string[] { } }; var cp = new ClangParser(); var result = cp.Process(parameters); // Write output var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace FreeTypeSharp\n{\n\t"); sb.AppendLine("unsafe partial class FreeType\n\t{"); Write(result.Constants, sb); Write(result.GlobalVariables, sb); Write(result.Enums, sb); Write(result.Structs, sb); Write(result.Methods, sb); sb.Append("}\n}"); var data = sb.ToString(); // Post processing Logger.Info("Post processing..."); data = PostProcess(data); File.WriteAllText(@"..\..\..\..\..\src\FtBase.Generated.cs", data); }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_vorbis.c", Output = output, Defines = new[] { "STB_VORBIS_NO_STDIO", "STB_VORBIS_NO_INLINE_DECODE", "STB_VORBIS_NO_FAST_SCALED_FLOAT" }, Namespace = "StbSharp", Class = "StbVorbis", SkipStructs = new[] { "Residue", "stb_vorbis", }, SkipGlobalVariables = new[] { "channel_position" }, SkipFunctions = new[] { "get_bits", }, Classes = new[] { "Residue", "stb_vorbis", }, GlobalArrays = new[] { "crc_table", "ogg_page_header", "inverse_db_table", "log2_4", "channel_selector" } }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("byte* minp;", "byte* minp = null;"); data = data.Replace("byte* maxp;", "byte* maxp = null;"); data = data.Replace("public static void stb__PrepareOptTable(byte* Table, byte* expand, int size)", "public static void stb__PrepareOptTable(byte[] Table, byte[] expand, int size)"); data = data.Replace("(enum STBVorbisError)", string.Empty); data = data.Replace("crc_table", "_crc_table"); data = data.Replace("memset(available, (int)(0), (ulong)(sizeof((available))))", "memset(available, 0, 32)"); data = data.Replace("return (int)((x) < (y)?-1:(x) > (y));", "return (int)((x) < (y)?-1:((x) > (y)?1:0));"); data = data.Replace("sizeof(float)* * n", "sizeof(float) * n"); data = data.Replace("uint16", "ushort"); data = data.Replace("sizeof(ushort)* * n", "sizeof(ushort) * n"); data = data.Replace("return (int)((a->x) < (b->x)?-1:(a->x) > (b->x));", "return (int)((a->x) < (b->x)?-1:((a->x) > (b->x)?1:0));"); data = data.Replace("!c->codewords) != 0", "c->codewords == null)"); data = data.Replace("(void *)(0)", "null"); data = data.Replace("sizeof((**part_classdata))", "sizeof(byte *)"); data = data.Replace("sizeof((**part_classdata))", "sizeof(byte *)"); data = data.Replace("alloc.alloc_buffer?", "alloc.alloc_buffer != null?"); data = data.Replace("float*[]", "float**"); data = data.Replace("sizeof((*buf2))", "sizeof(float)"); data = data.Replace("f.mode_config +", "(Mode *)f.mode_config +"); data = data.Replace("memcpy(really_zero_channel, zero_channel, (ulong)(sizeof((really_zero_channel[0])) * f.channels));", "memcpy(really_zero_channel, zero_channel, (ulong)(sizeof(int) * f.channels));"); data = data.Replace("memset(f.channel_buffers[i], (int)(0), (ulong)(sizeof((*f.channel_buffers[i])) * n2));", "memset(f.channel_buffers[i], (int)(0), (ulong)(sizeof(float) * n2));"); data = data.Replace("if ((f.page_flag & 4))", "if ((f.page_flag & 4) != 0)"); data = data.Replace("for ((s) == (-1); {", "for (;(s) == (-1);) {"); data = data.Replace("float** residue_buffers = stackalloc float[16];", "float** residue_buffers = stackalloc float*[16];"); data = data.Replace("if ((p[5] & 1))", "if ((p[5] & 1) != 0)"); data = data.Replace("sizeof((*f.codebooks))", "sizeof(Codebook)"); data = data.Replace("sizeof((c->codewords[0]))", "sizeof(uint)"); data = data.Replace("sizeof((*c->codewords))", "sizeof(uint)"); data = data.Replace("sizeof((*values))", "sizeof(uint)"); data = data.Replace("sizeof((*c->sorted_codewords))", "sizeof(uint)"); data = data.Replace("sizeof((*c->sorted_values))", "sizeof(int)"); data = data.Replace("sizeof((mults[0]))", "sizeof(ushort)"); data = data.Replace("sizeof((c->multiplicands[0]))", "sizeof(float)"); data = data.Replace("sizeof((*f.floor_config))", "sizeof(Floor)"); data = data.Replace("(Residue)(setup_malloc(f, (int)(f.residue_count * sizeof((f.residue_config[0])))))", "new Residue[f.residue_count]"); data = data.Replace("sizeof((*r.classdata))", "sizeof(byte *)"); data = data.Replace("sizeof((*f.mapping))", "sizeof(Mapping)"); data = data.Replace("sizeof((r.classdata[j][0]))", "sizeof(byte)"); data = data.Replace("sizeof((r.residue_books[0]))", "sizeof(short)"); data = data.Replace("sizeof((*m->chan))", "sizeof(MappingChannel)"); data = data.Replace("(short [8]*)(setup_malloc(f, (int)(sizeof(short) * r.classifications)))", "new short*[r.classifications]"); data = data.Replace("sizeof(float)* *", "sizeof(float) *"); data = data.Replace("sizeof(short)* *", "sizeof(short) *"); data = data.Replace("sizeof(float)>> >>", "sizeof(float) >>"); data = data.Replace("sizeof(float)+ +", "sizeof(float) +"); data = data.Replace("sizeof(void*)+ +", "sizeof(void*) +"); data = data.Replace("classify_mem = (uint)((f.channels * (sizeof(void*) + max_part_read * sizeof(char*)))));", "classify_mem = (uint)((f.channels * (sizeof(void*) + max_part_read * sizeof(char*))));"); data = data.Replace("(stb_vorbis)(setup_malloc(f, (int)(sizeof((p)))))", "new stb_vorbis()"); data = data.Replace("memset(buffer, (int)(0), (ulong)(sizeof((buffer))))", "memset(buffer, (int)(0), (ulong)(sizeof(float) * 32))"); data = data.Replace("channel_position[num_c][j]", "channel_position[num_c,j]"); data = data.Replace("channel_selector[buf_c][i]", "channel_selector[buf_c,i]"); data = data.Replace("int[] channel_selector", "int[,] channel_selector"); data = data.Replace("sizeof((*data))", "sizeof(short)"); data = data.Replace("float** output;", "float*[] output = null;"); data = data.Replace("float** outputs;", "float*[] outputs = null;"); data = data.Replace("&output", "ref output"); data = data.Replace("float*** output", "ref float*[] output"); data = data.Replace("float** data", "float*[] data"); data = data.Replace("if ((output) != null) *output = f.outputs;", "if ((output) != null) output = f.outputs;"); data = data.Replace("stb_vorbis_get_frame_float(f, &n, (null));", "float*[] output = null; stb_vorbis_get_frame_float(f, &n, ref output);"); data = data.Replace("*output = f.outputs;", "output = f.outputs;"); data = data.Replace("*output = f.outputs;", "output = f.outputs;"); data = data.Replace("f.current_loc_valid = (int)(f.current_loc != ~0U);", "f.current_loc_valid = f.current_loc != ~0U?1:0;"); data = data.Replace("setup_free(p, c->sorted_values?c->sorted_values - 1:(null));", "setup_free(p, c->sorted_values != null?c->sorted_values - 1:(null));"); data = data.Replace("f.scan[n].sample_loc = (uint)(~0);", "f.scan[n].sample_loc = uint.MaxValue;"); data = data.Replace("; ) {}", ""); data = data.Replace("if (((f.current_loc_valid) != 0) && (f.page_flag & 4))", "if (((f.current_loc_valid) != 0) && (f.page_flag & 4) != 0)"); File.WriteAllText(@"..\..\..\..\..\StbSharp\StbVorbis.Generated.cs", data); } }
static void Main(string[] args) { const string dir = @"..\..\..\ZlibSharp\"; var sourceEntries = new string[][] { new [] { "adler32.c", "Adler32", }, new [] { "compress.c", "Compress" }, new [] { "crc32.c", "Crc32", }, new [] { "deflate.c", "Deflate", }, new [] { "gzclose.c", "GZClose", }, new [] { "gzlib.c", "GZLib", }, new [] { "gzread.c", "GZRead", }, new [] { "gzwrite.c", "GZWrite", }, new [] { "infback.c", "InfBack", }, new [] { "inffast.c", "InfFast", }, new [] { "inflate.c", "InfLate", }, new [] { "inftrees.c", "InfTrees" }, new [] { "trees.c", "Trees", }, new [] { "uncompr.c", "Uncompress", }, new [] { "zutil.c", "ZUtil" } }; Directory.CreateDirectory(dir); var cp = new ClangParser(); var sb = new StringBuilder(); for (int i = 0; i < sourceEntries.Length; i++) { Console.WriteLine(); Console.WriteLine(); var parameters = new ConversionParameters { InputPath = Path.GetFullPath(@"..\..\..\zlib\" + sourceEntries[i][0]), Class = sourceEntries[i][1], Namespace = "ZlibSharp", Defines = new string[] { }, }; Logger.Info($"Reading {parameters.InputPath}..."); ConversionResult result; //try { result = cp.Process(parameters); } //catch (Exception ex) //{ // Console.WriteLine(ex); // continue; //} // Post processing Logger.Info($"Writing {parameters.InputPath}..."); var builder = new StringBuilder(); Write(GroupType.Constants, result.Constants, builder); Write(GroupType.Globals, result.GlobalVariables, builder); Write(GroupType.Enums, result.Enums, builder); Write(GroupType.Structs, result.Structs, builder); Write(GroupType.Methods, result.Methods, builder); var data = builder; // PostProcess(pair.Value); sb.Clear(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine("using static CRuntime;"); sb.AppendLine(); sb.Append($"namespace {parameters.Namespace}\n{{\n\t"); sb.AppendLine($"unsafe class {parameters.Class}\n\t{{"); data.Insert(0, sb); data.Append("}\n}"); string path = dir + parameters.Class + ".cs"; if (data.Length > 0) { File.WriteAllText(path, data.ToString()); } else { Console.WriteLine("Empy " + path); } } Console.ReadKey(); }
static void Convert() { var cp = new ClangParser(); var skipStructs = new HashSet <string> { "nk_handle", "nk_user_font", "nk_font", "nk_allocator", "nk_clipboard", "nk_style_item_data", "nk_style_item", "nk_font_atlas", "nk_page_data", "nk_page_element", "nk_buffer", "nk_text_undo_state", "nk_property", "nk_property_variant", "nk_keyboard", "nk_mouse", "nk_draw_list", "nk_style", "nk_chart", "nk_command_custom", "nk_rp_context", "nk_context", "nk_page", "nk_pool", "nk_window", "nk_panel", "nk_config_stack_button_behavior_element", "nk_convert_config", "nk_user_font_glyph", "nk_popup_buffer", }; var treatAsClasses = new HashSet <string> { "nk_str", "nk_clipboard", "nk_context", "nk_font_atlas", "nk_buffer", "nk_text_undo_state", "nk_page_element", "nk_keyboard", "nk_mouse", "nk_input", "nk_draw_list", "nk_command_buffer", "nk_style", "nk_chart", "nk_panel", "nk_window", "nk_popup_state", "nk_page", "nk_text_edit", "nk_pool", "nk_table", "nk_list_view", "nk_convert_config", "nk_style_item", "nk_config_stack_style_item_element", "nk_style_text", "nk_popup_buffer", "nk_image", "nk_cursor", "nk_user_font", "nk_font", "nk_config_stack_user_font_element", "nk_font_config", "nk_baked_font", "nk_chart_slot", "nk_row_layout", "nk_edit_state", "nk_property_state", "nk_configuration_stacks", "nk_scroll", "nk_memory_status", "nk_menu_state", }; var skipGlobalVariables = new HashSet <string> { "nk_null_rect", "nk_red", "nk_green", "nk_blue", "nk_white", "nk_black", "nk_yellow", "nk_default_color_style", "nk_color_names", "nk_cursor_data", "hue_colors", }; var skipFunctions = new HashSet <string> { "nk_inv_sqrt", "nk_strmatch_fuzzy_text", "nk_strmatch_fuzzy_string", "nk_str_append_text_runes", "nk_str_append_str_runes", "nk_stricmp", "nk_strfilter", "nk_utf_validate", "nk_utf_decode_byte", "nk_utf_decode", "nk_utf_encode_byte", "nk_utf_encode", "nk_utf_len", "nk_utf_at", "nk_style_get_color_by_name", "nk_pool_init_fixed", "nk_init_custom", "nk_pool_init", "nk_pool_free", "nk_pool_alloc", "nk_create_page_element", "nk_link_page_element_into_freelist", "nk_free_page_element", "nk_create_panel", "nk_free_panel", "nk_create_table", "nk_free_table", "nk_init_fixed", "nk_init", "nk_free", "nk_create_window", "nk_free_window", "nk_buffer_init_default", "nk_str_init_default", "nk_str_init", "nk_font_atlas_init_default", "nk_font_atlas_init", "nk_font_atlas_init_custom", "nk_init_default", "nk_command_buffer_push", "nk__begin", "nk_command_buffer_init", "nk_command_buffer_reset", "nk__next", "nk_build", "nk_property_", "nk_font_atlas_add_default", "nk_stroke_polygon", "nk_fill_polygon", "nk_stroke_polyline", "nk_font_default_glyph_ranges", "nk_font_chinese_glyph_ranges", "nk_font_cyrillic_glyph_ranges", "nk_font_korean_glyph_ranges", }; var globalArrays = new HashSet <string> { "nk_utfbyte", "nk_utfmask", "nk_utfmin", "nk_utfmax", "nk_proggy_clean_ttf_compressed_data_base85", "nk_custom_cursor_data", "nk_cursor_data", }; var parameters = new ConversionParameters { InputPath = @"nuklear.h", Defines = new[] { "NK_IMPLEMENTATION", "NK_INCLUDE_DEFAULT_ALLOCATOR", "NK_INCLUDE_VERTEX_BUFFER_OUTPUT", "NK_INCLUDE_FONT_BAKING", "NK_INCLUDE_DEFAULT_FONT" }, Namespace = "NuklearSharp", }; parameters.StructSource = n => { var result = new StructConfig { Name = n, Source = new SourceInfo { Class = "Nuklear", StructType = StructType.StaticClass } }; if (!skipStructs.Contains(n) && !n.StartsWith("nk_command_")) { var sourceName = GetSourceName(n); result.Source.Source = @"..\..\..\..\..\NuklearSharp\Nuklear." + sourceName + ".Generated.cs"; } if (treatAsClasses.Contains(n) || n.StartsWith("nk_command_") || n.StartsWith("nk_style_") || n.StartsWith("nk_config_")) { result.StructType = StructType.Class; } else { result.StructType = StructType.Struct; } return(result); }; parameters.GlobalVariableSource = n => new BaseConfig { Name = n, Source = new SourceInfo { Class = "Nuklear", Source = @"..\..\..\..\..\NuklearSharp\Nuklear.GlobalVariables.Generated.cs", StructType = StructType.StaticClass } }; parameters.EnumSource = n => new BaseConfig { Name = string.Empty, Source = new SourceInfo { Class = "Nuklear", Source = @"..\..\..\..\..\NuklearSharp\Nuklear.Enums.Generated.cs", StructType = StructType.StaticClass } }; parameters.FunctionSource = n => { var fc = new FunctionConfig { Name = n.Name, Static = true, Source = new SourceInfo { Source = @"..\..\..\..\..\NuklearSharp\Nuklear.Utility.Generated.cs", Class = "Nuklear", StructType = StructType.StaticClass, } }; var parts = n.Signature.Split(','); var s = string.Empty; if (parts.Length > 0) { for (var i = 0; i < parts.Length; ++i) { var parts2 = parts[i].Trim().Split(' '); var typeName = parts2[0]; if (typeName.EndsWith("*")) { typeName = typeName.Substring(0, typeName.Length - 1); } var recordType = cp.Processor.GetRecordType(typeName); if (recordType != RecordType.None) { s = typeName; } break; } } if (!string.IsNullOrEmpty(s)) { var sourceName = GetSourceName(s); fc.Source.Source = @"..\..\..\..\..\NuklearSharp\Nuklear." + sourceName + ".Generated.cs"; } if (skipFunctions.Contains(n.Name)) { fc.Source.Source = null; } return(fc); }; parameters.TreatGlobalPointerAsArray = n => globalArrays.Contains(n); parameters.UseRefInsteadOfPointer = (f, t, n) => n == "custom" || f == "nk_unify" || n == "state" || n == "ws" || n == "size" || n == "glyph_count" || n == "width" || n == "height" || n == "value" || n == "val" || n == "cursor" || n == "len" || n == "select_begin" || n == "select_end"; parameters.CustomGlobalVariableProcessor += cpr => { if (cpr.Info.Spelling == "nk_proggy_clean_ttf_compressed_data_base85" || cpr.Info.Spelling == "nk_custom_cursor_data") { var sb = new StringBuilder(); sb.Append("{"); var start = cpr.Expression.IndexOf('\"') + 1; for (var i = start; i < cpr.Expression.Length; ++i) { var c = cpr.Expression[i]; if (c == '\"') { break; } if (i > start) { sb.Append(", "); } sb.AppendFormat("0x{0:X}", (int)c); } sb.Append("}"); cpr.Expression = "byte[] " + cpr.Info.Spelling + " = " + sb.ToString(); } }; parameters.FunctionHeaderProcessed = (fn, args) => { if (fn.Contains("nk_stricmpn") || fn.Contains("nk_tree_state_base") || fn.Contains("nk_tree_state_push") || fn.Contains("nk_tree_state_image_push") || fn.Contains("nk_group_scrolled_offset_begin") || fn.Contains("nk_parse_hex") || fn.Contains("nk_itoa") | fn.Contains("nk_string_float_limit") || fn.Contains("nk_text_clamp") || fn.Contains("nk_text_calculate_text_bounds") || fn.Contains("nk_str_") || fn.Contains("nk_draw_") || fn.Contains("nk_font_")) { return; } if (args.Length == 0 || !args[0].StartsWith("nk_context")) { return; } var sb = new StringFunctionBinding { Header = fn, Args = args, }; _bindings[fn] = sb; }; var outputs = cp.Process(parameters); // Post processing Logger.Info("Post processing..."); foreach (var output in outputs) { if (output.Key.Contains("GlobalVariables") || output.Key.Contains("Enums") /* || * output.Key.Contains("Commands\\") || * output.Key.Contains("Config\\") || * output.Key.Contains("Core\\") || * output.Key.Contains("Drawing\\") || * output.Key.Contains("Fonts\\") || * output.Key.Contains("InputSystem\\") || * output.Key.Contains("MemoryManagement\\") || * output.Key.Contains("RectPacts\\") || * output.Key.Contains("Styling\\") || * output.Key.Contains("TextEditing\\")*/) { continue; } var data = output.Value; // Post processing Logger.Info("Post processing '{0}'...", output.Key); data = PostProcess(data); File.WriteAllText(output.Key, data); } }
static void Process() { var data = string.Empty; using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_truetype.h", Output = output, Defines = new[] { "STB_TRUETYPE_IMPLEMENTATION", }, Namespace = "StbSharp", Class = "StbTrueType", SkipStructs = new string[] { }, SkipGlobalVariables = new string[] { }, SkipFunctions = new string[] { "stbtt__find_table", }, Classes = new string[] { }, GlobalArrays = new string[] { } }; var cp = new ClangParser(); cp.Process(parameters); data = output.ToString(); } // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("(void *)(0)", "null"); data = data.Replace("stbtt_vertex* vertices = 0;", "stbtt_vertex* vertices = null;"); data = data.Replace("(flags & 16)?dx:-dx", "(flags & 16) != 0?dx:-dx"); data = data.Replace("(flags & 32)?dy:-dy", "(flags & 32) != 0?dy:-dy"); data = data.Replace("(vertices) == (0)", "vertices == null"); data = data.Replace("sizeof((vertices[0]))", "sizeof(stbtt_vertex)"); data = data.Replace("(int)(!(flags & 1))", "((flags & 1) != 0?0:1)"); data = data.Replace("vertices = 0;", "vertices = null;"); data = data.Replace("stbtt_vertex* comp_verts = 0;", "stbtt_vertex* comp_verts = null;"); data = data.Replace("stbtt_vertex* tmp = 0;", "stbtt_vertex* tmp = null;"); data = data.Replace(",)", ")"); data = data.Replace("+ +", "+"); data = data.Replace("(sizeof(stbtt__hheap_chunk) + size * count)", "((ulong)sizeof(stbtt__hheap_chunk)+ size * (ulong)(count))"); data = data.Replace("size * hh->num_remaining_in_head_chunk", "size * (ulong)hh->num_remaining_in_head_chunk"); data = data.Replace("sizeof((*z))", "sizeof(stbtt__active_edge)"); data = data.Replace("_next_ = 0;", "_next_ = null;"); data = data.Replace("sizeof((scanline[0]))", "sizeof(float)"); data = data.Replace("int c = (int)(((a)->y0) < ((b)->y0));", "int c = (int)(a->y0 < b->y0?1:0);"); data = data.Replace("sizeof((*e))", "sizeof(stbtt__edge)"); data = data.Replace("sizeof((**contour_lengths))", "sizeof(int)"); data = data.Replace("sizeof((points[0]))", "sizeof(stbtt__point)"); data = data.Replace("sizeof((*context))", "sizeof(stbrp_context)"); data = data.Replace("sizeof((*nodes))", "sizeof(stbrp_node)"); data = data.Replace("sizeof((*rects))", "sizeof(stbrp_rect)"); data = data.Replace("(int)(((a[0]) == (b[0])) && ((a[1]) == (b[1])));", "(int)(((a[0] == b[0]) && (a[1] == b[1]))?1:0);"); File.WriteAllText(SourceFile, data); }
static void Process() { var parameters = new ConversionParameters { InputPath = @"dds-ktx.h", Defines = new[] { "DDSKTX_IMPLEMENT" }, SkipStructs = new string[] { "stbir__filter_info", "stbir__info", "stbir__FP32", }, SkipGlobalVariables = new string[] { "stbir__filter_info_table" }, SkipFunctions = new[] { "dds_ktx_err" }, Classes = new string[] { "stbir__info", "ddsktx__dds_translate_pixel_format" }, GlobalArrays = new string[] { } }; var cp = new ClangParser(); var result = cp.Process(parameters); // Write output var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace DdsKtxSharp\n{\n\t"); sb.AppendLine("unsafe partial class DdsKtx\n\t{"); Write(result.Constants, sb); Write(result.GlobalVariables, sb); Write(result.Enums, sb); Write(result.Structs, sb); Write(result.Methods, sb); sb.Append("}\n}"); var data = sb.ToString(); // Post processing Logger.Info("Post processing..."); data = PostProcess(data); File.WriteAllText(@"..\..\..\..\..\src\DdsKtxSharp.Generated.cs", data); }
static void Process() { var skipFunctions = new HashSet <string> { "stbtt__find_table" }; var parameters = new ConversionParameters { InputPath = @"stb_truetype.h", Defines = new[] { "STB_TRUETYPE_IMPLEMENTATION" }, Namespace = "StbSharp", }; parameters.StructSource = n => { var result = new StructConfig { Name = n, Source = new SourceInfo { Class = "StbTrueType", StructType = StructType.StaticClass, Source = SourceFile } }; return(result); }; parameters.GlobalVariableSource = n => new BaseConfig { Name = n, Source = new SourceInfo { Class = "StbTrueType", Source = SourceFile, StructType = StructType.StaticClass } }; parameters.EnumSource = n => new BaseConfig { Name = string.Empty, Source = new SourceInfo { Class = "StbTrueType", Source = SourceFile, StructType = StructType.StaticClass } }; parameters.FunctionSource = n => { var fc = new FunctionConfig { Name = n.Name, Static = true, Source = new SourceInfo { Source = SourceFile, Class = "StbTrueType", StructType = StructType.StaticClass, } }; if (skipFunctions.Contains(n.Name)) { fc.Source.Source = null; } return(fc); }; var cp = new ClangParser(); var outputs = cp.Process(parameters); // Post processing Logger.Info("Post processing..."); foreach (var output in outputs) { var data = output.Value; data = Utility.ReplaceNativeCalls(data); data = data.Replace("(void *)(0)", "null"); data = data.Replace("stbtt_vertex* vertices = 0;", "stbtt_vertex* vertices = null;"); data = data.Replace("(flags & 16)?dx:-dx", "(flags & 16) != 0?dx:-dx"); data = data.Replace("(flags & 32)?dy:-dy", "(flags & 32) != 0?dy:-dy"); data = data.Replace("(vertices) == (0)", "vertices == null"); data = data.Replace("sizeof((vertices[0]))", "sizeof(stbtt_vertex)"); data = data.Replace("(int)(!(flags & 1))", "((flags & 1) != 0?0:1)"); data = data.Replace("vertices = 0;", "vertices = null;"); data = data.Replace("stbtt_vertex* comp_verts = 0;", "stbtt_vertex* comp_verts = null;"); data = data.Replace("stbtt_vertex* tmp = 0;", "stbtt_vertex* tmp = null;"); data = data.Replace(",)", ")"); data = data.Replace("+ +", "+"); data = data.Replace("(sizeof(stbtt__hheap_chunk) + size * count)", "((ulong)sizeof(stbtt__hheap_chunk)+ size * (ulong)(count))"); data = data.Replace("size * hh->num_remaining_in_head_chunk", "size * (ulong)hh->num_remaining_in_head_chunk"); data = data.Replace("sizeof((*z))", "sizeof(stbtt__active_edge)"); data = data.Replace("_next_ = 0;", "_next_ = null;"); data = data.Replace("sizeof((scanline[0]))", "sizeof(float)"); data = data.Replace("int c = (int)(((a)->y0) < ((b)->y0));", "int c = (int)(a->y0 < b->y0?1:0);"); data = data.Replace("sizeof((*e))", "sizeof(stbtt__edge)"); data = data.Replace("sizeof((**contour_lengths))", "sizeof(int)"); data = data.Replace("sizeof((points[0]))", "sizeof(stbtt__point)"); data = data.Replace("sizeof((*context))", "sizeof(stbrp_context)"); data = data.Replace("sizeof((*nodes))", "sizeof(stbrp_node)"); data = data.Replace("sizeof((*rects))", "sizeof(stbrp_rect)"); data = data.Replace("(int)(((a[0]) == (b[0])) && ((a[1]) == (b[1])));", "(int)(((a[0] == b[0]) && (a[1] == b[1]))?1:0);"); File.WriteAllText(output.Key, data); } }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_image.h", Output = output, Defines = new[] { "STBI_NO_SIMD", "STBI_NO_LINEAR", "STBI_NO_HDR", "STBI_NO_PIC", "STBI_NO_PNM", "STBI_NO_STDIO", "STB_IMAGE_IMPLEMENTATION", }, Namespace = "StbSharp", Class = "StbImage", SkipStructs = new[] { "stbi_io_callbacks", "img_comp", "stbi__jpeg", "stbi__resample", "stbi__gif_lzw", "stbi__gif" }, SkipGlobalVariables = new[] { "stbi__g_failure_reason", "stbi__vertically_flip_on_load" }, SkipFunctions = new[] { "stbi__malloc", "stbi_image_free", "stbi_failure_reason", "stbi__err", "stbi_is_hdr_from_memory", "stbi_is_hdr_from_callbacks", "stbi__pnm_isspace", "stbi__pnm_skip_whitespace", "stbi__pic_is4", "stbi__gif_parse_colortable" }, Classes = new[] { "stbi_io_callbacks", "stbi__jpeg", "stbi__resample", "stbi__gif", "stbi__context", "stbi__png" }, GlobalArrays = new[] { "stbi__bmask", "stbi__jbias", "stbi__jpeg_dezigzag", "stbi__zlength_base", "stbi__zlength_extra", "stbi__zdist_base", "stbi__zdist_extra", "first_row_filter", "stbi__depth_scale_table", "stbi__zdefault_length", "stbi__zdefault_distance", "length_dezigzag", "png_sig" } }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); data = data.Replace("(int)(a <= 2147483647 - b)", "(a <= 2147483647 - b)?1:0"); data = data.Replace("(int)(a <= 2147483647 / b)", "(a <= 2147483647 / b)?1:0"); data = data.Replace("(ulong)((ulong)(w) * bytes_per_pixel)", "(ulong)(w * bytes_per_pixel)"); data = data.Replace("bytes + row * bytes_per_row", "bytes + (ulong)row * bytes_per_row"); data = data.Replace("bytes + (h - row - 1) * bytes_per_row", "bytes + (ulong)(h - row - 1) * bytes_per_row"); data = data.Replace("(void *)(0)", "null"); data = data.Replace("s.img_buffer_end = s.buffer_start + 1;", "s.img_buffer_end = s.buffer_start; s.img_buffer_end++;"); data = data.Replace("s.img_buffer_end = s.buffer_start + n;", "s.img_buffer_end = s.buffer_start; s.img_buffer_end += n;"); data = data.Replace(" != 0?(null):(null)", " != 0?((byte *)null):(null)"); data = data.Replace("(int)(j.code_buffer)", "j.code_buffer"); data = data.Replace("z.huff_dc + ", "(stbi__huffman *)z.huff_dc + "); data = data.Replace("z.huff_ac + ", "(stbi__huffman *)z.huff_ac + "); data = data.Replace("z.dequant[z.img_comp[n].tq]", "(ushort *)z.dequant[z.img_comp[n].tq]"); data = data.Replace("int sixteen = (int)(p != 0);", "int sixteen = (p != 0)?1:0;"); data = data.Replace("(byte)('')", "(byte)('\\0')"); data = data.Replace("coeff = 0", "coeff = null"); data = data.Replace("if (stbi__zbuild_huffman(&a->z_length, stbi__zdefault_length, (int)(288))== 0) return (int)(0);", "fixed (byte* b = stbi__zdefault_length) {if (stbi__zbuild_huffman(&a->z_length, b, (int) (288)) == 0) return (int) (0);}"); data = data.Replace("if (stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, (int)(32))== 0) return (int)(0);", "fixed (byte* b = stbi__zdefault_distance) {if (stbi__zbuild_huffman(&a->z_distance, b, (int) (32)) == 0) return (int) (0);}"); data = data.Replace("sbyte* invalid_chunk", "string invalid_chunk"); data = data.Replace("sizeof((s.buffer_start))", "s.buffer_start.Size"); data = data.Replace("sizeof((data[0]))", "sizeof(short)"); data = data.Replace("sizeof((sizes))", "sizeof(int)"); data = data.Replace("memset(z->fast, (int)(0), (ulong)(sizeof((z->fast))));", "memset(((ushort*)(z->fast)), (int)(0), (ulong)((1 << 9) * sizeof(ushort)));"); data = data.Replace("memset(codelength_sizes, (int)(0), (ulong)(sizeof((codelength_sizes))));", "memset(((byte*)(codelength_sizes)), (int)(0), (ulong)(19 * sizeof(byte)));"); data = data.Replace("comp != 0", "comp != null"); data = data.Replace("(int)((tga_image_type) == (3))", "(tga_image_type) == (3)?1:0"); data = data.Replace("short* d = ((short*)data.Pointer);", "short* d = data;"); data = data.Replace("byte** coutput = stackalloc byte[4];", "byte** coutput = stackalloc byte *[4];"); data = data.Replace("stbi__resample res_comp = new PinnedArray<stbi__resample>(4);", "var res_comp = new stbi__resample[4]; for (var kkk = 0; kkk < res_comp.Length; ++kkk) res_comp[kkk] = new stbi__resample();"); data = data.Replace("((byte**)coutput.Pointer)", "coutput"); data = data.Replace("stbi__jpeg j = (stbi__jpeg)(stbi__malloc((ulong)(sizeof(stbi__jpeg)))));", "stbi__jpeg j = new stbi__jpeg();"); data = data.Replace("stbi__jpeg j = (stbi__jpeg)((stbi__malloc((ulong)(sizeof(stbi__jpeg))))));", "stbi__jpeg j = new stbi__jpeg();"); data = data.Replace("stbi__jpeg j = (stbi__jpeg)((stbi__malloc((ulong)(.Size))));", "stbi__jpeg j = new stbi__jpeg();"); data = data.Replace("CRuntime.free(j);", string.Empty); data = data.Replace("z.img_comp[i].data = (byte*)(((ulong)(z.img_comp[i].raw_data) + 15) & ~15);", "z.img_comp[i].data = (byte*)((((long)z.img_comp[i].raw_data + 15) & ~15));"); data = data.Replace("z.img_comp[i].coeff = (short*)(((ulong)(z.img_comp[i].raw_coeff) + 15) & ~15);", "z.img_comp[i].coeff = (short*)((((long)z.img_comp[i].raw_coeff + 15) & ~15));"); data = data.Replace("(int)(!is_iphone)", "is_iphone!=0?0:1"); data = data.Replace("ArrayPointer<sbyte> invalid_chunk = \"XXXX PNG chunk not known\";", "var invalid_chunk = \"XXXX PNG chunk not known\";"); data = data.Replace("return (int)(stbi__err(((sbyte*)invalid_chunk.Pointer)));", "return (int)(stbi__err(invalid_chunk));"); data = data.Replace("if ((p) == ((void *)(0))) return (int)(stbi__err(\"outofmem\"));", "if (p == null) return (int) (stbi__err(\"outofmem\"));"); data = data.Replace("ArrayPointer<ArrayPointer<byte>> pal = new ArrayPointer<byte>(256);", "ArrayPointer<byte>[] pal = new ArrayPointer<byte>[256]; for (var kkk = 0; kkk < pal.Length; ++kkk) pal[kkk] = new ArrayPointer<byte>(4);"); data = data.Replace("pal[i][", "pal[i * 4 +"); data = data.Replace("pal[v][", "pal[v * 4 +"); data = data.Replace("pal[g.transparent][", "pal[g.transparent * 4 +"); data = data.Replace("uint v = (uint)((uint)((bpp) == (16)?stbi__get16le(s):stbi__get32le(s)));", "uint v = (uint)((uint)((bpp) == (16)?(uint)stbi__get16le(s):stbi__get32le(s)));"); data = data.Replace("(int)(((tga_image_type) == (3)) || ((tga_image_type) == (11)))", "(((tga_image_type) == (3))) || (((tga_image_type) == (11)))?1:0"); data = data.Replace("int r = (int)((stbi__get32be(s)) == (0x38425053));", "int r = (((stbi__get32be(s)) == (0x38425053)))?1:0;"); data = data.Replace("(packets).Size / (packets[0]).Size", "packets.Size"); data = data.Replace("stbi__gif g = (stbi__gif)(stbi__malloc((ulong)(sizeof(stbi__gif)))));", "stbi__gif g = new stbi__gif();"); data = data.Replace("CRuntime.free(g);", string.Empty); data = data.Replace("CRuntime.memset(g, (int)(0), (ulong)(sizeof((g))));", string.Empty); data = data.Replace("if (((g.transparent) >= (0)) && ((g.eflags & 0x01)))", "if (((g.transparent) >= (0)) && ((g.eflags & 0x01) != 0))"); data = data.Replace("&z.huff_dc[z.img_comp[n].hd]", "(stbi__huffman*)z.huff_dc + z.img_comp[n].hd"); data = data.Replace("&z.huff_ac[ha]", "(stbi__huffman*)z.huff_ac + ha"); data = data.Replace("g.codes[init_code]", "((stbi__gif_lzw*) (g.codes))[init_code]"); data = data.Replace("&g.codes[avail++]", "(stbi__gif_lzw*)g.codes + avail++"); data = data.Replace("byte* c = g.pal[g.bgindex]", "byte* c = (byte *)g.pal + g.bgindex"); data = data.Replace("(g._out_) == (0)", "(g._out_) == null"); data = data.Replace("((byte*)(tc))[k] = ((byte)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z.depth]);", "((byte*)(tc))[k] = (byte)((byte)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z.depth]);"); data = data.Replace("byte** pal = stackalloc byte[256];", "byte* pal = stackalloc byte[256 * 4];"); data = data.Replace("tga_data = (byte*)(stbi__malloc((ulong)(tga_width) * tga_height * tga_comp));", "tga_data = (byte*)(stbi__malloc(tga_width * tga_height * tga_comp));"); data = data.Replace("case 0x3B:return (byte*)(s);", "case 0x3B:return null;"); data = data.Replace("if ((u) == ((byte*)(s))) u = ((byte*)(0));", string.Empty); data = data.Replace("sgn = (int)(j.code_buffer >> 31);", "sgn = (int)((int)j.code_buffer >> 31);"); File.WriteAllText(@"..\..\..\..\..\StbSharp\StbImage.Generated.cs", data); } }
static void Process() { var parameters = new ConversionParameters { InputPath = @"stb_image_write.h", Defines = new[] { "STBI_WRITE_NO_STDIO", "STB_IMAGE_WRITE_IMPLEMENTATION", "STB_IMAGE_WRITE_STATIC" }, Namespace = "StbImageWriteSharp", Class = "StbImageWrite", SkipStructs = new[] { "stbi__write_context" }, SkipGlobalVariables = new[] { "stbi_write_tga_with_rle" }, SkipFunctions = new[] { "stbi__start_write_callbacks", "stbiw__writefv", "stbiw__writef", "stbiw__outfile", "stbi_write_bmp_to_func", "stbi_write_tga_to_func", "stbi_write_hdr_to_func", "stbi_write_png_to_func", "stbi_write_jpg_to_func", "stbi_write_hdr_core", }, Classes = new[] { "stbi__write_context" }, GlobalArrays = new[] { "lengthc", "lengtheb", "distc", "disteb", "crc_table", "stbiw__jpg_ZigZag", "std_dc_luminance_nrcodes", "std_dc_luminance_values", "std_ac_luminance_nrcodes", "std_ac_luminance_values", "std_dc_chrominance_nrcodes", "std_dc_chrominance_values", "std_ac_chrominance_nrcodes", "std_ac_chrominance_values", "std_dc_chrominance_nrcodes", "std_dc_chrominance_values", "YDC_HT", "UVDC_HT", "YAC_HT", "UVAC_HT", "YQT", "UVQT", "aasf", "head0", "head2" } }; var cp = new ClangParser(); var result = cp.Process(parameters); // Write output var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace StbImageWriteSharp\n{\n\t"); sb.AppendLine("unsafe partial class StbImageWrite\n\t{"); Write(result.Constants, sb); Write(result.GlobalVariables, sb); Write(result.Enums, sb); Write(result.Structs, sb); Write(result.Methods, sb); sb.Append("}\n}"); var data = sb.ToString(); // Post processing Logger.Info("Post processing..."); data = PostProcess(data); File.WriteAllText(@"..\..\..\..\..\src\StbImageWrite.Generated.cs", data); }
static void Process() { var parameters = new ConversionParameters { InputPath = @"stb_truetype.h", Defines = new[] { "STB_TRUETYPE_IMPLEMENTATION", }, SkipStructs = new string[] { }, SkipGlobalVariables = new string[] { }, SkipFunctions = new string[] { "stbtt__find_table", }, Classes = new string[] { "stbtt_pack_context", "stbtt_fontinfo", }, GlobalArrays = new string[] { }, GenerateSafeCode = false, }; var cp = new ClangParser(); var result = cp.Process(parameters); // Post processing Logger.Info("Post processing..."); var outputFiles = new Dictionary <string, string>(); Write(result.Constants, outputFiles); Write(result.GlobalVariables, outputFiles); Write(result.Enums, outputFiles); Write(result.Structs, outputFiles); Write(result.Methods, outputFiles); foreach (var pair in outputFiles) { var data = PostProcess(pair.Value); var sb = new StringBuilder(); sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now)); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Runtime.InteropServices;"); sb.AppendLine(); sb.Append("namespace StbTrueTypeSharp\n{\n\t"); sb.AppendLine("unsafe partial class StbTrueType\n\t{"); data = sb.ToString() + data; data += "}\n}"; var fileName = @"..\..\..\..\..\src\StbTrueType.Generated." + pair.Key + ".cs"; Logger.Info("Writing {0}", fileName); File.WriteAllText(fileName, data); } }
static void Process() { using (var output = new StringWriter()) { var parameters = new ConversionParameters { InputPath = @"stb_image_resize.h", Output = output, Defines = new[] { "STB_IMAGE_RESIZE_IMPLEMENTATION" }, Namespace = "StbSharp", Class = "StbImageResize", SkipStructs = new[] { "stbir__filter_info", "stbir__info", "stbir__FP32" }, SkipGlobalVariables = new[] { "stbir__filter_info_table" }, SkipFunctions = new[] { "stbir__linear_to_srgb_uchar", "stbiw__writefv", "stbiw__writef", "stbiw__outfile", "stbi_write_bmp_to_func", "stbi_write_tga_to_func", "stbi_write_hdr_to_func", "stbi_write_png_to_func", "stbi_write_hdr_core", }, Classes = new[] { "stbir__filter_info", "stbir__info" }, GlobalArrays = new[] { "stbir__type_size", "stbir__srgb_uchar_to_linear_float", "fp32_to_srgb8_tab4" } }; var cp = new ClangParser(); cp.Process(parameters); var data = output.ToString(); // Post processing Logger.Info("Post processing..."); data = Utility.ReplaceNativeCalls(data); File.WriteAllText(@"..\..\..\..\..\StbSharp\StbImageResize.Generated.cs", data); } }