/*========================================================================= Program: KWStyle - Kitware Style Checker Module: kwsGenerator.cxx Copyright (c) Kitware, Inc. All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "kwsGenerator.h" #include "kwsXMLReader.h" #include // atoi #include namespace kws { struct DirectorySorting { bool operator()(const std::string& a,const std::string& b) { return a.compare(b) < 0; } }; struct FilenameSorting { bool operator()(const std::string& a,const std::string& b) { std::string nameA = kwssys::SystemTools::GetFilenameName(a); std::string nameB = kwssys::SystemTools::GetFilenameName(b); return nameA.compare(nameB) < 0; } }; /** Constructor */ Generator::Generator() { m_Parsers = nullptr; m_ProjectTitle = ""; m_ProjectLogo = "Logo.gif"; m_KWStyleLogo = "kwstylelogo.jpg"; m_MaxDirectoryDepth = 99; m_ErrorThreshold = 0; } /** Destructor */ Generator::~Generator() = default; /** Read the configuration file */ void Generator::ReadConfigurationFile(const char* configFile) { kws::XMLReader reader; if(reader.Open(configFile)) { m_ProjectTitle = reader.GetValue("Project"); m_ProjectLogo = reader.GetValue("ProjectLogo"); m_KWStyleLogo = reader.GetValue("KWStyleLogo"); m_ErrorThreshold = atoi(reader.GetValue("ErrorThreshold").c_str()); reader.Close(); } } /** Generate the description of the test. * For the moment we assume that all the test have the same description */ bool Generator::GenerateDescription(const char* dir) { std::cout << "Generating Description..."; std::string filename = dir; if((dir[strlen(dir)-1] != '/') && dir[strlen(dir)-1] != '\\') { filename += "/"; } filename += "KWSDescription.html"; std::ofstream file; file.open(filename.c_str(), std::ios::binary | std::ios::out); if(!file.is_open()) { std::cout << "Cannot open file for writing: " << std::endl; return false; } std::string title = filename; if (!m_ProjectTitle.empty()) { title = "Description for " + m_ProjectTitle; } this->CreateHeader(&file,title.c_str()); file << "
" << std::endl; if (!m_Parsers->empty()) { ParserVectorType::const_iterator it = m_Parsers->begin(); for(unsigned int i=0;i" << std::endl; file << ErrorTag[i] << std::endl; file << " : " << std::endl; file << (*it).GetTestDescription(i).c_str() << std::endl; file << "
" << std::endl; } } } this->CreateFooter(&file); file.close(); std::cout << "done" << std::endl; return true; } /** Generate the Matrix representation */ bool Generator::GenerateMatrix(const char* dir,bool showAllErrors) { std::cout << "Generating Matrix..."; std::string filename = dir; if((dir[strlen(dir)-1] != '/') && dir[strlen(dir)-1] != '\\') { filename += "/"; } filename += "KWSMatrix.html"; std::ofstream file; file.open(filename.c_str(), std::ios::binary | std::ios::out); if(!file.is_open()) { std::cout << "Cannot open file for writing: " << std::endl; return false; } std::string title = filename; if (!m_ProjectTitle.empty()) { title = "Matrix for " + m_ProjectTitle; } this->CreateHeader(&file,title.c_str()); // Contruct the table file << R"()" << std::endl; file << "" << std::endl; file << " " << std::endl; unsigned int i = 0; // Check the number of tests that have been performed int tests[NUMBER_ERRORS]; for(i=0;ibegin(); while(it != m_Parsers->end()) { for(i=0;i" << std::endl; file << "
" << ErrorTag[i] << "
" << std::endl; file << " " << std::endl; } file << "
" << std::endl; bool gotErrors = false; // The sorting is tricky. std::vector directories; std::vector filenames; std::vector singleFilenames; it = m_Parsers->begin(); while(it != m_Parsers->end()) { std::string localdir = kwssys::SystemTools::GetFilenamePath((*it).GetFilename()); if (!localdir.empty()) { directories.push_back(localdir); } else { singleFilenames.push_back((*it).GetFilename()); } filenames.push_back((*it).GetFilename()); it++; } // We sort first by directory std::sort(directories.begin(),directories.end(),DirectorySorting()); // Then by filenames std::sort(filenames.begin(),filenames.end(),FilenameSorting()); std::sort(singleFilenames.begin(),singleFilenames.end(),FilenameSorting()); // Add the singleFilenames first std::vector sortedFilenames; std::vector::const_iterator itSF = singleFilenames.begin(); while(itSF != singleFilenames.end()) { sortedFilenames.push_back(*itSF); itSF++; } // Then merge the two lists std::vector::const_iterator itDir = directories.begin(); std::string currentDir = ""; while(itDir != directories.end()) { if(strcmp((*itDir).c_str(),currentDir.c_str())) { currentDir = *itDir; std::vector::const_iterator itFiles = filenames.begin(); while(itFiles != filenames.end()) { if(!strcmp(kwssys::SystemTools::GetFilenamePath(*itFiles).c_str(),currentDir.c_str())) { sortedFilenames.push_back(*itFiles); } itFiles++; } } itDir++; } std::vector::const_iterator itSorted = sortedFilenames.begin(); std::string currentPath = ""; while(itSorted != sortedFilenames.end()) { Parser parser; // Find the current parser it = m_Parsers->begin(); while(it != m_Parsers->end()) { if(!strcmp((*it).GetFilename().c_str(),(*itSorted).c_str())) { parser = *it; break; } it++; } if (parser.GetFilename().empty()) { std::cout << "CANNOT FIND PARSER!" << std::endl; continue; } if (!showAllErrors && parser.GetErrors().empty()) { itSorted++; continue; } gotErrors = true; // If we have a new directory we show it on a new line std::string filenamePath = kwssys::SystemTools::GetFilenamePath(parser.GetFilename()); if(currentPath != filenamePath) { file << "" << std::endl; file << " " << std::endl; file << R"( " << std::endl; currentPath = filenamePath; } // Replace '/' by '_' (and strip any colon) std::string localfilename = parser.GetFilename(); if(long int pos = localfilename.find(":/") != std::string::npos) { localfilename = localfilename.substr(pos+2,localfilename.size()-pos-2); } if(long int pos = localfilename.find(":\\") != std::string::npos) { localfilename = localfilename.substr(pos+2,localfilename.size()-pos-2); } auto slash = static_cast(localfilename.find_last_of("/")); unsigned int index = 0; while (slash != -1 && index < m_MaxDirectoryDepth) { localfilename.replace(slash, 1, "_"); slash = static_cast(localfilename.find_last_of("/")); index++; } slash = static_cast(localfilename.find_last_of("/")); if(slash != -1) { localfilename = localfilename.substr(slash+1,localfilename.size()-slash-1); } slash = static_cast(parser.GetFilename().find_last_of("/")); std::string nameofclass = parser.GetFilename().substr(slash+1,(parser.GetFilename().size())-slash-1); std::string filenamecorrect = nameofclass; localfilename += ".html"; // Fill in the table file << "" << std::endl; file << " " << std::endl; width = 90/nTests; for(i=0;i" << std::endl; file << "
" << nerror << "
" << std::endl; file << " " << std::endl; } file << "
" << std::endl; itSorted++; } // If we have error reporting we display a summary if(gotErrors) { file << "" << std::endl; file << " " << std::endl; width = 90/nTests; for (int nerror : tests) { // Count the number of errors for this type of error if (nerror == -1) { continue; } file << " " << std::endl; } file << "" << std::endl; } file << "
" << std::endl; file << "
Filename
" << std::endl; file << "
)" << std::endl; ; file << filenamePath.c_str() << std::endl; file << "
" << std::endl; file << R"( " << std::endl; file << "
" << std::endl; file << "
Summary
" << std::endl; file << "
" << std::endl; file << "
" << nerror << "
" << std::endl; file << "
" << std::endl; // If no error we say it if(!gotErrors) { file << "
No error reported
" << std::endl; } this->CreateFooter(&file); file.close(); std::cout << "done" << std::endl; return true; } /** Generate the HTML files */ bool Generator::GenerateHTML(const char* dir,bool showAllErrors) { // Check if the directory exists. If not create it kwssys::Directory directory; if(!directory.Load(dir)) { std::cout << "Creating HTML directory: " << dir << std::endl; if(!kwssys::SystemTools::MakeDirectory(dir)) { std::cout << "Cannot create HTML directory: " << dir << std::endl; } } std::string imagedir = dir; imagedir += "/images"; // Copy the m_ProjectLogo and m_KWStyleLogo to the images directory if (!m_ProjectLogo.empty() || !m_KWStyleLogo.empty()) { if(!kwssys::SystemTools::MakeDirectory(imagedir.c_str())) { std::cout << "Cannot create images directory: " << imagedir.c_str() << std::endl; } } if (!m_ProjectLogo.empty()) { std::string imageProjectLogo = imagedir; imageProjectLogo += "/"; imageProjectLogo += kwssys::SystemTools::GetFilenameName(m_ProjectLogo.c_str()); if(!kwssys::SystemTools::CopyFileIfDifferent(m_ProjectLogo.c_str(),imageProjectLogo.c_str())) { std::cout << "Cannot copy the project logo file: " << m_ProjectLogo.c_str() << " into " << imageProjectLogo.c_str() << std::endl; } } if (!m_KWStyleLogo.empty()) { std::string imageKWStyleLogo = imagedir; imageKWStyleLogo += "/"; imageKWStyleLogo += kwssys::SystemTools::GetFilenameName(m_KWStyleLogo.c_str()); if(!kwssys::SystemTools::CopyFileIfDifferent(m_KWStyleLogo.c_str(),imageKWStyleLogo.c_str())) { std::cout << "Cannot copy the KWStyle logo file: " << m_KWStyleLogo.c_str() << " into " << imageKWStyleLogo.c_str() << std::endl; } } // Generate the matrix representation this->GenerateMatrix(dir,showAllErrors); this->GenerateDescription(dir); std::cout << "Generating HTML..."; // For each file we generate an html page ParserVectorType::const_iterator it = m_Parsers->begin(); while(it != m_Parsers->end()) { if (!showAllErrors && (*it).GetErrors().empty()) { it++; continue; } std::ofstream file; if ((*it).GetFilename().empty()) { it++; continue; } // Extract the filename // Replace '/' by '_' std::string filename = dir; filename += "/"; std::string filename2 = (*it).GetFilename(); if(long int pos = filename2.find(":/") != std::string::npos) { filename2 = filename2.substr(pos+2,filename2.size()-pos-2); } if(long int pos = filename2.find(":\\") != std::string::npos) { filename2 = filename2.substr(pos+2,filename2.size()-pos-2); } auto slash = static_cast(filename2.find_last_of("/")); unsigned int i = 0; while (slash != -1 && i < m_MaxDirectoryDepth) { filename2.replace(slash, 1, "_"); slash = static_cast(filename2.find_last_of("/")); i++; } slash = static_cast(filename2.find_last_of("/")); if(slash != -1) { filename2 = filename2.substr(slash+1,filename2.size()-slash-1); } filename += filename2; filename += ".html"; file.open(filename.c_str(), std::ios::binary | std::ios::out); if(!file.is_open()) { std::cout << "Cannot open file for writing: " << std::endl; return false; } this->CreateHeader(&file,filename.c_str()); file << R"()" << std::endl; // To speedup the process we list the lines that have errors using ErrorLineType = std::pair>; std::vector errorLines; const Parser::ErrorVectorType errors = (*it).GetErrors(); auto itError = errors.begin(); while (itError != errors.end()) { for (unsigned long index = (*itError).line; index <= (*itError).line2; index++) { ErrorLineType errLine; errLine.first = index; // Check if the line already exists auto errorLineIt = errorLines.begin(); while (errorLineIt != errorLines.end()) { if ((*errorLineIt).first == static_cast(index)) { break; } errorLineIt++; } if (errorLineIt != errorLines.end()) { (*errorLineIt).second.push_back((*itError).number); } else { errLine.second.push_back((*itError).number); errorLines.push_back(errLine); } } itError++; } bool comment = false; unsigned long nLines = (*it).GetNumberOfLines(); for(i=0;i::const_iterator errorLineIt = errorLines.begin(); while(errorLineIt != errorLines.end()) { if((*errorLineIt).first == static_cast(i+1)) { auto err = (*errorLineIt).second.begin(); while(err != (*errorLineIt).second.end()) { error = *err; if (errorTag.empty()) { errorTag += (*it).GetErrorTag(error); } else { errorTag += ","; errorTag += (*it).GetErrorTag(error); } err++; } break; } errorLineIt++; } if(error>=0) { file << "" << std::endl; } else { file << "" << std::endl; } // First column is the line number file << "" << std::endl; // Second column is the error tag file << "" << std::endl; std::string l = (*it).GetLine(i); // If the error is of type INDENT we show the problem as * if(errorTag.find("IND") != std::string::npos) { unsigned int k = 0; while((l[k] == ' ') || (l[k] == '\n')) { if(l[k] == ' ') { l[k]='*'; } k++; } } // If the error is of type extra spaces we show the problem as * if(errorTag.find("ESP") != std::string::npos) { int k = static_cast(l.size())-1; while(k>0 && (l[k] == ' ')) { l[k]='*'; k--; } } // Remove the first \n auto p = static_cast(l.find('\n')); if (p != -1) { l.replace(p, 1, ""); } // Replace < and > auto inf = static_cast(l.find("<", 0)); while (inf != -1) { l.replace(inf, 1, "<"); inf = static_cast(l.find("<", 0)); } auto sup = static_cast(l.find(">", 0)); while (sup != -1) { l.replace(sup, 1, ">"); sup = static_cast(l.find(">", 0)); } // Replace the space by   auto space = static_cast(l.find(' ', 0)); while (space != -1) { l.replace(space, 1, " "); space = static_cast(l.find(' ', space + 1)); } // Show the comments in green if(comment) { l.insert(0,""); } // Show the comments in green space = static_cast(l.find("//",0)); if(space != -1) { l.insert(space,""); l += ""; } else { space = static_cast(l.find("/*",0)); while(space != -1) { comment = true; l.insert(space,""); space = static_cast(l.find("/*",space+23)); } if(comment) { l.insert(l.size(),""); } space = static_cast(l.find("*/",0)); while(space != -1) { comment = false; l.insert(space+2,""); space = static_cast(l.find("*/",space+8)); } } file << R"(" << std::endl; file << "" << std::endl; } file << "
" << i+1 << "" << errorTag.c_str() << ")" << l.c_str() << "
" << std::endl; this->CreateFooter(&file); file.close(); it++; } std::cout << "done" << std::endl; return true; } /** Create Header */ bool Generator::CreateHeader(std::ostream * file,const char* title) { *file << "" << std::endl; *file << "" << std::endl; *file << R"( )" << std::endl; *file << R"( )" << std::endl; *file << R"( )" << std::endl; *file << R"( )" << std::endl; *file << R"( )" << std::endl; *file << " KWStyle - " << title << "" << std::endl; *file << "" << std::endl; // Now create the top frame *file << R"()" << std::endl; *file << " " << std::endl; *file << R"( " << std::endl; *file << R"( " << std::endl; *file << " " << std::endl; *file << "
)" << std::endl; // remove the last extension std::string tit = title; auto pos = static_cast(tit.find_last_of(".")); if (pos != -1) { tit = tit.substr(0, pos); } pos = static_cast(tit.find_last_of("/")); if(pos!=-1) { tit = tit.substr(pos+1,tit.size()-pos-1); } *file << R"(
KWStyle - )" << tit.c_str() << "
" << std::endl; *file << "
" << std::endl; *file << R"()" << std::endl; *file << " " << std::endl; *file << R"( )" << std::endl; *file << R"( " << std::endl; *file << R"( " << std::endl; *file << R"( " << std::endl; *file << " " << std::endl; *file << "
  )" << std::endl; *file << R"( )" << std::endl; *file << " )" << std::endl; *file << R"( )" << std::endl; *file << " )" << std::endl; *file << "
" << std::endl; *file << "
" << std::endl; *file << "
" << std::endl; *file << "
"; return true; } /** Create Footer */ bool Generator::CreateFooter(std::ostream * file) { *file << "
"; *file << R"()"; *file << ""; *file << ""; *file << ""; *file << ")"; *file << ""; *file << "
Generated by KWStyle 1.0b on " << kwssys::SystemTools::GetCurrentDateTime("%A %B,%d at %I:%M:%S%p") << ""; if (!m_KWStyleLogo.empty()) { *file << R"(
)" << std::endl; } *file << "
"; *file << R"(
"; *file << "
"; *file << "" << std::endl; return true; } /** Export the HTML report */ void Generator::ExportHTML(std::ostream & output) { // For each file we generate an html page ParserVectorType::const_iterator it = m_Parsers->begin(); while(it != m_Parsers->end()) { if ((*it).GetFilename().empty()) { it++; continue; } // Extract the filename std::string filename = ""; long int slash = static_cast((*it).GetFilename().find_last_of("/")); if(slash == -1) { slash = 0; } std::string nameofclass = (*it).GetFilename().substr(slash+1,((*it).GetFilename().size())-slash-1); filename += nameofclass; filename += ".html"; //this->CreateHeader(&output,filename.c_str()); output << R"()" << std::endl; bool comment = false; for(unsigned int i=0;i<(*it).GetNumberOfLines();i++) { // Look in the errors if there is a match for this line long error = -1; std::string errorTag = ""; const Parser::ErrorVectorType errors = (*it).GetErrors(); auto itError = errors.begin(); while(itError != errors.end()) { if( ((i+1>=(*itError).line) && (i+1<=(*itError).line2)) ) { if (errorTag.empty()) { errorTag += (*it).GetErrorTag((*itError).number); } else { errorTag += ","; errorTag += (*it).GetErrorTag((*itError).number); } error = (*itError).number; } itError++; } if(error>=0) { output << "" << std::endl; } else { output << "" << std::endl; } // First column is the line number output << "" << std::endl; // Second column is the error tag output << "" << std::endl; std::string l = (*it).GetLine(i); // If the error is of type INDENT we show the problem as _ if(errorTag.find("IND") != std::string::npos) { unsigned int k = 0; while((l[k] == ' ') || (l[k] == '\n')) { if(l[k] == ' ') { l[k]='*'; } k++; } } // Remove the first \n auto p = static_cast(l.find('\n')); if (p != -1) { l.replace(p, 1, ""); } // Replace < and > auto inf = static_cast(l.find("<", 0)); while (inf != -1) { l.replace(inf, 1, "<"); inf = static_cast(l.find("<", 0)); } auto sup = static_cast(l.find(">", 0)); while (sup != -1) { l.replace(sup, 1, ">"); sup = static_cast(l.find(">", 0)); } // Replace the space by   auto space = static_cast(l.find(' ', 0)); while (space != -1) { l.replace(space, 1, " "); space = static_cast(l.find(' ', space + 1)); } // Show the comments in green if(comment) { l.insert(0,""); } // Show the comments in green space = static_cast(l.find("//",0)); if(space != -1) { l.insert(space,""); l += ""; } else // if we have a line like // */ this is a single line comment { space = static_cast(l.find("/*",0)); while(space != -1) { comment = true; l.insert(space,""); space = static_cast(l.find("/*",space+23)); } if(comment) { l.insert(l.size(),""); } space = static_cast(l.find("*/",0)); while(space != -1) { comment = false; l.insert(space+2,""); space = static_cast(l.find("*/",space+8)); } } output << R"(" << std::endl; output << "" << std::endl; } output << "
" << i+1 << "" << errorTag.c_str() << ")" << l.c_str() << "
" << std::endl; this->CreateFooter(&output); it++; } } /** Generate dart files */ bool Generator::GenerateDart(const char* dir,int maxError, bool group,std::string url, double time,std::string basedirectory) { std::cout << "Generating Dart..."; // We try to find the TAG file std::string dirname = dir; if(dir[strlen(dir)-1] != '/' && dir[strlen(dir)-1] != '\\') { dirname += "/"; } dirname += "Testing/"; std::string tag = dirname+"TAG"; std::ifstream tagfile; tagfile.open(tag.c_str(), std::ios::binary | std::ios::in); if(!tagfile.is_open()) { std::cout << "Cannot open file for reading: " << tag.c_str() << std::endl; return false; } // We read the first line of the file which gives the path to the actual // directory char* bufferTag = new char[255]; tagfile.getline(bufferTag,255); if(bufferTag[strlen(bufferTag)-1] == '\r') { bufferTag[strlen(bufferTag)-1] = '\0'; } dirname += bufferTag; dirname += "/"; delete [] bufferTag; // We should have a Configure.xml file in the directory std::string configname = dirname+"Configure.xml"; std::ifstream configfile; configfile.open(configname.c_str(), std::ios::binary | std::ios::in); if(!configfile.is_open()) { std::cout << "Cannot open file for reading: " << configname.c_str() << std::endl; return false; } // Create the Build.xml file std::ofstream file; std::string filename = dirname+"Build.xml"; file.open(filename.c_str(), std::ios::binary | std::ios::out); if(!file.is_open()) { std::cout << "Cannot open file for writing: " << std::endl; return false; } // Generate the header char* buffer = new char[255]; configfile.getline(buffer,255); file << buffer << std::endl; configfile.getline(buffer,255); file << buffer << std::endl; std::string currentLine = buffer; while(currentLine.find(">") == std::string::npos) { configfile.getline(buffer,255); currentLine = buffer; file << buffer << std::endl; } delete [] buffer; file << "" << std::endl; file << " "; file << kwssys::SystemTools::GetCurrentDateTime("%b %d %H:%M:%S %z"); file << "" << std::endl; file << " "; file << static_cast(kwssys::SystemTools::GetTime()); file << "" << std::endl; file << "KWStyle" << std::endl; int nErrors = 0; ParserVectorType::const_iterator it = m_Parsers->begin(); while(it != m_Parsers->end()) { std::string sourcefile = (*it).GetFilename(); if (!basedirectory.empty()) { sourcefile = sourcefile.substr(basedirectory.size()); } bool first = true; const Parser::ErrorVectorType errors = (*it).GetErrors(); auto itError = errors.begin(); while(itError != errors.end()) { if((!group) || (first && group)) { file << "" << std::endl; file << " 1" << std::endl; file << " "; file << sourcefile.c_str(); file << "" << std::endl; file << " "; file << (*itError).line; file << "" << std::endl; if (!url.empty()) { // We had a link to the dashboard /*long int posslash = (*it).GetFilename().find_last_of("/"); long int posbackslash = (*it).GetFilename().find_last_of("\\"); long int pos = 0; if(posslash != -1 && posslash>posbackslash) { pos = posslash; } if(posbackslash != -1 && posbackslash>posslash) { pos = posbackslash; } if(pos == 0) { pos++; } std::string htmlfile = (*it).GetFilename().substr(pos+1,(*it).GetFilename().size()-pos-1); */ std::string htmlfile = (*it).GetFilename(); if(long int pos = htmlfile.find(":/") != std::string::npos) { htmlfile = htmlfile.substr(pos+2,htmlfile.size()-pos-2); } if(long int pos = htmlfile.find(":\\") != std::string::npos) { htmlfile = htmlfile.substr(pos+2,htmlfile.size()-pos-2); } auto slash = static_cast(htmlfile.find_last_of("/")); unsigned int i = 0; while (slash != -1 && i < m_MaxDirectoryDepth) { htmlfile.replace(slash, 1, "_"); slash = static_cast(htmlfile.find_last_of("/")); i++; } slash = static_cast(htmlfile.find_last_of("/")); if(slash != -1) { htmlfile = htmlfile.substr(slash+1,htmlfile.size()-slash-1); } htmlfile += ".html"; file << ""<< url.c_str() << "/" << htmlfile.c_str() << "" << std::endl; file << "View KWStyle File" << std::endl; } first = false; file << " "; } file << sourcefile.c_str(); file << " : "; file << (*it).GetErrorTag((*itError).number); file << " : "; std::string desc = (*itError).description; auto pos = static_cast(desc.find("&", 0)); while(pos != -1) { desc.replace(pos,1,"&"); pos = static_cast(desc.find("&",pos+3)); } pos = static_cast(desc.find("<")); while(pos != -1) { desc.replace(pos,1,"<"); pos = static_cast(desc.find("<")); } pos = static_cast(desc.find(">")); while(pos != -1) { desc.replace(pos,1,">"); pos = static_cast(desc.find(">")); } desc += " ["+(*it).GetTestDescription((*itError).number)+"] ("; constexpr size_t length = 255; char* val = new char[length]; snprintf(val,length,"%ld",(*itError).line); desc += val; desc += ")\n"; delete [] val; file << desc; if(!group) { file << "" << std::endl; // Show the actual error in the precontext file << " "; //file << (*it).GetTestDescription((*itError).number) << std::endl; file << "" << std::endl; file << ""; file << "" << std::endl; file << "0" << std::endl; file << "" << std::endl; } itError++; nErrors++; if((maxError != -1) && (nErrors >= maxError)) { break; } } if(group && !first) { file << "" << std::endl; // Show the actual error in the precontext file << " "; //file << (*it).GetTestDescription((*itError).number) << std::endl; file << "" << std::endl; file << ""; file << "" << std::endl; file << "0" << std::endl; file << "" << std::endl; } if((maxError != -1) && (nErrors >= maxError)) { break; } it++; } // Write the footer file << R"( )" << std::endl; file << " " << std::endl; file << " "; file << kwssys::SystemTools::GetCurrentDateTime("%b %d %I:%M:%S %z"); file << "" << std::endl; double time1 = kwssys::SystemTools::GetTime(); constexpr size_t length = 10; char *timestr = new char[length]; snprintf(timestr, length, "%.1f", (time1 - time) / 60.0); file << " " << timestr << "" << std::endl; file << "" << std::endl; delete[] timestr; configfile.close(); file.close(); std::cout << "Done." << std::endl; return true; } /** Generate a simple XML report of the errors */ bool Generator::ExportXML(const char* filename) { std::ofstream file; file.open(filename, std::ios::binary | std::ios::out); if(!file.is_open()) { std::cout << "Cannot open file for writing: " << std::endl; return false; } ParserVectorType::const_iterator it = m_Parsers->begin(); while(it != m_Parsers->end()) { const Parser::ErrorVectorType errors = (*it).GetErrors(); auto itError = errors.begin(); while(itError != errors.end()) { file << "" << std::endl; file << " " << (*itError).line << "" << std::endl; file << " " << (*itError).line2 << "" << std::endl; file << " " << (*itError).number << "" << std::endl; file << "" << std::endl; itError++; } it++; } file.close(); return true; } } // end namespace kws