// balerrors.cpp Functions for producing the BAC error report /******************************************************************************* // MODULE NAME: BALerrors // INTERFACE FILE: balerrors.h // IMPLEMENTATION FILE: balerrors.cpp // // PURPOSE: To provide a set of functions useful in an implementation of the BAL // program which allows a client to produce a BAC-formatted error report by // reporting label or data errors and delimiter lines for formatting // // FUNCTIONS: Name Purpose // WriteSectionHeader Indicate which section is being parsed // WriteLabelError Report an incorrect label & its location // WriteDataError Report an incorrect data value & its location // WriteNoErrors Indicate no errors were found in the section // WriteSectionFooter Print section-delimiting lines // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 // REVISED: 3/22/1999 *******************************************************************************/ #include "balerrors.h" /******************************************************************************* // FUNCTION NAME: WriteSectionHeader // // DESCRIPTION OF FUNCTION: The function prints out the title line of // each section of the error report // // DESCRIPTION OF ALGORITHM: Depending on which section is currently being // printed, the function prints an appropriate title line to the output file // // CALLED BY: GetAlleyInfo, GetEventInfo, GetToolsInfo, GetReleaseInfo, // GetBallInfo, GetConditionsInfo, GetGameInfo, GetFramesInfo // CALLS: none // // PARAMETERS: / inout / File - output filestream for writing to // / in / Name - user-supplied file name // / in / section - Flag that indicates which section is being // worked on // // PRECONDITIONS: ofstream File has been properly opened,Name contains the // string value of the file's name. // // POSTCONDITIONS: Depending on the value of section, a title line indicating // which section is being worked on has been written to the specified file // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 *******************************************************************************/ void WriteSectionHeader(ofstream& File,string Name,BALSectionType section) { int counter; // For controlling loop & outputting long line of _s switch (section) { case ALLEY: File << "BAC Error Report: " << Name << endl; File << "==================================" << endl << endl; File << '\t' << "Alley section report" << endl; break; case EVENT: File << '\t' << "Event section report" << endl; break; case TOOLS: File << '\t' << "Tools section report" << endl; break; case BALL: File << '\t' << "Ball section report" << endl; break; case RELEASE: File << '\t' << "Release section report" << endl; break; case CONDITIONS: File << '\t' << "Conditions section report" << endl; break; case GAME: File << '\t' << "Game section report" << endl; break; case FRAMES: File << '\t' << "Frames section report" << endl; break; } // Output a line of delimiters followed by a newline: for (counter=0;counter<77;counter++) File << "_"; File << endl; return; // Return to calling function } /******************************************************************************* // FUNCTION NAME: WriteLabelError // // DESCRIPTION OF FUNCTION: The function write an error message to the output // file if an error has been discovered in the label portion of a field in // the input file // // DESCRIPTION OF ALGORITHM: The function echoes statements to the file // // CALLED BY: GetAlleyInfo, GetEventInfo, GetToolsInfo, GetReleaseInfo, // GetBallInfo, GetConditionsInfo, GetGameInfo, GetFramesInfo // CALLS: none // // PARAMETERS: / inout / File - output filestream for writing to // / in / otherErrors - bool that indicates whether we have found // any other errors in this section // / in / badLabel - string that contains the incorrect field label // / in / goodLabel - string that contains the correct field label // / in / record - int that tells what order this record appears in // in the input file // / in / line - int that tells what line of the input file this // error occurred on // // PRECONDITIONS: ofstream File has been properly initialized, otherErrors // actually indicates if any previous errors have been recorded. // // POSTCONDITIONS: An error message listing the erroneous label and the proper // one has been output to the error report file // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 *******************************************************************************/ void WriteLabelError(ofstream& File,bool otherErrors,string badLabel, string goodLabel,int record,int line) { int spaces; // used to control width of column and line up output if (!otherErrors) // If this is the first error that has been found, { // we need to output the labels that appear at the // very top of each section of the output file that // actually has any errors in the input file File << "| rec # | line | field name | error" << " |" << endl; File << "|-------+------+-----------------+" << "-------------------------------------------" << endl; } // Whether this is the first error in the section or not, we have to // do the remaining stuff: File << "|" << setw(4) << record << " " << "|" << setw(4) << line << " " << "| " << goodLabel << " label"; // Pad the field name column with spaces: for (spaces=0;spaces<(10-goodLabel.length());spaces++) File << " "; // Output the label error message and the bad label File << "| mismatched label name: \"" << badLabel << "\""; // Pad the error column with spaces: for (spaces=0;spaces<(16-badLabel.length());spaces++) File << " "; File << "|" << endl; // Bar at the end of the line return; } /******************************************************************************* // FUNCTION NAME: WriteDataError // // DESCRIPTION OF FUNCTION: The function writes an error message to the output // file depending on the type of error that was encountered // // DESCRIPTION OF ALGORITHM: The function selects the appropriate action based // on what type of error is being reported and whether this is the first error // in the section // // CALLED BY: GetAlleyInfo, GetEventInfo, GetToolsInfo, GetReleaseInfo, // GetBallInfo, GetConditionsInfo, GetGameInfo, GetFramesInfo // CALLS: none // // PARAMETERS: / inout / File - output filestream for writing to // / in / whatsWrong - DataErrorType that indicates the type of // error found in the field // / in / otherErrors - bool that indicates whether any other // errors have been found in this section // / in / badData - string that holds the incorrect data value // / in / Label - string that holds the field's label // / in / record - int that shows what order in the input file this // record appears // / in / line - int that shows on what line of the input file this // error appears // // PRECONDITIONS: File has been properly opened to a valid output file, // otherErrors actually indicates whether any other errors have been found in // this section, whatsWrong correctly identifies the type of error found // // POSTCONDITIONS: A message indicating the type of error, it's location in the // input file, and the erroneous data has been written to the output file // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 *******************************************************************************/ void WriteDataError(ofstream& File,DataErrorType whatsWrong,bool otherErrors, string badData,string Label,int record,int line) { int spaces; // used to control width of column and line up output if (!otherErrors) // If this is the first error that has been found, { // we need to output the labels that appear at the // very top of each section of the output file that // actually has any errors in the input file File << "| rec # | line | field name | error" << " |" << endl; File << "|-------+------+-----------------+" << "-------------------------------------------" << endl; } File << "|" << setw(4) << record << " " << "|" << setw(4) << line << " " << "| " << Label.substr(0,Label.find(":",0)); // Pad the field name column with the appropriate number of spaces: for (spaces=0;spaces<(18-(Label.length()));spaces++) File << " "; File << "| "; // Print field separator // Output the error message that pertains to this error, and pad the // output file with spaces wherever necessary: switch (whatsWrong) { case CHAR_ERR: File << "invalid character in field: \'" << badData << "\'" << " |" << endl; break; case RANGE_ERR: File << "out of range: " << badData; for (spaces=0;spaces<(27-(badData.length()));spaces++) File << " "; File << "|" << endl; break; case INDEX_RANGE_ERR: File << "Index value " << badData << " must be non-negative"; for (spaces=0;spaces<(8-badData.length());spaces++) File << " "; File << "|" << endl; break; case INDEX_EXIST_ERR: File << "Index " << badData << " not found in parent table |" << endl; break; case DATE_ERR: File << "invalid date: \"" << badData << "\""; for (spaces=0;spaces<17;spaces++) File << " "; File << "|" << endl; break; case TIME_ERR: File << "invalid time: \"" << badData << "\""; for (spaces=0;spaces<20;spaces++) File << " "; File << "|" << endl; break; case ZIP_ERR: File << "invalid zip code format: \"" << badData << "\"" << " |" << endl; break; case ST_ERR: File << "invalid state code format: \"" << badData << "\"" << " |" << endl; break; case LANES_ERR: File << "invalid lane number: \"" << badData << "\"" << " |" << endl; break; } return; } /******************************************************************************* // FUNCTION NAME: WriteNoErrors // // DESCRIPTION OF FUNCTION: The function writes a message to the output file // saying that no errors were encountered in the section. // // DESCRIPTION OF ALGORITHM: The function echoes a line to the file // // CALLED BY: GetAlleyInfo, GetEventInfo, GetToolsInfo, GetReleaseInfo, // GetBallInfo, GetConditionsInfo, GetGameInfo, GetFramesInfo // CALLS: none // // PARAMETERS: / inout / File - File we're writing to // // PRECONDITIONS: File has been properly intialized to a valid output file. // // POSTCONDITIONS: A line containing the message "No errors." has been written // to the specified output file // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 *******************************************************************************/ void WriteNoErrors(ofstream& File) { File << '\t' << "No errors." << endl; // dull and deadly boring return; } /******************************************************************************* // FUNCTION NAME: WriteSectionFooter // // DESCRIPTION OF FUNCTION: The function prints a delimiter line marking the // end of a section in the file // // DESCRIPTION OF ALGORITHM: The function prints out 77 underscore marks // // CALLED BY: GetAlleyInfo, GetEventInfo, GetToolsInfo, GetReleaseInfo, // GetBallInfo, GetConditionsInfo, GetGameInfo, GetFramesInfo // CALLS: none // // PARAMETERS: / inout / File - output file we're writing stuff to // // PRECONDITIONS: File has been properly intialized to a valid output file // // POSTCONDITIONS: A line delimiting the sections of a BAM file has been // written to the specified file // // AUTHOR: Amy Langill *2B DATE: 2/22/1999 *******************************************************************************/ void WriteSectionFooter(ofstream& File) { int counter; // print out 77 underscore marks for (counter=0;counter<77;counter++) File << "_"; File << endl << endl; return; }