Dot output working again.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 30 Aug 2008 23:34:42 +0000 (23:34 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 30 Aug 2008 23:34:42 +0000 (23:34 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@463 052ea7fc-9027-0410-9066-f65837a77df0

Makefile.in
ragel/Makefile.in
ragel/main.cpp
ragel/ragel.h
redfsm/gendata.h
redfsm/xmlparse.kl
rlgen-dot/Makefile.in
rlgen-dot/gvdotgen.cpp
rlgen-dot/gvdotgen.h
rlgen-dot/main.cpp

index 1324f37..2666c48 100644 (file)
@@ -18,7 +18,7 @@
 #   along with Ragel; if not, write to the Free Software
 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
-BUILD_COMMON = common redfsm rlgen-cd rlgen-java rlgen-ruby rlgen-csharp
+BUILD_COMMON = common redfsm rlgen-cd rlgen-java rlgen-ruby rlgen-csharp rlgen-dot
 BUILD_SUBDIRS = ragel 
 ALL_SUBDIRS = $(BUILD_COMMON) $(BUILD_SUBDIRS) test examples doc
 
index 018283f..4185933 100644 (file)
@@ -36,6 +36,7 @@ RAGEL_LIBS = ../common/common.a \
        ../rlgen-java/rlgen-java.a \
        ../rlgen-ruby/rlgen-ruby.a \
        ../rlgen-csharp/rlgen-csharp.a \
+       ../rlgen-dot/rlgen-dot.a \
        ../redfsm/redfsm.a 
 
 LIBS = $(RAGEL_LIBS)
index 6e539ba..6be7b67 100644 (file)
@@ -594,6 +594,7 @@ 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);
 
 
 void forkAndExec( const char *progName, char **pathChecks, 
@@ -629,6 +630,8 @@ void forkAndExec( const char *progName, char **pathChecks,
                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. */
index 942f3d2..125ceb7 100644 (file)
@@ -52,6 +52,7 @@ extern MinimizeOpt minimizeOpt;
 extern const char *machineSpec, *machineName;
 extern bool printStatistics;
 extern bool wantDupsRemoved;
+extern bool generateDot;
 
 /* Error reporting format. */
 enum ErrorFormat {
index 7c68c6e..b9ab577 100644 (file)
@@ -29,6 +29,8 @@
 
 using std::ostream;
 
+extern bool generateDot;
+
 struct NameInst;
 typedef DList<Action> ActionList;
 
@@ -52,6 +54,7 @@ std::ostream *cdOpenOutput( char *inputFile );
 std::ostream *javaOpenOutput( char *inputFile );
 std::ostream *rubyOpenOutput( char *inputFile );
 std::ostream *csharpOpenOutput( char *inputFile );
+std::ostream *dotOpenOutput( char *inputFile );
 
 CodeGenData *cdMakeCodeGen( char *sourceFileName, 
                char *fsmName, ostream &out, bool wantComplete );
@@ -61,6 +64,8 @@ CodeGenData *rubyMakeCodeGen( char *sourceFileName,
                char *fsmName, ostream &out, bool wantComplete );
 CodeGenData *csharpMakeCodeGen( char *sourceFileName, 
                char *fsmName, ostream &out, bool wantComplete );
+CodeGenData *dotMakeCodeGen( char *sourceFileName, 
+               char *fsmName, ostream &out, bool wantComplete );
 
 void cdLineDirective( ostream &out, const char *fileName, int line );
 void javaLineDirective( ostream &out, const char *fileName, int line );
index cd4d69d..967f6ef 100644 (file)
@@ -40,7 +40,9 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName,
                ostream &out, bool wantComplete )
 {
        CodeGenData *cgd = 0;
-       if ( hostLang == &hostLangC )
+       if ( generateDot )
+               cgd = dotMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangC )
                cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
        else if ( hostLang == &hostLangD )
                cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
@@ -56,16 +58,18 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName,
 void lineDirective( ostream &out, const char *fileName, int line )
 {
        CodeGenData *cgd = 0;
-       if ( hostLang == &hostLangC )
-               cdLineDirective( out, fileName, line );
-       else if ( hostLang == &hostLangD )
-               cdLineDirective( out, fileName, line );
-       else if ( hostLang == &hostLangJava )
-               javaLineDirective( out, fileName, line );
-       else if ( hostLang == &hostLangRuby )
-               rubyLineDirective( out, fileName, line );
-       else if ( hostLang == &hostLangCSharp )
-               csharpLineDirective( out, fileName, line );
+       if ( !generateDot ) {
+               if ( hostLang == &hostLangC )
+                       cdLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangD )
+                       cdLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangJava )
+                       javaLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangRuby )
+                       rubyLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangCSharp )
+                       csharpLineDirective( out, fileName, line );
+       }
 }
 
 void genLineDirective( ostream &out )
@@ -112,7 +116,9 @@ tag_ragel_head: TAG_ragel
                if ( langAttr == 0 )
                        error($1->loc) << "tag <ragel> requires a lang attribute" << endp;
 
-               if ( strcmp( langAttr->value, "C" ) == 0 ) {
+               if ( generateDot )
+                       outStream = dotOpenOutput( sourceFileName );
+               else if ( strcmp( langAttr->value, "C" ) == 0 ) {
                        hostLang = &hostLangC;
                        outStream = cdOpenOutput( sourceFileName );
                }
index 9e7972d..3f7b7f6 100644 (file)
@@ -32,8 +32,10 @@ LIBS = ../common/common.a ../redfsm/redfsm.a
 #*************************************
 
 prefix = @prefix@
-CXX = @CXX@
 EXEEXT = @EXEEXT@
+CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
 
 # Get objects and dependencies from sources.
 OBJS = $(CC_SRCS:%.cpp=%.o)
@@ -43,10 +45,11 @@ DEPS = $(CC_SRCS:%.cpp=.%.d)
 include ../version.mk
 
 # Rules.
-all: rlgen-dot$(EXEEXT)
+all: rlgen-dot.a
 
-rlgen-dot$(EXEEXT): $(LIBS) $(OBJS)
-       $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+rlgen-dot.a: $(LIBS) $(OBJS)
+       $(AR) -cr $@ $(OBJS) 
+       $(RANLIB) $@
 
 %.o: %.cpp
        @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d
index 631f3cb..bcce3a1 100644 (file)
 
 using namespace std;
 
-void lineDirective( ostream &out, char *fileName, int line )
-{
-}
-
-void genLineDirective( ostream &out )
-{
-}
-
 /* Override this so that write statement processing is ignored */
-void GraphvizDotGen::writeStatement( InputLoc &, int, char ** )
+void GraphvizDotGen::writeStatement( GenInputLoc &, int, char ** )
 {
 }
 
index 356317a..8bd239e 100644 (file)
@@ -35,7 +35,7 @@ public:
        void writeDotFile( );
 
        virtual void finishRagelDef();
-       virtual void writeStatement( InputLoc &, int, char ** );
+       virtual void writeStatement( GenInputLoc &, int, char ** );
 
 private:
        /* Writing labels and actions. */
index d5b1618..d0c01cb 100644 (file)
@@ -44,19 +44,19 @@ 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;
+extern bool graphvizDone;
 
-int numSplitPartitions = 0;
+extern int numSplitPartitions;
 bool displayPrintables = false;
 
 /* Print a summary of the options. */
-void usage()
+void dot_usage()
 {
        cout <<
 "usage: " PROGNAME " [options] file\n"
@@ -70,14 +70,14 @@ void usage()
 }
 
 /* Print version information. */
-void version()
+void dot_version()
 {
        cout << "Ragel Code Generator for Graphviz" << endl <<
                        "Version " VERSION << ", " PUBDATE << endl <<
                        "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
 }
 
-ostream &error()
+ostream &dot_error()
 {
        gblErrorCount += 1;
        cerr << PROGNAME ": ";
@@ -89,11 +89,11 @@ ostream &error()
  */
 
 /* Invoked by the parser when the root element is opened. */
-ostream *openOutput( char *inputFile )
+ostream *dotOpenOutput( 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  << 
+               dot_error() << "output file \"" << outputFileName  << 
                                "\" is the same as the input file" << endl;
        }
 
@@ -102,7 +102,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;
+                       dot_error() << "error opening " << outputFileName << " for writing" << endl;
                        exit(1);
                }
 
@@ -117,7 +117,7 @@ ostream *openOutput( char *inputFile )
 }
 
 /* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, 
+CodeGenData *dotMakeCodeGen( char *sourceFileName, char *fsmName, 
                ostream &out, bool wantComplete )
 {
        CodeGenData *codeGen = new GraphvizDotGen(out);
@@ -131,10 +131,10 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName,
 
 
 /* Main, process args and call yyparse to start scanning input. */
-int main(int argc, char **argv)
+int dot_main(int argc, const char **argv)
 {
        ParamCheck pc("o:pvHh?-:", argc, argv);
-       char *xmlInputFileName = 0;
+       const char *xmlInputFileName = 0;
 
        while ( pc.check() ) {
                switch ( pc.state ) {
@@ -143,9 +143,9 @@ int main(int argc, char **argv)
                        /* Output. */
                        case 'o':
                                if ( *pc.paramArg == 0 )
-                                       error() << "a zero length output file name was given" << endl;
+                                       dot_error() << "a zero length output file name was given" << endl;
                                else if ( outputFileName != 0 )
-                                       error() << "more than one output file name was given" << endl;
+                                       dot_error() << "more than one output file name was given" << endl;
                                else {
                                        /* Ok, remember the output file name. */
                                        outputFileName = pc.paramArg;
@@ -158,22 +158,22 @@ int main(int argc, char **argv)
 
                        /* Version and help. */
                        case 'v':
-                               version();
+                               dot_version();
                                exit(0);
                        case 'H': case 'h': case '?':
-                               usage();
+                               dot_usage();
                                exit(0);
                        case '-':
                                if ( strcmp(pc.paramArg, "help") == 0 ) {
-                                       usage();
+                                       dot_usage();
                                        exit(0);
                                }
                                else if ( strcmp(pc.paramArg, "version") == 0 ) {
-                                       version();
+                                       dot_version();
                                        exit(0);
                                }
                                else {
-                                       error() << "--" << pc.paramArg << 
+                                       dot_error() << "--" << pc.paramArg << 
                                                        " is an invalid argument" << endl;
                                        break;
                                }
@@ -181,14 +181,14 @@ int main(int argc, char **argv)
                        break;
 
                case ParamCheck::invalid:
-                       error() << "-" << pc.parameter << " is an invalid argument" << endl;
+                       dot_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;
+                               dot_error() << "a zero length input file name was given" << endl;
                        else if ( xmlInputFileName != 0 )
-                               error() << "more than one input file name was given" << endl;
+                               dot_error() << "more than one input file name was given" << endl;
                        else {
                                /* OK, Remember the filename. */
                                xmlInputFileName = pc.curArg;
@@ -207,7 +207,7 @@ int main(int argc, char **argv)
                ifstream *inFile = new ifstream( xmlInputFileName );
                inStream = inFile;
                if ( ! inFile->is_open() )
-                       error() << "could not open " << xmlInputFileName << " for reading" << endl;
+                       dot_error() << "could not open " << xmlInputFileName << " for reading" << endl;
        }
        else {
                xmlInputFileName = strdup("<stdin>");