tizen 2.3.1 release
[external/ragel.git] / ragel / main.cpp
index 3a5e3df..2b54b51 100644 (file)
@@ -77,7 +77,7 @@ bool machineSpecFound = false;
 bool wantDupsRemoved = true;
 
 bool printStatistics = false;
-bool frontendOnly = false;
+bool generateXML = false;
 bool generateDot = false;
 
 /* Target language and output style. */
@@ -147,7 +147,7 @@ void usage()
 void version()
 {
        cout << "Ragel State Machine Compiler version " VERSION << " " PUBDATE << endl <<
-                       "Copyright (c) 2001-2008 by Adrian Thurston" << endl;
+                       "Copyright (c) 2001-2009 by Adrian Thurston" << endl;
        exit(0);
 }
 
@@ -230,7 +230,7 @@ void processArgs( int argc, const char **argv, InputData &id )
                                break;
 
                        case 'x':
-                               frontendOnly = true;
+                               generateXML = true;
                                break;
 
                        /* Output. */
@@ -336,16 +336,17 @@ void processArgs( int argc, const char **argv, InputData &id )
                                printStatistics = true;
                                break;
                        case '-': {
-                               char *eq = strchr( pc.paramArg, '=' );
+                               char *arg = strdup( pc.paramArg );
+                               char *eq = strchr( arg, '=' );
 
                                if ( eq != 0 )
                                        *eq++ = 0;
 
-                               if ( strcmp( pc.paramArg, "help" ) == 0 )
+                               if ( strcmp( arg, "help" ) == 0 )
                                        usage();
-                               else if ( strcmp( pc.paramArg, "version" ) == 0 )
+                               else if ( strcmp( arg, "version" ) == 0 )
                                        version();
-                               else if ( strcmp( pc.paramArg, "error-format" ) == 0 ) {
+                               else if ( strcmp( arg, "error-format" ) == 0 ) {
                                        if ( eq == 0 )
                                                error() << "expecting '=value' for error-format" << endl;
                                        else if ( strcmp( eq, "gnu" ) == 0 )
@@ -355,12 +356,13 @@ void processArgs( int argc, const char **argv, InputData &id )
                                        else
                                                error() << "invalid value for error-format" << endl;
                                }
-                               else if ( strcmp( pc.paramArg, "rbx" ) == 0 )
+                               else if ( strcmp( arg, "rbx" ) == 0 )
                                        rubyImpl = Rubinius;
                                else {
                                        error() << "--" << pc.paramArg << 
                                                        " is an invalid argument" << endl;
                                }
+                               free( arg );
                                break;
                        }
 
@@ -448,6 +450,7 @@ void process( InputData &id )
        /* Make the first input item. */
        InputItem *firstInputItem = new InputItem;
        firstInputItem->type = InputItem::HostData;
+       firstInputItem->loc.fileName = id.inputFileName;
        firstInputItem->loc.line = 1;
        firstInputItem->loc.col = 1;
        id.inputItems.append( firstInputItem );
@@ -476,11 +479,17 @@ void process( InputData &id )
        id.makeOutputStream();
 
        /* Generates the reduced machine, which we use to write output. */
-       id.generateReduced();
+       if ( !generateXML ) {
+               id.generateReduced();
 
+               if ( gblErrorCount > 0 )
+                       exit(1);
+       }
+
+       id.verifyWritesHaveData();
        if ( gblErrorCount > 0 )
                exit(1);
-       
+
        /*
         * From this point on we should not be reporting any errors.
         */
@@ -491,10 +500,6 @@ void process( InputData &id )
        /* Close the input and the intermediate file. */
        delete inFile;
 
-       /* Bail on above error. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* If writing to a file, delete the ostream, causing it to flush.
         * Standard out is flushed automatically. */
        if ( id.outputFileName != 0 ) {
@@ -509,7 +514,7 @@ char *makeIntermedTemplate( const char *baseFileName )
 {
        char *result = 0;
        const char *templ = "ragel-XXXXXX.xml";
-       char *lastSlash = strrchr( baseFileName, '/' );
+       const char *lastSlash = strrchr( baseFileName, '/' );
        if ( lastSlash == 0 ) {
                result = new char[strlen(templ)+1];
                strcpy( result, templ );
@@ -530,13 +535,6 @@ int main( int argc, const char **argv )
 
        processArgs( argc, argv, id );
 
-       /* 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. */
-       if ( machineName != 0 || machineSpec != 0 ) {
-               if ( !generateDot )
-                       frontendOnly = true;
-       }
-
        /* Require an input file. If we use standard in then we won't have a file
         * name on which to base the output. */
        if ( id.inputFileName == 0 )