Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
10 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. MergedHHK.h
  5. Abstract:
  6. This file contains the declaration of the classes used to parse and
  7. process HHK files.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 12/18/99
  10. created
  11. ******************************************************************************/
  12. #if !defined(__INCLUDED___HCP___MERGEDHHK_H___)
  13. #define __INCLUDED___HCP___MERGEDHHK_H___
  14. #include <TaxonomyDatabase.h>
  15. #define HHK_BUF_SIZE (32 * 1024)
  16. namespace HHK
  17. {
  18. /*
  19. The Following HHK Exerpt serves as an example to keep at hand in order to understand
  20. the way the different objects interact.
  21. <LI> <OBJECT type="text/sitemap">
  22. <param name="Name" value=".bmp files">
  23. <param name="Name" value="Using Paint to create pictures">
  24. <param name="Local" value="app_paintbrush.htm">
  25. <param name="Name" value="To change the background of your desktop">
  26. <param name="Local" value="win_deskpr_changebackgrnd.htm">
  27. </OBJECT>
  28. */
  29. /*
  30. Entry represents just the basic HHK entries. Basic HHK entries are comprised of
  31. a couple of Param Name="Name" and Param Name="Local" lines. the first line contains
  32. in its value attribute the Title of the Entry, and the second the url. In the example
  33. the relevant lines are:
  34. <param name="Name" value="Using Paint to create pictures">
  35. <param name="Local" value="app_paintbrush.htm">
  36. In this case m_strTitle == "Using Paint to create pictures"
  37. and m_lstUrl == "app_paintbrush.htm"
  38. */
  39. class Entry
  40. {
  41. public:
  42. typedef std::list<MPC::string> UrlList;
  43. typedef UrlList::iterator UrlIter;
  44. typedef UrlList::const_iterator UrlIterConst;
  45. MPC::string m_strTitle;
  46. UrlList m_lstUrl;
  47. void MergeURLs( const Entry& entry );
  48. };
  49. /*
  50. A section, is everything that is between a line that starts with:
  51. <LI> <OBJECT type="text/sitemap"
  52. and the closing line which is:
  53. </OBJECT>
  54. A section may contain subsections. Finally a section may be in the form of multiple
  55. entries, or in the form of see also
  56. */
  57. class Section
  58. {
  59. public:
  60. typedef std::list<Entry> EntryList;
  61. typedef EntryList::iterator EntryIter;
  62. typedef EntryList::const_iterator EntryIterConst;
  63. typedef std::list<Section*> SectionList;
  64. typedef SectionList::iterator SectionIter;
  65. typedef SectionList::const_iterator SectionIterConst;
  66. MPC::string m_strTitle;
  67. EntryList m_lstEntries;
  68. MPC::string m_strSeeAlso;
  69. SectionList m_lstSeeAlso;
  70. Section();
  71. ~Section();
  72. void MergeURLs ( const Entry& entry );
  73. void MergeSeeAlso( const Section& sec );
  74. void CleanEntries( EntryList& lstEntries );
  75. };
  76. /*
  77. A reader essentially Opens a stream on the CHM and reads the HHK file from within
  78. the CHM
  79. */
  80. class Reader
  81. {
  82. private:
  83. static BOOL s_fDBCSSystem;
  84. static LCID s_lcidSystem;
  85. ////////////////////////////////////////////////////////////
  86. CComPtr<IStream> m_stream;
  87. MPC::string m_strStorage;
  88. CHAR m_rgBuf[HHK_BUF_SIZE];
  89. LPSTR m_szBuf_Pos;
  90. LPSTR m_szBuf_End;
  91. MPC::string m_strLine;
  92. LPCSTR m_szLine_Pos;
  93. LPCSTR m_szLine_End;
  94. int m_iLevel;
  95. bool m_fOpeningBraceSeen;
  96. inline bool IsEndOfBuffer() { return m_szBuf_Pos >= m_szBuf_End; }
  97. inline bool IsEndOfLine () { return m_szLine_Pos >= m_szLine_End; }
  98. ////////////////////////////////////////////////////////////
  99. public:
  100. static LPCSTR StrChr ( LPCSTR szString, CHAR cSearch );
  101. static LPCSTR StriStr ( LPCSTR szString, LPCSTR szSearch );
  102. static int StrColl ( LPCSTR szLeft , LPCSTR szRight );
  103. static LPCSTR ComparePrefix( LPCSTR szString, LPCSTR szPrefix );
  104. Reader();
  105. ~Reader();
  106. HRESULT Init( LPCWSTR szFile );
  107. bool ReadNextBuffer ( );
  108. bool GetLine ( MPC::wstring* pstrString = NULL );
  109. bool FirstNonSpace ( bool fWrap = true );
  110. bool FindCharacter ( CHAR ch, bool fSkip = true, bool fWrap = true );
  111. bool FindDblQuote ( bool fSkip = true, bool fWrap = true );
  112. bool FindOpeningBrace( bool fSkip = true, bool fWrap = true );
  113. bool FindClosingBrace( bool fSkip = true, bool fWrap = true );
  114. bool GetQuotedString( MPC::string& strString );
  115. bool GetValue ( MPC::string& strName, MPC::string& strValue );
  116. bool GetType ( MPC::string& strType );
  117. Section* Parse();
  118. };
  119. /*
  120. Writer has as task writing the output MERGED.HHK file
  121. */
  122. class Writer
  123. {
  124. private:
  125. CComPtr<MPC::FileStream> m_stream;
  126. CHAR m_rgBuf[HHK_BUF_SIZE];
  127. LPSTR m_szBuf_Pos;
  128. inline size_t Available() { return &m_rgBuf[HHK_BUF_SIZE] - m_szBuf_Pos; }
  129. ////////////////////////////////////////////////////////////
  130. HRESULT FlushBuffer();
  131. public:
  132. Writer();
  133. ~Writer();
  134. HRESULT Init ( LPCWSTR szFile );
  135. HRESULT Close( );
  136. HRESULT OutputLine ( LPCSTR szLine );
  137. HRESULT OutputSection( Section* sec );
  138. };
  139. ////////////////////////////////////////////////////////////
  140. class Merger
  141. {
  142. public:
  143. class Entity
  144. {
  145. Section* m_Section;
  146. protected:
  147. void SetSection( Section* sec );
  148. public:
  149. Entity();
  150. virtual ~Entity();
  151. virtual HRESULT Init() = 0;
  152. Section* GetSection();
  153. Section* Detach ();
  154. virtual bool MoveNext() = 0;
  155. virtual long Size() const = 0;
  156. };
  157. class FileEntity : public Entity
  158. {
  159. MPC::wstring m_strFile;
  160. Reader m_Input;
  161. public:
  162. FileEntity( LPCWSTR szFile );
  163. virtual ~FileEntity();
  164. virtual HRESULT Init();
  165. virtual bool MoveNext();
  166. virtual long Size() const;
  167. };
  168. class DbEntity : public Entity
  169. {
  170. public:
  171. struct match
  172. {
  173. long ID_keyword;
  174. long ID_topic;
  175. MPC::string strKeyword;
  176. MPC::string strTitle;
  177. MPC::string strURI;
  178. };
  179. class CompareMatches
  180. {
  181. public:
  182. bool operator()( /*[in]*/ const match *, /*[in]*/ const match * ) const;
  183. };
  184. typedef std::list<match> MatchList;
  185. typedef MatchList::iterator MatchIter;
  186. typedef MatchList::const_iterator MatchIterConst;
  187. typedef std::map<match*,match*,CompareMatches> SortMap;
  188. typedef SortMap::iterator SortIter;
  189. typedef SortMap::const_iterator SortIterConst;
  190. typedef std::map<long,match*> TopicMap;
  191. typedef TopicMap::iterator TopicIter;
  192. typedef TopicMap::const_iterator TopicIterConst;
  193. typedef std::map<long,MPC::string> KeywordMap;
  194. typedef KeywordMap::iterator KeywordIter;
  195. typedef KeywordMap::const_iterator KeywordIterConst;
  196. private:
  197. Section::SectionList m_lst;
  198. Taxonomy::Updater& m_updater;
  199. Taxonomy::WordSet m_setCHM;
  200. public:
  201. DbEntity( /*[in]*/ Taxonomy::Updater& updater, /*[in]*/ Taxonomy::WordSet& setCHM );
  202. virtual ~DbEntity();
  203. virtual HRESULT Init();
  204. virtual bool MoveNext();
  205. virtual long Size() const;
  206. };
  207. class SortingFileEntity : public Entity
  208. {
  209. typedef std::vector<Section*> SectionVec;
  210. typedef SectionVec::iterator SectionIter;
  211. typedef SectionVec::const_iterator SectionIterConst;
  212. Section::SectionList m_lst;
  213. FileEntity m_in;
  214. public:
  215. SortingFileEntity( LPCWSTR szFile );
  216. virtual ~SortingFileEntity();
  217. virtual HRESULT Init();
  218. virtual bool MoveNext();
  219. virtual long Size() const;
  220. };
  221. typedef std::list<Entity*> EntityList;
  222. typedef EntityList::iterator EntityIter;
  223. typedef EntityList::const_iterator EntityIterConst;
  224. EntityList m_lst;
  225. EntityList m_lstSelected;
  226. Section* m_SectionSelected;
  227. Section* m_SectionTemp;
  228. public:
  229. Merger();
  230. ~Merger();
  231. HRESULT AddFile( Entity* ent, bool fIgnoreMissing = true );
  232. bool MoveNext();
  233. Section* GetSection();
  234. long Size() const;
  235. HRESULT PrepareMergedHhk ( Writer& writer, Taxonomy::Updater& updater , Taxonomy::WordSet& setCHM, MPC::WStringList& lst, LPCWSTR szOutputHHK );
  236. HRESULT PrepareSortingOfHhk( Writer& writer, LPCWSTR szInputHHK, LPCWSTR szOutputHHK );
  237. static Section* MergeSections( Section::SectionList& lst );
  238. };
  239. ////////////////////////////////////////////////////////////
  240. };
  241. /////////////////////////////////////////////////////////////////////////////
  242. #endif // !defined(__INCLUDED___HCP___MERGEDHHK_H___)