Пример #1
0
        private static void Main(string[] args)
        {
            // These prevent us to accidently generate wrong code because of
            // locale dependent string functions. Whether it actually affects
            // this program in particular have not been tested yet, but better
            // be safe than sorry.
            CultureInfo.CurrentCulture                = CultureInfo.InvariantCulture;
            CultureInfo.CurrentUICulture              = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(result => CLIOptions = result)
            .WithNotParsed(error => Environment.Exit(-1));

            try
            {
                XmlParser xmlParser = new GLXmlParser {
                    Prefix = CLIOptions.Prefix
                };

                var sigs = CLIOptions.InputFiles.Select(h => xmlParser.Parse(h)).ToList();

                // Merge any duplicate enum entries (in case an enum is declared
                // in multiple files with different entries in each file).
                var entries = MergeDuplicates(sigs);
                SortTokens(entries);

                var settings = new XmlWriterSettings();
                settings.Indent   = true;
                settings.Encoding = System.Text.Encoding.UTF8;

                TextWriter out_stream = null;
                if (CLIOptions.OutputFile == null)
                {
                    out_stream             = Console.Out;
                    Console.OutputEncoding = System.Text.Encoding.UTF8;
                }
                else
                {
                    out_stream = new StreamWriter(CLIOptions.OutputFile, false);
                }

                using (var writer = XmlWriter.Create(out_stream, settings))
                {
                    var output = new XElement("signatures", new XAttribute("version", "2"));
                    foreach (var api in sigs.SelectMany(s => s))
                    {
                        output.Add(
                            new XElement("add",
                                         new XAttribute("name", api.Attribute("name").Value),
                                         api.Attribute("version") != null ? new XAttribute("version", api.Attribute("version").Value) : null,
                                         api.Elements()
                                         .OrderBy(s => s.Name.LocalName)
                                         .ThenBy(s => (string)s.Attribute("value") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("name") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("version") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("extension") ?? String.Empty)
                                         ));
                    }
                    output.WriteTo(writer);
                    writer.Flush();
                    writer.Close();
                }

                out_stream.Dispose();
            }
            finally
            {
                Console.WriteLine();
                if (Debugger.IsAttached)
                {
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                bool      showHelp = false;
                string    prefix   = "gl";
                string    version  = null;
                string    path     = null;
                OptionSet opts     = new OptionSet
                {
                    { "p=", "The {PREFIX} to remove from parsed functions and constants.  " +
                      "Defaults to \"" + prefix + "\".",
                      v => prefix = v },
                    { "v:", "The {VERSION} of the specification being parsed.",
                      v => version = v },
                    { "o:", "The {PATH} to the output file.",
                      v => path = v },
                    { "?|h|help", "Show this message and exit.",
                      v => showHelp = v != null },
                };
                var headers = opts.Parse(args);
                var app     = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
                if (showHelp)
                {
                    Console.WriteLine("usage: {0} -p:PREFIX -v:VERSION SPECIFICATIONS", app);
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    opts.WriteOptionDescriptions(Console.Out);
                    Console.WriteLine();
                    Console.WriteLine("SPECIFICATIONS are the Khronos XML files to parse into OpenTK XML.");
                    return;
                }
                if (prefix == null)
                {
                    Console.WriteLine("{0}: missing required parameter -p.", app);
                    Console.WriteLine("Use '{0} --help' for usage.", app);
                    return;
                }

                Parser parser = new GLXmlParser {
                    Prefix = prefix, Version = version
                };

                var sigs = headers.Select(h => parser.Parse(h)).ToList();

                // Merge any duplicate enum entries (in case an enum is declared
                // in multiple files with different entries in each file).
                var entries = MergeDuplicates(sigs);
                SortTokens(entries);

                var settings = new XmlWriterSettings();
                settings.Indent   = true;
                settings.Encoding = System.Text.Encoding.UTF8;

                TextWriter out_stream = null;
                if (path == null)
                {
                    out_stream             = Console.Out;
                    Console.OutputEncoding = System.Text.Encoding.UTF8;
                }
                else
                {
                    out_stream = new StreamWriter(path, false);
                }

                using (var writer = XmlWriter.Create(out_stream, settings))
                {
                    var output = new XElement("signatures", new XAttribute("version", "2"));
                    foreach (var api in sigs.SelectMany(s => s))
                    {
                        output.Add(
                            new XElement("add",
                                         new XAttribute("name", api.Attribute("name").Value),
                                         api.Attribute("version") != null ? new XAttribute("version", api.Attribute("version").Value) : null,
                                         api.Elements()
                                         .OrderBy(s => s.Name.LocalName)
                                         .ThenBy(s => (string)s.Attribute("value") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("name") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("version") ?? String.Empty)
                                         .ThenBy(s => (string)s.Attribute("extension") ?? String.Empty)
                                         ));
                    }
                    output.WriteTo(writer);
                    writer.Flush();
                    writer.Close();
                }

                out_stream.Dispose();
            }
            finally
            {
                Console.WriteLine();
                if (Debugger.IsAttached)
                {
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                }
            }
        }
        private static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(result => CLIOptions = result)
            .WithNotParsed(error => Environment.Exit(-1));

            try
            {
                XmlParser xmlParser = new GLXmlParser {
                    Prefix = CLIOptions.Prefix
                };

                var sigs = CLIOptions.InputFiles.Select(h => xmlParser.Parse(h)).ToList();

                // Merge any duplicate enum entries (in case an enum is declared
                // in multiple files with different entries in each file).
                var entries = MergeDuplicates(sigs);
                SortTokens(entries);

                var settings = new XmlWriterSettings();
                settings.Indent   = true;
                settings.Encoding = Encoding.UTF8;

                TextWriter out_stream = null;
                if (CLIOptions.OutputFile == null)
                {
                    out_stream             = Console.Out;
                    Console.OutputEncoding = Encoding.UTF8;
                }
                else
                {
                    out_stream = new StreamWriter(CLIOptions.OutputFile, false);
                }

                using (var writer = XmlWriter.Create(out_stream, settings))
                {
                    var output = new XElement
                                 (
                        "signatures",
                        new XAttribute("version", "2"),
                        new XAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"),
                        new XAttribute("xsi:noNamespaceSchemaLocation", "../signatures.xsd")
                                 );

                    foreach (var api in sigs.SelectMany(s => s))
                    {
                        output.Add(
                            new XElement("add",
                                         new XAttribute("name", api.Attribute("name").Value),
                                         api.Attribute("version") != null
                                    ? new XAttribute("version", api.Attribute("version").Value)
                                    : null,
                                         api.Elements()
                                         .OrderBy(s => s.Name.LocalName)
                                         .ThenBy(s => (string)s.Attribute("value") ?? string.Empty)
                                         .ThenBy(s => (string)s.Attribute("name") ?? string.Empty)
                                         .ThenBy(s => (string)s.Attribute("version") ?? string.Empty)
                                         .ThenBy(s => (string)s.Attribute("extension") ?? string.Empty)
                                         ));
                    }

                    output.WriteTo(writer);
                    writer.Flush();
                    writer.Close();
                }

                out_stream.Dispose();
            }
            finally
            {
                Console.WriteLine();
                if (Debugger.IsAttached)
                {
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                }
            }
        }