mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
Add utility to automatically generate a static class with tags definitions from a C header
This commit is contained in:
parent
a97db534ed
commit
31a1bb9ca2
4 changed files with 97 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
TARGETS = gst-gapi-fixup.exe
|
TARGETS = gst-gapi-fixup.exe gst-generate-tags.exe
|
||||||
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
@ -6,11 +6,16 @@ all: $(TARGETS)
|
||||||
gst-gapi-fixup.exe: $(srcdir)/gst-gapi-fixup.cs
|
gst-gapi-fixup.exe: $(srcdir)/gst-gapi-fixup.cs
|
||||||
$(CSC) -out:$@ $(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)
|
noinst_SCRIPTS = $(TARGETS)
|
||||||
|
|
||||||
CLEANFILES = $(TARGETS) $(DEBUGS)
|
CLEANFILES = $(TARGETS) $(DEBUGS)
|
||||||
MAINTAINERCLEANFILES = Makefile.in
|
MAINTAINERCLEANFILES = Makefile.in
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
gst-gapi-fixup.cs
|
gst-gapi-fixup.cs \
|
||||||
|
gst-generate-tags.cs
|
||||||
|
|
||||||
|
|
85
parser/gst-generate-tags.cs
Normal file
85
parser/gst-generate-tags.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,5 +2,9 @@ MAINTAINERCLEANFILES = Makefile.in
|
||||||
|
|
||||||
api:
|
api:
|
||||||
$(GAPI_PARSER) gstreamer-sharp-source.xml
|
$(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
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<dir>../../gstreamer/gst</dir>
|
<dir>../../gstreamer/gst</dir>
|
||||||
<!-- Needs to be bound -->
|
<!-- Needs to be bound -->
|
||||||
<exclude>../../gstreamer/gst/gstdebugutils.h</exclude>
|
<exclude>../../gstreamer/gst/gstdebugutils.h</exclude>
|
||||||
<exclude>../../gstreamer/gst/gsterror.h</exclude>
|
|
||||||
<exclude>../../gstreamer/gst/gstinfo.h</exclude>
|
<exclude>../../gstreamer/gst/gstinfo.h</exclude>
|
||||||
<exclude>../../gstreamer/gst/gstinterface.h</exclude>
|
<exclude>../../gstreamer/gst/gstinterface.h</exclude>
|
||||||
<exclude>../../gstreamer/gst/gsturi.h</exclude>
|
<exclude>../../gstreamer/gst/gsturi.h</exclude>
|
||||||
|
|
Loading…
Reference in a new issue