From 31a1bb9ca209cc554704597d05bbb4b6aa99141f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 17 Apr 2009 16:41:00 +0200 Subject: [PATCH] Add utility to automatically generate a static class with tags definitions from a C header --- parser/Makefile.am | 9 +++- parser/gst-generate-tags.cs | 85 +++++++++++++++++++++++++++++++ source/Makefile.am | 6 ++- source/gstreamer-sharp-source.xml | 1 - 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 parser/gst-generate-tags.cs diff --git a/parser/Makefile.am b/parser/Makefile.am index 55738c4a2a..d7f6acbbbc 100644 --- a/parser/Makefile.am +++ b/parser/Makefile.am @@ -1,4 +1,4 @@ -TARGETS = gst-gapi-fixup.exe +TARGETS = gst-gapi-fixup.exe gst-generate-tags.exe DEBUGS = $(addsuffix .mdb, $(TARGETS)) all: $(TARGETS) @@ -6,11 +6,16 @@ all: $(TARGETS) gst-gapi-fixup.exe: $(srcdir)/gst-gapi-fixup.cs $(CSC) -out:$@ $(srcdir)/gst-gapi-fixup.cs +gst-generate-tags.exe: $(srcdir)/gst-generate-tags.cs + $(CSC) -out:$@ $(srcdir)/gst-generate-tags.cs + + noinst_SCRIPTS = $(TARGETS) CLEANFILES = $(TARGETS) $(DEBUGS) MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = \ - gst-gapi-fixup.cs + gst-gapi-fixup.cs \ + gst-generate-tags.cs diff --git a/parser/gst-generate-tags.cs b/parser/gst-generate-tags.cs new file mode 100644 index 0000000000..2591f93c2c --- /dev/null +++ b/parser/gst-generate-tags.cs @@ -0,0 +1,85 @@ +using System; +using System.IO; + +public class GenerateTags { + public static int Main (string[] args) { + if (args.Length != 3) { + Console.WriteLine ("usage: gst-generate-tags --header= --namespace= --class="); + return 1; + } + + StreamReader header = null; + string ns = "Gst"; + string cls = "Tags"; + + foreach (string arg in args) { + + if (arg.StartsWith ("--header=")) { + + string filename = arg.Substring (9); + + try { + header = new StreamReader (filename); + } catch (Exception e) { + Console.WriteLine ("Invalid header file."); + Console.WriteLine (e); + return 2; + } + } else if (arg.StartsWith ("--namespace=")) { + ns = arg.Substring (12); + } else if (arg.StartsWith ("--class=")) { + cls = arg.Substring (8); + } else { + Console.WriteLine ("Invalid argument '" + arg + "'"); + return 3; + } + } + + Console.WriteLine ("namespace " + ns + " {"); + Console.WriteLine ("\tpublic static class " + cls + " {"); + + string line; + while ( (line = header.ReadLine ()) != null) { + if (!line.StartsWith ("#define GST_TAG_")) + continue; + + string tag_name = line.Substring (16); + string tag_string = tag_name.Substring (tag_name.IndexOf (' ')); + tag_name = tag_name.Substring (0, tag_name.IndexOf (' ')); + if (tag_name.IndexOf ('(') != -1) + continue; + + /* FIXME: This is not exactly optimal */ + tag_name = tag_name.ToLower (); + string tag_tmp = new String (new char[] {tag_name[0]}).ToUpper (); + for (int i = 1; i < tag_name.Length; i++) { + if (tag_name[i-1] == '_') { + tag_tmp += (new String (new char[] {tag_name[i]})).ToUpper (); + } else { + tag_tmp += (new String (new char[] {tag_name[i]})); + } + } + tag_name = tag_tmp; + tag_name = tag_name.Replace ("_", String.Empty); + + tag_string = tag_string.Trim (); + if (tag_string.IndexOf (' ') != -1) + tag_string = tag_string.Substring (0, tag_string.IndexOf (' ')); + tag_string = tag_string.Trim (); + if (tag_string[0] != '"' || tag_string[tag_string.Length-1] != '"') { + Console.WriteLine ("Parse error"); + return 4; + } + tag_string = tag_string.Substring (1, tag_string.Length - 2); + + Console.WriteLine ("\t\t public const string " + tag_name + " = \"" + tag_string + "\";"); + + + } + + Console.WriteLine ("\t}"); + Console.WriteLine ("}"); + + return 0; + } +} diff --git a/source/Makefile.am b/source/Makefile.am index fb2746228b..50fee98208 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -2,5 +2,9 @@ MAINTAINERCLEANFILES = Makefile.in api: $(GAPI_PARSER) gstreamer-sharp-source.xml - + $(MONO) $(top_builddir)/parser/gst-generate-tags.exe \ + --header=../../gstreamer/gst/gsttaglist.h \ + --namespace=Gst \ + --class=Tags \ + > $(top_srcdir)/gstreamer-sharp/Tags.cs diff --git a/source/gstreamer-sharp-source.xml b/source/gstreamer-sharp-source.xml index f19bb2b641..17bad99754 100644 --- a/source/gstreamer-sharp-source.xml +++ b/source/gstreamer-sharp-source.xml @@ -5,7 +5,6 @@ ../../gstreamer/gst ../../gstreamer/gst/gstdebugutils.h - ../../gstreamer/gst/gsterror.h ../../gstreamer/gst/gstinfo.h ../../gstreamer/gst/gstinterface.h ../../gstreamer/gst/gsturi.h