From: Tim R. <ti...@us...> - 2004-08-05 15:05:38
|
Update of /cvsroot/csdopenglnet/csdOpenGL/generator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7767 Modified Files: Makefile generator.cs Added Files: config.cs Log Message: The generator is now configured by an XML file. This is more flexible and easier than by command line Index: generator.cs =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/generator/generator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** generator.cs 5 Aug 2004 13:09:15 -0000 1.2 --- generator.cs 5 Aug 2004 15:05:28 -0000 1.3 *************** *** 4,7 **** --- 4,8 ---- using System.IO; using System.Xml; + using System.Xml.Serialization; namespace csDragons { *************** *** 14,40 **** */ public class Generator { - - /** \brief library to be wrapped - * - * The attribute linkLibrary holds the name of the library which should be wrapped. - * All external calls are linked to this library. - */ - protected string linkLibrary = ""; - /** \brief name of created class. - * - * The attribute className holds the name of the new class. - */ - protected string className = ""; - /** \brief name of upper class. - * - * The attribute upperClase is the class from which the new class heirs. - */ - protected string upperClass = ""; - /** \brief name XML source file - * - * The attribute xmlInput holds the name of the input file. - * This files must be an XML-file created with Doygen. - */ - protected string xmlInput = ""; /** \brief reader for parsing xml file * --- 15,18 ---- *************** *** 42,50 **** */ protected XmlTextReader reader; - /** \brief target file - * - * The attribute outputFile holds the name of the target file. - */ - protected string outputFile; /** \brief Define-Compiler. * --- 20,23 ---- *************** *** 67,78 **** */ protected StreamWriter writer; - /** \brief XML input files for additional typedefs. - * - * This attrbute holds the names of input files for additional typedef statements. - * This files must be an XML-file created with Doygen. - */ - protected ArrayList typedefFiles; ! protected bool onlyFunctions = false; /** \brief The constructor Generator is the main entry point. --- 40,47 ---- */ protected StreamWriter writer; ! protected Configuration config; ! ! /** \brief The constructor Generator is the main entry point. *************** *** 85,109 **** Debug.WriteLine( "Entering Generator.Generator(string[])" ); ! if (args.Length>=5) { ! ! xmlInput = args[0]; ! linkLibrary = args[1]; ! className = args[2]; ! upperClass = args[3]; ! outputFile = args[4]; ! typedefFiles = new ArrayList(); ! for ( int i=5; i<args.Length; i++ ) { ! typedefFiles.Add( args[i] ); } ! createClass(); ! } else { ! Console.WriteLine( "Illegale parameter count!" ); ! Console.WriteLine( "Usage: csdGenerator.exe xmlInput linkLibrary className outputFile" ); ! Console.WriteLine(); ! Console.WriteLine( " xmlInput: XML-representation of header file generated by Doxygen" ); ! Console.WriteLine( " linkLibrary: library which shall be target of PInvoke" ); ! Console.WriteLine( " className: name of the generated C# wrapper class" ); ! Console.WriteLine( " outputFile: name of output file" ); ! } Debug.WriteLine( "Exiting Generator.Generator(string[])" ); --- 54,68 ---- Debug.WriteLine( "Entering Generator.Generator(string[])" ); ! if (args.Length==1) { ! if (args[0] == "--createConfig") { ! Debug.WriteLine( "Writing sample configuration" ); ! config = new Configuration(); ! saveConfig( "generator.xml" ); ! } else { ! Debug.WriteLine( "Loading Configuration" ); ! loadConfig( args[0] ); ! createClass(); } ! } Debug.WriteLine( "Exiting Generator.Generator(string[])" ); *************** *** 119,127 **** Debug.WriteLine( "Entering Generator.createClass()" ); ! FileStream fs = new FileStream( outputFile, FileMode.Create, FileAccess.Write ); // Open or create file with write access writer = new StreamWriter( fs ); // bind stream to file define = new Define( writer ); // initialize define compiler typedef = new TypeDef( writer ); // initialize typedef compiler ! function = new Function( writer, typedef, linkLibrary ); // initiaize function compiler writeHeader(); // write file header --- 78,86 ---- Debug.WriteLine( "Entering Generator.createClass()" ); ! FileStream fs = new FileStream( config.outputFile, FileMode.Create, FileAccess.Write ); // Open or create file with write access writer = new StreamWriter( fs ); // bind stream to file define = new Define( writer ); // initialize define compiler typedef = new TypeDef( writer ); // initialize typedef compiler ! function = new Function( writer, typedef, config.linkLibrary ); // initiaize function compiler writeHeader(); // write file header *************** *** 131,138 **** try { Debug.WriteLine( "Initializing XmlTestReader" ); ! reader = new XmlTextReader( xmlInput ); } catch (Exception e) { Debug.WriteLine( "***** " + e.ToString() ); ! Console.WriteLine( "Error Opening inputfile '"+xmlInput+"'" ); } --- 90,97 ---- try { Debug.WriteLine( "Initializing XmlTestReader" ); ! reader = new XmlTextReader( config.xmlInput ); } catch (Exception e) { Debug.WriteLine( "***** " + e.ToString() ); ! Console.WriteLine( "Error Opening inputfile '"+config.xmlInput+"'" ); } *************** *** 150,160 **** protected void loadTypeDefs() { ! for ( int i=0; i<typedefFiles.Count; i++ ) { try { Debug.WriteLine( "Initializing XmlTestReader" ); ! reader = new XmlTextReader( (string)typedefFiles[i] ); } catch (Exception e) { Debug.WriteLine( "***** " + e.ToString() ); ! Console.WriteLine( "Error Opening inputfile '"+(string)typedefFiles[i]+"'" ); } --- 109,119 ---- protected void loadTypeDefs() { ! for ( int i=0; i<config.typedefFiles.Count; i++ ) { try { Debug.WriteLine( "Initializing XmlTestReader" ); ! reader = new XmlTextReader( (string)config.typedefFiles[i] ); } catch (Exception e) { Debug.WriteLine( "***** " + e.ToString() ); ! Console.WriteLine( "Error Opening inputfile '"+(string)config.typedefFiles[i]+"'" ); } *************** *** 163,167 **** Console.Write( "Laoding typedef statements in " ); ! Console.WriteLine( (string)typedefFiles[i] ); while (!reader.EOF) { // read hole xml file reader.Read(); --- 122,126 ---- Console.Write( "Laoding typedef statements in " ); ! Console.WriteLine( (string)config.typedefFiles[i] ); while (!reader.EOF) { // read hole xml file reader.Read(); *************** *** 219,231 **** function.process(); // pre-processing ! if (!onlyFunctions) { writer.WriteLine( "\n // constant definitions" ); define.write(); // write defines writer.WriteLine( "\n // delegates" ); typedef.write(); } ! ! writer.WriteLine( "\n // functions" ); ! function.write(); // write functions Debug.WriteLine( "Exiting Generater.compile()" ); --- 178,193 ---- function.process(); // pre-processing ! if (config.writeDefines) { writer.WriteLine( "\n // constant definitions" ); define.write(); // write defines + } + if (config.writeDelegates) { writer.WriteLine( "\n // delegates" ); typedef.write(); } ! if (config.writeFunctions) { ! writer.WriteLine( "\n // functions" ); ! function.write(); // write functions ! } Debug.WriteLine( "Exiting Generater.compile()" ); *************** *** 248,254 **** // class header writer.Write( "public class " ); ! writer.Write( className ); writer.Write( " : " ); ! writer.Write( upperClass ); writer.WriteLine( " {" ); --- 210,216 ---- // class header writer.Write( "public class " ); ! writer.Write( config.className ); writer.Write( " : " ); ! writer.Write( config.upperClass ); writer.WriteLine( " {" ); *************** *** 271,275 **** --- 233,271 ---- Debug.Unindent(); } + + protected void saveConfig( string file ) { + Debug.Indent(); + Debug.WriteLine( "Entering Generator.saveConfig()" ); + + try { // try, because of I/O-failure. + XmlSerializer serializer = new XmlSerializer( typeof(Configuration) ); // initializing serializer object + StreamWriter writer = new StreamWriter( file ); // initalizing stream + serializer.Serialize( writer, config ); // save configuration + writer.Close(); + } catch (Exception e) { + Debug.WriteLine( e.Message ); + } + + Debug.WriteLine( "Exiting Generator.saveConfig()" ); + Debug.Unindent(); + } + protected void loadConfig( string fileName ) { + Debug.Indent(); + Debug.WriteLine( "Entering Configuration.loadConfig()" ); + + try { // try, because of I/O-failure + XmlSerializer serializer = new XmlSerializer( typeof(Configuration) ); // initialize seriaizer object + FileStream stream = new FileStream( fileName, FileMode.Open ); // create file stream + config = (Configuration) serializer.Deserialize( stream ); // load configuration + stream.Close(); + } catch (Exception e) { + Debug.WriteLine( e.Message ); + } + + Debug.WriteLine( "Exiting Configuration.loadConfig()" ); + Debug.Unindent(); + } + /** \brief entry point * --- NEW FILE: config.cs --- using System.Collections; namespace csDragons { namespace OpenGL { namespace WrapperGenerator { public class Configuration { /** \brief name XML source file * * The attribute xmlInput holds the name of the input file. * This files must be an XML-file created with Doygen. */ public string xmlInput; /** \brief library to be wrapped * * The attribute linkLibrary holds the name of the library which should be wrapped. * All external calls are linked to this library. */ public string linkLibrary; /** \brief name of created class. * * The attribute className holds the name of the new class. */ public string className; /** \brief name of upper class. * * The attribute upperClase is the class from which the new class heirs. */ public string upperClass; /** \brief target file * * The attribute outputFile holds the name of the target file. */ public string outputFile; public bool writeFunctions; public bool writeDelegates; public bool writeDefines; /** \brief basetypes which should not be replaced */ [System.Xml.Serialization.XmlArray("BaseTypes")] [System.Xml.Serialization.XmlArrayItem("Type",typeof(string))] public ArrayList baseTypes; /** \brief XML input files for additional typedefs. * * This attrbute holds the names of input files for additional typedef statements. * This files must be an XML-file created with Doygen. */ [System.Xml.Serialization.XmlArray("TypeDefs")] [System.Xml.Serialization.XmlArrayItem("File",typeof(string))] public ArrayList typedefFiles; public Configuration() { xmlInput = "XML"; linkLibrary = "library"; className = "Class"; upperClass = "Super"; outputFile = "target"; baseTypes = new ArrayList(); baseTypes.Add( "Typ" ); typedefFiles = new ArrayList(); typedefFiles.Add( "File" ); } } } } } Index: Makefile =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/generator/Makefile,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile 5 Aug 2004 13:09:15 -0000 1.9 --- Makefile 5 Aug 2004 15:05:28 -0000 1.10 *************** *** 1,3 **** ! FILES=generator.cs AssemblyInfo.cs define.cs typedef.cs function.cs CC=mcs --- 1,3 ---- ! FILES=generator.cs AssemblyInfo.cs define.cs typedef.cs function.cs config.cs CC=mcs |