Add utility to automatically generate a static class with tags definitions from a...
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 17 Apr 2009 14:41:00 +0000 (16:41 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 17 Apr 2009 14:41:00 +0000 (16:41 +0200)
parser/Makefile.am
parser/gst-generate-tags.cs [new file with mode: 0644]
source/Makefile.am
source/gstreamer-sharp-source.xml

index 55738c4..d7f6acb 100644 (file)
@@ -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 (file)
index 0000000..2591f93
--- /dev/null
@@ -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=<filename> --namespace=<namespace> --class=<name>");
+      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;
+  }
+}
index fb27462..50fee98 100644 (file)
@@ -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
 
index f19bb2b..17bad99 100644 (file)
@@ -5,7 +5,6 @@
         <dir>../../gstreamer/gst</dir>
         <!-- Needs to be bound -->
         <exclude>../../gstreamer/gst/gstdebugutils.h</exclude>
-        <exclude>../../gstreamer/gst/gsterror.h</exclude>
         <exclude>../../gstreamer/gst/gstinfo.h</exclude>
         <exclude>../../gstreamer/gst/gstinterface.h</exclude>
         <exclude>../../gstreamer/gst/gsturi.h</exclude>