using std::cerr;
using std::endl;
-/* Io globals. */
-istream *inStream = 0;
-ostream *outStream = 0;
-char *outputFileName = 0;
-
/* Controls minimization. */
MinimizeLevel minimizeLevel = MinimizePartition2;
MinimizeOpt minimizeOpt = MinimizeMostOps;
/* Total error count. */
int gblErrorCount = 0;
+/* Print the opening to a warning in the input, then return the error ostream. */
+ostream &warning( const InputLoc &loc )
+{
+ assert( loc.fileName != 0 );
+ cerr << loc.fileName << ":" << loc.line << ":" <<
+ loc.col << ": warning: ";
+ return cerr;
+}
+
/* Print the opening to a program error, then return the error stream. */
ostream &error()
{
return cerr;
}
-
-/* Print the opening to a warning in the input, then return the error ostream. */
-ostream &warning( const InputLoc &loc )
+ostream &error( const InputLoc &loc )
{
- cerr << loc.fileName << ":" << loc.line << ":" <<
- loc.col << ": warning: ";
+ gblErrorCount += 1;
+ assert( loc.fileName != 0 );
+ cerr << loc.fileName << ":" << loc.line << ": ";
return cerr;
}
{
ParamCheck pc("o:nmleabjkS:M:CDJvHh?-:s", argc, argv);
char *inputFileName = 0;
+ char *outputFileName = 0;
while ( pc.check() ) {
switch ( pc.state ) {
}
/* Open the input file for reading. */
+ istream *inStream;
if ( inputFileName != 0 ) {
/* Open the input file for reading. */
ifstream *inFile = new ifstream( inputFileName );
exit(1);
std::ostringstream outputBuffer;
- outStream = &outputBuffer;
if ( machineSpec == 0 && machineName == 0 )
- *outStream << "<host line=\"1\" col=\"1\">";
+ outputBuffer << "<host line=\"1\" col=\"1\">";
- scan( inputFileName, *inStream );
+ scan( inputFileName, *inStream, outputBuffer );
/* Finished, final check for errors.. */
if ( gblErrorCount > 0 )
return 1;
if ( machineSpec == 0 && machineName == 0 )
- *outStream << "</host>\n";
+ outputBuffer << "</host>\n";
checkMachines();
};
typedef Vector<IncludeStackItem> IncludeStack;
-IncludeStack includeStack;
enum InlineBlockType
{
struct Scanner
{
- Scanner( char *fileName, istream &input,
+ Scanner( char *fileName, istream &input, ostream &output,
Parser *inclToParser, char *inclSectionTarg,
- int include_depth )
+ int includeDepth )
:
- fileName(fileName), input(input),
+ fileName(fileName), input(input), output(output),
inclToParser(inclToParser),
inclSectionTarg(inclSectionTarg),
- include_depth(include_depth),
+ includeDepth(includeDepth),
line(1), column(1), lastnl(0),
parser(0), active(false),
parserExistsError(false), ragelDefOpen(false),
whitespaceOn(true)
{}
- bool recursiveInclude( IncludeStack &includeStack,
- char *inclFileName, char *inclSectionName );
+ bool recursiveInclude( char *inclFileName, char *inclSectionName );
char *prepareFileName( char *fileName, int len )
{
void openRagelDef();
void do_scan();
bool parserExists();
- ostream &error();
+ ostream &scan_error();
char *fileName;
istream &input;
+ ostream &output;
Parser *inclToParser;
char *inclSectionTarg;
- int include_depth;
+ int includeDepth;
int cs;
int line;
* allowing for unnamed sections. */
Parser *parser;
bool active;
+ IncludeStack includeStack;
/* This is set if ragel has already emitted an error stating that
* no section name has been seen and thus no parser exists. */
return true;
if ( ! parserExistsError ) {
- error() << "include: there is no previous specification name" << endl;
+ scan_error() << "include: there is no previous specification name" << endl;
parserExistsError = true;
}
return false;
}
-ostream &Scanner::error()
+ostream &Scanner::scan_error()
{
/* Maintain the error count. */
gblErrorCount += 1;
-
cerr << fileName << ":" << line << ":" << column << ": ";
return cerr;
}
-bool Scanner::recursiveInclude( IncludeStack &includeStack,
- char *inclFileName, char *inclSectionName )
+bool Scanner::recursiveInclude( char *inclFileName, char *inclSectionName )
{
for ( IncludeStack::Iter si = includeStack; si.lte(); si++ ) {
if ( strcmp( si->fileName, inclFileName ) == 0 &&
action store_word { word = tokdata; word_len = toklen; }
action store_lit { lit = tokdata; lit_len = toklen; }
- action mach_err { error() << "bad machine statement" << endl; }
- action incl_err { error() << "bad include statement" << endl; }
- action write_err { error() << "bad write statement" << endl; }
+ action mach_err { scan_error() << "bad machine statement" << endl; }
+ action incl_err { scan_error() << "bad include statement" << endl; }
+ action write_err { scan_error() << "bad write statement" << endl; }
action handle_machine
{
* name then check if what we are including is already in the stack. */
includeStack.append( IncludeStackItem( fileName, parser->sectionName ) );
- if ( recursiveInclude( includeStack, inclFileName, inclSectionName ) )
- error() << "include: this is a recursive include operation" << endl;
+ if ( recursiveInclude( inclFileName, inclSectionName ) )
+ scan_error() << "include: this is a recursive include operation" << endl;
else {
/* Open the input file for reading. */
ifstream *inFile = new ifstream( inclFileName );
if ( ! inFile->is_open() ) {
- error() << "include: could not open " <<
+ scan_error() << "include: could not open " <<
inclFileName << " for reading" << endl;
}
- Scanner scanner( inclFileName, *inFile, parser,
- inclSectionName, include_depth+1 );
+ Scanner scanner( inclFileName, *inFile, output, parser,
+ inclSectionName, includeDepth+1 );
scanner.init();
scanner.do_scan( );
delete inFile;
strcmp( tokdata, "exec" ) != 0 &&
strcmp( tokdata, "eof" ) != 0 )
{
- error() << "unknown write command" << endl;
+ scan_error() << "unknown write command" << endl;
}
- *outStream << " <write what=\"" << tokdata << "\">";
+ output << " <write what=\"" << tokdata << "\">";
}
}
action write_option
{
if ( active )
- *outStream << "<option>" << tokdata << "</option>";
+ output << "<option>" << tokdata << "</option>";
}
action write_close
{
if ( active )
- *outStream << "</write>\n";
+ output << "</write>\n";
}
write_stmt =
{
parserExistsError = false;
- if ( include_depth == 0 ) {
+ if ( includeDepth == 0 ) {
if ( machineSpec == 0 && machineName == 0 )
- *outStream << "</host>\n";
+ output << "</host>\n";
ragelDefOpen = false;
}
{
if ( ! ragelDefOpen ) {
ragelDefOpen = true;
- *outStream << "<ragel_def name=\"" << parser->sectionName << "\">\n";
+ output << "<ragel_def name=\"" << parser->sectionName << "\">\n";
}
}
parser->token( loc, TK_EndSection, 0, 0 );
}
- if ( include_depth == 0 ) {
+ if ( includeDepth == 0 ) {
if ( ragelDefOpen ) {
- *outStream << "</ragel_def>\n";
+ output << "</ragel_def>\n";
ragelDefOpen = false;
}
if ( machineSpec == 0 && machineName == 0 ) {
/* The end section may include a newline on the end, so
* we use the last line, which will count the newline. */
- *outStream << "<host line=\"" << line << "\">";
+ output << "<host line=\"" << line << "\">";
}
}
}
};
EOF => {
- error() << "unterminated code block" << endl;
+ scan_error() << "unterminated code block" << endl;
};
# Send every other character as a symbol.
']' => { token( RE_SqClose ); fret; };
EOF => {
- error() << "unterminated OR literal" << endl;
+ scan_error() << "unterminated OR literal" << endl;
};
# Characters in an OR expression.
'[^' => { token( RE_SqOpenNeg ); fcall or_literal; };
EOF => {
- error() << "unterminated regular expression" << endl;
+ scan_error() << "unterminated regular expression" << endl;
};
# Characters in an OR expression.
';' => { token( ';' ); fgoto parser_def; };
EOF => {
- error() << "unterminated write statement" << endl;
+ scan_error() << "unterminated write statement" << endl;
};
*|;
};
EOF => {
- error() << "unterminated ragel section" << endl;
+ scan_error() << "unterminated ragel section" << endl;
};
any => { token( *tokstart ); } ;
/* If no errors and we are at the bottom of the include stack (the
* source file listed on the command line) then write out the data. */
- if ( include_depth == 0 && machineSpec == 0 && machineName == 0 )
- xmlEscapeHost( *outStream, tokstart, tokend-tokstart );
+ if ( includeDepth == 0 && machineSpec == 0 && machineName == 0 )
+ xmlEscapeHost( output, tokstart, tokend-tokstart );
}
# Outside code scanner. These tokens get passed through.
if ( cs == rlscan_error ) {
/* Machine failed before finding a token. I'm not yet sure if this
* is reachable. */
- error() << "scanner error" << endl;
+ scan_error() << "scanner error" << endl;
exit(1);
}
delete[] buf;
}
-void scan( char *fileName, istream &input )
+void scan( char *fileName, istream &input, ostream &output )
{
- Scanner scanner( fileName, input, 0, 0, 0 );
+ Scanner scanner( fileName, input, output, 0, 0, 0 );
scanner.init();
scanner.do_scan();