# 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
../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)
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,
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. */
extern const char *machineSpec, *machineName;
extern bool printStatistics;
extern bool wantDupsRemoved;
+extern bool generateDot;
/* Error reporting format. */
enum ErrorFormat {
using std::ostream;
+extern bool generateDot;
+
struct NameInst;
typedef DList<Action> ActionList;
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 );
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 );
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 );
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 )
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 );
}
#*************************************
prefix = @prefix@
-CXX = @CXX@
EXEEXT = @EXEEXT@
+CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
# Get objects and dependencies from sources.
OBJS = $(CC_SRCS:%.cpp=%.o)
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
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 ** )
{
}
void writeDotFile( );
virtual void finishRagelDef();
- virtual void writeStatement( InputLoc &, int, char ** );
+ virtual void writeStatement( GenInputLoc &, int, char ** );
private:
/* Writing labels and actions. */
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"
}
/* 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 ": ";
*/
/* 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;
}
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);
}
}
/* 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);
/* 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 ) {
/* 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;
/* 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;
}
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;
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>");