📄 docsystem.cpp
字号:
bool ecHtmlIndexer::CreateHHCItem(const wxString& title, const wxString& topURL, const wxString& docDir, wxOutputStream& stream, int indent){ wxString sep(wxFILE_SEP_PATH); wxString topURL1(topURL); if (!UseRelativeURLs()) topURL1 = docDir + sep + topURL1; int i; for (i = 0; i < indent*2; i++) stream << " "; stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(title) << "\"><param name=\"Local\" value=\""; stream << topURL1 << "\"></OBJECT>\n"; return TRUE;}void ecHtmlIndexer::CreateHHCOutputItem(wxSimpleHtmlTag* tag, int level, int& indent, const wxString& pathPrefix, const wxString& docDir, wxOutputStream& stream){ wxString url, text; tag->GetAttributeValue(url, "HREF"); tag->FindTextUntilTagClose(text, "A"); text.Trim(TRUE); // Trim spaces from right of string text.Replace("\n", " "); // Remove newlines // Need to adjust the URL to give the path relative to where the index is url = pathPrefix + wxString(wxT("/")) + url; wxString sep(wxFILE_SEP_PATH); wxString url1(url); if (!UseRelativeURLs() && !wxIsAbsolutePath(url)) url1 = docDir + sep + url; int i; while (level > indent) { for (i = 0; i < indent*2; i++) stream << " "; stream << "<UL>"; indent ++; // If we're skipping one or more levels, we need to insert // a dummy node. if (level > indent) { stream << "\n"; for (i = 0; i < indent*2; i++) stream << " "; stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(text) << "\"><param name=\"Local\" value=\""; stream << url1 << "\"></OBJECT>"; } stream << "\n"; } while (level < indent) { indent--; for (i = 0; i < indent*2; i++) stream << " "; stream << "</UL>\n"; } for (i = 0; i < indent*2; i++) stream << " "; stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(text) << "\"><param name=\"Local\" value=\""; stream << url1 << "\"></OBJECT>\n";}void ecHtmlIndexer::CreateHHCWriteHeader(wxOutputStream& stream){ stream << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"; stream << "<HTML>\n<HEAD>\n<meta name=\"GENERATOR\" content=\"Microsoft® HTML Help Workshop 4.1\">\n"; stream << "<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n"; stream << "<UL>\n";}void ecHtmlIndexer::CreateHHCWriteFooter(wxOutputStream& stream){ stream << "</UL>\n"; stream << "</BODY></HTML>";}bool ecHtmlIndexer::CreateHHCStartSection(const wxString& title, const wxString& topURL, const wxString& docDir, wxOutputStream& stream){ wxString sep(wxFILE_SEP_PATH); wxString url1(topURL); if (!UseRelativeURLs() && !wxIsAbsolutePath(url1)) url1 = docDir + sep + url1; stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(title) << wxString("\">"); if (!topURL.IsEmpty()) { stream << "<param name=\"Local\" value=\""; stream << url1 << "\">" ; } stream << "</OBJECT>\n<UL>\n" ; return TRUE;}bool ecHtmlIndexer::CreateHHCEndSection(wxOutputStream& stream){ stream << "</UL>\n"; return TRUE;}// Write the project filebool ecHtmlIndexer::WriteHHP(const wxString& filename, const wxString& docDir){ wxFileOutputStream stream(filename); wxString sep(wxFILE_SEP_PATH); wxString path, name, ext; wxSplitPath(filename, & path, & name, & ext); wxString compiledFile(name + wxT(".chm")); wxString contentsFile(name + wxT(".hhc")); wxString keywordFile(name + wxT(".hhk")); stream << "[OPTIONS]\n\Auto Index=Yes\n\Binary Index=No\n\Compatibility=1.1 or later\n\Compiled file="; stream << compiledFile << "\nContents file=" << contentsFile << "\n"; stream << "Default Window=mainwin\n\Default topic="; if (!UseRelativeURLs()) stream << docDir + sep; stream << wxT("index.html") << "\n\Display compile progress=Yes\n\Full-text search=Yes\n" <<// Index file=" << keywordFile << "\n"Language=0x409 English (United States)\n\Title=eCos\n"; stream << "[WINDOWS]\n\mainwin=\"eCos Documentation\",\"eCos.hhc\",,,\"index.html\",\"http://sources.redhat.com/ecos/\",\"Net Release\",\"http://www.redhat.com/products/ecos/\",\"eCos Product\",0x40060420,,0xc287e,[0,0,762,400],,,,,,,0\n\\n\[FILES]\n\index.html\n\\n\[INFOTYPES]\n" ; // When we have the ability to generate a hhk, replace above line with: // mainwin=\"eCos Documentation\",\"eCos.hhc\",\"eCos.hhk\",,\"index.html\",\"http://sources.redhat.com/ecos/\",\"Net Release\",\"http://www.redhat.com/products/ecos/\",\"eCos Product\",0x40060420,,0xc287e,[0,0,762,400],,,,,,,0\n\ return TRUE;}// Create a section for all the Packages in the system, using the current document/repository.// TODO: check each URL for redirection.bool ecHtmlIndexer::CreateHHCPackagesSection(const wxString& title, const wxString& topURL, wxOutputStream& stream, const wxString& htmlPath){ ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); if (!doc) return FALSE; // If we have multiple tutorials or whatever, then we need to repeat this line ONCE // and then generate the multiple files. Otherwise we'll be repeating the same "Getting Started with eCos" // line. I.e. it'll only look right if we only have one tutorial. stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(title) << wxString("\">"); if (!topURL.IsEmpty()) { stream << "<param name=\"Local\" value=\""; stream << topURL << "\">" ; } stream << "</OBJECT>\n<UL>\n" ; // generate the contents of the add/remove list boxes const std::vector<std::string> & packages = doc->GetCdlPkgData ()->get_packages (); std::vector<std::string>::const_iterator package_i; for (package_i = packages.begin (); package_i != packages.end (); package_i++) { // if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not list hardware packages { const std::vector<std::string> & aliases = doc->GetCdlPkgData ()->get_package_aliases (* package_i); wxString strMacroName = package_i->c_str (); // use the first alias (if any) as the package identifier wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str(); ecConfigItem * pItem = doc->Find (strMacroName); if (pItem) // if the package is loaded { // TODO: what if the package is not loaded? how do we access the URL?? wxString url(pItem->GetURL()); url = htmlPath + wxString(wxFILE_SEP_PATH) + Redirect(htmlPath, url); stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(strPackageName) << wxString("\">"); if (!url.IsEmpty()) { stream << "<param name=\"Local\" value=\""; stream << url << "\">" ; } stream << "</OBJECT>\n" ; } } } stream << "</UL>\n"; return TRUE;}// Keeping looking for redirection until there's none.wxString ecHtmlIndexer::Redirect(const wxString& baseName, const wxString& url){ wxString path(baseName); path += wxFILE_SEP_PATH; path += url; wxString relativePath(wxPathOnly(url)); wxSimpleHtmlParser parser; if ((path.Find(wxT('#')) == -1) && wxFileExists(path) && parser.ParseFile(path)) { wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren(); wxSimpleHtmlTag* refreshTag = tag->FindTag(wxT("meta"), wxT("http-equiv")); if (refreshTag) { wxString value; if (refreshTag->GetAttributeValue(value, wxT("content"))) { if (!value.AfterFirst(wxT('=')).IsEmpty()) value = value.AfterFirst(wxT('=')) ; wxString newURL(relativePath + wxString(wxFILE_SEP_PATH) + value); return Redirect(baseName, newURL); } } } return url;}bool ecHtmlIndexer::DoIndexDocs(const wxString& reposDir, wxString& projectFile, bool force){ wxString sep(wxFILE_SEP_PATH); wxString docDir(reposDir + sep + wxString(wxT("doc"))) ; // The CVS repository has an HTML subdirectory, but the // packaged version doesn't if (wxDirExists(docDir + sep + wxT("html"))) docDir = docDir + sep + wxString(wxT("html")); wxString projectDir = FindIndexFilesDir(reposDir); projectFile = projectDir + sep + wxT("eCos.hhp"); wxString contentsFile = projectDir + sep + wxT("eCos.hhc"); wxString keywordFile = projectDir + sep + wxT("eCos.hhk"); // See if it's already been generated if (wxFileExists(projectFile) && !force) return TRUE; // Project file if (!WriteHHP(projectFile, docDir)) return FALSE; wxFileOutputStream stream(contentsFile); if (!stream.Ok()) return FALSE; // Pop up a progress dialog wxProgressDialog dialog(wxGetApp().GetSettings().GetAppName(), _("Compiling documentation index..."), m_indexItems.Number(), wxGetApp().GetTopWindow()); CreateHHCWriteHeader(stream); int count = 1; wxNode* node = m_indexItems.First(); while (node) { dialog.Update(count); count ++; ecIndexItem* item = (ecIndexItem*) node->Data(); wxString filename(item->m_urlToExamine); wxString urlFilename(item->m_urlToShow); if (!filename.IsEmpty()) { if (!wxIsAbsolutePath(filename)) filename = docDir + sep + filename;#ifdef __WXMSW__ filename.Replace(wxT("/"), wxT("\\"));#endif } // Check that the URL we're going to show is available, // otherwise don't output it bool isOk = TRUE; if (!urlFilename.IsEmpty()) { if (!wxIsAbsolutePath(urlFilename)) urlFilename = docDir + sep + urlFilename;#ifdef __WXMSW__ urlFilename.Replace(wxT("/"), wxT("\\"));#endif // Remove # part if there is any if (urlFilename.Find(wxT('#')) != -1) urlFilename = urlFilename.BeforeLast(wxT('#')); if (!wxFileExists(urlFilename)) isOk = FALSE; } if (isOk) { switch (item->m_type) { case ecIndexByClass: { CreateHHCByExaminingClass(item->m_title, item->m_urlToShow, filename, docDir, stream, item->m_startLevel); break; } case ecIndexByList: { CreateHHCByExaminingList(item->m_title, item->m_urlToShow, filename, docDir, stream, item->m_startLevel); break; } case ecIndexNoParse: { CreateHHCItem(item->m_title, item->m_urlToShow, docDir, stream, item->m_startLevel); break; } case ecIndexStartSection: { CreateHHCStartSection(item->m_title, item->m_urlToShow, docDir, stream); break; } case ecIndexEndSection: {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -