#include "pcheck.h"
#include "common.h"
+#include <assert.h>
HostType hostTypesC[] =
{
return true;
}
+/* Counts newlines before sending sync. */
+int output_filter::sync( )
+{
+ line += 1;
+ return std::filebuf::sync();
+}
+
+/* Counts newlines before sending data out to file. */
+std::streamsize output_filter::xsputn( const char *s, std::streamsize n )
+{
+ for ( int i = 0; i < n; i++ ) {
+ if ( s[i] == '\n' )
+ line += 1;
+ }
+ return std::filebuf::xsputn( s, n );
+}
+
+/* Scans a string looking for the file extension. If there is a file
+ * extension then pointer returned points to inside the string
+ * passed in. Otherwise returns null. */
+char *findFileExtension( char *stemFile )
+{
+ char *ppos = stemFile + strlen(stemFile) - 1;
+
+ /* Scan backwards from the end looking for the first dot.
+ * If we encounter a '/' before the first dot, then stop the scan. */
+ while ( 1 ) {
+ /* If we found a dot or got to the beginning of the string then
+ * we are done. */
+ if ( ppos == stemFile || *ppos == '.' )
+ break;
+
+ /* If we hit a / then there is no extension. Done. */
+ if ( *ppos == '/' ) {
+ ppos = stemFile;
+ break;
+ }
+ ppos--;
+ }
+
+ /* If we got to the front of the string then bail we
+ * did not find an extension */
+ if ( ppos == stemFile )
+ ppos = 0;
+
+ return ppos;
+}
+
+/* Make a file name from a stem. Removes the old filename suffix and
+ * replaces it with a new one. Returns a newed up string. */
+char *fileNameFromStem( char *stemFile, char *suffix )
+{
+ int len = strlen( stemFile );
+ assert( len > 0 );
+
+ /* Get the extension. */
+ char *ppos = findFileExtension( stemFile );
+
+ /* If an extension was found, then shorten what we think the len is. */
+ if ( ppos != 0 )
+ len = ppos - stemFile;
+
+ /* Make the return string from the stem and the suffix. */
+ char *retVal = new char[ len + strlen( suffix ) + 1 ];
+ strncpy( retVal, stemFile, len );
+ strcpy( retVal + len, suffix );
+
+ return retVal;
+}
+
#ifndef _COMMON_H
#define _COMMON_H
+#include <fstream>
#include <climits>
typedef unsigned long long Size;
return key1.key / key2.key;
}
+/* Filter on the output stream that keeps track of the number of lines
+ * output. */
+class output_filter : public std::filebuf
+{
+public:
+ output_filter( char *fileName ) : fileName(fileName), line(1) { }
+
+ virtual int sync();
+ virtual std::streamsize xsputn(const char* s, std::streamsize n);
+
+ char *fileName;
+ int line;
+};
+
+char *findFileExtension( char *stemFile );
+char *fileNameFromStem( char *stemFile, char *suffix );
+
#endif /* _COMMON_H */
"Copyright (c) 2001-2007 by Adrian Thurston" << endl;
}
-/* Scans a string looking for the file extension. If there is a file
- * extension then pointer returned points to inside the string
- * passed in. Otherwise returns null. */
-char *findFileExtension( char *stemFile )
-{
- char *ppos = stemFile + strlen(stemFile) - 1;
-
- /* Scan backwards from the end looking for the first dot.
- * If we encounter a '/' before the first dot, then stop the scan. */
- while ( 1 ) {
- /* If we found a dot or got to the beginning of the string then
- * we are done. */
- if ( ppos == stemFile || *ppos == '.' )
- break;
-
- /* If we hit a / then there is no extension. Done. */
- if ( *ppos == '/' ) {
- ppos = stemFile;
- break;
- }
- ppos--;
- }
-
- /* If we got to the front of the string then bail we
- * did not find an extension */
- if ( ppos == stemFile )
- ppos = 0;
-
- return ppos;
-}
-
-/* Make a file name from a stem. Removes the old filename suffix and
- * replaces it with a new one. Returns a newed up string. */
-char *fileNameFromStem( char *stemFile, char *suffix )
-{
- int len = strlen( stemFile );
- assert( len > 0 );
-
- /* Get the extension. */
- char *ppos = findFileExtension( stemFile );
-
- /* If an extension was found, then shorten what we think the len is. */
- if ( ppos != 0 )
- len = ppos - stemFile;
-
- /* Make the return string from the stem and the suffix. */
- char *retVal = new char[ len + strlen( suffix ) + 1 ];
- strncpy( retVal, stemFile, len );
- strcpy( retVal + len, suffix );
-
- return retVal;
-}
-
/* Total error count. */
int gblErrorCount = 0;
return cerr;
}
-/* Counts newlines before sending sync. */
-int output_filter::sync( )
-{
- line += 1;
- return std::filebuf::sync();
-}
-
-/* Counts newlines before sending data out to file. */
-std::streamsize output_filter::xsputn( const char *s, std::streamsize n )
-{
- for ( int i = 0; i < n; i++ ) {
- if ( s[i] == '\n' )
- line += 1;
- }
- return std::filebuf::xsputn( s, n );
-}
-
-void escapeLineDirectivePath( std::ostream &out, char *path )
-{
- for ( char *pc = path; *pc != 0; pc++ ) {
- if ( *pc == '\\' )
- out << "\\\\";
- else
- out << *pc;
- }
-}
-
/*
* Callbacks invoked by the XML data parser.
*/
#include <stdio.h>
#include <iostream>
-#include <fstream>
#include "avltree.h"
#include "vector.h"
#include "config.h"
GenSplit
};
-/* Filter on the output stream that keeps track of the number of lines
- * output. */
-class output_filter : public std::filebuf
-{
-public:
- output_filter( char *fileName ) : fileName(fileName), line(1) { }
-
- virtual int sync();
- virtual std::streamsize xsputn(const char* s, std::streamsize n);
-
- char *fileName;
- int line;
-};
-
extern OutputFormat outputFormat;
extern CodeStyleEnum codeStyle;
extern bool graphvizDone;
extern int gblErrorCount;
-extern char machineMain[];
-
extern int numSplitPartitions;
std::ostream &error();
-char *fileNameFromStem( char *stemFile, char *suffix );
#endif /* _RLCODEGEN_H */
"Copyright (c) 2001-2007 by Adrian Thurston" << endl;
}
-/* Scans a string looking for the file extension. If there is a file
- * extension then pointer returned points to inside the string
- * passed in. Otherwise returns null. */
-char *findFileExtension( char *stemFile )
-{
- char *ppos = stemFile + strlen(stemFile) - 1;
-
- /* Scan backwards from the end looking for the first dot.
- * If we encounter a '/' before the first dot, then stop the scan. */
- while ( 1 ) {
- /* If we found a dot or got to the beginning of the string then
- * we are done. */
- if ( ppos == stemFile || *ppos == '.' )
- break;
-
- /* If we hit a / then there is no extension. Done. */
- if ( *ppos == '/' ) {
- ppos = stemFile;
- break;
- }
- ppos--;
- }
-
- /* If we got to the front of the string then bail we
- * did not find an extension */
- if ( ppos == stemFile )
- ppos = 0;
-
- return ppos;
-}
-
-/* Make a file name from a stem. Removes the old filename suffix and
- * replaces it with a new one. Returns a newed up string. */
-char *fileNameFromStem( char *stemFile, char *suffix )
-{
- int len = strlen( stemFile );
- assert( len > 0 );
-
- /* Get the extension. */
- char *ppos = findFileExtension( stemFile );
-
- /* If an extension was found, then shorten what we think the len is. */
- if ( ppos != 0 )
- len = ppos - stemFile;
-
- /* Make the return string from the stem and the suffix. */
- char *retVal = new char[ len + strlen( suffix ) + 1 ];
- strncpy( retVal, stemFile, len );
- strcpy( retVal + len, suffix );
-
- return retVal;
-}
-
/* Total error count. */
int gblErrorCount = 0;
return cerr;
}
-/* Counts newlines before sending sync. */
-int output_filter::sync( )
-{
- line += 1;
- return std::filebuf::sync();
-}
-
-/* Counts newlines before sending data out to file. */
-std::streamsize output_filter::xsputn( const char *s, std::streamsize n )
-{
- for ( int i = 0; i < n; i++ ) {
- if ( s[i] == '\n' )
- line += 1;
- }
- return std::filebuf::xsputn( s, n );
-}
-
-void escapeLineDirectivePath( std::ostream &out, char *path )
-{
- for ( char *pc = path; *pc != 0; pc++ ) {
- if ( *pc == '\\' )
- out << "\\\\";
- else
- out << *pc;
- }
-}
-
/*
* Callbacks invoked by the XML data parser.
*/
/* Invoked by the parser when the root element is opened. */
ostream *openOutput( char *inputFile, char *language )
{
- if ( strcmp( language, "Java" ) == 0 ) {
- hostLangType = JavaCode;
- hostLang = &hostLangJava;
- }
- else {
- error() << "this code genreator is for Java only" << endl;
- }
+ if ( strcmp( language, "Java" ) != 0 )
+ error() << "this code generator is for Java only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
#ifndef _RLGEN_JAVA_H
#define _RLGEN_JAVA_H
-#include <stdio.h>
#include <iostream>
-#include <fstream>
-#include "avltree.h"
-#include "vector.h"
#include "config.h"
#define PROGNAME "rlgen-java"
-/* Filter on the output stream that keeps track of the number of lines
- * output. */
-class output_filter : public std::filebuf
-{
-public:
- output_filter( char *fileName ) : fileName(fileName), line(1) { }
-
- virtual int sync();
- virtual std::streamsize xsputn(const char* s, std::streamsize n);
-
- char *fileName;
- int line;
-};
-
extern int gblErrorCount;
-extern char machineMain[];
-
std::ostream &error();
-char *fileNameFromStem( char *stemFile, char *suffix );
#endif /* _RLGEN_JAVA_H */
"Copyright (c) 2001-2007 by Adrian Thurston" << endl;
}
-/* Scans a string looking for the file extension. If there is a file
- * extension then pointer returned points to inside the string
- * passed in. Otherwise returns null. */
-char *findFileExtension( char *stemFile )
-{
- char *ppos = stemFile + strlen(stemFile) - 1;
-
- /* Scan backwards from the end looking for the first dot.
- * If we encounter a '/' before the first dot, then stop the scan. */
- while ( 1 ) {
- /* If we found a dot or got to the beginning of the string then
- * we are done. */
- if ( ppos == stemFile || *ppos == '.' )
- break;
-
- /* If we hit a / then there is no extension. Done. */
- if ( *ppos == '/' ) {
- ppos = stemFile;
- break;
- }
- ppos--;
- }
-
- /* If we got to the front of the string then bail we
- * did not find an extension */
- if ( ppos == stemFile )
- ppos = 0;
-
- return ppos;
-}
-
-/* Make a file name from a stem. Removes the old filename suffix and
- * replaces it with a new one. Returns a newed up string. */
-char *fileNameFromStem( char *stemFile, char *suffix )
-{
- int len = strlen( stemFile );
- assert( len > 0 );
-
- /* Get the extension. */
- char *ppos = findFileExtension( stemFile );
-
- /* If an extension was found, then shorten what we think the len is. */
- if ( ppos != 0 )
- len = ppos - stemFile;
-
- /* Make the return string from the stem and the suffix. */
- char *retVal = new char[ len + strlen( suffix ) + 1 ];
- strncpy( retVal, stemFile, len );
- strcpy( retVal + len, suffix );
-
- return retVal;
-}
-
/* Total error count. */
int gblErrorCount = 0;
return cerr;
}
-/* Counts newlines before sending sync. */
-int output_filter::sync( )
-{
- line += 1;
- return std::filebuf::sync();
-}
-
-/* Counts newlines before sending data out to file. */
-std::streamsize output_filter::xsputn( const char *s, std::streamsize n )
-{
- for ( int i = 0; i < n; i++ ) {
- if ( s[i] == '\n' )
- line += 1;
- }
- return std::filebuf::xsputn( s, n );
-}
-
-void escapeLineDirectivePath( std::ostream &out, char *path )
-{
- for ( char *pc = path; *pc != 0; pc++ ) {
- if ( *pc == '\\' )
- out << "\\\\";
- else
- out << *pc;
- }
-}
-
/*
* Callbacks invoked by the XML data parser.
*/
/* Invoked by the parser when the root element is opened. */
ostream *openOutput( char *inputFile, char *language )
{
- if ( strcmp( language, "Ruby" ) == 0 ) {
-// hostLangType = JavaCode;
-// hostLang = &hostLangJava;
- }
- else {
- error() << "this code genreator is for Java only" << endl;
- }
+ if ( strcmp( language, "Ruby" ) != 0 )
+ error() << "this code generator is for Ruby only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _RLGEN_JAVA_H
-#define _RLGEN_JAVA_H
+#ifndef _RLGEN_RUBY_H
+#define _RLGEN_RUBY_H
-#include <stdio.h>
#include <iostream>
-#include <fstream>
-#include "avltree.h"
-#include "vector.h"
#include "config.h"
#define PROGNAME "rlgen-java"
-/* Filter on the output stream that keeps track of the number of lines
- * output. */
-class output_filter : public std::filebuf
-{
-public:
- output_filter( char *fileName ) : fileName(fileName), line(1) { }
-
- virtual int sync();
- virtual std::streamsize xsputn(const char* s, std::streamsize n);
-
- char *fileName;
- int line;
-};
-
extern int gblErrorCount;
extern char machineMain[];
std::ostream &error();
-char *fileNameFromStem( char *stemFile, char *suffix );
#endif /* _RLGEN_JAVA_H */