Now supplying the XmlParser to writeMachines.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 1 Sep 2008 23:31:52 +0000 (23:31 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 1 Sep 2008 23:31:52 +0000 (23:31 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@468 052ea7fc-9027-0410-9066-f65837a77df0

ragel/main.cpp
ragel/parsedata.cpp
ragel/ragel.h

index 5261ff1..1e7ccc0 100644 (file)
@@ -443,10 +443,13 @@ void processArgs( int argc, const char **argv, const char *&inputFileName )
 
 void process( const char *inputFileName, const char *intermed )
 {
+       const char *xmlFileName = intermed;
+       bool wantComplete = true;
+       bool outputActive = true;
+
        /* Open the input file for reading. */
        assert( inputFileName != 0 );
        ifstream *inFile = new ifstream( inputFileName );
-       istream *inStream = inFile;
        if ( ! inFile->is_open() )
                error() << "could not open " << inputFileName << " for reading" << endp;
 
@@ -456,7 +459,7 @@ void process( const char *inputFileName, const char *intermed )
        if ( machineSpec == 0 && machineName == 0 )
                hostData << "<host line=\"1\" col=\"1\">";
 
-       Scanner scanner( inputFileName, *inStream, hostData, 0, 0, 0, false );
+       Scanner scanner( inputFileName, *inFile, hostData, 0, 0, 0, false );
        scanner.do_scan();
 
        /* Finished, final check for errors.. */
@@ -476,29 +479,13 @@ void process( const char *inputFileName, const char *intermed )
        if ( gblErrorCount > 0 )
                exit(1);
        
-       ostream *outputFile = new ofstream( intermed );
+       /* Open the XML file for writing. */
+       ostream *xmlOutFile = new ofstream( xmlFileName );
 
-       /* Write the machines, then the surrounding code. */
-       writeMachines( *outputFile, hostData.str(), inputFileName );
-
-       /* Close the input and the intermediate file. */
-       delete outputFile;
-       delete inFile;
-
-       /* Bail on above error. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
-       const char *xmlInputFileName = intermed;
-
-       bool wantComplete = true;
-       bool outputActive = true;
-
-       /* Open the input file for reading. */
-       inFile = new ifstream( xmlInputFileName );
-       inStream = inFile;
-       if ( ! inFile->is_open() )
-               error() << "could not open " << xmlInputFileName << " for reading" << endl;
+       /* Open the XML file for reading. */
+       ifstream *xmlInFile = new ifstream( xmlFileName );
+       if ( ! xmlInFile->is_open() )
+               error() << "could not open " << xmlFileName << " for reading" << endl;
 
        /* Bail on above error. */
        if ( gblErrorCount > 0 )
@@ -510,11 +497,22 @@ void process( const char *inputFileName, const char *intermed )
                outputActive = false;
        }
 
-       XmlScanner xmlScanner( xmlInputFileName, *inStream );
-       XmlParser xmlParser( xmlInputFileName, outputActive, wantComplete );
+       XmlScanner xmlScanner( xmlFileName, *xmlInFile );
+       XmlParser xmlParser( xmlFileName, outputActive, wantComplete );
        xmlParser.init();
 
-       xml_parse( *inStream, xmlInputFileName, 
+       /* Write the machines, then the surrounding code. */
+       writeMachines( *xmlOutFile, hostData.str(), inputFileName, xmlParser );
+
+       /* Close the input and the intermediate file. */
+       delete xmlOutFile;
+       delete inFile;
+
+       /* Bail on above error. */
+       if ( gblErrorCount > 0 )
+               exit(1);
+
+       xml_parse( *xmlInFile, xmlFileName, 
                outputActive, wantComplete,
                xmlScanner, xmlParser );
 
index 8d862cd..73f52c6 100644 (file)
@@ -1470,7 +1470,8 @@ void writeLanguage( std::ostream &out )
        
 }
 
-void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName )
+void writeMachines( std::ostream &out, std::string hostData, 
+               const char *inputFileName, XmlParser &xmlParser )
 {
        if ( machineSpec == 0 && machineName == 0 ) {
                /* No machine spec or machine name given. Generate everything. */
index 125ceb7..cf5951b 100644 (file)
@@ -80,8 +80,11 @@ std::ostream &error();
 std::ostream &error( const InputLoc &loc ); 
 std::ostream &warning( const InputLoc &loc ); 
 
+struct XmlParser;
+
 void terminateAllParsers( );
-void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName );
+void writeMachines( std::ostream &out, std::string hostData, 
+       const char *inputFileName, XmlParser &xmlParser );
 void xmlEscapeHost( std::ostream &out, char *data, long len );
 
 typedef Vector<const char *> ArgsVector;