Removed arg passing from frontend to backend functions.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 31 Aug 2008 15:45:26 +0000 (15:45 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 31 Aug 2008 15:45:26 +0000 (15:45 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@464 052ea7fc-9027-0410-9066-f65837a77df0

common/common.h
ragel/main.cpp
rlgen-cd/main.cpp
rlgen-cd/rlgen-cd.h
rlgen-csharp/main.cpp
rlgen-csharp/rlgen-csharp.h
rlgen-dot/main.cpp
rlgen-java/main.cpp
rlgen-ruby/main.cpp
rlgen-ruby/rlgen-ruby.h

index 0bda125..6fd51b9 100644 (file)
@@ -366,4 +366,24 @@ struct exit_object { };
 extern exit_object endp;
 void operator<<( std::ostream &out, exit_object & );
 
+/* Target output style. */
+enum CodeStyleEnum
+{
+       GenTables,
+       GenFTables,
+       GenFlat,
+       GenFFlat,
+       GenGoto,
+       GenFGoto,
+       GenIpGoto,
+       GenSplit
+};
+
+/* Target implementation */
+enum RubyImplEnum
+{
+       MRI,
+       Rubinius
+};
+
 #endif /* _COMMON_H */
index 6be7b67..19c6bce 100644 (file)
@@ -32,9 +32,7 @@
 #include <fcntl.h>
 #include <errno.h>
 
-#ifndef _WIN32
-#include <sys/wait.h>
-#else
+#ifdef _WIN32
 #include <windows.h>
 #include <psapi.h>
 #include <time.h>
@@ -81,10 +79,20 @@ bool printStatistics = false;
 bool frontendOnly = false;
 bool generateDot = false;
 
-ArgsVector frontendArgs;
-ArgsVector backendArgs;
+/* Target language and output style. */
+CodeStyleEnum codeStyle = GenTables;
+
+int numSplitPartitions = 0;
+bool noLineDirectives = false;
+bool displayPrintables = false;
+
+/* Target ruby impl */
+RubyImplEnum rubyImpl = MRI;
+
 ArgsVector includePaths;
 
+const char *outputFileName = 0;
+
 /* Print a summary of the options. */
 void usage()
 {
@@ -208,11 +216,12 @@ void escapeLineDirectivePath( std::ostream &out, char *path )
        }
 }
 
-void processArgs( int argc, const char **argv, 
-               const char *&inputFileName, const char *&outputFileName )
+void processArgs( int argc, const char **argv, const char *&inputFileName )
 {
        ParamCheck pc("xo:dnmleabjkS:M:I:CDJRAvHh?-:sT:F:G:P:LpV", argc, argv);
 
+       /* FIXME: Need to check code styles VS langauge. */
+
        while ( pc.check() ) {
                switch ( pc.state ) {
                case ParamCheck::match:
@@ -237,44 +246,35 @@ void processArgs( int argc, const char **argv,
                                }
                                break;
 
-                       /* Minimization, mostly hidden options. */
+                       /* Flag for turning off duplicate action removal. */
                        case 'd':
                                wantDupsRemoved = false;
-                               frontendArgs.append( "-d" );
                                break;
 
                        /* Minimization, mostly hidden options. */
                        case 'n':
                                minimizeOpt = MinimizeNone;
-                               frontendArgs.append( "-n" );
                                break;
                        case 'm':
                                minimizeOpt = MinimizeEnd;
-                               frontendArgs.append( "-m" );
                                break;
                        case 'l':
                                minimizeOpt = MinimizeMostOps;
-                               frontendArgs.append( "-l" );
                                break;
                        case 'e':
                                minimizeOpt = MinimizeEveryOp;
-                               frontendArgs.append( "-e" );
                                break;
                        case 'a':
                                minimizeLevel = MinimizeApprox;
-                               frontendArgs.append( "-a" );
                                break;
                        case 'b':
                                minimizeLevel = MinimizeStable;
-                               frontendArgs.append( "-b" );
                                break;
                        case 'j':
                                minimizeLevel = MinimizePartition1;
-                               frontendArgs.append( "-j" );
                                break;
                        case 'k':
                                minimizeLevel = MinimizePartition2;
-                               frontendArgs.append( "-k" );
                                break;
 
                        /* Machine spec. */
@@ -286,8 +286,6 @@ void processArgs( int argc, const char **argv,
                                else {
                                        /* Ok, remember the path to the machine to generate. */
                                        machineSpec = pc.paramArg;
-                                       frontendArgs.append( "-S" );
-                                       frontendArgs.append( pc.paramArg );
                                }
                                break;
 
@@ -300,8 +298,6 @@ void processArgs( int argc, const char **argv,
                                else {
                                        /* Ok, remember the machine name to generate. */
                                        machineName = pc.paramArg;
-                                       frontendArgs.append( "-M" );
-                                       frontendArgs.append( pc.paramArg );
                                }
                                break;
 
@@ -310,31 +306,24 @@ void processArgs( int argc, const char **argv,
                                        error() << "please specify an argument to -I" << endl;
                                else {
                                        includePaths.append( pc.paramArg );
-                                       frontendArgs.append( "-I" );
-                                       frontendArgs.append( pc.paramArg );
                                }
                                break;
 
                        /* Host language types. */
                        case 'C':
                                hostLang = &hostLangC;
-                               frontendArgs.append( "-C" );
                                break;
                        case 'D':
                                hostLang = &hostLangD;
-                               frontendArgs.append( "-D" );
                                break;
                        case 'J':
                                hostLang = &hostLangJava;
-                               frontendArgs.append( "-J" );
                                break;
                        case 'R':
                                hostLang = &hostLangRuby;
-                               frontendArgs.append( "-R" );
                                break;
                        case 'A':
                                hostLang = &hostLangCSharp;
-                               frontendArgs.append( "-A" );
                                break;
 
                        /* Version and help. */
@@ -346,7 +335,6 @@ void processArgs( int argc, const char **argv,
                                break;
                        case 's':
                                printStatistics = true;
-                               frontendArgs.append( "-s" );
                                break;
                        case '-': {
                                char *eq = strchr( pc.paramArg, '=' );
@@ -361,20 +349,15 @@ void processArgs( int argc, const char **argv,
                                else if ( strcmp( pc.paramArg, "error-format" ) == 0 ) {
                                        if ( eq == 0 )
                                                error() << "expecting '=value' for error-format" << endl;
-                                       else if ( strcmp( eq, "gnu" ) == 0 ) {
+                                       else if ( strcmp( eq, "gnu" ) == 0 )
                                                errorFormat = ErrorFormatGNU;
-                                               frontendArgs.append( "--error-format=gnu" );
-                                       }
-                                       else if ( strcmp( eq, "msvc" ) == 0 ) {
+                                       else if ( strcmp( eq, "msvc" ) == 0 )
                                                errorFormat = ErrorFormatMSVC;
-                                               frontendArgs.append( "--error-format=msvc" );
-                                       }
-                                       else {
+                                       else
                                                error() << "invalid value for error-format" << endl;
-                                       }
                                }
                                else if ( strcmp( pc.paramArg, "rbx" ) == 0 )
-                                       backendArgs.append( "--rbx" );
+                                       rubyImpl = Rubinius;
                                else {
                                        error() << "--" << pc.paramArg << 
                                                        " is an invalid argument" << endl;
@@ -384,26 +367,51 @@ void processArgs( int argc, const char **argv,
 
                        /* Passthrough args. */
                        case 'T': 
-                               backendArgs.append( "-T" );
-                               backendArgs.append( pc.paramArg );
+                               if ( pc.paramArg[0] == '0' )
+                                       codeStyle = GenTables;
+                               else if ( pc.paramArg[0] == '1' )
+                                       codeStyle = GenFTables;
+                               else {
+                                       error() << "-T" << pc.paramArg[0] << 
+                                                       " is an invalid argument" << endl;
+                                       exit(1);
+                               }
                                break;
                        case 'F': 
-                               backendArgs.append( "-F" );
-                               backendArgs.append( pc.paramArg );
+                               if ( pc.paramArg[0] == '0' )
+                                       codeStyle = GenFlat;
+                               else if ( pc.paramArg[0] == '1' )
+                                       codeStyle = GenFFlat;
+                               else {
+                                       error() << "-F" << pc.paramArg[0] << 
+                                                       " is an invalid argument" << endl;
+                                       exit(1);
+                               }
                                break;
                        case 'G': 
-                               backendArgs.append( "-G" );
-                               backendArgs.append( pc.paramArg );
+                               if ( pc.paramArg[0] == '0' )
+                                       codeStyle = GenGoto;
+                               else if ( pc.paramArg[0] == '1' )
+                                       codeStyle = GenFGoto;
+                               else if ( pc.paramArg[0] == '2' )
+                                       codeStyle = GenIpGoto;
+                               else {
+                                       error() << "-G" << pc.paramArg[0] << 
+                                                       " is an invalid argument" << endl;
+                                       exit(1);
+                               }
                                break;
                        case 'P':
-                               backendArgs.append( "-P" );
-                               backendArgs.append( pc.paramArg );
+                               codeStyle = GenSplit;
+                               numSplitPartitions = atoi( pc.paramArg );
                                break;
+
                        case 'p':
-                               backendArgs.append( "-p" );
+                               displayPrintables = true;
                                break;
+
                        case 'L':
-                               backendArgs.append( "-L" );
+                               noLineDirectives = true;
                                break;
                        }
                        break;
@@ -427,7 +435,7 @@ void processArgs( int argc, const char **argv,
        }
 }
 
-int frontend( const char *inputFileName, const char *outputFileName )
+int frontend( const char *inputFileName, const char *intermed )
 {
        /* Open the input file for reading. */
        assert( inputFileName != 0 );
@@ -462,18 +470,13 @@ int frontend( const char *inputFileName, const char *outputFileName )
        if ( gblErrorCount > 0 )
                return 1;
        
-       ostream *outputFile = 0;
-       if ( outputFileName != 0 )
-               outputFile = new ofstream( outputFileName );
-       else
-               outputFile = &cout;
+       ostream *outputFile = new ofstream( intermed );
 
        /* Write the machines, then the surrounding code. */
        writeMachines( *outputFile, hostData.str(), inputFileName );
 
        /* Close the intermediate file. */
-       if ( outputFileName != 0 )
-               delete outputFile;
+       delete outputFile;
 
        return gblErrorCount > 0;
 }
@@ -545,240 +548,41 @@ void cleanExit( const char *intermed, int status )
        exit( status );
 }
 
-#ifndef _WIN32
-
-/* If any forward slash is found in argv0 then it is assumed that the path is
- * explicit and the path to the backend executable should be derived from
- * that. Whe check that location and also go up one then inside a directory of
- * the same name in case we are executing from the source tree. If no forward
- * slash is found it is assumed the file is being run from the installed
- * location. The PREFIX supplied during configuration is used. */
-char **makePathChecksUnix( const char *argv0, const char *progName )
-{
-       char **result = new char*[3];
-       const char *lastSlash = strrchr( argv0, '/' );
-       int numChecks = 0;
-
-       if ( lastSlash != 0 ) {
-               char *path = strdup( argv0 );
-               int givenPathLen = (lastSlash - argv0) + 1;
-               path[givenPathLen] = 0;
-
-               int progNameLen = strlen(progName);
-               int length = givenPathLen + progNameLen + 1;
-               char *check = new char[length];
-               sprintf( check, "%s%s", path, progName );
-               result[numChecks++] = check;
-
-               length = givenPathLen + 3 + progNameLen + 1 + progNameLen + 1;
-               check = new char[length];
-               sprintf( check, "%s../%s/%s", path, progName, progName );
-               result[numChecks++] = check;
-       }
-       else {
-               int prefixLen = strlen(PREFIX);
-               int progNameLen = strlen(progName);
-               int length = prefixLen + 5 + progNameLen + 1;
-               char *check = new char[length];
-
-               sprintf( check, PREFIX "/bin/%s", progName );
-               result[numChecks++] = check;
-       }
-
-       result[numChecks] = 0;
-       return result;
-}
-
-int main(int argc, const char **argv);
-int cd_main(int argc, const char **argv);
-int java_main(int argc, const char **argv);
-int ruby_main(int argc, const char **argv);
-int csharp_main(int argc, const char **argv);
-int dot_main(int argc, const char **argv);
-
+int cd_main( const char *xmlInputFileName );
+int java_main( const char *xmlInputFileName );
+int ruby_main( const char *xmlInputFileName );
+int csharp_main( const char *xmlInputFileName );
+int dot_main( const char *xmlInputFileName );
 
-void forkAndExec( const char *progName, char **pathChecks, 
-               ArgsVector &args, const char *intermed )
-{
-#if 0
-       pid_t pid = fork();
-       if ( pid < 0 ) {
-               /* Error, no child created. */
-               error() << "failed to fork for " << progName << endl;
-               cleanExit( intermed, 1 );
-       }
-       else if ( pid == 0 ) {
-               /* child */
-               while ( *pathChecks != 0 ) {
-                       /* Execv does not modify argv, it just uses the const form that is
-                        * compatible with the most code. Ours not included. */
-                       execv( *pathChecks, (char *const*) args.data );
-                       pathChecks += 1;
-               }
-               error() << "failed to exec " << progName << endl;
-               cleanExit( intermed, 1 );
-       }
-#endif
-
-       if ( strcmp( progName, "ragel" ) == 0 )
-               main( args.length()-1, args.data );
-       else if ( strcmp( progName, "rlgen-cd" ) == 0 )
-               cd_main( args.length()-1, args.data );
-       else if ( strcmp( progName, "rlgen-java" ) == 0 )
-               java_main( args.length()-1, args.data );
-       else if ( strcmp( progName, "rlgen-ruby" ) == 0 )
-               ruby_main( args.length()-1, args.data );
-       else if ( strcmp( progName, "rlgen-csharp" ) == 0 )
-               csharp_main( args.length()-1, args.data );
-       else if ( strcmp( progName, "rlgen-dot" ) == 0 )
-               dot_main( args.length()-1, args.data );
-
-#if 0
-       /* Parent process, wait for the child. */
-       int status;
-       wait( &status );
-
-       /* What happened with the child. */
-       if ( ! WIFEXITED( status ) ) {
-               error() << progName << " did not exit normally" << endl;
-               cleanExit( intermed, 1 );
-       }
-       
-       if ( WEXITSTATUS(status) != 0 )
-               cleanExit( intermed, WEXITSTATUS(status) );
-#endif
-}
-
-#else
-
-/* GetModuleFileNameEx is used to find out where the the current process's
- * binary is. That location is searched first. If that fails then we go up one
- * directory and look for the executable inside a directory of the same name
- * in case we are executing from the source tree.
- * */
-char **makePathChecksWin( const char *progName )
-{
-       int len = 1024;
-       char *imageFileName = new char[len];
-       HANDLE h = GetCurrentProcess();
-       len = GetModuleFileNameEx( h, NULL, imageFileName, len );
-       imageFileName[len] = 0;
-
-       char **result = new char*[3];
-       const char *lastSlash = strrchr( imageFileName, '\\' );
-       int numChecks = 0;
-
-       assert( lastSlash != 0 );
-       char *path = strdup( imageFileName );
-       int givenPathLen = (lastSlash - imageFileName) + 1;
-       path[givenPathLen] = 0;
-
-       int progNameLen = strlen(progName);
-       int length = givenPathLen + progNameLen + 1;
-       char *check = new char[length];
-       sprintf( check, "%s%s", path, progName );
-       result[numChecks++] = check;
-
-       length = givenPathLen + 3 + progNameLen + 1 + progNameLen + 1;
-       check = new char[length];
-       sprintf( check, "%s..\\%s\\%s", path, progName, progName );
-       result[numChecks++] = check;
-
-       result[numChecks] = 0;
-       return result;
-}
-
-void spawn( const char *progName, char **pathChecks, 
-               ArgsVector &args, char *intermed )
-{
-       int result = 0;
-       while ( *pathChecks != 0 ) {
-               //cerr << "trying to execute " << *pathChecks << endl;
-               result = _spawnv( _P_WAIT, *pathChecks, args.data );
-               if ( result >= 0 || errno != ENOENT )
-                       break;
-               pathChecks += 1;
-       }
-
-       if ( result < 0 ) {
-               error() << "failed to spawn " << progName << endl;
-               cleanExit( intermed, 1 );
-       }
-
-       if ( result > 0 )
-               cleanExit( intermed, 1 );
-}
-
-#endif
-
-void execFrontend( const char *argv0, const char *inputFileName, const char *intermed )
-{
-       /* The frontend program name. */
-       const char *progName = "ragel";
-
-       frontendArgs.insert( 0, progName );
-       frontendArgs.insert( 1, "-x" );
-       frontendArgs.append( "-o" );
-       frontendArgs.append( intermed );
-       frontendArgs.append( inputFileName );
-       frontendArgs.append( 0 );
-
-#ifndef _WIN32
-       char **pathChecks = makePathChecksUnix( argv0, progName );
-       forkAndExec( progName, pathChecks, frontendArgs, intermed );
-#else
-       char **pathChecks = makePathChecksWin( progName );
-       spawn( progName, pathChecks, frontendArgs, intermed );
-#endif
-}
-
-void execBackend( const char *argv0, const char *intermed, const char *outputFileName )
+void backend( const char *intermed )
 {
        /* Locate the backend program */
-       const char *progName = 0;
        if ( generateDot )
-               progName = "rlgen-dot";
+               dot_main( intermed );
        else {
                switch ( hostLang->lang ) {
                        case HostLang::C:
                        case HostLang::D:
-                               progName = "rlgen-cd";
+                               cd_main( intermed );
                                break;
                        case HostLang::Java:
-                               progName = "rlgen-java";
+                               java_main( intermed );
                                break;
                        case HostLang::Ruby:
-                               progName = "rlgen-ruby";
+                               ruby_main( intermed );
                                break;
                        case HostLang::CSharp:
-                               progName = "rlgen-csharp";
+                               csharp_main( intermed );
+                               break;
                }
        }
-
-       backendArgs.insert( 0, progName );
-       if ( outputFileName != 0 ) {
-               backendArgs.append( "-o" );
-               backendArgs.append( outputFileName );
-       }
-       backendArgs.append( intermed );
-       backendArgs.append( 0 );
-
-#ifndef _WIN32
-       char **pathChecks = makePathChecksUnix( argv0, progName );
-       forkAndExec( progName, pathChecks, backendArgs, intermed );
-#else
-       char **pathChecks = makePathChecksWin( progName );
-       spawn( progName, pathChecks, backendArgs, intermed );
-#endif
 }
 
 /* Main, process args and call yyparse to start scanning input. */
-int main(int argc, const char **argv)
+int main( int argc, const char **argv )
 {
        const char *inputFileName = 0;
-       const char *outputFileName = 0;
-
-       processArgs( argc, argv, inputFileName, outputFileName );
+       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. */
@@ -806,7 +610,7 @@ int main(int argc, const char **argv)
 
        const char *intermed = openIntermed( inputFileName, outputFileName );
        frontend( inputFileName, intermed );
-       execBackend( argv[0], intermed, outputFileName );
+       backend( intermed );
 
        /* Clean up the intermediate. */
        cleanExit( intermed, 0 );
index 4de2bce..a389afd 100644 (file)
@@ -53,20 +53,19 @@ using std::cerr;
 using std::endl;
 
 /* Target language and output style. */
-CodeStyleEnum codeStyle = GenTables;
+extern CodeStyleEnum codeStyle;
 
 /* Io globals. */
 istream *inStream = 0;
 ostream *outStream = 0;
 output_filter *outFilter = 0;
-const char *outputFileName = 0;
+extern const char *outputFileName;
 
 /* Graphviz dot file generation. */
 bool graphvizDone = false;
 
-int numSplitPartitions = 0;
-bool noLineDirectives = false;
-bool printPrintables = false;
+extern int numSplitPartitions;
+extern bool noLineDirectives;
 
 /* Print a summary of the options. */
 void cd_usage()
@@ -235,129 +234,13 @@ CodeGenData *cdMakeCodeGen( char *sourceFileName, char *fsmName,
 }
 
 /* Main, process args and call yyparse to start scanning input. */
-int cd_main(int argc, const char **argv)
+int cd_main( const char *xmlInputFileName )
 {
-       ParamCheck pc("-:Hh?vLo:T:F:G:P:", argc, argv);
-       const char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       cd_error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       cd_error() << "more than one output file name was given" << endl;
-                               else {
-                                       /* Ok, remember the output file name. */
-                                       outputFileName = pc.paramArg;
-                               }
-                               break;
-
-                       case 'L':
-                               noLineDirectives = true;
-                               break;
-
-                       /* Code style. */
-                       case 'T':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenTables;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFTables;
-                               else {
-                                       cd_error() << "-T" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'F':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenFlat;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFFlat;
-                               else {
-                                       cd_error() << "-F" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'G':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenGoto;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFGoto;
-                               else if ( pc.paramArg[0] == '2' )
-                                       codeStyle = GenIpGoto;
-                               else {
-                                       cd_error() << "-G" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'P':
-                               codeStyle = GenSplit;
-                               numSplitPartitions = atoi( pc.paramArg );
-                               break;
-
-                       /* Version and help. */
-                       case 'v':
-                               cd_version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               cd_usage();
-                               exit(0);
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       cd_usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       cd_version();
-                                       exit(0);
-                               }
-                               else {
-                                       cd_error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       cd_error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               cd_error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               cd_error() << "more than one input file name was given" << endl;
-                       else {
-                               /* OK, Remember the filename. */
-                               xmlInputFileName = pc.curArg;
-                       }
-                       break;
-               }
-       }
-
-       /* Bail on above errors. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* Open the input file for reading. */
-       if ( xmlInputFileName != 0 ) {
-               /* Open the input file for reading. */
-               ifstream *inFile = new ifstream( xmlInputFileName );
-               inStream = inFile;
-               if ( ! inFile->is_open() )
-                       cd_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-       }
-       else {
-               xmlInputFileName = strdup("<stdin>");
-               inStream = &cin;
-       }
+       ifstream *inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               cd_error() << "could not open " << xmlInputFileName << " for reading" << endl;
 
        /* Bail on above errors. */
        if ( gblErrorCount > 0 )
index 30fe11f..9d280f2 100644 (file)
 #include "avltree.h"
 #include "vector.h"
 #include "config.h"
+#include "common.h"
 
 #define PROGNAME "rlgen-cd"
 
-/* Target output style. */
-enum CodeStyleEnum
-{
-       GenTables,
-       GenFTables,
-       GenFlat,
-       GenFFlat,
-       GenGoto,
-       GenFGoto,
-       GenIpGoto,
-       GenSplit
-};
-
 extern CodeStyleEnum codeStyle;
 
-
 /* IO filenames and stream. */
 extern bool graphvizDone;
 
index ab2dc1c..1c67390 100644 (file)
@@ -66,7 +66,6 @@ extern bool graphvizDone;
 
 extern int numSplitPartitions;
 extern bool noLineDirectives;
-extern bool printPrintables;
 
 /* Print a summary of the options. */
 void csharp_usage()
@@ -191,133 +190,14 @@ CodeGenData *csharpMakeCodeGen( char *sourceFileName, char *fsmName,
        return codeGen;
 }
 
-
-
 /* Main, process args and call yyparse to start scanning input. */
-int csharp_main(int argc, const char **argv)
+int csharp_main( const char *xmlInputFileName )
 {
-//     ParamCheck pc("-:Hh?vLo:T:F:G:P:", argc, argv);
-       ParamCheck pc("-:Hh?vLo:T:F:G:", argc, argv);
-       const char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       csharp_error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       csharp_error() << "more than one output file name was given" << endl;
-                               else {
-                                       /* Ok, remember the output file name. */
-                                       outputFileName = pc.paramArg;
-                               }
-                               break;
-
-                       case 'L':
-                               noLineDirectives = true;
-                               break;
-
-                       /* Code style. */
-                       case 'T':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenTables;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFTables;
-                               else {
-                                       csharp_error() << "-T" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'F':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenFlat;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFFlat;
-                               else {
-                                       csharp_error() << "-F" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'G':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenGoto;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFGoto;
-                               else if ( pc.paramArg[0] == '2' )
-                                       codeStyle = GenIpGoto;
-                               else {
-                                       csharp_error() << "-G" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'P':
-                               codeStyle = GenSplit;
-                               numSplitPartitions = atoi( pc.paramArg );
-                               break;
-
-                       /* Version and help. */
-                       case 'v':
-                               csharp_version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               csharp_usage();
-                               exit(0);
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       csharp_usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       csharp_version();
-                                       exit(0);
-                               }
-                               else {
-                                       csharp_error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       csharp_error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               csharp_error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               csharp_error() << "more than one input file name was given" << endl;
-                       else {
-                               /* OK, Remember the filename. */
-                               xmlInputFileName = pc.curArg;
-                       }
-                       break;
-               }
-       }
-
-       /* Bail on above errors. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* Open the input file for reading. */
-       if ( xmlInputFileName != 0 ) {
-               /* Open the input file for reading. */
-               ifstream *inFile = new ifstream( xmlInputFileName );
-               inStream = inFile;
-               if ( ! inFile->is_open() )
-                       csharp_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-       }
-       else {
-               xmlInputFileName = strdup("<stdin>");
-               inStream = &cin;
-       }
+       ifstream *inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               csharp_error() << "could not open " << xmlInputFileName << " for reading" << endl;
 
        /* Bail on above errors. */
        if ( gblErrorCount > 0 )
index 1e26229..21899c4 100644 (file)
 #include "avltree.h"
 #include "vector.h"
 #include "config.h"
+#include "common.h"
 
 #define PROGNAME "rlgen-csharp"
 
-/* Target output style. */
-enum CodeStyleEnum
-{
-       GenTables,
-       GenFTables,
-       GenFlat,
-       GenFFlat,
-       GenGoto,
-       GenFGoto,
-       GenIpGoto,
-       GenSplit
-};
-
 extern CodeStyleEnum codeStyle;
 
 
index d0c01cb..d2f19d8 100644 (file)
@@ -51,9 +51,9 @@ extern const char *outputFileName;
 
 /* Graphviz dot file generation. */
 extern bool graphvizDone;
+extern bool displayPrintables;
 
 extern int numSplitPartitions;
-bool displayPrintables = false;
 
 /* Print a summary of the options. */
 void dot_usage()
@@ -131,88 +131,13 @@ CodeGenData *dotMakeCodeGen( char *sourceFileName, char *fsmName,
 
 
 /* Main, process args and call yyparse to start scanning input. */
-int dot_main(int argc, const char **argv)
+int dot_main( const char *xmlInputFileName )
 {
-       ParamCheck pc("o:pvHh?-:", argc, argv);
-       const char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       dot_error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       dot_error() << "more than one output file name was given" << endl;
-                               else {
-                                       /* Ok, remember the output file name. */
-                                       outputFileName = pc.paramArg;
-                               }
-                               break;
-
-                       case 'p':
-                               displayPrintables = true;
-                               break;
-
-                       /* Version and help. */
-                       case 'v':
-                               dot_version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               dot_usage();
-                               exit(0);
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       dot_usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       dot_version();
-                                       exit(0);
-                               }
-                               else {
-                                       dot_error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       dot_error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               dot_error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               dot_error() << "more than one input file name was given" << endl;
-                       else {
-                               /* OK, Remember the filename. */
-                               xmlInputFileName = pc.curArg;
-                       }
-                       break;
-               }
-       }
-
-       /* Bail on above errors. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* Open the input file for reading. */
-       if ( xmlInputFileName != 0 ) {
-               /* Open the input file for reading. */
-               ifstream *inFile = new ifstream( xmlInputFileName );
-               inStream = inFile;
-               if ( ! inFile->is_open() )
-                       dot_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-       }
-       else {
-               xmlInputFileName = strdup("<stdin>");
-               inStream = &cin;
-       }
+       ifstream *inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               dot_error() << "could not open " << xmlInputFileName << " for reading" << endl;
 
        /* Bail on above errors. */
        if ( gblErrorCount > 0 )
index 9294a52..06398c2 100644 (file)
@@ -50,7 +50,6 @@ extern output_filter *outFilter;
 extern const char *outputFileName;
 
 extern int numSplitPartitions;
-extern bool printPrintables;
 
 /* Print a summary of the options. */
 void java_usage()
@@ -140,84 +139,13 @@ CodeGenData *javaMakeCodeGen( char *sourceFileName, char *fsmName,
 }
 
 /* Main, process args and call yyparse to start scanning input. */
-int java_main(int argc, const char **argv)
+int java_main( const char *xmlInputFileName )
 {
-       ParamCheck pc("o:vHh?-:", argc, argv);
-       const char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       java_error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       java_error() << "more than one output file name was given" << endl;
-                               else {
-                                       /* Ok, remember the output file name. */
-                                       outputFileName = pc.paramArg;
-                               }
-                               break;
-
-                       /* Version and help. */
-                       case 'v':
-                               java_version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               java_usage();
-                               exit(0);
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       java_usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       java_version();
-                                       exit(0);
-                               }
-                               else {
-                                       java_error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       java_error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               java_error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               java_error() << "more than one input file name was given" << endl;
-                       else {
-                               /* OK, Remember the filename. */
-                               xmlInputFileName = pc.curArg;
-                       }
-                       break;
-               }
-       }
-
-       /* Bail on above errors. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* Open the input file for reading. */
-       if ( xmlInputFileName != 0 ) {
-               /* Open the input file for reading. */
-               ifstream *inFile = new ifstream( xmlInputFileName );
-               inStream = inFile;
-               if ( ! inFile->is_open() )
-                       java_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-       }
-       else {
-               xmlInputFileName = strdup("<stdin>");
-               inStream = &cin;
-       }
+       ifstream *inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               java_error() << "could not open " << xmlInputFileName << " for reading" << endl;
 
        /* Bail on above errors. */
        if ( gblErrorCount > 0 )
index 1e50d9f..7e89968 100644 (file)
@@ -49,7 +49,7 @@ using std::cerr;
 using std::endl;
 
 /* Target ruby impl */
-RubyImplEnum rubyImpl = MRI;
+extern RubyImplEnum rubyImpl;
 
 /* Target language and output style. */
 extern CodeStyleEnum codeStyle;
@@ -64,7 +64,6 @@ extern const char *outputFileName;
 extern bool graphvizDone;
 
 extern int numSplitPartitions;
-extern bool printPrintables;
 
 /* Print a summary of the options. */
 void ruby_usage()
@@ -190,128 +189,13 @@ CodeGenData *rubyMakeCodeGen( char *sourceFileName, char *fsmName,
 }
 
 /* Main, process args and call yyparse to start scanning input. */
-int ruby_main(int argc, const char **argv)
+int ruby_main( const char *xmlInputFileName )
 {
-       ParamCheck pc("-:Hlh?vo:T:F:G:P:", argc, argv);
-       const char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       ruby_error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       ruby_error() << "more than one output file name was given" << endl;
-                               else {
-                                       /* Ok, remember the output file name. */
-                                       outputFileName = pc.paramArg;
-                               }
-                               break;
-
-                       /* Code style. */
-                       case 'T':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenTables;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFTables;
-                               else {
-                                       ruby_error() << "-T" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'F':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenFlat;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFFlat;
-                               else {
-                                       ruby_error() << "-F" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'G':
-                               if ( pc.paramArg[0] == '0' )
-                                       codeStyle = GenGoto;
-                               else if ( pc.paramArg[0] == '1' )
-                                       codeStyle = GenFGoto;
-                               else if ( pc.paramArg[0] == '2' )
-                                       codeStyle = GenIpGoto;
-                               else {
-                                       ruby_error() << "-G" << pc.paramArg[0] << 
-                                                       " is an invalid argument" << endl;
-                                       exit(1);
-                               }
-                               break;
-                       case 'P':
-                               codeStyle = GenSplit;
-                               numSplitPartitions = atoi( pc.paramArg );
-                               break;
-
-                       /* Version and help. */
-                       case 'v':
-                               ruby_version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               ruby_usage();
-                               exit(0);
-
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       ruby_usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       ruby_version();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "rbx") == 0 ) {
-                                       rubyImpl = Rubinius;
-                               }
-                               else {
-                                       ruby_error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       ruby_error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               ruby_error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               ruby_error() << "more than one input file name was given" << endl;
-                       else {
-                               /* OK, Remember the filename. */
-                               xmlInputFileName = pc.curArg;
-                       }
-                       break;
-               }
-       }
-
-       /* Bail on above errors. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* Open the input file for reading. */
-       if ( xmlInputFileName != 0 ) {
-               /* Open the input file for reading. */
-               ifstream *inFile = new ifstream( xmlInputFileName );
-               inStream = inFile;
-               if ( ! inFile->is_open() )
-                       ruby_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-       }
-       else {
-               xmlInputFileName = strdup("<stdin>");
-               inStream = &cin;
-       }
+       ifstream *inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               ruby_error() << "could not open " << xmlInputFileName << " for reading" << endl;
 
        /* Bail on above errors. */
        if ( gblErrorCount > 0 )
index 7b5c21c..5756459 100644 (file)
 
 #include <iostream>
 #include "config.h"
+#include "common.h"
 
 #define PROGNAME "rlgen-ruby"
 
-/* Target implementation */
-enum RubyImplEnum
-{
-  MRI,
-  Rubinius
-};
-
 extern RubyImplEnum rubyImpl;
-
-/* Target output style. */
-enum CodeStyleEnum
-{
-       GenTables,
-       GenFTables,
-       GenFlat,
-       GenFFlat,
-       GenGoto,
-       GenFGoto,
-       GenIpGoto,
-       GenSplit
-
-};
-
 extern CodeStyleEnum codeStyle;
 
 extern int gblErrorCount;