diff options
author | Adrian Thurston <thurston@complang.org> | 2013-03-02 09:13:08 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-03-02 09:13:08 -0500 |
commit | b790a9eeb8b5bc92b3b3cd02372637707df26a55 (patch) | |
tree | f383bcb5c0ee2afd449e39b84bbd7abe6f1677af /colm/main.cc | |
parent | b9cc49c119b71236b9a03431a33a077f4ef20ff2 (diff) | |
download | colm-b790a9eeb8b5bc92b3b3cd02372637707df26a55.tar.gz |
handle input output files appropriately when bootstrapping ( -B )
Diffstat (limited to 'colm/main.cc')
-rw-r--r-- | colm/main.cc | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/colm/main.cc b/colm/main.cc index 40b7db9e..8bd0ada1 100644 --- a/colm/main.cc +++ b/colm/main.cc @@ -167,6 +167,7 @@ void usage() " -i show conflict information\n" " -d make colm verbose\n" " -l compile logging into the output executable\n" +" -B compile a boot strapping colm, replaces source file\n" ; } @@ -249,7 +250,9 @@ void openOutput( ) debug( REALM_PARSE, "opening output file: %s\n", outputFileName ); /* Make sure we are not writing to the same file as the input file. */ - if ( outputFileName != 0 && strcmp( inputFileName, outputFileName ) == 0 ) { + if ( outputFileName != 0 && inputFileName != 0 && + strcmp( inputFileName, outputFileName ) == 0 ) + { error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -551,16 +554,24 @@ int main(int argc, const char **argv) /* Open the input file for reading. */ istream *inStream; - if ( inputFileName != 0 ) { - /* Open the input file for reading. */ - ifstream *inFile = new ifstream( inputFileName ); - inStream = inFile; - if ( ! inFile->is_open() ) - error() << "could not open " << inputFileName << " for reading" << endl; + if ( bootStrap ) { + inStream = &cin; + if ( outputFileName == 0 ) { + error() << "colm: an output file name is required when " + "compiling bootstrap grammar" << endl; + } } else { - inputFileName = "<stdin>"; - inStream = &cin; + if ( inputFileName == 0 ) { + error() << "colm: no input file given" << endl; + } + else { + /* Open the input file for reading. */ + ifstream *inFile = new ifstream( inputFileName ); + inStream = inFile; + if ( ! inFile->is_open() ) + error() << "could not open " << inputFileName << " for reading" << endl; + } } /* Bail on above errors. */ |