static void TooManyTypeError( ) { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cout << "Error - Cannot have both " << subchar << subgoodchar << " and " << subchar << subbadchar << " on the same line." << endl; DieInFlames( ); };
static char MakeNewOutFile( // MAKE NEW TEST/ERROR FILE ofstream& of, // - output stream MsgDscr& file_des, // - files descriptor int msg_ctr ) // - message no. { char filename[ _MAX_PATH ]; MakeTestFileName( filename , file_des , msg_ctr , file_des.AddFile( msg_ctr ) ); if( WOpenForWrite( of, filename ) ) { //error cout << "Error - could not create \"" << filename << "\"." << endl; DieInFlames( ); return( 1 ); } else { return( 0 ); } }
GMLfilestat ReadGMLFile( MsgDscr& file_ok, MsgDscr& file_er ) { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ofstream outfile; strstream out_text; int current_good_file = 0; int current_bad_file = 0; char buffer[ 256 ]; int counter = 0; int line_count = 0; GML_STATE state = ST_READING; GML_READ gml_input; if( WOpenForRead( MsgFile, msg_file ) ) { cout << "Error - could not open \"" << msg_file << "\"." << endl; DieInFlames( ); }; cout << "Reading message file"; for( ;; ) { MsgFile.getline( buffer, 255 ); if( MsgFile.eof() ) { cout << endl; break; }; if( MsgFile.fail() ) { cout << endl << "I/O error reading input file " << endl; DieInFlames( ); }; if( counter == 0 ) { counter = 1001; cout << '.' << flush; }; --counter; ++line_count; if( *buffer == ':' ) { if( textis( buffer, ErrMsg1 ) ) { gml_input = RD_MSGSYM; } else if( textis( buffer, ErrMsg2 ) ) { gml_input = RD_MSGTXT; } else if( textis( buffer, GoodCodeStart ) ) { gml_input = RD_ERRGOOD; } else if( textis( buffer, GoodCodeEnd ) ) { gml_input = RD_EERRGOOD; } else if( textis( buffer, BadCodeStart ) ) { gml_input = RD_ERRBAD; } else if( textis( buffer, BadCodeEnd ) ) { gml_input = RD_EERRBAD; } else { gml_input = RD_TEXT; } } else { gml_input = RD_TEXT; } switch( trans[ gml_input ][ state ] ) { case OLD_MSGSYM : Purge( out_text ); case NEW_MSGSYM : ++msg_ctr; state = ST_MSGSYM; out_text << Comment << buffer; break; case GET_MSGTXT : state = ST_MSGTXT; out_text << Comment << buffer; break; case BEG_ERRGOOD : emitTestStart( outfile, out_text, file_ok, msg_ctr ); current_good_file++; state = ST_ERRGOOD; break; case BEG_ERRBAD : emitTestStart( outfile, out_text, file_er, msg_ctr ); current_bad_file++; state = ST_ERRBAD; break; case WR_FILE : if( processingMsg() ) { outfile << buffer; } break; case END_FILE : emitTestEnd( outfile ); case SET_MSGTXT : state = ST_MSGTXT; break; case SET_READING : state = ST_READING; break; case BAD_FOLLOW : cout << endl << "GML file at line " << line_count << ":" << "state " << gmlState( state ) << " followed by " << gmlTrans( gml_input ) << endl; DieInFlames( ); } }; return GMLfilestat( current_good_file - 1, current_bad_file - 1 ); };
void ProcessModelFile( // PROCESS MODEL FILE MsgDscr& file_ok, // - description of good files MsgDscr& file_er, // - description of bad files GMLfilestat g ) // - statistics { char filename[ _MAX_PATH ]; // - test file name char buffer[ 256 ]; char * buf = buffer; int counter = 0; bool dotflag = FALSE; strstream out_text; char * sub; int idx, jdx, kdx; int tot; GoodBad gb; // - indicates type of test file name cout << "Processing model file..." << endl; if( WOpenForRead( ModelFile, model_file ) ) { cout << "Error - could not open \"" << model_file << "\"." << endl; DieInFlames( ); }; if( WOpenForWrite( DestFile, dest_file ) ) { cout << "Error - could not open \"" << dest_file << "\"." << endl; DieInFlames( ); }; memset( buffer, 0, 256 ); for( ;; ) { // for( idx = 0; idx < 20; idx ++ ) { // sublocs[ idx ] = 0; // }; ModelFile.getline( buffer, 252 ); buf = buffer; counter++; if( counter == 1000 ) { counter = 0; dotflag = TRUE; cout << '.' << flush; }; if( ( ModelFile.eof( ) ) || ( ModelFile.fail( ) ) ) { break; }; if( strchr( buffer, '\n' ) == NULL ) { strcat( buffer, "\n" ); }; if( ( sub = strchr( buffer, subchar ) ) != NULL ) { if( sub[ 1 ] == subgoodchar ) { if( g.last_good == 0 ) { cout << "Warning: Model file, line " << counter << ":" << endl; cout << "There are no GOOD.CPP files to process" << endl; continue; }; gb = GOOD; } else if( sub[ 1 ] == subbadchar ) { if( g.last_bad == 0 ) { cout << "Warning: Model file, line " << counter << ":" << endl; cout << "There are no BAD.CPP files to process" << endl; continue; }; gb = BAD; } else { DestFile << buffer; continue; }; kdx = strlen( buffer ); for( idx = 0; idx <= kdx; idx++ ) { if( buffer[ idx ] == subchar ) { if( ( ( buffer[ idx + 1 ] == subgoodchar ) &&( gb == GOOD ) ) ||( ( buffer[ idx + 1 ] == subbadchar ) &&( gb == BAD ) ) ) { buffer[ idx ] = 0; } else if( ( buffer[ idx + 1 ] == subgoodchar ) ||( buffer[ idx + 1 ] == subbadchar ) ) { TooManyTypeError( ); }; }; }; // Substitution strings done. buffer[ idx ] = 'E'; buffer[ idx + 1 ] = '\0'; { MsgDscr& descr = (gb == GOOD ) ? file_ok : file_er; tot = descr.GetMaxMsgNo(); for( jdx = 1; jdx < tot; jdx++ ) { for( int fdx = 0; ; ) { fdx = descr.GetNextFile( jdx, fdx ); if( fdx == 0 ) break; MakeTestFileName( filename, descr, jdx, fdx ); kdx = 0; sub = buffer; for( ;; ) { out_text << sub; kdx = strlen( sub ); if( sub[ kdx + 1 ] == 'E' ) { break; } else { out_text << filename; }; sub = &sub[ kdx + 2 ]; } } out_text << ends; Write( DestFile, out_text ); Purge( out_text ); } } } else { DestFile << buffer; }; }; if( dotflag ) { cout << endl; }; };