📄 docsystem.cpp
字号:
//####COPYRIGHTBEGIN####//// ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.// Copyright (C) 2003 John Dallaway//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 of the License, or (at your option)// any later version.//// This program is distributed in the hope that it will be useful, but WITHOUT// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for// more details.//// You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------////####COPYRIGHTEND####// docsystem.cpp :////===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): julians, jld// Contact(s): julians// Date: 2001/04/04// Version: $Id: docsystem.cpp,v 1.19 2001/12/11 15:59:51 julians Exp $// Purpose:// Description: Various classes for the documentation system// Requires:// Provides:// See also:// Known bugs:// Usage:////####DESCRIPTIONEND####////===========================================================================// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifdef __GNUG__#pragma implementation "docsystem.h"#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__#pragma hdrstop#endif#include "wx/dir.h"#include "wx/file.h"#include "wx/wfstream.h"#include "wx/progdlg.h"#include "docsystem.h"#include "htmlparser.h"#include "configtooldoc.h"#include "mainwin.h"#include "shortdescrwin.h"/* * ecHtmlIndexer * A class to parse files and generate suitable MS Html Help/wxHTML Help compatible * project, contents and keyword files. */ecHtmlIndexer::ecHtmlIndexer(bool useRelativeURLs){#if ecDOCSYSTEM_USE_RELATIVE_URLS m_useRelativeURLs = useRelativeURLs;#else m_useRelativeURLs = FALSE;#endif m_useOldDocs = TRUE; // Initialise some tables AddTutorialDirectory(wxT("arm"), wxT("ARM")); AddTutorialDirectory(wxT("am31-33"), wxT("AM31-33")); AddTutorialDirectory(wxT("i386pc"), wxT("i386 PC")); AddTutorialDirectory(wxT("ppc"), wxT("PowerPC")); AddTutorialDirectory(wxT("sh3"), wxT("SH-3")); AddTutorialDirectory(wxT("sparclite"), wxT("SPARClite")); AddTutorialDirectory(wxT("mips"), wxT("MIPS")); AddTutorialDirectory(wxT("v850"), wxT("V850")); AddEntityTranslation(wxT("—"), wxT("--")); AddEntityTranslation(wxT("&"), wxT("&")); AddEntityTranslation(wxT("“"), wxT("\"")); AddEntityTranslation(wxT("”"), wxT("\"")); AddEntityTranslation(wxT("["), wxT("[")); AddEntityTranslation(wxT("]"), wxT("]"));}ecHtmlIndexer::~ecHtmlIndexer(){ ClearItems();}// Append HHC-compatible code to a stream according to the tags found in the// given HTML file./*Find the name and URL from a chunk of HTML likethe following.<P CLASS="ChapterTitleTOC"> <A NAME="pgfId=141252"> </A> <A HREF="ecos-tutorial.4.html#pgfId=1065474" CLASS="Index"> Documentation Roadmap </A> <EM CLASS="PageNumber"></EM></P>We need to output something like this: <UL> <LI> <OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT> <LI> <UL> <LI> <OBJECT type="text/sitemap"><param name="Name" value="ARM"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT> <LI> <UL> <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html#pgfId=2052424"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="Foreword"><param name="Local" value="tutorials/arm/ecos-tutorial.3.html#pgfId=1065235"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="Documentation Roadmap"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1065474"></OBJECT> <LI><UL> <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046487"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos User's Guide"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046592"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos Reference Manual"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046692"></OBJECT> </UL> </UL> </UL> </UL>*/bool ecHtmlIndexer::CreateHHCByExaminingClass(const wxString& title, const wxString& topURL, const wxString& htmlFile, const wxString& docDir, wxOutputStream& stream, int startIndent){ if (!wxFileExists(htmlFile)) return FALSE; wxString sep(wxFILE_SEP_PATH); wxString pathPrefix(wxPathOnly(htmlFile)); if (!wxIsAbsolutePath(htmlFile)) { pathPrefix = pathPrefix.Mid(docDir.Length() + 1); } wxString topURL1(topURL); if (!UseRelativeURLs() && !wxIsAbsolutePath(topURL1)) topURL1 = docDir + sep + topURL1; wxSimpleHtmlParser parser; if (parser.ParseFile(htmlFile)) { stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(title) << wxString("\">"); if (!topURL.IsEmpty()) { stream << "<param name=\"Local\" value=\""; stream << topURL1 << "\"></OBJECT>"; } stream << "\n"; int indent = startIndent; wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren(); while (tag) { if (tag->GetType() == wxSimpleHtmlTag_Open) { wxSimpleHtmlAttribute* attr = NULL; if ((tag->NameIs("P") || tag->NameIs("DIV") || tag->NameIs("H1") || tag->NameIs("H2") || tag->NameIs("H3") || tag->NameIs("H4")) && (attr = tag->FindAttribute("CLASS"))) { int level = -1; if (attr->HasValue("Level1IX") || attr->HasValue("SectionTitleTOC") || attr->HasValue("IndexTitleTOC")) level = 1; else if (attr->HasValue("Level2IX") || attr->HasValue("ChapterTitleTOC") || attr->HasValue("IntroTitleTOC")) level = 2; else if (attr->HasValue("Heading1TOC")) level = 3; else if (attr->HasValue("Heading2TOC")) level = 4; if (level > -1) { wxSimpleHtmlTag* aTag = tag->FindTag("A", "HREF"); if (aTag) CreateHHCOutputItem(aTag, level, indent, pathPrefix, docDir, stream); } } } tag = tag->GetNext(); } // Close any remaining levels int i; while (indent > startIndent) { indent --; for (i = 0; i < indent*2; i++) stream << " "; stream << "</UL>\n"; } return TRUE; } else return FALSE; }// Append HHC-compatible code to a stream according to the tags found in the// given HTML file. Use level of <DL> to determine contents heading level./*Find the name and URL from a chunk of HTML likethe following.<DL> <DT> <B>Table of Contents</B> </DT> <DT> 1. <A HREF="overview.html">Overview</A> </DT> <DD> <DL> <DT> <A HREF="overview.html#OVERVIEW.TERMINOLOGY">Terminology</A> </DT> <DD> <DL> <DT> <A HREF="overview.html#CONCEPTS.TERMINOLOGY.FRAMEWORK">Component Framework</A> </DT> ... <UL> <LI> <OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT> <LI> <UL> <LI> <OBJECT type="text/sitemap"><param name="Name" value="ARM"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT> <LI> <UL> <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html#pgfId=2052424"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="Foreword"><param name="Local" value="tutorials/arm/ecos-tutorial.3.html#pgfId=1065235"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="Documentation Roadmap"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1065474"></OBJECT> <LI><UL> <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046487"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos User's Guide"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046592"></OBJECT> <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos Reference Manual"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046692"></OBJECT> </UL> </UL> </UL> </UL>*/bool ecHtmlIndexer::CreateHHCByExaminingList(const wxString& title, const wxString& topURL, const wxString& htmlFile, const wxString& docDir, wxOutputStream& stream, int startIndent){ if (!wxFileExists(htmlFile)) return FALSE; // The path prefix is the path relative to the doc dir wxString sep(wxFILE_SEP_PATH); wxString pathPrefix(wxPathOnly(htmlFile)); if (!wxIsAbsolutePath(htmlFile)) { pathPrefix = pathPrefix.Mid(docDir.Length() + 1); } wxString topURL1(topURL); if (!UseRelativeURLs() && !wxIsAbsolutePath(topURL1)) topURL1 = docDir + sep + topURL1; wxSimpleHtmlParser parser; if (parser.ParseFile(htmlFile)) { stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\""; stream << TranslateEntities(title) << wxString("\">"); if (!topURL.IsEmpty()) { stream << "<param name=\"Local\" value=\""; stream << topURL1 << "\"></OBJECT>"; } stream << "\n"; int indent = startIndent; int level = 0; wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren(); while (tag) { if (tag->GetType() == wxSimpleHtmlTag_Open && tag->NameIs("DL")) level ++ ; if (tag->GetType() == wxSimpleHtmlTag_Close && tag->NameIs("DL")) level -- ; if (tag->GetType() == wxSimpleHtmlTag_Open && tag->NameIs("A") && tag->HasAttribute("HREF") && level > 0) CreateHHCOutputItem(tag, level, indent, pathPrefix, docDir, stream); // If we get to list of figures/tables/examples, finish if (tag->GetType() == wxSimpleHtmlTag_Text) { if (tag->GetText() == wxT("List of Figures") || tag->GetText() == wxT("List of Tables") || tag->GetText() == wxT("List of Examples")) { tag = NULL; } } if (tag) tag = tag->GetNext(); } // Close any remaining levels int i; while (indent > startIndent) { indent --; for (i = 0; i < indent*2; i++) stream << " "; stream << "</UL>\n"; } return TRUE; } else return FALSE; }// Just add the given contents item without parsing
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -