Removed arg passing from frontend to backend functions.
[external/ragel.git] / rlgen-java / main.cpp
index 0585ecb..06398c2 100644 (file)
@@ -44,19 +44,15 @@ using std::cerr;
 using std::endl;
 
 /* Io globals. */
-istream *inStream = 0;
-ostream *outStream = 0;
-output_filter *outFilter = 0;
-char *outputFileName = 0;
+extern istream *inStream;
+extern ostream *outStream;
+extern output_filter *outFilter;
+extern const char *outputFileName;
 
-/* Graphviz dot file generation. */
-bool graphvizDone = false;
-
-int numSplitPartitions = 0;
-bool printPrintables = false;
+extern int numSplitPartitions;
 
 /* Print a summary of the options. */
-void usage()
+void java_usage()
 {
        cout <<
 "usage: " PROGNAME " [options] file\n"
@@ -68,14 +64,14 @@ void usage()
 }
 
 /* Print version information. */
-void version()
+void java_version()
 {
        cout << "Ragel Code Generator for Java" << endl <<
                        "Version " VERSION << ", " PUBDATE << endl <<
                        "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
 }
 
-ostream &error()
+ostream &java_error()
 {
        gblErrorCount += 1;
        cerr << PROGNAME ": ";
@@ -87,10 +83,10 @@ ostream &error()
  */
 
 /* Invoked by the parser when the root element is opened. */
-ostream *openOutput( char *inputFile )
+ostream *javaOpenOutput( char *inputFile )
 {
        if ( hostLang->lang != HostLang::Java ) {
-               error() << "this code generator is for Java only" << endl;
+               java_error() << "this code generator is for Java only" << endl;
                exit(1);
        }
 
@@ -106,7 +102,7 @@ ostream *openOutput( char *inputFile )
 
        /* Make sure we are not writing to the same file as the input file. */
        if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
+               java_error() << "output file \"" << outputFileName  << 
                                "\" is the same as the input file" << endl;
        }
 
@@ -115,7 +111,7 @@ ostream *openOutput( char *inputFile )
                outFilter = new output_filter( outputFileName );
                outFilter->open( outputFileName, ios::out|ios::trunc );
                if ( !outFilter->is_open() ) {
-                       error() << "error opening " << outputFileName << " for writing" << endl;
+                       java_error() << "error opening " << outputFileName << " for writing" << endl;
                        exit(1);
                }
 
@@ -130,7 +126,7 @@ ostream *openOutput( char *inputFile )
 }
 
 /* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, 
+CodeGenData *javaMakeCodeGen( char *sourceFileName, char *fsmName, 
                ostream &out, bool wantComplete )
 {
        CodeGenData *codeGen = new JavaTabCodeGen(out);
@@ -143,84 +139,13 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName,
 }
 
 /* Main, process args and call yyparse to start scanning input. */
-int main(int argc, char **argv)
+int java_main( const char *xmlInputFileName )
 {
-       ParamCheck pc("o:vHh?-:", argc, argv);
-       char *xmlInputFileName = 0;
-
-       while ( pc.check() ) {
-               switch ( pc.state ) {
-               case ParamCheck::match:
-                       switch ( pc.parameter ) {
-                       /* Output. */
-                       case 'o':
-                               if ( *pc.paramArg == 0 )
-                                       error() << "a zero length output file name was given" << endl;
-                               else if ( outputFileName != 0 )
-                                       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':
-                               version();
-                               exit(0);
-                       case 'H': case 'h': case '?':
-                               usage();
-                               exit(0);
-                       case '-':
-                               if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       usage();
-                                       exit(0);
-                               }
-                               else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       version();
-                                       exit(0);
-                               }
-                               else {
-                                       error() << "--" << pc.paramArg << 
-                                                       " is an invalid argument" << endl;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case ParamCheck::invalid:
-                       error() << "-" << pc.parameter << " is an invalid argument" << endl;
-                       break;
-
-               case ParamCheck::noparam:
-                       if ( *pc.curArg == 0 )
-                               error() << "a zero length input file name was given" << endl;
-                       else if ( xmlInputFileName != 0 )
-                               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() )
-                       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 )