Source code of Windows XP (NT5)
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.

306 lines
7.4 KiB

  1. //------------------------------------------------------------------------------
  2. //
  3. // File: impparse.cpp
  4. // Copyright (C) 1995-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Purpose:
  8. // Implementation of CLocImpParser, which provides the ILocParser interface
  9. // for the parser.
  10. //
  11. // Owner:
  12. //
  13. //------------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "dllvars.h"
  16. #include "resource.h"
  17. #include "impfile.h"
  18. #include "impparse.h"
  19. //
  20. // Init statics
  21. // TODO: get a ParserId in PARSERID.H for this new parser.
  22. //
  23. const ParserId CLocImpParser::m_pid = pidExchangeMNC; // note: 100 is a bogus number
  24. // Reference count the registering of options since these are global
  25. // to the parser.
  26. INT g_nOptionRegisterCount = 0;
  27. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. //
  29. // Constructor for CLocImpParser.
  30. //------------------------------------------------------------------------------
  31. CLocImpParser::CLocImpParser()
  32. : CPULocParser(g_hDll)
  33. {
  34. LTTRACEPOINT("CLocImpParser constructor");
  35. m_fOptionInit = FALSE;
  36. IncrementClassCount();
  37. // TODO to add support for Binary objects, run this code
  38. // EnableInterface(IID_ILocBinary, TRUE);
  39. }
  40. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41. //
  42. // Destructor for CLocImpParser.
  43. //------------------------------------------------------------------------------
  44. CLocImpParser::~CLocImpParser()
  45. {
  46. LTTRACEPOINT("CLocImpParser destructor");
  47. LTASSERTONLY(AssertValid());
  48. DecrementClassCount();
  49. // Remove any options
  50. UnRegisterOptions();
  51. } // end of CLocImpParser::~CLocImpParser()
  52. HRESULT
  53. CLocImpParser::OnInit(
  54. IUnknown *)
  55. {
  56. LTASSERT(!m_fOptionInit);
  57. RegisterOptions();
  58. return ERROR_SUCCESS;
  59. }
  60. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  61. //
  62. // Create the file instance for the given file type
  63. //
  64. //------------------------------------------------------------------------------
  65. HRESULT
  66. CLocImpParser::OnCreateFileInstance(
  67. ILocFile * &pLocFile,
  68. FileType ft)
  69. {
  70. SCODE sc = E_INVALIDARG;
  71. pLocFile = NULL;
  72. switch (ft)
  73. {
  74. // TODO: This switch cases on the ft* constants supplied by you in
  75. // impfile.h. For each filetype, allocate an object of the correct
  76. // class to handle it and return a pointer to the object in pLocFile.
  77. // Most parsers user one class (CLocImpFile) which adjusts its behavior
  78. // according to the type.
  79. case ftUnknown:
  80. case ftMNCFileType:
  81. // Have to leave ftUnknown in because that is the type used until the
  82. // file has been parsed once successfully and the actual type is known.
  83. try
  84. {
  85. pLocFile = new CLocImpFile(NULL);
  86. sc = S_OK;
  87. }
  88. catch(CMemoryException *e)
  89. {
  90. sc = E_OUTOFMEMORY;
  91. e->Delete();
  92. }
  93. break;
  94. default:
  95. // Do nothing, sc falls through as E_INVALIDARG and the correct
  96. // result is returned.
  97. break;
  98. }
  99. return ResultFromScode(sc);
  100. }
  101. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  102. //
  103. // Supply the basic information about this parser.
  104. //
  105. //------------------------------------------------------------------------------
  106. void
  107. CLocImpParser::OnGetParserInfo(
  108. ParserInfo &pi)
  109. const
  110. {
  111. pi.aParserIds.SetSize(1);
  112. pi.aParserIds[0].m_pid = m_pid;
  113. pi.aParserIds[0].m_pidParent = pidNone;
  114. pi.elExtensions.AddTail("msc");
  115. // TODO: Add the extentions for this parser's files to the
  116. // elExtensions list in pi, with lines of the form:
  117. // pi.elExtensions.AddTail("TMP");
  118. // TODO: Update the IDS_IMP_PARSER_DESC resource string with
  119. // the description for this parser. (For consistency with other
  120. // parsers, it should be 'FOO', not 'FOO parser', 'FOO format',
  121. // 'FOO files', etc.)
  122. LTVERIFY(pi.strDescription.LoadString(g_hDll, IDS_IMP_PARSER_DESC));
  123. LTVERIFY(pi.strHelp.LoadString(g_hDll, IDS_IMP_PARSER_DESC_HELP));
  124. return;
  125. }
  126. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  127. //
  128. // Supply descriptions for each file type supported
  129. //
  130. //------------------------------------------------------------------------------
  131. void
  132. CLocImpParser::OnGetFileDescriptions(
  133. CEnumCallback &cb)
  134. const
  135. {
  136. EnumInfo eiFileInfo;
  137. CLString strDesc;
  138. eiFileInfo.szAbbreviation = NULL;
  139. // TODO: For each file type supported (the ft* constants you supplied in
  140. // impfile.h), return a string (loaded from a resource) describing it:
  141. //
  142. LTVERIFY(strDesc.LoadString(g_hDll, IDS_IMP_PARSER_DESC));
  143. eiFileInfo.szDescription = (const TCHAR *)strDesc;
  144. eiFileInfo.ulValue = ftMNCFileType;
  145. cb.ProcessEnum(eiFileInfo);
  146. }
  147. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  148. //
  149. // Supply the version of this parser
  150. //
  151. //------------------------------------------------------------------------------
  152. void
  153. CLocImpParser::OnGetParserVersion(
  154. DWORD &dwMajor,
  155. DWORD &dwMinor,
  156. BOOL &fDebug)
  157. const
  158. {
  159. dwMajor = dwCurrentMajorVersion;
  160. dwMinor = dwCurrentMinorVersion;
  161. fDebug = fCurrentDebugMode;
  162. }
  163. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  164. //
  165. // Do any parser specific validation on the string
  166. //
  167. //------------------------------------------------------------------------------
  168. CVC::ValidationCode
  169. CLocImpParser::OnValidateString(
  170. const CLocTypeId &ltiType,
  171. const CLocTranslation &lTrans,
  172. CReporter *pReporter,
  173. const CContext &context)
  174. {
  175. UNREFERENCED_PARAMETER(ltiType);
  176. UNREFERENCED_PARAMETER(lTrans);
  177. UNREFERENCED_PARAMETER(pReporter);
  178. UNREFERENCED_PARAMETER(context);
  179. // Edit time validation.
  180. // TODO if validation is done on strings this function and the Generate
  181. // functions should go through a common routine.
  182. return CVC::NoError;
  183. }
  184. #define INCOMAPTIBLE_VERSION_TEXT _T("IncompatibleVersion")
  185. BEGIN_LOC_UI_OPTIONS_BOOL(optCompatibleVersion)
  186. LOC_UI_OPTIONS_BOOL_ENTRY(INCOMAPTIBLE_VERSION_TEXT, TRUE, CLocUIOption::etCheckBox,
  187. IDS_INCOMPAT_PARSER, IDS_INCOMPAT_PARSER_HELP, NULL,
  188. CLocUIOption::stOverride),
  189. END_LOC_UI_OPTIONS_BOOL();
  190. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  191. //
  192. // Register any options for the parser
  193. //
  194. //------------------------------------------------------------------------------
  195. void
  196. CLocImpParser::RegisterOptions()
  197. {
  198. LTASSERT(g_nOptionRegisterCount >= 0);
  199. if (g_nOptionRegisterCount++ > 0)
  200. {
  201. // Already registered
  202. m_fOptionInit = true;
  203. return;
  204. }
  205. SmartRef<CLocUIOptionSet> spOptSet;
  206. CLocUIOptionImpHelper OptHelp(g_hDll);
  207. spOptSet = new CLocUIOptionSetDef;
  208. spOptSet->SetGroupName(g_puid.GetName());
  209. OptHelp.SetBools(optCompatibleVersion, COUNTOF(optCompatibleVersion));
  210. OptHelp.GetOptions(spOptSet.GetInterface(), IDS_PARSER_OPTIONS, IDS_PARSER_OPTIONS_HELP);
  211. m_fOptionInit = RegisterParserOptions(spOptSet.GetInterface());
  212. if (m_fOptionInit)
  213. {
  214. spOptSet.Extract();
  215. }
  216. }
  217. void
  218. CLocImpParser::UnRegisterOptions()
  219. {
  220. if (m_fOptionInit)
  221. {
  222. if (--g_nOptionRegisterCount == 0)
  223. {
  224. UnRegisterParserOptions(g_puid);
  225. }
  226. }
  227. }
  228. /***************************************************************************\
  229. *
  230. * METHOD: IsConfiguredToUseBracesForStringTables
  231. *
  232. * PURPOSE: Reads option specifying how string table identifers should appear
  233. *
  234. * PARAMETERS:
  235. *
  236. * RETURNS:
  237. * bool - true == use braces
  238. *
  239. \***************************************************************************/
  240. bool IsConfiguredToUseBracesForStringTables()
  241. {
  242. BOOL bIncompatibleVersion = GetParserOptionBool(g_puid, INCOMAPTIBLE_VERSION_TEXT);
  243. // true if compatible
  244. return !bIncompatibleVersion;
  245. }