A bit more cleanup.
[external/ragel.git] / ragel / main.cpp
index 98123ca..120fae7 100644 (file)
@@ -55,6 +55,7 @@
 #include "version.h"
 #include "common.h"
 #include "xmlparse.h"
+#include "inputdata.h"
 
 using std::istream;
 using std::ostream;
@@ -124,8 +125,8 @@ void usage()
 "   -x                   Run the frontend only: emit XML intermediate format\n"
 "   -V                   Generate a dot file for Graphviz\n"
 "   -p                   Display printable characters on labels\n"
-"   -S <spec>            FSM specification to output (for rlgen-dot)\n"
-"   -M <machine>         Machine definition/instantiation to output (for rlgen-dot)\n"
+"   -S <spec>            FSM specification to output (for graphviz output)\n"
+"   -M <machine>         Machine definition/instantiation to output (for graphviz output)\n"
 "host language:\n"
 "   -C                   The host language is C, C++, Obj-C or Obj-C++ (default)\n"
 "   -D                   The host language is D\n"
@@ -441,9 +442,8 @@ void processArgs( int argc, const char **argv, const char *&inputFileName )
        }
 }
 
-void process( const char *inputFileName, const char *intermed )
+void process( const char *inputFileName )
 {
-       const char *xmlFileName = intermed;
        bool wantComplete = true;
        bool outputActive = true;
 
@@ -487,8 +487,24 @@ void process( const char *inputFileName, const char *intermed )
                outputActive = false;
        }
 
-       /* Write the machines, then the surrounding code. */
-       generateReduced( inputFileName, xmlFileName, outputActive, wantComplete );
+       InputData inputData( inputFileName, outputActive, wantComplete );
+
+       /* Compiles machines. */
+       inputData.prepareMachineGen();
+
+       if ( gblErrorCount > 0 )
+               exit(1);
+
+       inputData.openOutput();
+
+       /* Generates the reduced machine, which we use to write output. */
+       inputData.generateReduced();
+
+       if ( gblErrorCount > 0 )
+               exit(1);
+
+       inputData.openOutput2();
+       inputData.writeOutput();
 
        /* Close the input and the intermediate file. */
        delete inFile;
@@ -574,17 +590,13 @@ const char *openIntermed( const char *inputFileName, const char *outputFileName
 }
 
 
-void cleanExit( const char *intermed, int status )
-{
-       //unlink( intermed );
-       exit( status );
-}
 
 /* Main, process args and call yyparse to start scanning input. */
 int main( int argc, const char **argv )
 {
        const char *inputFileName = 0;
        processArgs( argc, argv, inputFileName );
+       
 
        /* If -M or -S are given and we're not generating a dot file then invoke
         * the frontend. These options are not useful with code generators. */
@@ -610,11 +622,10 @@ int main( int argc, const char **argv )
                                "\" is the same as the input file" << endp;
        }
 
-       const char *intermed = 0; //openIntermed( inputFileName, outputFileName );
-       process( inputFileName, intermed );
+       process( inputFileName );
 
        /* Clean up the intermediate. */
-       cleanExit( intermed, 0 );
+       exit( 0 );
 
        return 0;
 }