diff --git a/ChangeLog b/ChangeLog index b2431fbaa..0b3288a36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-04-15 Mike Kestner + + * parser/gapi-parser.cs : C# rewrite of the old perl driver script. + * parser/gapi_parser.pl : kill. + * parser/gapi2-parser.in : invoke via $(RUNTIME). + * parser/Makefile.am : build rework for C# parser driver. + * sources/Makefile.am : use $(RUNTIME) to invoke new parser assm. + 2005-04-12 Mike Kestner * configure.in : bump version to 1.9.3 and tag. diff --git a/parser/Makefile.am b/parser/Makefile.am index 613f331f7..409a678c7 100644 --- a/parser/Makefile.am +++ b/parser/Makefile.am @@ -1,28 +1,29 @@ assemblydir = $(libdir)/gtk-sharp-2.0 pkgconfigdir = $(libdir)/pkgconfig -assembly_DATA = gapi-fixup.exe +assembly_DATA = gapi-fixup.exe gapi-parser.exe pkgconfig_DATA = gapi-2.0.pc bin_SCRIPTS = gapi2-fixup gapi2-parser -assembly_SCRIPTS = gapi_parser.pl gapi_pp.pl gapi2xml.pl +assembly_SCRIPTS = gapi_pp.pl gapi2xml.pl CLEANFILES = gapi-fixup.exe DISTCLEANFILES = gapi2-fixup gapi2-parser gapi-2.0.pc sources = \ - gapi-fixup.cs - -build_sources = $(addprefix $(srcdir)/, $(sources)) + gapi-fixup.cs \ + gapi-parser.cs EXTRA_DIST = \ makefile.win32 \ $(sources) \ gapi2-parser.in \ - gapi_parser.pl \ gapi_pp.pl \ gapi2xml.pl \ gapi-2.0.pc.in -gapi-fixup.exe: $(build_sources) - $(CSC) /out:gapi-fixup.exe $(build_sources) +gapi-fixup.exe: $(srcdir)/gapi-fixup.cs + $(CSC) /out:gapi-fixup.exe $(srcdir)/gapi-fixup.cs + +gapi-parser.exe: $(srcdir)/gapi-parser.cs + $(CSC) /out:gapi-parser.exe $(srcdir)/gapi-parser.cs INCLUDES = $(GLIB_CFLAGS) $(XML_CFLAGS) diff --git a/parser/gapi-parser.cs b/parser/gapi-parser.cs new file mode 100644 index 000000000..9cac71d44 --- /dev/null +++ b/parser/gapi-parser.cs @@ -0,0 +1,143 @@ +// gapi-parser.cs - parsing driver application. +// +// Author: Mike Kestner +// +// Copyright (c) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +namespace GtkSharp.Parsing { + + using System; + using System.Collections; + using System.IO; + using System.Runtime.InteropServices; + using System.Xml; + + public class Parser { + + [DllImport ("libc")] + static extern int system (string command); + + public static int Main (string[] args) + { + if (args.Length != 1) { + Console.WriteLine ("Usage: gapi2-parser "); + return 0; + } + + XmlDocument src_doc = new XmlDocument (); + + try { + using (Stream stream = File.OpenRead (args [0])) + src_doc.Load (stream); + } catch (XmlException e) { + Console.WriteLine ("Couldn't open source file."); + Console.WriteLine (e); + return 1; + } + + XmlNode root = src_doc.DocumentElement; + if (root.Name != "gapi-parser-input") { + Console.WriteLine ("Improperly formatted input file: " + args [0]); + return 1; + } + + foreach (XmlNode apinode in root.ChildNodes) { + if (apinode.Name != "api") + continue; + + string outfile = (apinode as XmlElement).GetAttribute ("filename"); + string prefile = outfile + ".pre"; + + if (File.Exists (prefile)) + File.Delete (prefile); + + foreach (XmlNode libnode in apinode.ChildNodes) { + if (libnode.Name != "library") + continue; + + string lib = (libnode as XmlElement).GetAttribute ("name"); + + foreach (XmlNode nsnode in libnode.ChildNodes) { + if (nsnode.Name != "namespace") + continue; + + string ns = (nsnode as XmlElement).GetAttribute ("name"); + + ArrayList files = new ArrayList (); + Hashtable excludes = new Hashtable (); + + foreach (XmlNode srcnode in nsnode.ChildNodes) { + if (!(srcnode is XmlElement)) + continue; + + XmlElement elem = srcnode as XmlElement; + + switch (srcnode.Name) { + case "dir": + string dir = elem.InnerXml; + Console.Write (" ", dir); + DirectoryInfo di = new DirectoryInfo (dir); + foreach (FileInfo file in di.GetFiles ("*.c")) + files.Add (dir + Path.DirectorySeparatorChar + file.Name); + foreach (FileInfo file in di.GetFiles ("*.h")) + files.Add (dir + Path.DirectorySeparatorChar + file.Name); + break; + case "file": + string incfile = elem.InnerXml; + Console.Write (" ", incfile); + files.Add (incfile); + break; + case "exclude": + string excfile = elem.InnerXml; + Console.Write (" ", excfile); + excludes [excfile] = 1; + break; + default: + Console.WriteLine ("Invalid source: " + srcnode.Name); + break; + } + + } + + Console.WriteLine (); + + if (files.Count == 0) + continue; + + ArrayList realfiles = new ArrayList (); + foreach (string file in files) { + string trimfile = file.TrimEnd (); + if (excludes.Contains (trimfile)) + continue; + + realfiles.Add (trimfile); + } + + string[] filenames = (string[]) realfiles.ToArray (typeof (string)); + string pp_args = String.Join (" ", filenames); + system ("gapi_pp.pl " + pp_args + " | gapi2xml.pl " + ns + " " + prefile + " " + lib); + } + } + + system ("gapi_format_xml " + prefile + " " + outfile); + File.Delete (prefile); + } + + return 0; + } + } +} diff --git a/parser/gapi2-parser.in b/parser/gapi2-parser.in index 842bf028c..25e54ca38 100755 --- a/parser/gapi2-parser.in +++ b/parser/gapi2-parser.in @@ -1,3 +1,3 @@ #!/bin/sh export PATH=@prefix@/lib/gtk-sharp-2.0:$PATH -@prefix@/lib/gtk-sharp-2.0/gapi_parser.pl "$@" +@RUNTIME@ @prefix@/lib/gtk-sharp-2.0/gapi-parser.exe "$@" diff --git a/parser/gapi_parser.pl b/parser/gapi_parser.pl deleted file mode 100755 index c1dbea0ff..000000000 --- a/parser/gapi_parser.pl +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/perl -w -# gapi-parser - parser frontend for XML-based sources file format. -# -# Author: Mike Kestner -# -# Copyright (c) 2003 Mike Kestner -# Copyright (c) 2003 Novell, Inc. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of version 2 of the GNU General Public -# License as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -use XML::LibXML; - -die "Usage: gapi-parser \n" if (!$ARGV[0]); - -my $parser = new XML::LibXML; -my $doc = $parser->parse_file($ARGV[0]); -die "Unable to parse input file $ARGV[0].\n" if (!$doc); -my $root = $doc->documentElement; -die "Improperly formatted input file $ARGV[0].\n" if (!$root || $root->nodeName ne "gapi-parser-input"); - -for ($apinode = $root->firstChild; $apinode; $apinode = $apinode->nextSibling ()) { - next if ($apinode->nodeName ne "api"); - @attrs = $apinode->attributes; - my $outfile = ""; - foreach $attr (@attrs) { - if ($attr->name eq "filename") { - $outfile = $attr->value; - } else { - die "Unexpected attribute $attr->name\n"; - } - } - - unlink "$outfile.pre"; - - for ($libnode = $apinode->firstChild; $libnode; $libnode = $libnode->nextSibling ()) { - next if ($libnode->nodeName ne "library"); - @attrs = $libnode->attributes; - my ($lib); - foreach $attr (@attrs) { - if ($attr->name eq "name") { - $lib = $attr->value; - } else { - die "Unexpected attribute $attr->name\n"; - } - } - - for ($nsnode = $libnode->firstChild; $nsnode; $nsnode = $nsnode->nextSibling ()) { - next if ($nsnode->nodeName ne "namespace"); - @attrs = $nsnode->attributes; - my ($ns); - foreach $attr (@attrs) { - if ($attr->name eq "name") { - $ns = $attr->value; - } else { - die "Unexpected attribute $attr->name\n"; - } - } - - my @files = (); - my @realfiles = (); - my %excludes = (); - for ($srcnode = $nsnode->firstChild; $srcnode; $srcnode = $srcnode->nextSibling ()) { - next if ($srcnode->nodeName ne "dir" && $srcnode->nodeName ne "file" && $srcnode->nodeName ne "exclude"); - - if ($srcnode->nodeName eq "dir") { - my ($dir); - $dir = $srcnode->firstChild->nodeValue; - print " "; - @files = (@files, `ls $dir/*.c`); - @files = (@files, `ls $dir/*.h`); - } elsif ($srcnode->nodeName eq "file") { - $incfile = $srcnode->firstChild->nodeValue; - print " "; - @files = (@files, $srcnode->firstChild->nodeValue); - } elsif ($srcnode->nodeName eq "exclude") { - $excfile = $srcnode->firstChild->nodeValue; - print " "; - $excludes{$srcnode->firstChild->nodeValue} = 1; - } else { - die "Unexpected source $srcnode->nodeName \n"; - } - - } - print "\n"; - if ($#files >= 0) { - foreach $file (@files) { - chomp ($file); - @realfiles = (@realfiles, $file) if (!exists($excludes{$file})); - } - - $pp_args = join (" ", @realfiles); - system ("gapi_pp.pl $pp_args | gapi2xml.pl $ns $outfile.pre $lib"); - } - } - } - - system ("gapi_format_xml $outfile.pre $outfile"); - unlink "$outfile.pre"; -} - diff --git a/sources/Makefile.am b/sources/Makefile.am index 99eb71ad9..a2c27dcce 100644 --- a/sources/Makefile.am +++ b/sources/Makefile.am @@ -37,7 +37,7 @@ GTKHTML_SOURCEFILES = \ gtkhtml-3.0.10/src/gtkhtml-stream.h api: - PATH=../parser:$$PATH ../parser/gapi_parser.pl gtk-sharp-sources.xml + PATH=../parser:$$PATH $(RUNTIME) ../parser/gapi-parser.exe gtk-sharp-sources.xml get-gtkhtml-code: wget http://ftp.gnome.org/pub/GNOME/sources/gtkhtml/3.0/gtkhtml-3.0.10.tar.gz --output-document=- | tar -xz $(GTKHTML_SOURCEFILES)