tizen 2.3.1 release
[external/ragel.git] / ragel / main.cpp
index a16a50a..2b54b51 100644 (file)
@@ -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 );
@@ -482,7 +485,11 @@ void process( InputData &id )
                if ( gblErrorCount > 0 )
                        exit(1);
        }
-       
+
+       id.verifyWritesHaveData();
+       if ( gblErrorCount > 0 )
+               exit(1);
+
        /*
         * From this point on we should not be reporting any errors.
         */
@@ -507,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 );