const std::vector<std::string> QtSitemapGeneratorMainDialog::GetHtmlFilesInFolder(const std::string& folder)
{
  //Get all filenames
  const std::vector<std::string> v = GetFilesInFolder(folder);

  //Create the regex for a correct HTML filename
  const boost::regex cpp_file_regex(".*\\.(html|htm)\\z");

  //Create the resulting std::vector
  std::vector<std::string> w;

  //Copy all filenames matching the regex in the resulting std::vector
  BOOST_FOREACH(const std::string& s, v)
  {
    if (boost::regex_match(s,cpp_file_regex)) w.push_back(s);
  }
  return w;
}
const std::vector<std::string> CreateGlossaryMainDialog::GetFilesInFolder(
  const std::string& folder,
  const std::string& regex_str)
{
  //Get all filenames
  const std::vector<std::string> v = GetFilesInFolder(folder);

  //Create the regex for a correct C++ filename
  const boost::regex regex(regex_str);

  //Create the resulting std::vector
  std::vector<std::string> w;

  //Copy all filenames matching the regex in the resulting std::vector
  std::for_each(v.begin(), v.end(),
    [&w,regex](const std::string& s)
    {
      if (boost::regex_match(s,regex)) w.push_back(s);
    }
  );

  return w;
}
Esempio n. 3
0
bool ComputeCommitSelection(const CommitDialog::SelectedFiles& userSelection,
                            const FilesWithBugnumbers* modified,
                            const FilesWithBugnumbers* added,
                            const FilesWithBugnumbers* removed,
                            const FilesWithBugnumbers* renamed,
                            std::vector<std::string>& result)
{
#if 0
    // Optimization: If all files are selected, we can simply do a 'cvs commit' in the top-level directories
    if (Includes(userSelection, modified) &&
        Includes(userSelection, added) &&
        Includes(userSelection, removed) &&
        Includes(userSelection, renamed))
    {
        std::set<std::string> modifiedDirs;
        if (modified)
            modifiedDirs = GetTopLevelDirs(*modified);
        std::set<std::string> addedDirs;
        if (addedDirs)
            addedDirs = GetTopLevelDirs(*added);
        std::set<std::string> removedDirs;
        if (removedDirs)
            removedDirs = GetTopLevelDirs(*removed);
        std::set<std::string> renamedDirs;
        if (renamedDirs)
            renamedDirs = GetTopLevelDirs(*renamed);
        std::set<std::string> dirs1;
        std::set_union(modifiedDirs.begin(), modifiedDirs.end(), addedDirs.begin(), addedDirs.end(), std::inserter(dirs1, dirs1.begin()));
        std::set<std::string> dirs2;
        std::set_union(removedDirs.begin(), removedDirs.end(), renamedDirs.begin(), renamedDirs.end(), std::inserter(dirs2, dirs2.begin()));
        std::set<std::string> dirs;
        std::set_union(dirs1.begin(), dirs1.end(), dirs2.begin(), dirs2.end(), std::inserter(dirs, dirs.begin()));
        result.clear();
        for (std::set<std::string>::iterator it = dirs.begin(); it != dirs.end(); ++it)
            result.push_back(*it);
        return true;
    }
    else
#endif
    {
        // Get list of non-renamed files
        result.clear();
        for (CommitDialog::SelectedFiles::const_iterator it = userSelection.begin(); it != userSelection.end(); ++it)
            result.push_back(it->first);

        // Check if any renames are to be committed
        std::vector<std::string> renameDirs;
        for (CommitDialog::SelectedFiles::const_iterator it = userSelection.begin(); it != userSelection.end(); ++it)
            if (it->second == CVSStatus::STATUS_RENAMED)
                renameDirs.push_back(GetDirectoryPart(it->first));

        // For each directory containing renamed files
        for (std::vector<std::string>::iterator it = renameDirs.begin(); it != renameDirs.end(); ++it)
        {
            // Check if this directory contains any modified files that the user did not select
            std::vector<std::string> files;
            if (modified)
                files = GetFilesInFolder(*modified, *it);  
            for (std::vector<std::string>::iterator fileIter = files.begin(); fileIter != files.end(); ++fileIter)
                if (find(result.begin(), result.end(), *fileIter) == result.end())
                    // This file is not selected
                    return false;

            // Same for added
            files.clear();
            if (added)
                files = GetFilesInFolder(*added, *it);  
            for (std::vector<std::string>::iterator fileIter = files.begin(); fileIter != files.end(); ++fileIter)
                if (find(result.begin(), result.end(), *fileIter) == result.end())
                    // This file is not selected
                    return false;

            // Same for removed
            files.clear();
            if (removed)
                files = GetFilesInFolder(*removed, *it);  
            for (std::vector<std::string>::iterator fileIter = files.begin(); fileIter != files.end(); ++fileIter)
                if (find(result.begin(), result.end(), *fileIter) == result.end())
                    // This file is not selected
                    return false;

            // Same for renamed
            files.clear();
            if (renamed)
                files = GetFilesInFolder(*renamed, *it);  
            for (std::vector<std::string>::iterator fileIter = files.begin(); fileIter != files.end(); ++fileIter)
                if (find(result.begin(), result.end(), *fileIter) == result.end())
                    // This file is not selected
                    return false;
        }
        // Remove all files from the directories where renames are being committed
        result.clear();
        for (CommitDialog::SelectedFiles::const_iterator it = userSelection.begin(); it != userSelection.end(); ++it)
        {
            std::string dir = GetDirectoryPart(it->first);
            if (find(renameDirs.begin(), renameDirs.end(), dir) == renameDirs.end())
                result.push_back(it->first);
        }
        // Add directories where renames are being committed
        for (std::vector<std::string>::iterator it = renameDirs.begin(); it != renameDirs.end(); ++it)
            result.push_back(*it);
    }
    return true;
}
void CreateGlossaryMainDialog::CreatePage(
  const std::string& page_name,
  const std::string& page_url,
  const std::string& regex)
{
  const std::vector<std::string> pagenames
    = GetFilesInFolder("/home/richel/ProjectRichelBilderbeek/Projects/RichelbilderbeekNl",regex);

  std::vector<HtmlPage> pages;
  std::for_each(pagenames.begin(),pagenames.end(),
    [&pages](const std::string& s)
    {
      pages.push_back(HtmlPage("/home/richel/ProjectRichelBilderbeek/Projects/RichelbilderbeekNl/" + s));
    }
  );

  std::sort(pages.begin(),pages.end());

  std::ofstream f(page_url.c_str());

  f
    << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
    << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
    << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
    << "<head>\n"
    << "  <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n"
    << "  <title>" << page_name << "</title>\n"
    << "  <meta name=\"description\" content=\"" << page_name << "\"/>\n"
    << "  <meta name=\"keywords\" content=\"" << page_name << " table of content index overview\"/>\n"
    << "  <link rel=\"stylesheet\" href=\"Richelbilderbeek.css\" type=\"text/css\"/>\n"
    << "</head>\n"
    << "<!-- End of head, start of body -->\n"
    << "<body>\n"
    << "<p><a href=\"index.htm\">Go back to Richel Bilderbeek's homepage</a>.</p>\n"
//    << "<p><a href=\"Cpp.htm\">Go back to Richel Bilderbeek's C++ page</a>.</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<!-- Page header -->\n"
    << "<h1><a href=\"" << page_url << "\">" << page_name << "</a></h1>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>This page is generated by the\n"
    << "<a href=\"CppTools.htm\">tool</a> <a href=\"ToolCreateGlossary.htm\">CreateGlossary</a>.</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<ul>\n";

  std::for_each(pages.begin(),pages.end(),
    [&f](const HtmlPage& p)
    {
      if (p.GetTitle() == "Redirection page"
        || p.GetTitle().empty()
        || p.GetFilename().find("_old.htm") != std::string::npos)
      {
        //continue;
      }
      else
      {
        std::string s
          = "  <li><a href=\""
          + boost::filesystem::path(p.GetFilename()).filename().string()
          + "\">"
          + p.GetTitle()
          + "</a></li>";

        s = HtmlPage::ReplaceAll(s,"&","[AMPERSAND]");
        s = HtmlPage::ReplaceAll(s,"[AMPERSAND]","&amp;");

        f << s << '\n';
      }
    }
  );

  TRACE(pagenames.size());

  f
    << "</ul>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>Number of pages: " << pagenames.size() << "</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p>&nbsp;</p>\n"
//    << "<p><a href=\"Cpp.htm\">Go back to Richel Bilderbeek's C++ page</a>.</p>\n"
    << "<p><a href=\"index.htm\">Go back to Richel Bilderbeek's homepage</a>.</p>\n"
    << "<p>&nbsp;</p>\n"
    << "<p><a href=\"http://validator.w3.org/check?uri=referer\"><img src=\"valid-xhtml10.png\" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a></p>\n"
    << "</body>\n"
    << "</html>\n";
}