From: thurston Date: Sun, 4 Feb 2007 18:21:42 +0000 (+0000) Subject: Movement of common classes and code to common.a. X-Git-Tag: 2.0_alpha~411 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc73fd848fc3c8e3f080289ad2e66911f3febb25;p=external%2Fragel.git Movement of common classes and code to common.a. git-svn-id: http://svn.complang.org/ragel/trunk@75 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/common/common.cpp b/common/common.cpp index 94fb98c..2faaef5 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -21,6 +21,7 @@ #include "pcheck.h" #include "common.h" +#include HostType hostTypesC[] = { @@ -200,4 +201,74 @@ bool ParamCheck::check() 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; +} + diff --git a/common/common.h b/common/common.h index ca24db0..0c61e65 100644 --- a/common/common.h +++ b/common/common.h @@ -22,6 +22,7 @@ #ifndef _COMMON_H #define _COMMON_H +#include #include typedef unsigned long long Size; @@ -270,4 +271,21 @@ inline Key operator/(const Key key1, const Key key2) 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 */ diff --git a/rlcodegen/main.cpp b/rlcodegen/main.cpp index b5e57bb..7b06d14 100644 --- a/rlcodegen/main.cpp +++ b/rlcodegen/main.cpp @@ -103,59 +103,6 @@ void version() "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; @@ -166,33 +113,6 @@ ostream &error() 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. */ diff --git a/rlcodegen/rlcodegen.h b/rlcodegen/rlcodegen.h index b787291..959b58a 100644 --- a/rlcodegen/rlcodegen.h +++ b/rlcodegen/rlcodegen.h @@ -24,7 +24,6 @@ #include #include -#include #include "avltree.h" #include "vector.h" #include "config.h" @@ -51,20 +50,6 @@ enum CodeStyleEnum 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; @@ -73,11 +58,8 @@ extern bool printPrintables; extern bool graphvizDone; extern int gblErrorCount; -extern char machineMain[]; - extern int numSplitPartitions; std::ostream &error(); -char *fileNameFromStem( char *stemFile, char *suffix ); #endif /* _RLCODEGEN_H */ diff --git a/rlgen-java/main.cpp b/rlgen-java/main.cpp index 42ca2f1..caf8405 100644 --- a/rlgen-java/main.cpp +++ b/rlgen-java/main.cpp @@ -75,59 +75,6 @@ void version() "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; @@ -138,33 +85,6 @@ ostream &error() 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. */ @@ -172,13 +92,8 @@ void escapeLineDirectivePath( std::ostream &out, char *path ) /* 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. */ diff --git a/rlgen-java/rlgen-java.h b/rlgen-java/rlgen-java.h index cfaf1f9..388afd0 100644 --- a/rlgen-java/rlgen-java.h +++ b/rlgen-java/rlgen-java.h @@ -22,33 +22,12 @@ #ifndef _RLGEN_JAVA_H #define _RLGEN_JAVA_H -#include #include -#include -#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 */ diff --git a/rlgen-ruby/main.cpp b/rlgen-ruby/main.cpp index fdc9499..3f238d5 100644 --- a/rlgen-ruby/main.cpp +++ b/rlgen-ruby/main.cpp @@ -75,59 +75,6 @@ void version() "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; @@ -138,33 +85,6 @@ ostream &error() 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. */ @@ -172,13 +92,8 @@ void escapeLineDirectivePath( std::ostream &out, char *path ) /* 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. */ diff --git a/rlgen-ruby/rlgen-ruby.h b/rlgen-ruby/rlgen-ruby.h index cfaf1f9..219c674 100644 --- a/rlgen-ruby/rlgen-ruby.h +++ b/rlgen-ruby/rlgen-ruby.h @@ -19,36 +19,17 @@ * 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 #include -#include -#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 */