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.

3666 lines
109 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-2002 Microsoft Corporation
  3. File Name : FormatEngine.cpp
  4. Project Name : WMI Command Line
  5. Author Name : Ch. Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Brief Description : The Format Engine is primarily responsible for
  9. displaying the
  10. a) the data views for the management areas by
  11. using predefined XSL style sheets
  12. b) the property update/method execution status
  13. c) error messages and
  14. d) display of usage information. It depends
  15. on the output of Parsing and/or Format Engine.
  16. Revision History :
  17. Last Modified By : Ch. Sriramachandramurthy
  18. Last Modified Date : 11th-April-2001
  19. ******************************************************************************/
  20. // FormatEngine.cpp : implementation file
  21. //
  22. #include "Precomp.h"
  23. #include "CommandSwitches.h"
  24. #include "GlobalSwitches.h"
  25. #include "HelpInfo.h"
  26. #include "ErrorLog.h"
  27. #include "ParsedInfo.h"
  28. #include "ErrorInfo.h"
  29. #include "WMICliXMLLog.h"
  30. #include "FormatEngine.h"
  31. #include "CmdTokenizer.h"
  32. #include "CmdAlias.h"
  33. #include "ParserEngine.h"
  34. #include "ExecEngine.h"
  35. #include "WmiCmdLn.h"
  36. #include "OutputStream.h"
  37. /*------------------------------------------------------------------------
  38. Name :CFormatEngine
  39. Synopsis :This function initializes the member variables when
  40. an object of the class type is instantiated.
  41. Type :Constructor
  42. Input parameter :None
  43. Output parameters :None
  44. Return Type :None
  45. Global Variables :None
  46. Calling Syntax :None
  47. Notes :None
  48. ------------------------------------------------------------------------*/
  49. CFormatEngine::CFormatEngine()
  50. {
  51. m_pIXMLDoc = NULL;
  52. m_pIXSLDoc = NULL;
  53. m_bRecord = FALSE;
  54. m_bTrace = FALSE;
  55. m_bHelp = FALSE;
  56. m_bGetOutOpt = TRUE;
  57. m_bGetAppendFilePinter = TRUE;
  58. m_bGetOutputFilePinter = TRUE;
  59. m_bLog = TRUE;
  60. m_bInteractiveHelp = FALSE;
  61. m_bOutputGoingToStream = FALSE;
  62. }
  63. /*------------------------------------------------------------------------
  64. Name :~CFormatEngine
  65. Synopsis :Destructor
  66. Type :Destructor
  67. Input parameter :None
  68. Output parameters :None
  69. Return Type :None
  70. Global Variables :None
  71. Calling Syntax :None
  72. Notes :None
  73. ------------------------------------------------------------------------*/
  74. CFormatEngine::~CFormatEngine()
  75. {
  76. Uninitialize(TRUE);
  77. }
  78. /*------------------------------------------------------------------------
  79. Name :CreateEmptyDocument
  80. Synopsis :Creates an empty XML Document and returns the same
  81. in Passed Parameter.
  82. Type :Member Function
  83. Input parameter :
  84. Output parameters :None
  85. pDoc - Pointer to pointer to IXMLDOMDocument2 Interface
  86. Return Type :HRESULT
  87. Global Variables :None
  88. Calling Syntax :CreateEmptyDocument(&pIXMLDoc)
  89. Notes :None
  90. ------------------------------------------------------------------------*/
  91. HRESULT CFormatEngine::CreateEmptyDocument(IXMLDOMDocument2** pIDoc)
  92. {
  93. // Create an empty XML document
  94. return CoCreateInstance(CLSID_FreeThreadedDOMDocument, NULL,
  95. CLSCTX_INPROC_SERVER,
  96. IID_IXMLDOMDocument2, (LPVOID*)pIDoc);
  97. }
  98. /*------------------------------------------------------------------------
  99. Name :Uninitialize
  100. Synopsis :Carries out the releasing process.
  101. Type :Member Function
  102. Input parameter :None
  103. Output parameters :None
  104. Return Type :void
  105. Global Variables :None
  106. Calling Syntax :Uninitialize()
  107. Notes :None
  108. ------------------------------------------------------------------------*/
  109. void CFormatEngine::Uninitialize(BOOL bFinal)
  110. {
  111. // Release the interface pointers
  112. SAFEIRELEASE(m_pIXMLDoc);
  113. SAFEIRELEASE(m_pIXSLDoc);
  114. m_bTrace = FALSE;
  115. m_eloErrLogOpt = NO_LOGGING;
  116. m_bHelp = FALSE;
  117. m_bGetOutOpt = TRUE;
  118. m_bGetAppendFilePinter = TRUE;
  119. m_bGetOutputFilePinter = TRUE;
  120. m_bLog = TRUE;
  121. m_bInteractiveHelp = FALSE;
  122. m_bOutputGoingToStream = FALSE;
  123. m_chsOutput.Empty();
  124. // Uninitialize the ErrInfo object
  125. m_ErrInfo.Uninitialize();
  126. // Erase the help vector
  127. if ( !m_cvHelp.empty() )
  128. {
  129. if (m_cvHelp.size())
  130. {
  131. CHARVECTOR::iterator theIterator = m_cvHelp.begin();
  132. while (theIterator != m_cvHelp.end())
  133. {
  134. SAFEDELETE(*theIterator);
  135. theIterator++;
  136. }
  137. }
  138. m_cvHelp.erase(m_cvHelp.begin(), m_cvHelp.end());
  139. }
  140. m_WmiCliLog.Uninitialize(bFinal);
  141. }
  142. /*------------------------------------------------------------------------
  143. Name :ApplyXSLFormatting
  144. Synopsis :Applies a XSL style sheet containing format of the
  145. display to a XML stream containing result set.
  146. Type :Member Function
  147. Input parameter :
  148. rParsedInfo - reference to CParsedInfo class object
  149. Output parameters :
  150. rParsedInfo - reference to CParsedInfo class object
  151. Return Type :BOOL
  152. Global Variables :None
  153. Calling Syntax :ApplyXSLFormatting(rParsedInfo);
  154. Notes :None
  155. ------------------------------------------------------------------------*/
  156. BOOL CFormatEngine::ApplyXSLFormatting(CParsedInfo& rParsedInfo)
  157. {
  158. BOOL bRet = TRUE;
  159. DWORD dwThreadId = GetCurrentThreadId();
  160. if ( g_wmiCmd.GetBreakEvent() == TRUE )
  161. {
  162. bRet = TRUE;
  163. }
  164. // If the XML stream is empty (or) XSL file path is empty
  165. // set the return value as FALSE.
  166. else if (!rParsedInfo.GetCmdSwitchesObject().GetXMLResultSet() ||
  167. rParsedInfo.GetCmdSwitchesObject().GetXSLTDetailsVector().empty())
  168. {
  169. bRet = FALSE;
  170. }
  171. else
  172. {
  173. HRESULT hr = S_OK;
  174. //BSTR bstrOutput = NULL;
  175. _bstr_t bstrOutput;
  176. CHString chsMsg;
  177. VARIANT_BOOL varBool = VARIANT_FALSE;
  178. VARIANT varXSL;
  179. VariantInit(&varXSL);
  180. try
  181. {
  182. // Create an empty XML Document
  183. hr = CreateEmptyDocument(&m_pIXMLDoc);
  184. if (m_bTrace || m_eloErrLogOpt)
  185. {
  186. chsMsg.Format(L"CoCreateInstance(CLSID_FreeThreadedDOMDocument, NULL,"
  187. L" CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument2, -)");
  188. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  189. dwThreadId, rParsedInfo, m_bTrace);
  190. }
  191. ONFAILTHROWERROR(hr);
  192. BOOL bFlag = FALSE;
  193. BOOL bTranslateTable = FALSE;
  194. // If Translate table name is given and before format switch
  195. // translate switch is given then set the flag
  196. if( rParsedInfo.GetCmdSwitchesObject().
  197. GetTranslateTableName() != NULL &&
  198. rParsedInfo.GetCmdSwitchesObject().
  199. GetTranslateFirstFlag() == TRUE)
  200. {
  201. bTranslateTable = TRUE;
  202. }
  203. // If Translate table name is given then translate
  204. // the XML node list
  205. if ( bTranslateTable == TRUE )
  206. {
  207. bFlag = TraverseNode(rParsedInfo);
  208. }
  209. else
  210. {
  211. // Load XML content
  212. hr = m_pIXMLDoc->loadXML(rParsedInfo.GetCmdSwitchesObject().
  213. GetXMLResultSet(), &varBool);
  214. if (m_bTrace || m_eloErrLogOpt)
  215. {
  216. WMITRACEORERRORLOG(hr, __LINE__,
  217. __FILE__, _T("IXMLDOMDocument::loadXML(-, -)"),
  218. dwThreadId, rParsedInfo, m_bTrace);
  219. }
  220. ONFAILTHROWERROR(hr);
  221. }
  222. // If loading the XML document is successful or if translate table
  223. // name is given and translation is successful
  224. if( (bTranslateTable == TRUE && bFlag == TRUE) ||
  225. (bTranslateTable == FALSE && varBool == VARIANT_TRUE) )
  226. {
  227. bRet = DoCascadeTransforms(rParsedInfo, bstrOutput);
  228. if (bRet)
  229. {
  230. STRING strOutput((_TCHAR*)bstrOutput);
  231. // If /TRANSLATE:<table> is specified and after format
  232. // switch translate switch is given then translate the
  233. // result
  234. if ( bTranslateTable == FALSE)
  235. {
  236. // Translate the result
  237. ApplyTranslateTable(strOutput, rParsedInfo);
  238. }
  239. bRet = TRUE;
  240. if (m_bRecord && m_bLog && !m_bInteractiveHelp)
  241. {
  242. hr = m_WmiCliLog.WriteToXMLLog(rParsedInfo,
  243. _bstr_t(strOutput.data()));
  244. if (FAILED(hr))
  245. {
  246. m_WmiCliLog.StopLogging();
  247. m_bRecord = FALSE;
  248. hr = S_OK;
  249. DisplayString(IDS_E_WRITELOG_FAILED, FALSE,
  250. NULL, TRUE);
  251. }
  252. m_bLog = FALSE;
  253. }
  254. // Display the result
  255. DisplayLargeString(rParsedInfo, strOutput);
  256. bRet = TRUE;
  257. }
  258. }
  259. else
  260. {
  261. // Invalid XML content.
  262. rParsedInfo.GetCmdSwitchesObject()
  263. .SetErrataCode(IDS_E_INVALID_XML_CONTENT);
  264. bRet = FALSE;
  265. }
  266. }
  267. catch(_com_error& e)
  268. {
  269. // Set the COM error.
  270. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  271. bRet = FALSE;
  272. }
  273. catch(CHeap_Exception)
  274. {
  275. hr = WBEM_E_OUT_OF_MEMORY;
  276. _com_issue_error(hr);
  277. }
  278. }
  279. return bRet;
  280. }
  281. /*------------------------------------------------------------------------
  282. Name :DisplayResults
  283. Synopsis :Displays the result referring CcommandSwitches and
  284. CGlobalSwitches Objects of the CParsedInfo object.
  285. Type :Member Function
  286. Input parameter :
  287. rParsedInfo - reference to CParsedInfo class object
  288. bInteractiveHelp
  289. TRUE - indicates intermediate help display in
  290. interactive mode
  291. FALSE - indicates results display in normal mode
  292. Output parameters :
  293. rParsedInfo - reference to CParsedInfo class object
  294. Return Type :BOOL
  295. Global Variables :None
  296. Calling Syntax :DisplayResults(rParsedInfo, bInteractiveHelp)
  297. Notes :None
  298. ------------------------------------------------------------------------*/
  299. BOOL CFormatEngine::DisplayResults(CParsedInfo& rParsedInfo,
  300. BOOL bInteractiveHelp)
  301. {
  302. BOOL bRet = TRUE;
  303. DWORD dwThreadId = GetCurrentThreadId();
  304. _TCHAR* pszVerbName = NULL;
  305. BOOL bLog = TRUE;
  306. HRESULT hr = S_OK;
  307. m_bInteractiveHelp = bInteractiveHelp;
  308. // Frame the command part of the log entry:
  309. // "command: <<command input>>"
  310. try
  311. {
  312. CHString chsCmdMsg(_T("command: "));
  313. chsCmdMsg += rParsedInfo.GetCmdSwitchesObject().GetCommandInput();
  314. // Get the TRACE status and store it in m_bTrace
  315. m_bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  316. // Get the Logging mode (VERBOSE | ERRORONLY | NOLOGGING) and store
  317. // it in m_eloErrLogOpt
  318. m_eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  319. // Get the output option to redirect the output.
  320. m_opsOutputOpt = rParsedInfo.GetGlblSwitchesObject().
  321. GetOutputOrAppendOption(TRUE);
  322. m_bGetOutOpt = FALSE;
  323. // FALSE for getting append file pointer.
  324. m_fpAppendFile = rParsedInfo.GetGlblSwitchesObject().
  325. GetOutputOrAppendFilePointer(FALSE);
  326. m_bGetAppendFilePinter = FALSE;
  327. // TRUE for getting out file pointer.
  328. m_fpOutFile = rParsedInfo.GetGlblSwitchesObject().
  329. GetOutputOrAppendFilePointer(TRUE);
  330. m_bGetOutputFilePinter = FALSE;
  331. // If /RECORD global switch has been specified, create the log file
  332. // and write the input command.
  333. if (rParsedInfo.GetGlblSwitchesObject().GetRPChangeStatus())
  334. {
  335. // Stop logging
  336. m_WmiCliLog.StopLogging();
  337. if (rParsedInfo.GetGlblSwitchesObject().GetRecordPath() != NULL)
  338. {
  339. if (!rParsedInfo.GetCmdSwitchesObject().GetEverySwitchFlag())
  340. {
  341. // Set the log file path
  342. m_WmiCliLog.SetLogFilePath(rParsedInfo.
  343. GetGlblSwitchesObject().GetRecordPath());
  344. // Set the m_bRecord flag to TRUE
  345. m_bRecord = TRUE;
  346. // Set the recordpath change flag to FALSE
  347. rParsedInfo.GetGlblSwitchesObject().
  348. SetRPChangeStatus(FALSE);
  349. }
  350. }
  351. else
  352. {
  353. // Set the m_bRecord flag to FALSE
  354. m_bRecord = FALSE;
  355. }
  356. // Get Token vector
  357. CHARVECTOR cvTokens = g_wmiCmd.GetTokenVector();
  358. // if command consist of only /RECORD switch option then don't
  359. // record it. (It will come here only when /RECORD is given)
  360. if (cvTokens.size() <= 4)
  361. m_bLog = FALSE;
  362. }
  363. //If the COM error is not NULL , then display the error
  364. if (rParsedInfo.GetCmdSwitchesObject().GetCOMError() != NULL)
  365. {
  366. DisplayCOMError(rParsedInfo);
  367. }
  368. // Check the success flag , display error in case error flag is set.
  369. else if (!rParsedInfo.GetCmdSwitchesObject().GetSuccessFlag())
  370. {
  371. _bstr_t bstrErrMsg;
  372. if (IDS_E_ALIAS_NOT_FOUND == rParsedInfo.GetCmdSwitchesObject()
  373. .GetErrataCode())
  374. {
  375. WMIFormatMessage(IDS_E_ALIAS_NOT_FOUND, 1, bstrErrMsg,
  376. rParsedInfo.GetCmdSwitchesObject().
  377. GetAliasName());
  378. DisplayString((LPTSTR) bstrErrMsg, TRUE, TRUE);
  379. }
  380. else if (IDS_E_INVALID_CLASS == rParsedInfo.GetCmdSwitchesObject()
  381. .GetErrataCode())
  382. {
  383. WMIFormatMessage(IDS_E_INVALID_CLASS, 1, bstrErrMsg,
  384. rParsedInfo.GetCmdSwitchesObject().
  385. GetClassPath());
  386. DisplayString((LPTSTR) bstrErrMsg, TRUE, TRUE);
  387. }
  388. else
  389. DisplayString(rParsedInfo.GetCmdSwitchesObject().
  390. GetErrataCode(), TRUE, NULL, TRUE);
  391. if ( m_eloErrLogOpt )
  392. {
  393. chsCmdMsg += _T(", Utility returned error ID.");
  394. // explicit error -1 to specify errata code.
  395. WMITRACEORERRORLOG(-1, __LINE__, __FILE__, (LPCWSTR)chsCmdMsg,
  396. dwThreadId, rParsedInfo, FALSE,
  397. rParsedInfo.GetCmdSwitchesObject().GetErrataCode());
  398. }
  399. }
  400. //if the help has been specified , FrameHelpVector is called .
  401. else if (rParsedInfo.GetGlblSwitchesObject().GetHelpFlag())
  402. {
  403. m_bHelp = TRUE;
  404. // Form help vector
  405. FrameHelpVector(rParsedInfo);
  406. // Display paged help
  407. DisplayPagedHelp(rParsedInfo);
  408. if ( m_eloErrLogOpt )
  409. WMITRACEORERRORLOG(S_OK, __LINE__, __FILE__, (LPCWSTR)chsCmdMsg,
  410. dwThreadId, rParsedInfo, FALSE);
  411. }
  412. else
  413. {
  414. // Get the verb name
  415. pszVerbName = rParsedInfo.GetCmdSwitchesObject().
  416. GetVerbName();
  417. // Check the information code
  418. if (rParsedInfo.GetCmdSwitchesObject().GetInformationCode())
  419. {
  420. DisplayString(rParsedInfo.GetCmdSwitchesObject().
  421. GetInformationCode());
  422. if ( m_eloErrLogOpt )
  423. {
  424. WMITRACEORERRORLOG(S_OK, __LINE__, __FILE__, (LPCWSTR)chsCmdMsg,
  425. dwThreadId, rParsedInfo, FALSE);
  426. }
  427. }
  428. else if ( CompareTokens(pszVerbName, CLI_TOKEN_LIST) ||
  429. CompareTokens(pszVerbName, CLI_TOKEN_ASSOC) ||
  430. CompareTokens(pszVerbName, CLI_TOKEN_GET) ||
  431. m_bInteractiveHelp)
  432. {
  433. //If XSL file is not specified - pick the default XSL.
  434. if(rParsedInfo.GetCmdSwitchesObject().GetXSLTDetailsVector().
  435. empty())
  436. {
  437. if(IsClassOperation(rParsedInfo))
  438. {
  439. rParsedInfo.GetCmdSwitchesObject().
  440. ClearXSLTDetailsVector();
  441. //default format is MOF if CLASS
  442. bRet = FrameFileAndAddToXSLTDetVector (
  443. XSL_FORMAT_MOF,
  444. CLI_TOKEN_MOF,
  445. rParsedInfo
  446. );
  447. }
  448. else
  449. {
  450. rParsedInfo.GetCmdSwitchesObject().
  451. ClearXSLTDetailsVector();
  452. // Default format is TABLE if an alias or path
  453. // with where expression or with keyclause
  454. bRet = FrameFileAndAddToXSLTDetVector (
  455. XSL_FORMAT_TABLE,
  456. CLI_TOKEN_TABLE,
  457. rParsedInfo
  458. );
  459. }
  460. if (bInteractiveHelp && !CompareTokens(pszVerbName,
  461. CLI_TOKEN_ASSOC))
  462. {
  463. rParsedInfo.GetCmdSwitchesObject().
  464. ClearXSLTDetailsVector();
  465. //otherwise go with LIST
  466. bRet = FrameFileAndAddToXSLTDetVector (
  467. XSL_FORMAT_TEXTVALUE,
  468. CLI_TOKEN_TEXTVALUE,
  469. rParsedInfo
  470. );
  471. }
  472. }
  473. // If result set is not empty
  474. if (!(!rParsedInfo.GetCmdSwitchesObject().GetXMLResultSet()))
  475. {
  476. // Apply the XSL formatting.
  477. bRet = ApplyXSLFormatting(rParsedInfo);
  478. // If XSL formatting fails
  479. if (!bRet)
  480. {
  481. //If the COM error is not NULL , then display the error
  482. if (rParsedInfo.GetCmdSwitchesObject().
  483. GetCOMError() != NULL)
  484. {
  485. DisplayCOMError(rParsedInfo);
  486. }
  487. else
  488. {
  489. DisplayString(rParsedInfo.
  490. GetCmdSwitchesObject().GetErrataCode(),
  491. TRUE, NULL, TRUE);
  492. if ( m_eloErrLogOpt )
  493. {
  494. chsCmdMsg += _T(", Utility returned error ID.");
  495. // explicit error -1 to specify errata code.
  496. WMITRACEORERRORLOG(-1, __LINE__, __FILE__,
  497. (LPCWSTR)chsCmdMsg,
  498. dwThreadId, rParsedInfo, FALSE,
  499. rParsedInfo.GetCmdSwitchesObject().
  500. GetErrataCode());
  501. }
  502. }
  503. }
  504. if ( m_eloErrLogOpt )
  505. {
  506. HRESULT hrTemp;
  507. if ( g_wmiCmd.GetSessionErrorLevel() != 0)
  508. hrTemp = -1;
  509. else
  510. hrTemp = S_OK;
  511. WMITRACEORERRORLOG(hrTemp, __LINE__, __FILE__,
  512. (LPCWSTR)chsCmdMsg,
  513. dwThreadId, rParsedInfo, FALSE);
  514. }
  515. }
  516. else
  517. {
  518. if (CompareTokens(pszVerbName, CLI_TOKEN_ASSOC))
  519. {
  520. if (m_bRecord && m_bLog)
  521. {
  522. hr = m_WmiCliLog.WriteToXMLLog(rParsedInfo,
  523. _bstr_t((LPCWSTR)m_chsOutput));
  524. if (FAILED(hr))
  525. {
  526. m_WmiCliLog.StopLogging();
  527. m_bRecord = FALSE;
  528. hr = S_OK;
  529. DisplayString(IDS_E_WRITELOG_FAILED,
  530. FALSE, NULL, TRUE);
  531. }
  532. m_bLog = FALSE;
  533. }
  534. }
  535. }
  536. }
  537. //SET, DELETE, CREATE verbs - on successfully invoked
  538. else
  539. {
  540. if (m_bRecord && m_bLog)
  541. {
  542. hr = m_WmiCliLog.WriteToXMLLog(rParsedInfo,
  543. _bstr_t((LPCWSTR)m_chsOutput));
  544. if (FAILED(hr))
  545. {
  546. m_WmiCliLog.StopLogging();
  547. m_bRecord = FALSE;
  548. hr = S_OK;
  549. DisplayString(IDS_E_WRITELOG_FAILED,
  550. FALSE, NULL, TRUE);
  551. }
  552. m_bLog = FALSE;
  553. }
  554. }
  555. }
  556. }
  557. // To handle COM exception
  558. catch (_com_error& e)
  559. {
  560. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  561. bRet = FALSE;
  562. }
  563. // To handle user-defined exceptions
  564. catch(WMICLIINT nVal)
  565. {
  566. // If memory allocation failed.
  567. if (nVal == OUT_OF_MEMORY)
  568. {
  569. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(OUT_OF_MEMORY);
  570. }
  571. bRet = FALSE;
  572. }
  573. //trap for CHeap_Exception
  574. catch(CHeap_Exception)
  575. {
  576. hr = WBEM_E_OUT_OF_MEMORY;
  577. _com_issue_error(hr);
  578. }
  579. catch(DWORD dwError)
  580. {
  581. // If Win32 function call failed.
  582. ::SetLastError(dwError);
  583. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(dwError);
  584. DisplayWin32Error();
  585. ::SetLastError(dwError);
  586. bRet = FALSE;
  587. }
  588. return bRet;
  589. }
  590. /*------------------------------------------------------------------------
  591. Name :DisplayGETUsage
  592. Synopsis :Displays GET usage.
  593. Type :Member Function
  594. Input parameter :
  595. rParsedInfo - reference to CParsedInfo class object
  596. Output parameters :None
  597. Return Type :void
  598. Global Variables :None
  599. Calling Syntax :DisplayGETUsage(rParsedInfo)
  600. Notes :None
  601. ------------------------------------------------------------------------*/
  602. void CFormatEngine::DisplayGETUsage(CParsedInfo& rParsedInfo)
  603. {
  604. BOOL bClass = FALSE;
  605. if(IsClassOperation(rParsedInfo))
  606. {
  607. bClass = TRUE;
  608. }
  609. if(!bClass)
  610. {
  611. DisplayInvalidProperties(rParsedInfo);
  612. if (rParsedInfo.GetHelpInfoObject().GetHelp(GETSwitchesOnly) == FALSE)
  613. {
  614. if ( rParsedInfo.GetCmdSwitchesObject().
  615. GetPropertyList().size() == 0 )
  616. {
  617. // Display the usage of the GET verb
  618. DisplayString(IDS_I_NEWLINE);
  619. DisplayString(IDS_I_GET_DESC);
  620. DisplayString(IDS_I_USAGE);
  621. DisplayString(IDS_I_NEWLINE);
  622. DisplayString(IDS_I_GET_USAGE);
  623. DisplayString(IDS_I_PROPERTYLIST_NOTE1);
  624. }
  625. // Display the properties
  626. DisplayPropertyDetails(rParsedInfo);
  627. }
  628. }
  629. else
  630. {
  631. // Display the usage of the CLASS <class name> GET verb
  632. DisplayString(IDS_I_NEWLINE);
  633. DisplayString(IDS_I_CLASS_GET_DESC);
  634. DisplayString(IDS_I_USAGE);
  635. DisplayString(IDS_I_NEWLINE);
  636. DisplayString(IDS_I_CLASS_GET_USAGE);
  637. }
  638. // Enumerate the available GET switches
  639. DisplayString(IDS_I_NEWLINE);
  640. DisplayString(IDS_I_GET_SWITCH_HEAD);
  641. DisplayString(IDS_I_NEWLINE);
  642. DisplayString(IDS_I_GET_SWITCH_VALUE);
  643. DisplayString(IDS_I_GET_SWITCH_ALL);
  644. DisplayString(IDS_I_SWITCH_TRANSLATE);
  645. DisplayString(IDS_I_SWITCH_EVERY);
  646. DisplayString(IDS_I_SWITCH_FORMAT);
  647. DisplayString(IDS_I_NEWLINE);
  648. DisplayString(IDS_I_TRANSFORMAT_NOTE1);
  649. DisplayString(IDS_I_TRANSFORMAT_NOTE2);
  650. DisplayString(IDS_I_TRANSFORMAT_NOTE3);
  651. }
  652. /*------------------------------------------------------------------------
  653. Name :DisplayLISTUsage
  654. Synopsis :Displays LIST usage.
  655. Type :Member Function
  656. Input parameter :
  657. rParsedInfo - reference to CParsedInfo class object
  658. Output parameters :None
  659. Return Type :void
  660. Global Variables :None
  661. Calling Syntax :DisplayLISTUsage(rParsedInfo)
  662. Notes :None
  663. ------------------------------------------------------------------------*/
  664. void CFormatEngine::DisplayLISTUsage(CParsedInfo& rParsedInfo)
  665. {
  666. try
  667. {
  668. if (rParsedInfo.GetHelpInfoObject().GetHelp(LISTSwitchesOnly) == FALSE)
  669. {
  670. // Display the usage of the LIST verb
  671. DisplayString(IDS_I_NEWLINE);
  672. DisplayString(IDS_I_LIST_DESC);
  673. DisplayString(IDS_I_USAGE);
  674. DisplayString(IDS_I_NEWLINE);
  675. DisplayString(IDS_I_LIST_USAGE);
  676. ALSFMTDETMAP afdAlsFmtDet = rParsedInfo.
  677. GetCmdSwitchesObject().
  678. GetAliasFormatDetMap();
  679. ALSFMTDETMAP::iterator theIterator;
  680. if ( afdAlsFmtDet.empty() )
  681. {
  682. // If no list formats are available/defined for the
  683. // alias specified.
  684. DisplayString(IDS_I_NEWLINE);
  685. DisplayString(IDS_I_LIST_NOFORMATS);
  686. }
  687. else
  688. {
  689. // Display the available/defined LIST formats for
  690. // the alias specified.
  691. DisplayString(IDS_I_NEWLINE);
  692. DisplayString(IDS_I_LIST_FMT_HEAD);
  693. DisplayString(IDS_I_NEWLINE);
  694. for ( theIterator = afdAlsFmtDet.begin(); theIterator !=
  695. afdAlsFmtDet.end(); theIterator++ )
  696. {
  697. _bstr_t bstrProps = _bstr_t("");
  698. // Print props associated with the format.
  699. BSTRVECTOR bvProps = (*theIterator).second;
  700. BSTRVECTOR::iterator propIterator;
  701. for ( propIterator = bvProps.begin();
  702. propIterator != bvProps.end();
  703. propIterator++ )
  704. {
  705. if ( propIterator != bvProps.begin() )
  706. bstrProps += _bstr_t(", ");
  707. bstrProps += *propIterator;
  708. }
  709. _TCHAR szMsg[MAX_BUFFER] = NULL_STRING;
  710. _stprintf(szMsg, _T("%-25s - %s\r\n"),
  711. (_TCHAR*)(*theIterator).first,
  712. (_TCHAR*)bstrProps);
  713. DisplayString(szMsg);
  714. }
  715. }
  716. }
  717. // Display the LIST switches
  718. DisplayString(IDS_I_NEWLINE);
  719. DisplayString(IDS_I_LIST_SWITCH_HEAD);
  720. DisplayString(IDS_I_NEWLINE);
  721. DisplayString(IDS_I_SWITCH_TRANSLATE);
  722. DisplayString(IDS_I_SWITCH_EVERY);
  723. DisplayString(IDS_I_SWITCH_FORMAT);
  724. DisplayString(IDS_I_NEWLINE);
  725. DisplayString(IDS_I_TRANSFORMAT_NOTE1);
  726. DisplayString(IDS_I_TRANSFORMAT_NOTE2);
  727. DisplayString(IDS_I_TRANSFORMAT_NOTE3);
  728. }
  729. catch(_com_error& e)
  730. {
  731. _com_issue_error(e.Error());
  732. }
  733. }
  734. /*------------------------------------------------------------------------
  735. Name :DisplayCALLUsage
  736. Synopsis :Displays CALL usage.
  737. Type :Member Function
  738. Input parameter :
  739. rParsedInfo - reference to CParsedInfo class object
  740. Output parameters :None
  741. Return Type :void
  742. Global Variables :None
  743. Calling Syntax :DisplayCALLUsage(rParsedInfo)
  744. Notes :None
  745. ------------------------------------------------------------------------*/
  746. void CFormatEngine::DisplayCALLUsage(CParsedInfo& rParsedInfo)
  747. {
  748. // Display the usage of the CALL verb
  749. DisplayString(IDS_I_NEWLINE);
  750. DisplayString(IDS_I_CALL_DESC);
  751. DisplayString(IDS_I_USAGE);
  752. DisplayString(IDS_I_NEWLINE);
  753. DisplayString(IDS_I_CALL_USAGE);
  754. DisplayString(IDS_I_CALL_PARAM_NOTE);
  755. // Display the method details.
  756. DisplayMethodDetails(rParsedInfo);
  757. }
  758. /*------------------------------------------------------------------------
  759. Name :DisplaySETUsage
  760. Synopsis :Displays SET usage.
  761. Type :Member Function
  762. Input parameter :
  763. rParsedInfo - reference to CParsedInfo class object
  764. Output parameters :None
  765. Return Type :void
  766. Global Variables :None
  767. Calling Syntax :DisplaySETUsage(rParsedInfo)
  768. Notes :None
  769. ------------------------------------------------------------------------*/
  770. void CFormatEngine::DisplaySETUsage(CParsedInfo& rParsedInfo)
  771. {
  772. DisplayInvalidProperties(rParsedInfo, TRUE);
  773. if ( rParsedInfo.GetCmdSwitchesObject().
  774. GetPropertyList().size() == 0 )
  775. {
  776. // Display the usage of the SET verb
  777. DisplayString(IDS_I_NEWLINE);
  778. DisplayString(IDS_I_SET_DESC);
  779. DisplayString(IDS_I_USAGE);
  780. DisplayString(IDS_I_NEWLINE);
  781. DisplayString(IDS_I_SET_USAGE);
  782. DisplayString(IDS_I_ASSIGNLIST_NOTE1);
  783. DisplayString(IDS_I_ASSIGNLIST_NOTE2);
  784. }
  785. // Display the property details
  786. DisplayPropertyDetails(rParsedInfo);
  787. }
  788. /*------------------------------------------------------------------------
  789. Name :DisplayCREATEUsage
  790. Synopsis :Displays CREATE usage.
  791. Type :Member Function
  792. Input parameter :
  793. rParsedInfo - reference to CParsedInfo class object
  794. Output parameters :None
  795. Return Type :void
  796. Global Variables :None
  797. Calling Syntax :DisplayCREATEsage(rParsedInfo)
  798. Notes :None
  799. ------------------------------------------------------------------------*/
  800. void CFormatEngine::DisplayCREATEUsage(CParsedInfo& rParsedInfo)
  801. {
  802. DisplayInvalidProperties(rParsedInfo);
  803. if ( rParsedInfo.GetCmdSwitchesObject().
  804. GetPropertyList().size() == 0 )
  805. {
  806. // Display the usage of the CREATE verb
  807. DisplayString(IDS_I_NEWLINE);
  808. DisplayString(IDS_I_CREATE_DESC);
  809. DisplayString(IDS_I_USAGE);
  810. DisplayString(IDS_I_NEWLINE);
  811. DisplayString(IDS_I_CREATE_USAGE);
  812. DisplayString(IDS_I_ASSIGNLIST_NOTE1);
  813. DisplayString(IDS_I_ASSIGNLIST_NOTE2);
  814. DisplayString(IDS_I_NEWLINE);
  815. DisplayString(IDS_I_CREATE_NOTE);
  816. }
  817. // Display the property details
  818. DisplayPropertyDetails(rParsedInfo);
  819. }
  820. /*------------------------------------------------------------------------
  821. Name :DisplayDELETEUsage
  822. Synopsis :Displays DELETE usage.
  823. Type :Member Function
  824. Input parameter :
  825. rParsedInfo - reference to CParsedInfo class object
  826. Output parameters :None
  827. Return Type :void
  828. Global Variables :None
  829. Calling Syntax :DisplayDELETEUsage()
  830. Notes :None
  831. ------------------------------------------------------------------------*/
  832. void CFormatEngine::DisplayDELETEUsage(CParsedInfo& rParsedInfo)
  833. {
  834. // Display the usage of the DELETE verb
  835. DisplayString(IDS_I_NEWLINE);
  836. if(IsClassOperation(rParsedInfo))
  837. {
  838. DisplayString(IDS_I_CLASS_DELETE_DESC);
  839. }
  840. else
  841. {
  842. DisplayString(IDS_I_DELETE_DESC);
  843. }
  844. }
  845. /*------------------------------------------------------------------------
  846. Name :DisplayASSOCUsage
  847. Synopsis :Displays ASSOC usage.
  848. Type :Member Function
  849. Input parameter :
  850. rParsedInfo - reference to CParsedInfo class object
  851. Output parameters :None
  852. Return Type :void
  853. Global Variables :None
  854. Calling Syntax :DisplayASSOCUsage(rParsedInfo)
  855. Notes :None
  856. ------------------------------------------------------------------------*/
  857. void CFormatEngine::DisplayASSOCUsage(CParsedInfo& rParsedInfo)
  858. {
  859. if (rParsedInfo.GetHelpInfoObject().GetHelp(ASSOCSwitchesOnly) == FALSE)
  860. {
  861. DisplayString(IDS_I_NEWLINE);
  862. if(IsClassOperation(rParsedInfo))
  863. {
  864. DisplayString(IDS_I_CLASS_ASSOC_DESC);
  865. }
  866. else
  867. {
  868. DisplayString(IDS_I_ASSOC_DESC);
  869. }
  870. DisplayString(IDS_I_USAGE);
  871. DisplayString(IDS_I_NEWLINE);
  872. DisplayString(IDS_I_ASSOC_USAGE);
  873. DisplayString(IDS_I_ASSOC_FMT_NOTE);
  874. DisplayString(IDS_I_NEWLINE);
  875. }
  876. DisplayString(IDS_I_ASSOC_SWITCH_HEAD);
  877. DisplayString(IDS_I_NEWLINE);
  878. DisplayString(IDS_I_ASSOC_RESULTCLASS);
  879. DisplayString(IDS_I_ASSOC_RESULTROLE);
  880. DisplayString(IDS_I_ASSOC_ASSOCCLASS);
  881. }
  882. /*------------------------------------------------------------------------
  883. Name :DisplayAliasFriendlyNames
  884. Synopsis :Displays alias names
  885. Type :Member Function
  886. Input parameter :
  887. rParsedInfo - reference to CParsedInfo class object
  888. pszAlias - alias name (default null)
  889. Output parameters :None
  890. Return Type :void
  891. Global Variables :None
  892. Calling Syntax :DisplayAliasFriendlyNames(rParsedInfo, pszAlias)
  893. Notes :None
  894. ------------------------------------------------------------------------*/
  895. void CFormatEngine::DisplayAliasFriendlyNames(CParsedInfo& rParsedInfo,
  896. _TCHAR* pszAlias)
  897. {
  898. _TCHAR szMsg[MAX_BUFFER] = NULL_STRING;
  899. // display ALIAS help
  900. BSTRMAP theMap = rParsedInfo.GetCmdSwitchesObject()
  901. .GetAlsFrnNmsOrTrnsTblMap();
  902. BSTRMAP::iterator theIterator;
  903. // Displaying the alias specific description
  904. if (pszAlias)
  905. {
  906. theIterator = theMap.find(CharUpper(pszAlias));
  907. if (theIterator != theMap.end())
  908. {
  909. DisplayString(IDS_I_NEWLINE);
  910. _stprintf(szMsg,_T("%s - %s\r\n"),
  911. (LPTSTR) (*theIterator).first,
  912. (LPTSTR) (*theIterator).second);
  913. DisplayString((LPTSTR) szMsg);
  914. }
  915. }
  916. else if ( !theMap.empty() )
  917. {
  918. _TCHAR* pszCmdString = rParsedInfo.GetCmdSwitchesObject().
  919. GetCommandInput();
  920. DisplayString(IDS_I_NEWLINE);
  921. DisplayString(IDS_I_ALIASCMD_HEAD);
  922. // Display the alias friendly names together with the
  923. // descriptions
  924. for (theIterator = theMap.begin(); theIterator != theMap.end();
  925. theIterator++)
  926. {
  927. if ( rParsedInfo.GetGlblSwitchesObject().
  928. GetHelpOption() == HELPBRIEF &&
  929. StrStrI(pszCmdString, _T("BRIEF")) &&
  930. lstrlen((*theIterator).second) > 48)
  931. {
  932. _stprintf(szMsg,_T("%-25s- %.48s...\r\n"),
  933. (LPTSTR) (*theIterator).first,
  934. (LPTSTR) (*theIterator).second);
  935. }
  936. else
  937. {
  938. _stprintf(szMsg,_T("%-25s- %s\r\n"),
  939. (LPTSTR) (*theIterator).first,
  940. (LPTSTR) (*theIterator).second);
  941. }
  942. DisplayString((LPTSTR) szMsg);
  943. }
  944. DisplayString(IDS_I_NEWLINE);
  945. DisplayString(IDS_I_CMD_MORE);
  946. }
  947. else
  948. {
  949. DisplayString(IDS_I_NEWLINE);
  950. DisplayString(IDS_I_ALIASCMD_NOT_AVLBL);
  951. }
  952. }
  953. /*------------------------------------------------------------------------
  954. Name :DisplayGlobalSwitchesAndOtherDesc
  955. Synopsis :Display help for global switches
  956. Type :Member Function
  957. Input parameter :
  958. rParsedInfo - reference to CParsedInfo class object
  959. Output parameters :None
  960. Return Type :void
  961. Global Variables :None
  962. Calling Syntax :DisplayGlobalSwitchesAndOtherDesc(rParsedInfo)
  963. Notes :None
  964. ------------------------------------------------------------------------*/
  965. void CFormatEngine::DisplayGlobalSwitchesAndOtherDesc(
  966. CParsedInfo& rParsedInfo)
  967. {
  968. BOOL bDisplayAllInfo = rParsedInfo.GetHelpInfoObject().
  969. GetHelp(GlblAllInfo);
  970. // Display NAMESPACE help
  971. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Namespace))
  972. {
  973. DisplayString(IDS_I_NEWLINE);
  974. DisplayString(IDS_I_NAMESPACE_DESC1);
  975. DisplayString(IDS_I_NAMESPACE_DESC2);
  976. DisplayString(IDS_I_NAMESPACE_DESC3);
  977. DisplayString(IDS_I_USAGE);
  978. DisplayString(IDS_I_NEWLINE);
  979. DisplayString(IDS_I_NAMESPACE_USAGE);
  980. if (!bDisplayAllInfo)
  981. {
  982. DisplayString(IDS_I_NEWLINE);
  983. DisplayString(IDS_I_SPECIAL_NOTE);
  984. }
  985. }
  986. // Display ROLE help
  987. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Role))
  988. {
  989. DisplayString(IDS_I_NEWLINE);
  990. DisplayString(IDS_I_ROLE_DESC1);
  991. DisplayString(IDS_I_ROLE_DESC2);
  992. DisplayString(IDS_I_USAGE);
  993. DisplayString(IDS_I_NEWLINE);
  994. DisplayString(IDS_I_ROLE_USAGE);
  995. DisplayString(IDS_I_ROLE_NOTE1);
  996. DisplayString(IDS_I_ROLE_NOTE2);
  997. DisplayString(IDS_I_ROLE_NOTE3);
  998. if (!bDisplayAllInfo)
  999. {
  1000. DisplayString(IDS_I_NEWLINE);
  1001. DisplayString(IDS_I_SPECIAL_NOTE);
  1002. }
  1003. }
  1004. // Display NODE help
  1005. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Node))
  1006. {
  1007. DisplayString(IDS_I_NEWLINE);
  1008. DisplayString(IDS_I_NODE_DESC);
  1009. DisplayString(IDS_I_USAGE);
  1010. DisplayString(IDS_I_NEWLINE);
  1011. DisplayString(IDS_I_NODE_USAGE);
  1012. DisplayString(IDS_I_NODE_NOTE);
  1013. if (!bDisplayAllInfo)
  1014. {
  1015. DisplayString(IDS_I_NEWLINE);
  1016. DisplayString(IDS_I_SPECIAL_NOTE);
  1017. }
  1018. }
  1019. // Display IMPLEVEL help
  1020. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Level))
  1021. {
  1022. DisplayString(IDS_I_NEWLINE);
  1023. DisplayString(IDS_I_IMPLEVEL_DESC1);
  1024. DisplayString(IDS_I_IMPLEVEL_DESC2);
  1025. DisplayString(IDS_I_USAGE);
  1026. DisplayString(IDS_I_NEWLINE);
  1027. DisplayString(IDS_I_IMPLEVEL_USAGE);
  1028. DisplayString(IDS_I_IMPLEVEL_HEAD);
  1029. DisplayString(IDS_I_IMPLEVEL_HEAD1);
  1030. DisplayString(IDS_I_IMPLEVEL_HEAD2);
  1031. DisplayString(IDS_I_IMPLEVEL_ANON);
  1032. DisplayString(IDS_I_IMPLEVEL_IDENTIFY);
  1033. DisplayString(IDS_I_IMPLEVEL_IMPERSONATE);
  1034. DisplayString(IDS_I_IMPLEVEL_DELEGATE);
  1035. DisplayString(IDS_I_IMPLEVEL_NOTE);
  1036. }
  1037. // Display AUTHLEVEL help
  1038. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(AuthLevel))
  1039. {
  1040. DisplayString(IDS_I_NEWLINE);
  1041. DisplayString(IDS_I_AUTHLEVEL_DESC1);
  1042. DisplayString(IDS_I_AUTHLEVEL_DESC2);
  1043. DisplayString(IDS_I_USAGE);
  1044. DisplayString(IDS_I_NEWLINE);
  1045. DisplayString(IDS_I_AUTHLEVEL_USAGE);
  1046. DisplayString(IDS_I_AUTHLEVEL_HEAD);
  1047. DisplayString(IDS_I_AUTHLEVEL_HEAD1);
  1048. DisplayString(IDS_I_AUTHLEVEL_HEAD2);
  1049. DisplayString(IDS_I_AUTHLEVEL_DEFAULT);
  1050. DisplayString(IDS_I_AUTHLEVEL_NONE);
  1051. DisplayString(IDS_I_AUTHLEVEL_CONNECT);
  1052. DisplayString(IDS_I_AUTHLEVEL_CALL);
  1053. DisplayString(IDS_I_AUTHLEVEL_PKT);
  1054. DisplayString(IDS_I_AUTHLEVEL_PKTINTGRTY);
  1055. DisplayString(IDS_I_AUTHLEVEL_PKTPRVCY);
  1056. }
  1057. // Display LOCALE help
  1058. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Locale))
  1059. {
  1060. DisplayString(IDS_I_NEWLINE);
  1061. DisplayString(IDS_I_LOCALE_DESC);
  1062. DisplayString(IDS_I_USAGE);
  1063. DisplayString(IDS_I_NEWLINE);
  1064. DisplayString(IDS_I_LOCALE_USAGE);
  1065. DisplayString(IDS_I_LOCALE_NOTE1);
  1066. DisplayString(IDS_I_LOCALE_NOTE2);
  1067. }
  1068. // Display PRIVILEGES help
  1069. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Privileges))
  1070. {
  1071. DisplayString(IDS_I_NEWLINE);
  1072. DisplayString(IDS_I_PRIVILEGES_DESC);
  1073. DisplayString(IDS_I_USAGE);
  1074. DisplayString(IDS_I_NEWLINE);
  1075. DisplayString(IDS_I_PRIVILEGES_USAGE);
  1076. DisplayString(IDS_I_PRIVILEGES_NOTE);
  1077. }
  1078. // Display TRACE help
  1079. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Trace))
  1080. {
  1081. DisplayString(IDS_I_NEWLINE);
  1082. DisplayString(IDS_I_TRACE_DESC1);
  1083. DisplayString(IDS_I_TRACE_DESC2);
  1084. DisplayString(IDS_I_USAGE);
  1085. DisplayString(IDS_I_NEWLINE);
  1086. DisplayString(IDS_I_TRACE_USAGE);
  1087. DisplayString(IDS_I_TRACE_NOTE);
  1088. }
  1089. // Display RECORD help
  1090. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(RecordPath))
  1091. {
  1092. DisplayString(IDS_I_NEWLINE);
  1093. DisplayString(IDS_I_RECORD_DESC);
  1094. DisplayString(IDS_I_USAGE);
  1095. DisplayString(IDS_I_NEWLINE);
  1096. DisplayString(IDS_I_RECORD_USAGE);
  1097. if (!bDisplayAllInfo)
  1098. {
  1099. DisplayString(IDS_I_NEWLINE);
  1100. DisplayString(IDS_I_SPECIAL_NOTE);
  1101. }
  1102. }
  1103. // Display INTERACTIVE help
  1104. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Interactive))
  1105. {
  1106. DisplayString(IDS_I_NEWLINE);
  1107. DisplayString(IDS_I_INTERACTIVE_DESC);
  1108. DisplayString(IDS_I_USAGE);
  1109. DisplayString(IDS_I_NEWLINE);
  1110. DisplayString(IDS_I_INTERACTIVE_USAGE);
  1111. DisplayString(IDS_I_TRACE_NOTE);
  1112. }
  1113. // Display FAILFAST help
  1114. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(FAILFAST))
  1115. {
  1116. DisplayString(IDS_I_NEWLINE);
  1117. DisplayString(IDS_I_FAILFAST_DESC);
  1118. DisplayString(IDS_I_USAGE);
  1119. DisplayString(IDS_I_NEWLINE);
  1120. DisplayString(IDS_I_FAILFAST_USAGE);
  1121. DisplayString(IDS_I_TRACE_NOTE);
  1122. }
  1123. // Display OUTPUT help
  1124. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(OUTPUT))
  1125. {
  1126. DisplayString(IDS_I_NEWLINE);
  1127. DisplayString(IDS_I_OUTPUT_DESC);
  1128. DisplayString(IDS_I_USAGE);
  1129. DisplayString(IDS_I_NEWLINE);
  1130. DisplayString(IDS_I_OUTPUT_USAGE);
  1131. DisplayString(IDS_I_OUTPUT_NOTE);
  1132. DisplayString(IDS_I_STDOUT_NOTE);
  1133. DisplayString(IDS_I_CLIPBOARD_NOTE);
  1134. DisplayString(IDS_I_OUTPUT_FILE_NOTE);
  1135. if (!bDisplayAllInfo)
  1136. {
  1137. DisplayString(IDS_I_NEWLINE);
  1138. DisplayString(IDS_I_SPECIAL_NOTE);
  1139. }
  1140. }
  1141. // Display APPEND help
  1142. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(APPEND))
  1143. {
  1144. DisplayString(IDS_I_NEWLINE);
  1145. DisplayString(IDS_I_APPEND_DESC);
  1146. DisplayString(IDS_I_USAGE);
  1147. DisplayString(IDS_I_NEWLINE);
  1148. DisplayString(IDS_I_APPEND_USAGE);
  1149. DisplayString(IDS_I_OUTPUT_NOTE);
  1150. DisplayString(IDS_I_STDOUT_NOTE);
  1151. DisplayString(IDS_I_CLIPBOARD_NOTE);
  1152. DisplayString(IDS_I_APPEND_FILE_NOTE);
  1153. if (!bDisplayAllInfo)
  1154. {
  1155. DisplayString(IDS_I_NEWLINE);
  1156. DisplayString(IDS_I_SPECIAL_NOTE);
  1157. }
  1158. }
  1159. // Display USER help
  1160. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(User))
  1161. {
  1162. DisplayString(IDS_I_NEWLINE);
  1163. DisplayString(IDS_I_USER_DESC);
  1164. DisplayString(IDS_I_USAGE);
  1165. DisplayString(IDS_I_NEWLINE);
  1166. DisplayString(IDS_I_USER_USAGE);
  1167. DisplayString(IDS_I_USER_NOTE);
  1168. if (!bDisplayAllInfo)
  1169. {
  1170. DisplayString(IDS_I_NEWLINE);
  1171. DisplayString(IDS_I_SPECIAL_NOTE);
  1172. }
  1173. }
  1174. //Display AGGREGATE help
  1175. if(bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Aggregate))
  1176. {
  1177. DisplayString(IDS_I_NEWLINE);
  1178. DisplayString(IDS_I_AGGREGATE_DESC);
  1179. DisplayString(IDS_I_USAGE);
  1180. DisplayString(IDS_I_NEWLINE);
  1181. DisplayString(IDS_I_AGGREGATE_USAGE);
  1182. DisplayString(IDS_I_AGGREGATE_NOTE);
  1183. }
  1184. // Display PASSWORD help
  1185. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Password))
  1186. {
  1187. DisplayString(IDS_I_NEWLINE);
  1188. DisplayString(IDS_I_PASSWORD_DESC);
  1189. DisplayString(IDS_I_USAGE);
  1190. DisplayString(IDS_I_NEWLINE);
  1191. DisplayString(IDS_I_PASSWORD_USAGE);
  1192. if (!bDisplayAllInfo)
  1193. {
  1194. DisplayString(IDS_I_NEWLINE);
  1195. DisplayString(IDS_I_SPECIAL_NOTE);
  1196. }
  1197. }
  1198. // Display AUTHORITY help
  1199. if (bDisplayAllInfo || rParsedInfo.GetHelpInfoObject().GetHelp(Authority))
  1200. {
  1201. DisplayString(IDS_I_NEWLINE);
  1202. DisplayString(IDS_I_AUTHORITY_DESC);
  1203. DisplayString(IDS_I_USAGE);
  1204. DisplayString(IDS_I_NEWLINE);
  1205. DisplayString(IDS_I_AUTHORITY_USAGE);
  1206. }
  1207. if (bDisplayAllInfo)
  1208. {
  1209. DisplayString(IDS_I_NEWLINE);
  1210. DisplayString(IDS_I_HELP_DESC);
  1211. DisplayString(IDS_I_USAGE);
  1212. DisplayString(IDS_I_NEWLINE);
  1213. DisplayString(IDS_I_HELP_USAGE);
  1214. DisplayString(IDS_I_HELP_NOTE);
  1215. DisplayString(IDS_I_NEWLINE);
  1216. DisplayString(IDS_I_SPECIAL_NOTE);
  1217. }
  1218. }
  1219. /*------------------------------------------------------------------------
  1220. Name :DisplayMethodDetails
  1221. Synopsis :Display help for Alias verbs
  1222. Type :Member Function
  1223. Input parameter :
  1224. rParsedInfo - reference to CParsedInfo class object
  1225. Output parameters :None
  1226. Return Type :void
  1227. Global Variables :None
  1228. Calling Syntax :DisplayMethodDetails(rParsedInfo)
  1229. Notes :None
  1230. ------------------------------------------------------------------------*/
  1231. void CFormatEngine::DisplayMethodDetails(CParsedInfo& rParsedInfo)
  1232. {
  1233. // Obtain the help option.
  1234. HELPOPTION hoHelpType = rParsedInfo.GetGlblSwitchesObject()
  1235. .GetHelpOption();
  1236. // Obtain the method details.
  1237. METHDETMAP theMap = rParsedInfo.GetCmdSwitchesObject().
  1238. GetMethDetMap();
  1239. METHDETMAP::iterator theIterator;
  1240. BOOL bDisAliasVerb = rParsedInfo.GetHelpInfoObject().
  1241. GetHelp(AliasVerb);
  1242. BOOL bPrinted = FALSE;
  1243. _bstr_t bstrLine;
  1244. try
  1245. {
  1246. // Loop thru the method map
  1247. for (theIterator = theMap.begin();
  1248. theIterator != theMap.end(); theIterator++)
  1249. {
  1250. if (!bDisAliasVerb && theIterator == theMap.begin())
  1251. {
  1252. DisplayString(IDS_I_NEWLINE);
  1253. if (rParsedInfo.GetCmdSwitchesObject().GetAliasName())
  1254. DisplayString(IDS_I_ALIASVERB_HEAD);
  1255. else
  1256. DisplayString(IDS_I_VERB_HEAD);
  1257. DisplayString(IDS_I_NEWLINE);
  1258. }
  1259. if ( bPrinted == FALSE )
  1260. {
  1261. DisplayString(IDS_I_PARAM_HEAD);
  1262. DisplayString(IDS_I_PARAM_BORDER);
  1263. bPrinted = TRUE;
  1264. }
  1265. METHODDETAILS mdMethDet = (*theIterator).second;
  1266. _TCHAR szMsg[MAX_BUFFER] = NULL_STRING;
  1267. _stprintf(szMsg,_T("%-24s"),(LPTSTR) (*theIterator).first);
  1268. _bstr_t bstrMessage = _bstr_t(szMsg);
  1269. PROPDETMAP pdmParams = mdMethDet.Params;
  1270. PROPDETMAP::iterator paraIterator;
  1271. for ( paraIterator = pdmParams.begin() ; paraIterator !=
  1272. pdmParams.end(); paraIterator++ )
  1273. {
  1274. if ( paraIterator != pdmParams.begin())
  1275. {
  1276. DisplayString(IDS_I_NEWLINE);
  1277. _stprintf(szMsg, _T("\t\t\t"));
  1278. bstrMessage = szMsg;
  1279. }
  1280. LPSTR pszParaId = NULL, pszParaType = NULL;
  1281. PROPERTYDETAILS pdPropDet = (*paraIterator).second;
  1282. if (!ConvertWCToMBCS((LPTSTR)(*paraIterator).first,(LPVOID*) &pszParaId,
  1283. CP_OEMCP))
  1284. throw OUT_OF_MEMORY;
  1285. if (!ConvertWCToMBCS(pdPropDet.Type,(LPVOID*) &pszParaType, CP_OEMCP))
  1286. throw OUT_OF_MEMORY;
  1287. _bstr_t bstrInOrOut;
  1288. if ( pdPropDet.InOrOut == INP )
  1289. bstrInOrOut = _bstr_t("[IN ]");
  1290. else if ( pdPropDet.InOrOut == OUTP )
  1291. bstrInOrOut = _bstr_t("[OUT]");
  1292. else
  1293. bstrInOrOut = _bstr_t("[UNKNOWN]");
  1294. // Remove initial 5 chars from pszParaId to remove temporary
  1295. // number for maintaining order of paramas
  1296. _bstr_t bstrLine = bstrInOrOut
  1297. + _bstr_t(pszParaId + 5)
  1298. + _bstr_t("(")
  1299. + _bstr_t(pszParaType) + _bstr_t(")");
  1300. _stprintf(szMsg,_T("%-36s\t"),(LPTSTR) bstrLine);
  1301. bstrMessage += _bstr_t(szMsg);
  1302. SAFEDELETE(pszParaId);
  1303. SAFEDELETE(pszParaType);
  1304. if ( paraIterator == pdmParams.begin() )
  1305. {
  1306. _stprintf(szMsg,_T("%-15s"),(LPTSTR) mdMethDet.Status);
  1307. bstrMessage += szMsg;
  1308. }
  1309. bstrMessage += _bstr_t(L"\n");
  1310. DisplayString((LPTSTR) bstrMessage);
  1311. }
  1312. if ( paraIterator == pdmParams.begin() )
  1313. {
  1314. _stprintf(szMsg,_T("\t\t\t\t\t%-15s"),(LPTSTR)mdMethDet.Status);
  1315. bstrMessage += _bstr_t(szMsg) + _bstr_t(L"\n");
  1316. DisplayString((LPTSTR) bstrMessage);
  1317. DisplayString(IDS_I_NEWLINE);
  1318. }
  1319. DisplayString(IDS_I_NEWLINE);
  1320. if ( hoHelpType == HELPFULL )
  1321. {
  1322. DisplayString(IDS_I_DESCRIPTION);
  1323. bstrLine = mdMethDet.Description + _bstr_t(L"\n");
  1324. DisplayString((LPTSTR) bstrLine);
  1325. DisplayString(IDS_I_NEWLINE);
  1326. }
  1327. }
  1328. if (!bPrinted)
  1329. {
  1330. if (rParsedInfo.GetCmdSwitchesObject().GetMethodName() != NULL)
  1331. {
  1332. DisplayString(IDS_I_ALIASVERB_NOT_AVLBL);
  1333. }
  1334. else
  1335. {
  1336. DisplayString(IDS_I_NEWLINE);
  1337. DisplayString(IDS_I_VERB_NOT_AVLBL);
  1338. }
  1339. }
  1340. }
  1341. catch(_com_error& e)
  1342. {
  1343. _com_issue_error(e.Error());
  1344. }
  1345. catch(WMICLIINT nVal)
  1346. {
  1347. // If memory allocation failed.
  1348. if (nVal == OUT_OF_MEMORY)
  1349. {
  1350. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(OUT_OF_MEMORY);
  1351. }
  1352. }
  1353. }
  1354. /*------------------------------------------------------------------------
  1355. Name :DisplayPropertyDetails
  1356. Synopsis :Display help for Alias properties and their descriptions
  1357. Type :Member Function
  1358. Input parameter :
  1359. rParsedInfo - reference to CParsedInfo class object
  1360. Output parameters :None
  1361. Return Type :void
  1362. Global Variables :None
  1363. Calling Syntax :DisplayPropertyDetails(rParsedInfo)
  1364. Notes :None
  1365. ------------------------------------------------------------------------*/
  1366. void CFormatEngine::DisplayPropertyDetails(CParsedInfo& rParsedInfo)
  1367. {
  1368. BOOL bFirst = TRUE;
  1369. BOOL bSetVerb = FALSE;
  1370. _TCHAR szMsg[MAX_BUFFER] = NULL_STRING;
  1371. _bstr_t bstrLine;
  1372. PROPDETMAP::iterator theIterator = NULL;
  1373. PROPERTYDETAILS pdPropDet;
  1374. HELPOPTION hoHelpType = rParsedInfo.GetGlblSwitchesObject().
  1375. GetHelpOption();
  1376. PROPDETMAP theMap = rParsedInfo.GetCmdSwitchesObject().GetPropDetMap();
  1377. try
  1378. {
  1379. // If the verb is SET display only writable properties
  1380. if (CompareTokens(rParsedInfo.GetCmdSwitchesObject().GetVerbName(),
  1381. CLI_TOKEN_SET))
  1382. {
  1383. bSetVerb = TRUE;
  1384. }
  1385. for (theIterator = theMap.begin();
  1386. theIterator != theMap.end(); theIterator++)
  1387. {
  1388. pdPropDet = (PROPERTYDETAILS)((*theIterator).second);
  1389. if (bFirst)
  1390. {
  1391. DisplayString(IDS_I_NEWLINE);
  1392. if ( rParsedInfo.GetCmdSwitchesObject().
  1393. GetPropertyList().size() == 0 )
  1394. {
  1395. if (bSetVerb)
  1396. {
  1397. DisplayString(IDS_I_PROP_WRITEABLE_HEAD);
  1398. }
  1399. else
  1400. {
  1401. DisplayString(IDS_I_PROP_HEAD);
  1402. }
  1403. }
  1404. DisplayString(IDS_I_PROPS_HEAD);
  1405. DisplayString(IDS_I_PROPS_BORDER);
  1406. bFirst = FALSE;
  1407. }
  1408. _stprintf(szMsg,_T("%-35s\t%-20s\t%-10s\r\n"),
  1409. (LPTSTR)(*theIterator).first,
  1410. (LPTSTR) pdPropDet.Type, (LPTSTR) pdPropDet.Operation);
  1411. DisplayString((LPTSTR) szMsg);
  1412. if ( hoHelpType == HELPFULL )
  1413. {
  1414. DisplayString(IDS_I_DESCRIPTION);
  1415. bstrLine = pdPropDet.Description + _bstr_t(L"\n");
  1416. DisplayString((LPTSTR) bstrLine);
  1417. DisplayString(IDS_I_NEWLINE);
  1418. }
  1419. }
  1420. if ( bSetVerb &&
  1421. rParsedInfo.GetCmdSwitchesObject().
  1422. GetPropertyList().size() == 0 &&
  1423. bFirst == TRUE )
  1424. {
  1425. DisplayString(IDS_I_NEWLINE);
  1426. DisplayString(IDS_I_PROP_WRITEABLE_NOT_AVLBL);
  1427. }
  1428. }
  1429. catch(_com_error& e)
  1430. {
  1431. _com_issue_error(e.Error());
  1432. }
  1433. }
  1434. /*------------------------------------------------------------------------
  1435. Name :DisplayStdVerbDescriptions
  1436. Synopsis :Displays help for standard verbs
  1437. Type :Member Function
  1438. Input parameter :
  1439. rParsedInfo - reference to CParsedInfo class object
  1440. Output parameters :None
  1441. Return Type :void
  1442. Global Variables :None
  1443. Calling Syntax :DisplayStdVerbDescriptions(rParsedInfo)
  1444. Notes :None
  1445. ------------------------------------------------------------------------*/
  1446. void CFormatEngine::DisplayStdVerbDescriptions(CParsedInfo& rParsedInfo)
  1447. {
  1448. BOOL bDisAllCmdHelp = rParsedInfo.GetHelpInfoObject().GetHelp(CmdAllInfo);
  1449. if (bDisAllCmdHelp)
  1450. {
  1451. DisplayString(IDS_I_NEWLINE);
  1452. DisplayString(IDS_I_STDVERB_HEAD);
  1453. }
  1454. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(GETVerb))
  1455. DisplayGETUsage(rParsedInfo);
  1456. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(SETVerb))
  1457. DisplaySETUsage(rParsedInfo);
  1458. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(LISTVerb))
  1459. DisplayLISTUsage(rParsedInfo);
  1460. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(CALLVerb))
  1461. DisplayCALLUsage(rParsedInfo);
  1462. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(ASSOCVerb))
  1463. DisplayASSOCUsage(rParsedInfo);
  1464. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(CREATEVerb))
  1465. DisplayCREATEUsage(rParsedInfo);
  1466. if (bDisAllCmdHelp || rParsedInfo.GetHelpInfoObject().GetHelp(DELETEVerb))
  1467. DisplayDELETEUsage(rParsedInfo);
  1468. }
  1469. /*------------------------------------------------------------------------
  1470. Name :FrameHelpVector
  1471. Synopsis :Frames the help vector which will be later used for
  1472. displaying the help on a page by page basis
  1473. Type :Member Function
  1474. Input parameter :
  1475. rParsedInfo - reference to CParsedInfo class object
  1476. Output parameters :None
  1477. Return Type :void
  1478. Global Variables :None
  1479. Calling Syntax :FrameHelpVector(rParsedInfo)
  1480. Notes :None
  1481. ------------------------------------------------------------------------*/
  1482. void CFormatEngine::FrameHelpVector(CParsedInfo& rParsedInfo)
  1483. {
  1484. m_bDispCALL = rParsedInfo.GetCmdSwitchesObject().
  1485. GetMethodsAvailable();
  1486. m_bDispSET = rParsedInfo.GetCmdSwitchesObject().
  1487. GetWriteablePropsAvailable();
  1488. m_bDispLIST = rParsedInfo.GetCmdSwitchesObject().
  1489. GetLISTFormatsAvailable();
  1490. if (rParsedInfo.GetHelpInfoObject().GetHelp(GlblAllInfo))
  1491. {
  1492. DisplayString(IDS_I_NEWLINE);
  1493. DisplayString(IDS_I_GLBLCMD);
  1494. DisplayString(IDS_I_NEWLINE);
  1495. DisplayString(IDS_I_GLBL_SWITCH_HEAD);
  1496. if ( rParsedInfo.GetGlblSwitchesObject().GetHelpOption() == HELPBRIEF)
  1497. DisplayGlobalSwitchesBrief();
  1498. else
  1499. DisplayGlobalSwitchesAndOtherDesc(rParsedInfo);
  1500. DisplayString(IDS_I_NEWLINE);
  1501. DisplayAliasFriendlyNames(rParsedInfo);
  1502. DisplayString(IDS_I_NEWLINE);
  1503. DisplayString(IDS_I_CLASS_DESCFULL);
  1504. DisplayString(IDS_I_PATH_DESCFULL);
  1505. DisplayString(IDS_I_CONTEXT_DESCFULL);
  1506. DisplayString(IDS_I_QUITEXIT);
  1507. DisplayString(IDS_I_NEWLINE);
  1508. DisplayString(IDS_I_CLASSPATH_MORE);
  1509. }
  1510. else if (rParsedInfo.GetHelpInfoObject().GetHelp(CmdAllInfo))
  1511. {
  1512. DisplayAliasFriendlyNames(rParsedInfo,
  1513. rParsedInfo.GetCmdSwitchesObject().GetAliasName());
  1514. DisplayAliasHelp(rParsedInfo);
  1515. }
  1516. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(PATH))
  1517. DisplayPATHHelp(rParsedInfo);
  1518. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(WHERE))
  1519. DisplayWHEREHelp(rParsedInfo);
  1520. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(CLASS))
  1521. DisplayCLASSHelp(rParsedInfo);
  1522. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(PWhere))
  1523. DisplayPWhereHelp(rParsedInfo);
  1524. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(TRANSLATE))
  1525. DisplayTRANSLATEHelp(rParsedInfo);
  1526. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(EVERY))
  1527. DisplayEVERYHelp(rParsedInfo);
  1528. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(REPEAT))
  1529. DisplayREPEATHelp();
  1530. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(FORMAT))
  1531. DisplayFORMATHelp(rParsedInfo);
  1532. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(VERBSWITCHES))
  1533. DisplayVERBSWITCHESHelp(rParsedInfo);
  1534. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(GLBLCONTEXT))
  1535. DisplayContext(rParsedInfo);
  1536. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(CONTEXTHELP))
  1537. DisplayContextHelp();
  1538. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(RESULTCLASShelp))
  1539. DisplayRESULTCLASSHelp();
  1540. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(RESULTROLEhelp))
  1541. DisplayRESULTROLEHelp();
  1542. else if ( rParsedInfo.GetHelpInfoObject().GetHelp(ASSOCCLASShelp))
  1543. DisplayASSOCCLASSHelp();
  1544. else
  1545. {
  1546. DisplayGlobalSwitchesAndOtherDesc(rParsedInfo);
  1547. DisplayStdVerbDescriptions(rParsedInfo);
  1548. if ( rParsedInfo.GetHelpInfoObject().GetHelp(AliasVerb) )
  1549. DisplayMethodDetails(rParsedInfo);
  1550. }
  1551. }
  1552. /*------------------------------------------------------------------------
  1553. Name :DisplayAliasHelp
  1554. Synopsis :Displays help for Alias
  1555. Type :Member Function
  1556. Input parameter :
  1557. rParsedInfo - reference to CParsedInfo class object
  1558. Output parameters :None
  1559. Return Type :void
  1560. Global Variables :None
  1561. Calling Syntax :DisplayAliasHelp(rParsedInfo)
  1562. Notes :None
  1563. ------------------------------------------------------------------------*/
  1564. void CFormatEngine::DisplayAliasHelp(CParsedInfo& rParsedInfo)
  1565. {
  1566. try
  1567. {
  1568. DisplayString(IDS_I_NEWLINE);
  1569. DisplayString(IDS_I_ALIAS_USAGE1);
  1570. DisplayString(IDS_I_ALIAS_USAGE2);
  1571. DisplayString(IDS_I_NEWLINE);
  1572. // Get the Alias Name
  1573. _bstr_t bstrAliasName = _bstr_t(rParsedInfo.
  1574. GetCmdSwitchesObject().GetAliasName());
  1575. CharUpper(bstrAliasName);
  1576. DisplayStdVerbsUsage(bstrAliasName);
  1577. }
  1578. catch(_com_error& e)
  1579. {
  1580. _com_issue_error(e.Error());
  1581. }
  1582. }
  1583. /*------------------------------------------------------------------------
  1584. Name :DisplayPATHHelp
  1585. Synopsis :Displays help for Alias PATH
  1586. Type :Member Function
  1587. Input parameter :
  1588. rParsedInfo - reference to CParsedInfo class object
  1589. Output parameters :None
  1590. Return Type :void
  1591. Global Variables :None
  1592. Calling Syntax :DisplayPATHHelp(rParsedInfo)
  1593. Notes :None
  1594. ------------------------------------------------------------------------*/
  1595. void CFormatEngine::DisplayPATHHelp(CParsedInfo& rParsedInfo)
  1596. {
  1597. if ( rParsedInfo.GetCmdSwitchesObject().GetClassPath() == NULL )
  1598. {
  1599. DisplayString(IDS_I_NEWLINE);
  1600. DisplayString(IDS_I_PATH_DESC);
  1601. DisplayString(IDS_I_USAGE);
  1602. DisplayString(IDS_I_NEWLINE);
  1603. DisplayString(IDS_I_PATH_USAGE);
  1604. }
  1605. else
  1606. {
  1607. DisplayString(IDS_I_NEWLINE);
  1608. DisplayString(IDS_I_PATH_DESC);
  1609. _bstr_t bstrMsg;
  1610. WMIFormatMessage(IDS_I_PATHHELP_SUBST, 0, bstrMsg, NULL);
  1611. DisplayStdVerbsUsage(bstrMsg);
  1612. }
  1613. }
  1614. /*------------------------------------------------------------------------
  1615. Name :DisplayWHEREHelp
  1616. Synopsis :Displays help for WHERE
  1617. Type :Member Function
  1618. Input parameter :
  1619. rParsedInfo - reference to CParsedInfo class object
  1620. Output parameters :None
  1621. Return Type :void
  1622. Global Variables :None
  1623. Calling Syntax :DisplayWHEREHelp(rParsedInfo)
  1624. Notes :None
  1625. ------------------------------------------------------------------------*/
  1626. void CFormatEngine::DisplayWHEREHelp(CParsedInfo& rParsedInfo)
  1627. {
  1628. try
  1629. {
  1630. if ( rParsedInfo.GetCmdSwitchesObject().GetWhereExpression() == NULL )
  1631. {
  1632. DisplayString(IDS_I_NEWLINE);
  1633. DisplayString(IDS_I_WHERE_DESC1);
  1634. DisplayString(IDS_I_WHERE_DESC2);
  1635. DisplayString(IDS_I_USAGE);
  1636. DisplayString(IDS_I_NEWLINE);
  1637. DisplayString(IDS_I_WHERE_USAGE);
  1638. }
  1639. else
  1640. {
  1641. DisplayString(IDS_I_NEWLINE);
  1642. DisplayString(IDS_I_WHERE_DESC1);
  1643. DisplayString(IDS_I_WHERE_DESC2);
  1644. _bstr_t bstrMsg;
  1645. WMIFormatMessage(IDS_I_WHEREHELP_SUBST, 0, bstrMsg, NULL);
  1646. DisplayStdVerbsUsage(bstrMsg);
  1647. }
  1648. }
  1649. catch(_com_error& e)
  1650. {
  1651. _com_issue_error(e.Error());
  1652. }
  1653. }
  1654. /*------------------------------------------------------------------------
  1655. Name :DisplayCLASSHelp
  1656. Synopsis :Displays help for CLASS
  1657. Type :Member Function
  1658. Input parameter :
  1659. rParsedInfo - reference to CParsedInfo class object
  1660. Output parameters :None
  1661. Return Type :void
  1662. Global Variables :None
  1663. Calling Syntax :DisplayCLASSHelp(rParsedInfo)
  1664. Notes :None
  1665. ------------------------------------------------------------------------*/
  1666. void CFormatEngine::DisplayCLASSHelp(CParsedInfo& rParsedInfo)
  1667. {
  1668. if ( rParsedInfo.GetCmdSwitchesObject().GetClassPath() == NULL )
  1669. {
  1670. DisplayString(IDS_I_NEWLINE);
  1671. DisplayString(IDS_I_CLASS_DESC);
  1672. DisplayString(IDS_I_USAGE);
  1673. DisplayString(IDS_I_NEWLINE);
  1674. DisplayString(IDS_I_CLASS_USAGE);
  1675. }
  1676. else
  1677. {
  1678. DisplayString(IDS_I_NEWLINE);
  1679. DisplayString(IDS_I_CLASS_DESC);
  1680. _bstr_t bstrMsg;
  1681. WMIFormatMessage(IDS_I_CLASSHELP_SUBST, 0, bstrMsg, NULL);
  1682. DisplayStdVerbsUsage(bstrMsg, TRUE);
  1683. }
  1684. }
  1685. /*------------------------------------------------------------------------
  1686. Name :Help
  1687. Synopsis :Displays help for PWhere
  1688. Type :Member Function
  1689. Input parameter :
  1690. rParsedInfo - reference to CParsedInfo class object
  1691. Output parameters :None
  1692. Return Type :void
  1693. Global Variables :None
  1694. Calling Syntax :DisplayPWhereHelp(rParsedInfo)
  1695. Notes :None
  1696. ------------------------------------------------------------------------*/
  1697. void CFormatEngine::DisplayPWhereHelp(CParsedInfo& rParsedInfo)
  1698. {
  1699. DisplayString(IDS_I_NEWLINE);
  1700. DisplayString(IDS_I_PWHERE_DESC1);
  1701. DisplayString(IDS_I_PWHERE_DESC2);
  1702. DisplayString(IDS_I_NEWLINE);
  1703. _bstr_t bstrMsg;
  1704. WMIFormatMessage(IDS_I_PWHEREHELP_SUBST, 1, bstrMsg,
  1705. CharUpper(rParsedInfo.GetCmdSwitchesObject()
  1706. .GetAliasName()));
  1707. DisplayStdVerbsUsage(bstrMsg);
  1708. DisplayString(IDS_I_PWHERE_USAGE);
  1709. }
  1710. /*------------------------------------------------------------------------
  1711. Name :DisplayString
  1712. Synopsis :Displays localized string
  1713. Type :Member Function
  1714. Input parameter :None
  1715. uID - string table identifier
  1716. bAddToVector - add to help vector.
  1717. LPTSTR - lpszParam (parameter for substituion)
  1718. Output parameters :None
  1719. Return Type :void
  1720. Global Variables :None
  1721. Calling Syntax :DisplayString(uID, bAddToVector, lpszParam)
  1722. Notes :None
  1723. ------------------------------------------------------------------------*/
  1724. void CFormatEngine::DisplayString(UINT uID, BOOL bAddToVector, LPTSTR lpszParam, BOOL bIsError)
  1725. {
  1726. LPTSTR lpszMsg = NULL;
  1727. LPVOID lpMsgBuf = NULL;
  1728. HRESULT hr = S_OK;
  1729. try
  1730. {
  1731. lpszMsg = new _TCHAR [BUFFER1024];
  1732. if ( m_bGetOutOpt == TRUE )
  1733. {
  1734. // Get the output option to redirect the output.
  1735. m_opsOutputOpt = g_wmiCmd.GetParsedInfoObject().
  1736. GetGlblSwitchesObject().
  1737. GetOutputOrAppendOption(TRUE);
  1738. m_bGetOutOpt = FALSE;
  1739. }
  1740. if ( m_bGetAppendFilePinter == TRUE )
  1741. {
  1742. // FALSE for getting append file pointer.
  1743. m_fpAppendFile = g_wmiCmd.GetParsedInfoObject().
  1744. GetGlblSwitchesObject().
  1745. GetOutputOrAppendFilePointer(FALSE);
  1746. m_bGetAppendFilePinter = FALSE;
  1747. }
  1748. if ( m_bGetOutputFilePinter == TRUE )
  1749. {
  1750. // TRUE for getting append file pointer.
  1751. m_fpOutFile = g_wmiCmd.GetParsedInfoObject().
  1752. GetGlblSwitchesObject().
  1753. GetOutputOrAppendFilePointer(TRUE);
  1754. m_bGetOutputFilePinter = FALSE;
  1755. }
  1756. if (lpszMsg)
  1757. {
  1758. LoadString(NULL, uID, lpszMsg, BUFFER1024);
  1759. if (lpszParam)
  1760. {
  1761. char* pvaInsertStrs[1];
  1762. pvaInsertStrs[0] = (char*) lpszParam;
  1763. DWORD dwRet = FormatMessage(
  1764. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1765. FORMAT_MESSAGE_FROM_STRING |
  1766. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  1767. lpszMsg,
  1768. 0,
  1769. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  1770. (LPTSTR) &lpMsgBuf,
  1771. 0,
  1772. pvaInsertStrs);
  1773. if (dwRet == 0)
  1774. {
  1775. SAFEDELETE(lpszMsg);
  1776. throw (::GetLastError());
  1777. }
  1778. }
  1779. if (m_bHelp && bAddToVector)
  1780. {
  1781. LPWSTR wszHelp = NULL ;
  1782. if ( NULL != ( wszHelp = new WCHAR [ lstrlen ( reinterpret_cast < WCHAR* > ( ( lpMsgBuf ) ? lpMsgBuf : lpszMsg ) ) + 1 ] ) )
  1783. {
  1784. lstrcpy ( wszHelp, reinterpret_cast < WCHAR* > ( ( lpMsgBuf ) ? lpMsgBuf : lpszMsg ) ) ;
  1785. m_cvHelp.push_back ( wszHelp ) ;
  1786. }
  1787. if ( NULL == wszHelp )
  1788. {
  1789. //
  1790. // must delete here
  1791. //
  1792. SAFEDELETE(lpszMsg);
  1793. // Free the memory used up the error message
  1794. // and then exit
  1795. if ( lpMsgBuf != NULL )
  1796. {
  1797. LocalFree(lpMsgBuf);
  1798. lpMsgBuf = NULL ;
  1799. }
  1800. throw OUT_OF_MEMORY;
  1801. }
  1802. }
  1803. else
  1804. {
  1805. if (m_bRecord && m_bLog && !m_bInteractiveHelp)
  1806. {
  1807. hr = m_WmiCliLog.WriteToXMLLog(g_wmiCmd.GetParsedInfoObject(), ( lpMsgBuf ) ? ( LPTSTR ) lpMsgBuf : lpszMsg );
  1808. if (FAILED(hr))
  1809. {
  1810. m_WmiCliLog.StopLogging();
  1811. m_bRecord = FALSE;
  1812. hr = S_OK;
  1813. DisplayString(IDS_E_WRITELOG_FAILED, FALSE, NULL, TRUE);
  1814. }
  1815. m_bLog = FALSE;
  1816. }
  1817. if (m_bInteractiveHelp)
  1818. {
  1819. m_chsOutput += ( ( lpMsgBuf ) ? ( LPTSTR ) lpMsgBuf : lpszMsg ) ;
  1820. }
  1821. DisplayMessage ( ( ( lpMsgBuf ) ? ( LPTSTR ) lpMsgBuf : lpszMsg ), CP_OEMCP, bIsError, FALSE, m_bOutputGoingToStream ) ;
  1822. }
  1823. //
  1824. // must delete here
  1825. //
  1826. SAFEDELETE(lpszMsg);
  1827. // Free the memory used up the error message
  1828. // and then exit
  1829. if ( lpMsgBuf != NULL )
  1830. {
  1831. LocalFree(lpMsgBuf);
  1832. lpMsgBuf = NULL ;
  1833. }
  1834. }
  1835. else
  1836. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  1837. }
  1838. catch(_com_error& e)
  1839. {
  1840. if ( lpMsgBuf != NULL )
  1841. {
  1842. LocalFree(lpMsgBuf);
  1843. lpMsgBuf = NULL ;
  1844. }
  1845. SAFEDELETE(lpszMsg);
  1846. _com_issue_error(e.Error());
  1847. }
  1848. catch(CHeap_Exception)
  1849. {
  1850. if ( lpMsgBuf != NULL )
  1851. {
  1852. LocalFree(lpMsgBuf);
  1853. lpMsgBuf = NULL ;
  1854. }
  1855. SAFEDELETE(lpszMsg);
  1856. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  1857. }
  1858. }
  1859. /*------------------------------------------------------------------------
  1860. Name :DisplayString
  1861. Synopsis :Displays localized string
  1862. Type :Member Function
  1863. Input parameter :
  1864. lszpMsg - string
  1865. bScreen - TRUE - write to screen
  1866. FALSE - write only to log file
  1867. bIsError - TRUE - write to STDERR
  1868. Output parameters :None
  1869. Return Type :void
  1870. Global Variables :None
  1871. Calling Syntax :DisplayString(lpszMsg, bScreen, bIsError)
  1872. Notes :None
  1873. ------------------------------------------------------------------------*/
  1874. void CFormatEngine::DisplayString(LPTSTR lpszMsg, BOOL bScreen, BOOL bIsError)
  1875. {
  1876. HRESULT hr = S_OK;
  1877. try
  1878. {
  1879. if ( m_bGetOutOpt == TRUE )
  1880. {
  1881. // Get the output option to redirect the output.
  1882. m_opsOutputOpt = g_wmiCmd.GetParsedInfoObject().
  1883. GetGlblSwitchesObject().
  1884. GetOutputOrAppendOption(TRUE);
  1885. m_bGetOutOpt = FALSE;
  1886. }
  1887. if ( m_bGetAppendFilePinter == TRUE )
  1888. {
  1889. // FALSE for getting append file pointer.
  1890. m_fpAppendFile = g_wmiCmd.GetParsedInfoObject().
  1891. GetGlblSwitchesObject().
  1892. GetOutputOrAppendFilePointer(FALSE);
  1893. m_bGetAppendFilePinter = FALSE;
  1894. }
  1895. if ( m_bGetOutputFilePinter == TRUE )
  1896. {
  1897. // TRUE for getting append file pointer.
  1898. m_fpOutFile = g_wmiCmd.GetParsedInfoObject().
  1899. GetGlblSwitchesObject().
  1900. GetOutputOrAppendFilePointer(TRUE);
  1901. m_bGetOutputFilePinter = FALSE;
  1902. }
  1903. // If write to screen is TRUE and help flag is not enabled.
  1904. if (bScreen && !m_bHelp)
  1905. {
  1906. if (m_bRecord && m_bLog && !m_bInteractiveHelp)
  1907. {
  1908. hr = m_WmiCliLog.WriteToXMLLog(g_wmiCmd.GetParsedInfoObject(),lpszMsg);
  1909. if (FAILED(hr))
  1910. {
  1911. m_WmiCliLog.StopLogging();
  1912. m_bRecord = FALSE;
  1913. hr = S_OK;
  1914. DisplayString(IDS_E_WRITELOG_FAILED, FALSE, NULL, TRUE);
  1915. }
  1916. m_bLog = FALSE;
  1917. }
  1918. if (m_bInteractiveHelp)
  1919. {
  1920. m_chsOutput += lpszMsg;
  1921. }
  1922. DisplayMessage ( lpszMsg, CP_OEMCP, bIsError, FALSE, m_bOutputGoingToStream ) ;
  1923. }
  1924. else if (m_bHelp)
  1925. {
  1926. LPWSTR wszHelp = NULL ;
  1927. if ( NULL != ( wszHelp = new WCHAR [ lstrlen ( lpszMsg ) + 1 ] ) )
  1928. {
  1929. lstrcpy ( wszHelp, lpszMsg ) ;
  1930. m_cvHelp.push_back ( wszHelp ) ;
  1931. }
  1932. else
  1933. {
  1934. throw OUT_OF_MEMORY;
  1935. }
  1936. }
  1937. }
  1938. catch(_com_error& e)
  1939. {
  1940. _com_issue_error(e.Error());
  1941. }
  1942. catch(CHeap_Exception)
  1943. {
  1944. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  1945. }
  1946. }
  1947. /*------------------------------------------------------------------------
  1948. Name :DisplayPagedHelp
  1949. Synopsis :Displays help in pages
  1950. Type :Member Function
  1951. Input parameter :
  1952. rParsedInfo - reference to CParsedInfo object
  1953. Output parameters :None
  1954. Return Type :void
  1955. Global Variables :None
  1956. Calling Syntax :DisplayPagedHelp(rParsedInfo)
  1957. ------------------------------------------------------------------------*/
  1958. void CFormatEngine::DisplayPagedHelp(CParsedInfo& rParsedInfo)
  1959. {
  1960. CHARVECTOR::iterator itrStart = NULL,
  1961. itrEnd = NULL;
  1962. HANDLE hStdOut = NULL ;
  1963. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  1964. WMICLIINT nHeight = 0;
  1965. WMICLIINT nWidth = 1;
  1966. WMICLIINT nLines = 0;
  1967. _TCHAR cUserKey = 0;
  1968. _TCHAR cCharESC = 0x1B;
  1969. _TCHAR cCharCtrlC = 0x03;
  1970. _bstr_t bstrHelp;
  1971. HRESULT hr = S_OK;
  1972. itrStart = m_cvHelp.begin();
  1973. itrEnd = m_cvHelp.end();
  1974. try
  1975. {
  1976. if (m_bRecord && m_bLog)
  1977. {
  1978. while (itrStart != itrEnd)
  1979. {
  1980. bstrHelp += *itrStart;
  1981. itrStart++;
  1982. }
  1983. hr = m_WmiCliLog.WriteToXMLLog(rParsedInfo, bstrHelp);
  1984. if (FAILED(hr))
  1985. {
  1986. m_WmiCliLog.StopLogging();
  1987. m_bRecord = FALSE;
  1988. hr = S_OK;
  1989. DisplayString(IDS_E_WRITELOG_FAILED, FALSE, NULL, TRUE);
  1990. }
  1991. m_bLog = FALSE;
  1992. itrStart = m_cvHelp.begin();
  1993. }
  1994. if ( m_bGetOutOpt == TRUE )
  1995. {
  1996. // Get the output option to redirect the output.
  1997. m_opsOutputOpt = g_wmiCmd.GetParsedInfoObject().
  1998. GetGlblSwitchesObject().
  1999. GetOutputOrAppendOption(TRUE);
  2000. m_bGetOutOpt = FALSE;
  2001. }
  2002. if ( m_bGetAppendFilePinter == TRUE )
  2003. {
  2004. // FALSE for getting append file pointer.
  2005. m_fpAppendFile = g_wmiCmd.GetParsedInfoObject().
  2006. GetGlblSwitchesObject().
  2007. GetOutputOrAppendFilePointer(FALSE);
  2008. m_bGetAppendFilePinter = FALSE;
  2009. }
  2010. if ( m_bGetOutputFilePinter == TRUE )
  2011. {
  2012. // TRUE for getting append file pointer.
  2013. m_fpOutFile = g_wmiCmd.GetParsedInfoObject().
  2014. GetGlblSwitchesObject().
  2015. GetOutputOrAppendFilePointer(TRUE);
  2016. m_bGetOutputFilePinter = FALSE;
  2017. }
  2018. // Obtain the standard output handle
  2019. hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  2020. while (itrStart != itrEnd)
  2021. {
  2022. if ( STDOUT == m_opsOutputOpt )
  2023. {
  2024. // Get the screen buffer size.
  2025. if ( hStdOut != INVALID_HANDLE_VALUE &&
  2026. GetConsoleScreenBufferInfo ( hStdOut, &csbiInfo ) == TRUE )
  2027. {
  2028. nHeight = (csbiInfo.srWindow.Bottom - csbiInfo.srWindow.Top) - 1;
  2029. nWidth = csbiInfo.dwSize.X;
  2030. }
  2031. else
  2032. {
  2033. nHeight = 0;
  2034. nWidth = 0;
  2035. }
  2036. // if console size is positive (to address redirection)
  2037. if ( nHeight > 0 )
  2038. {
  2039. if (nLines >= nHeight)
  2040. {
  2041. GetConsoleScreenBufferInfo ( hStdOut, &csbiInfo ) ;
  2042. DisplayString(IDS_I_PAKTC, FALSE);
  2043. cUserKey = (_TCHAR)_getch();
  2044. EraseConsoleString(&csbiInfo);
  2045. nLines = 0;
  2046. if ( cUserKey == cCharESC || cUserKey == cCharCtrlC )
  2047. break;
  2048. }
  2049. nLines += ceil(((float) lstrlen(*itrStart) / (float)nWidth ));
  2050. }
  2051. }
  2052. DisplayMessage ( ( *itrStart ) ) ;
  2053. // Move to next entry
  2054. itrStart++;
  2055. }
  2056. DisplayMessage ( L"\r\n" ) ;
  2057. }
  2058. catch(_com_error& e)
  2059. {
  2060. _com_issue_error(e.Error());
  2061. }
  2062. catch(CHeap_Exception)
  2063. {
  2064. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  2065. }
  2066. }
  2067. /*------------------------------------------------------------------------
  2068. Name :DisplayStdVerbsUsage
  2069. Synopsis :Displays all standard verbs available.
  2070. Type :Member Function
  2071. Input Parameter(s):
  2072. bstrBeginStr - string that needs to be appended.
  2073. bClass
  2074. TRUE - indicates class (drop LIST from the help)
  2075. Output Parameter(s):None
  2076. Return Type :void
  2077. Global Variables :None
  2078. Calling Syntax :DisplayStdVerbsUsage(bstrBeginStr, bClass)
  2079. Notes :None
  2080. ------------------------------------------------------------------------*/
  2081. void CFormatEngine::DisplayStdVerbsUsage(_bstr_t bstrBeginStr, BOOL bClass)
  2082. {
  2083. DisplayString(IDS_I_USAGE);
  2084. DisplayString(IDS_I_NEWLINE);
  2085. // Display help for Alias name means standard verb available to this
  2086. // Alias name
  2087. DisplayString(IDS_I_STDVERB_ASSOC, TRUE, (LPTSTR)bstrBeginStr);
  2088. if ( m_bDispCALL == TRUE )
  2089. DisplayString(IDS_I_STDVERB_CALL, TRUE, (LPTSTR)bstrBeginStr);
  2090. DisplayString(IDS_I_STDVERB_CREATE, TRUE, (LPTSTR)bstrBeginStr);
  2091. DisplayString(IDS_I_STDVERB_DELETE, TRUE, (LPTSTR)bstrBeginStr);
  2092. if (!bClass)
  2093. {
  2094. DisplayString(IDS_I_STDVERB_GET, TRUE, (LPTSTR)bstrBeginStr);
  2095. }
  2096. else
  2097. {
  2098. DisplayString(IDS_I_CLASS_STDVERB_GET, TRUE, (LPTSTR)bstrBeginStr);
  2099. }
  2100. if (!bClass)
  2101. {
  2102. if ( m_bDispLIST == TRUE )
  2103. DisplayString(IDS_I_STDVERB_LIST, TRUE, (LPTSTR)bstrBeginStr);
  2104. }
  2105. if ( m_bDispSET == TRUE )
  2106. DisplayString(IDS_I_STDVERB_SET, TRUE, (LPTSTR)bstrBeginStr);
  2107. }
  2108. /*------------------------------------------------------------------------
  2109. Name :DisplayTRANSLATEHelp
  2110. Synopsis :Displays help for TRANSLATE switch
  2111. Type :Member Function
  2112. Input parameter :
  2113. rParsedInfo - reference to CParsedInfo class object
  2114. Output parameters :None
  2115. Return Type :void
  2116. Global Variables :None
  2117. Calling Syntax :DisplayTRANSLATEHelp(rParsedInfo)
  2118. Notes :None
  2119. ------------------------------------------------------------------------*/
  2120. void CFormatEngine::DisplayTRANSLATEHelp(CParsedInfo& rParsedInfo)
  2121. {
  2122. DisplayString(IDS_I_NEWLINE);
  2123. DisplayString(IDS_I_SWITCH_TRANSLATE_FULL_DESC);
  2124. DisplayString(IDS_I_USAGE);
  2125. DisplayString(IDS_I_NEWLINE);
  2126. DisplayString(IDS_I_SWITCH_TRANSLATE_USAGE);
  2127. CHARVECTOR cvTables = rParsedInfo.
  2128. GetCmdSwitchesObject().GetTrnsTablesList();
  2129. if ( !cvTables.empty() )
  2130. {
  2131. CHARVECTOR::iterator theIterator;
  2132. DisplayString(IDS_I_NEWLINE);
  2133. DisplayString(IDS_I_TRANSLATE_HEAD);
  2134. for ( theIterator = cvTables.begin();
  2135. theIterator != cvTables.end(); theIterator++ )
  2136. {
  2137. DisplayString(IDS_I_NEWLINE);
  2138. DisplayString(*theIterator);
  2139. }
  2140. DisplayString(IDS_I_NEWLINE);
  2141. }
  2142. else
  2143. {
  2144. DisplayString(IDS_I_NEWLINE);
  2145. DisplayString(IDS_I_TRANSLATE_NOTABLES);
  2146. }
  2147. }
  2148. /*------------------------------------------------------------------------
  2149. Name :DisplayEVERYHelp
  2150. Synopsis :Displays help for EVERY switch
  2151. Type :Member Function
  2152. Input parameter :
  2153. rParsedInfo - reference to CParsedInfo class object
  2154. Output parameters :None
  2155. Return Type :void
  2156. Global Variables :None
  2157. Calling Syntax :DisplayTRANSLATEHelp(rParsedInfo)
  2158. Notes :None
  2159. ------------------------------------------------------------------------*/
  2160. void CFormatEngine::DisplayEVERYHelp(CParsedInfo& rParsedInfo)
  2161. {
  2162. DisplayString(IDS_I_NEWLINE);
  2163. DisplayString(IDS_I_SWITCH_EVERY_DESC_FULL);
  2164. DisplayString(IDS_I_USAGE);
  2165. DisplayString(IDS_I_NEWLINE);
  2166. DisplayString(IDS_I_SWITCH_EVERY_USAGE);
  2167. DisplayString(IDS_I_EVERY_NOTE);
  2168. }
  2169. /*------------------------------------------------------------------------
  2170. Name :DisplayREPEATHelp
  2171. Synopsis :Displays help for REPEAT switch
  2172. Type :Member Function
  2173. Input parameter :None
  2174. Output parameters :None
  2175. Return Type :void
  2176. Global Variables :None
  2177. Calling Syntax :DisplayREPEATHelp()
  2178. Notes :None
  2179. ------------------------------------------------------------------------*/
  2180. void CFormatEngine::DisplayREPEATHelp()
  2181. {
  2182. DisplayString(IDS_I_NEWLINE);
  2183. DisplayString(IDS_I_SWITCH_REPEAT_DESC_FULL);
  2184. DisplayString(IDS_I_USAGE);
  2185. DisplayString(IDS_I_NEWLINE);
  2186. DisplayString(IDS_I_SWITCH_REPEAT_USAGE);
  2187. DisplayString(IDS_I_REPEAT_NOTE);
  2188. }
  2189. /*------------------------------------------------------------------------
  2190. Name :DisplayFORMATHelp
  2191. Synopsis :Displays help for FORMAT switch
  2192. Type :Member Function
  2193. Input parameter :
  2194. rParsedInfo - reference to CParsedInfo class object
  2195. Output parameters :None
  2196. Return Type :void
  2197. Global Variables :None
  2198. Calling Syntax :DisplayTRANSLATEHelp(rParsedInfo)
  2199. Notes :None
  2200. ------------------------------------------------------------------------*/
  2201. void CFormatEngine::DisplayFORMATHelp(CParsedInfo& rParsedInfo)
  2202. {
  2203. DisplayString(IDS_I_NEWLINE);
  2204. DisplayString(IDS_I_SWITCH_FORMAT_DESC_FULL);
  2205. DisplayString(IDS_I_USAGE);
  2206. DisplayString(IDS_I_NEWLINE);
  2207. DisplayString(IDS_I_SWITCH_FORMAT_USAGE);
  2208. DisplayString(IDS_I_FORMAT_NOTE);
  2209. DisplayString(IDS_I_NEWLINE);
  2210. //
  2211. // I need to get mappings from stl map
  2212. // I need to add this into help so it shows up
  2213. //
  2214. // DisplayString(IDS_I_FORMAT_KEYWORDS);
  2215. // DisplayString(IDS_I_NEWLINE);
  2216. // DisplayString(IDS_I_NEWLINE);
  2217. //
  2218. // DisplayString(keyword, FALSE);
  2219. //
  2220. // will do for all pairs from WmiCmdLn::m_bmKeyWordtoFileName
  2221. //
  2222. const BSTRMAP* pMap = g_wmiCmd.GetMappingsMap();
  2223. BSTRMAP::iterator theMapIterator = NULL;
  2224. if ( pMap->size() )
  2225. {
  2226. DisplayString(IDS_I_FORMAT_KEYWORDS);
  2227. DisplayString(IDS_I_NEWLINE);
  2228. DisplayString(IDS_I_NEWLINE);
  2229. }
  2230. for ( theMapIterator = pMap->begin(); theMapIterator != pMap->end(); theMapIterator++ )
  2231. {
  2232. DisplayString((*theMapIterator).first, FALSE);
  2233. DisplayString(IDS_I_NEWLINE);
  2234. }
  2235. }
  2236. /*------------------------------------------------------------------------
  2237. Name :DisplayVERBSWITCHESHelp
  2238. Synopsis :Displays help on <verb switches>
  2239. Type :Member Function
  2240. Input parameter :
  2241. rParsedInfo - reference to CParsedInfo class object
  2242. Output parameters :None
  2243. Return Type :void
  2244. Global Variables :None
  2245. Calling Syntax :DisplayVERBSWITCHESHelp(rParsedInfo)
  2246. Notes :None
  2247. ------------------------------------------------------------------------*/
  2248. void CFormatEngine::DisplayVERBSWITCHESHelp(CParsedInfo& rParsedInfo)
  2249. {
  2250. _TCHAR *pszVerbName = rParsedInfo.GetCmdSwitchesObject().GetVerbName();
  2251. BOOL bInstanceHelp = TRUE;
  2252. if(CompareTokens(pszVerbName, CLI_TOKEN_DELETE))
  2253. {
  2254. if(rParsedInfo.GetCmdSwitchesObject().
  2255. GetInteractiveMode() != INTERACTIVE)
  2256. {
  2257. DisplayDELETEUsage(rParsedInfo);
  2258. }
  2259. }
  2260. DisplayString(IDS_I_NEWLINE);
  2261. DisplayString(IDS_I_USAGE);
  2262. if(CompareTokens(pszVerbName, CLI_TOKEN_CALL)
  2263. || CompareTokens(pszVerbName, CLI_TOKEN_SET)
  2264. || CompareTokens(pszVerbName, CLI_TOKEN_DELETE))
  2265. {
  2266. if(IsClassOperation(rParsedInfo))
  2267. {
  2268. bInstanceHelp = FALSE;
  2269. }
  2270. else
  2271. {
  2272. if(CompareTokens(pszVerbName, CLI_TOKEN_CALL))
  2273. {
  2274. if ( rParsedInfo.GetCmdSwitchesObject().
  2275. GetAliasName() != NULL )
  2276. {
  2277. if (rParsedInfo.GetCmdSwitchesObject().
  2278. GetWhereExpression() == NULL)
  2279. {
  2280. bInstanceHelp = FALSE;
  2281. }
  2282. else
  2283. {
  2284. bInstanceHelp = TRUE;
  2285. }
  2286. }
  2287. else
  2288. {
  2289. if ((rParsedInfo.GetCmdSwitchesObject().
  2290. GetPathExpression() != NULL)
  2291. && (rParsedInfo.GetCmdSwitchesObject().
  2292. GetWhereExpression() == NULL))
  2293. {
  2294. bInstanceHelp = FALSE;
  2295. }
  2296. else
  2297. {
  2298. bInstanceHelp = TRUE;
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. bInstanceHelp = TRUE;
  2305. }
  2306. }
  2307. }
  2308. else
  2309. {
  2310. bInstanceHelp = FALSE;
  2311. }
  2312. if(bInstanceHelp)
  2313. {
  2314. DisplayString(IDS_I_VERB_INTERACTIVE_DESC1);
  2315. DisplayString(IDS_I_VERB_INTERACTIVE_DESC2);
  2316. DisplayString(IDS_I_NEWLINE);
  2317. DisplayString(IDS_I_PROPERTYLIST_NOTE1);
  2318. }
  2319. else
  2320. {
  2321. DisplayString(IDS_I_VERB_SWITCH_INTERACTIVE_DESC);
  2322. }
  2323. if(rParsedInfo.GetCmdSwitchesObject().GetInteractiveMode() != INTERACTIVE)
  2324. {
  2325. DisplayString(IDS_I_VERB_SWITCH_NOINTERACTIVE_DESC);
  2326. }
  2327. }
  2328. /*------------------------------------------------------------------------
  2329. Name :DisplayCOMError
  2330. Synopsis :Displays the formatted COM error
  2331. Type :Member Function
  2332. Input parameter :
  2333. rParsedInfo - reference to CParsedInfo class object
  2334. Output parameters :None
  2335. Return Type :void
  2336. Global Variables :None
  2337. Calling Syntax :DisplayCOMError(rParsedInfo)
  2338. Notes :None
  2339. ------------------------------------------------------------------------*/
  2340. void CFormatEngine::DisplayCOMError(CParsedInfo& rParsedInfo)
  2341. {
  2342. _com_error* pComError = NULL;
  2343. _TCHAR szBuffer[BUFFER32] = NULL_STRING;
  2344. _bstr_t bstrErr, bstrFacility, bstrMsg;
  2345. // Get the TRACE status and store it in m_bTrace
  2346. m_bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  2347. // Get the Logging mode (VERBOSE | ERRORONLY | NOLOGGING) and store
  2348. // it in m_eloErrLogOpt
  2349. m_eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  2350. try
  2351. {
  2352. //Getting the _com_error data.
  2353. pComError = rParsedInfo.GetCmdSwitchesObject().GetCOMError();
  2354. m_ErrInfo.GetErrorString(pComError->Error(), m_bTrace,
  2355. bstrErr, bstrFacility);
  2356. //Printing the _com_error into a string for displaying it
  2357. if (m_bTrace || m_eloErrLogOpt)
  2358. {
  2359. _stprintf(szBuffer, _T("0x%x"), pComError->Error());
  2360. WMIFormatMessage(IDS_I_ERROR_MSG, 3, bstrMsg, szBuffer,
  2361. (LPWSTR) bstrErr, (LPWSTR)bstrFacility);
  2362. }
  2363. else
  2364. {
  2365. WMIFormatMessage(IDS_I_ERROR_MSG_NOTRACE, 1, bstrMsg,
  2366. (LPWSTR)bstrErr);
  2367. }
  2368. DisplayMessage((LPWSTR) bstrMsg, CP_OEMCP, TRUE, FALSE);
  2369. }
  2370. catch(_com_error& e)
  2371. {
  2372. _com_issue_error(e.Error());
  2373. }
  2374. }
  2375. /*------------------------------------------------------------------------
  2376. Name :DisplayGlobalSwitchesBrief
  2377. Synopsis :Display help for global switches in brief
  2378. Type :Member Function
  2379. Input parameter :None
  2380. Output parameters :None
  2381. Return Type :void
  2382. Global Variables :None
  2383. Calling Syntax :DisplayGlobalSwitchesBrief()
  2384. Notes :None
  2385. ------------------------------------------------------------------------*/
  2386. void CFormatEngine::DisplayGlobalSwitchesBrief()
  2387. {
  2388. DisplayString(IDS_I_NAMESPACE_BRIEF);
  2389. DisplayString(IDS_I_ROLE_BRIEF);
  2390. DisplayString(IDS_I_NODE_BRIEF);
  2391. DisplayString(IDS_I_IMPLEVEL_BRIEF);
  2392. DisplayString(IDS_I_AUTHLEVEL_BRIEF);
  2393. DisplayString(IDS_I_LOCALE_BRIEF);
  2394. DisplayString(IDS_I_PRIVILEGES_BRIEF);
  2395. DisplayString(IDS_I_TRACE_BRIEF);
  2396. DisplayString(IDS_I_RECORD_BRIEF);
  2397. DisplayString(IDS_I_INTERACTIVE_BRIEF);
  2398. DisplayString(IDS_I_FAILFAST_BRIEF);
  2399. DisplayString(IDS_I_USER_BRIEF);
  2400. DisplayString(IDS_I_PASSWORD_BRIEF);
  2401. DisplayString(IDS_I_OUTPUT_BRIEF);
  2402. DisplayString(IDS_I_APPEND_BRIEF);
  2403. DisplayString(IDS_I_AGGREGATE_BRIEF);
  2404. DisplayString(IDS_I_AUTHORITY_BRIEF);
  2405. DisplayString(IDS_I_HELPBRIEF);
  2406. DisplayString(IDS_I_NEWLINE);
  2407. DisplayString(IDS_I_GLBL_MORE);
  2408. }
  2409. /*------------------------------------------------------------------------
  2410. Name :DisplayContext
  2411. Synopsis :Displays the environment variables (i.e global
  2412. switches)
  2413. Type :Member Function
  2414. Input parameter :
  2415. rParsedInfo - reference to rParsedInfo object
  2416. Output parameters :None
  2417. Return Type :None
  2418. Global Variables :None
  2419. Calling Syntax :DisplayContext(rParsedInfo)
  2420. Notes :None
  2421. ------------------------------------------------------------------------*/
  2422. void CFormatEngine::DisplayContext(CParsedInfo& rParsedInfo)
  2423. {
  2424. _bstr_t bstrTemp;
  2425. // NAMESPACE
  2426. DisplayString(IDS_I_NAMESPACE_VALUE, TRUE,
  2427. rParsedInfo.GetGlblSwitchesObject().GetNameSpace());
  2428. // ROLE
  2429. DisplayString(IDS_I_ROLE_VALUE, TRUE,
  2430. rParsedInfo.GetGlblSwitchesObject().GetRole());
  2431. // NODE(S)
  2432. rParsedInfo.GetGlblSwitchesObject().GetNodeString(bstrTemp);
  2433. DisplayString(IDS_I_NODELIST_VALUE, TRUE, (LPWSTR)bstrTemp);
  2434. // IMPLEVEL
  2435. rParsedInfo.GetGlblSwitchesObject().GetImpLevelTextDesc(bstrTemp);
  2436. DisplayString(IDS_I_IMPLEVEL_VALUE, TRUE, (LPWSTR)bstrTemp);
  2437. // AUTHORITY
  2438. rParsedInfo.GetAuthorityDesc(bstrTemp);
  2439. DisplayString(IDS_I_AUTHORITY_VALUE, TRUE, (LPWSTR)bstrTemp);
  2440. // AUTHLEVEL
  2441. rParsedInfo.GetGlblSwitchesObject().GetAuthLevelTextDesc(bstrTemp);
  2442. DisplayString(IDS_I_AUTHLEVEL_VALUE, TRUE, (LPWSTR)bstrTemp);
  2443. // LOCALE
  2444. DisplayString(IDS_I_LOCALE_VALUE, TRUE,
  2445. rParsedInfo.GetGlblSwitchesObject().GetLocale());
  2446. // PRIVILEGES
  2447. rParsedInfo.GetGlblSwitchesObject().GetPrivilegesTextDesc(bstrTemp);
  2448. DisplayString(IDS_I_PRIVILEGES_VALUE, TRUE, (LPWSTR)bstrTemp);
  2449. // TRACE
  2450. rParsedInfo.GetGlblSwitchesObject().GetTraceTextDesc(bstrTemp);
  2451. DisplayString(IDS_I_TRACE_VALUE, TRUE, (LPWSTR)bstrTemp);
  2452. // RECORDPATH
  2453. rParsedInfo.GetGlblSwitchesObject().GetRecordPathDesc(bstrTemp);
  2454. DisplayString(IDS_I_RECORDPATH_VALUE, TRUE, (LPWSTR)bstrTemp);
  2455. // INTERACTIVE
  2456. rParsedInfo.GetGlblSwitchesObject().GetInteractiveTextDesc(bstrTemp);
  2457. DisplayString(IDS_I_INTERACTIVE_VALUE, TRUE, (LPWSTR)bstrTemp);
  2458. // FAILFAST
  2459. rParsedInfo.GetGlblSwitchesObject().GetFailFastTextDesc(bstrTemp);
  2460. DisplayString(IDS_I_FAILFAST_VALUE, TRUE, (LPWSTR)bstrTemp);
  2461. // TRUE for OUTPUT option.
  2462. rParsedInfo.GetGlblSwitchesObject().GetOutputOrAppendTextDesc(bstrTemp,
  2463. TRUE);
  2464. DisplayString(IDS_I_OUTPUT_VALUE, TRUE, (LPWSTR)bstrTemp);
  2465. // FALSE for APPEND option.
  2466. rParsedInfo.GetGlblSwitchesObject().GetOutputOrAppendTextDesc(bstrTemp,
  2467. FALSE);
  2468. DisplayString(IDS_I_APPEND_VALUE, TRUE, (LPWSTR)bstrTemp);
  2469. // USER
  2470. rParsedInfo.GetUserDesc(bstrTemp);
  2471. DisplayString(IDS_I_USER_VALUE, TRUE, (LPWSTR)bstrTemp);
  2472. //AGGREGATE
  2473. if(rParsedInfo.GetGlblSwitchesObject().GetAggregateFlag())
  2474. DisplayString(IDS_I_AGGREGATE_VALUE, TRUE, CLI_TOKEN_ON);
  2475. else
  2476. DisplayString(IDS_I_AGGREGATE_VALUE, TRUE, CLI_TOKEN_OFF);
  2477. }
  2478. /*------------------------------------------------------------------------
  2479. Name :DisplayContextHelp
  2480. Synopsis :Displays the help on CONTEXT keyword
  2481. Type :Member Function
  2482. Input parameter :None
  2483. Output parameters :None
  2484. Return Type :None
  2485. Global Variables :None
  2486. Calling Syntax :DisplayContextHelp()
  2487. Notes :None
  2488. ------------------------------------------------------------------------*/
  2489. void CFormatEngine::DisplayContextHelp()
  2490. {
  2491. DisplayString(IDS_I_NEWLINE);
  2492. DisplayString(IDS_I_CONTEXT_DESC);
  2493. DisplayString(IDS_I_USAGE);
  2494. DisplayString(IDS_I_NEWLINE);
  2495. DisplayString(IDS_I_CONTEXT_USAGE);
  2496. }
  2497. /*------------------------------------------------------------------------
  2498. Name :ApplyTranslateTable
  2499. Synopsis :Processes the translation specified in translate table.
  2500. Type :Member Function
  2501. Input parameter :
  2502. rParsedInfo - CParsedInfo object, input information.
  2503. Output parameters :
  2504. strString - STRING type, string to be translated.
  2505. Return Type :void
  2506. Global Variables :None
  2507. Calling Syntax :ApplyTranslateTable(strOutput, rParsedInfo)
  2508. Notes :None
  2509. ------------------------------------------------------------------------*/
  2510. void CFormatEngine::ApplyTranslateTable(STRING& strString,
  2511. CParsedInfo& rParsedInfo)
  2512. {
  2513. BSTRMAP bmTransTbl = rParsedInfo.GetCmdSwitchesObject().
  2514. GetAlsFrnNmsOrTrnsTblMap();
  2515. BSTRMAP::iterator iTransTblEntry;
  2516. for( iTransTblEntry = bmTransTbl.begin();
  2517. iTransTblEntry != bmTransTbl.end();iTransTblEntry++ )
  2518. {
  2519. _TCHAR cValue1, cValue2, cTemp;
  2520. if ( IsValueSet((*iTransTblEntry).first, cValue1, cValue2) )
  2521. {
  2522. for ( cTemp = cValue1; cTemp <= cValue2 ; cTemp++)
  2523. {
  2524. _TCHAR szTemp[2];
  2525. szTemp[0] = cTemp;
  2526. szTemp[1] = _T('\0');
  2527. FindAndReplaceAll(strString, szTemp,
  2528. (*iTransTblEntry).second);
  2529. }
  2530. }
  2531. else
  2532. {
  2533. FindAndReplaceAll(strString, (*iTransTblEntry).first,
  2534. (*iTransTblEntry).second);
  2535. }
  2536. }
  2537. }
  2538. /*------------------------------------------------------------------------
  2539. Name :DisplayInvalidProperties
  2540. Synopsis :Displays the list of invalid properties
  2541. Type :Member Function
  2542. Input parameter :
  2543. rParsedInfo - CParsedInfo object, input information.
  2544. bSetVerb - SET verb
  2545. Output parameters :None
  2546. Return Type :void
  2547. Global Variables :None
  2548. Calling Syntax :DisplayInvalidProperties(rParsedInfo, bSetVerb)
  2549. Notes :None
  2550. ------------------------------------------------------------------------*/
  2551. void CFormatEngine::DisplayInvalidProperties(CParsedInfo& rParsedInfo,
  2552. BOOL bSetVerb)
  2553. {
  2554. CHARVECTOR::iterator cvIterator = NULL;
  2555. LONG lCount = 0;
  2556. _bstr_t bstrMsg;
  2557. try
  2558. {
  2559. // Get the list of properties.
  2560. CHARVECTOR cvPropertyList = rParsedInfo.GetCmdSwitchesObject().
  2561. GetPropertyList();
  2562. // Get the property details pooled up from alias definition
  2563. PROPDETMAP pdmPropDetMap = rParsedInfo.GetCmdSwitchesObject().
  2564. GetPropDetMap();
  2565. if (cvPropertyList.size() != pdmPropDetMap.size() &&
  2566. cvPropertyList.size() != 0)
  2567. {
  2568. for ( cvIterator = cvPropertyList.begin();
  2569. cvIterator != cvPropertyList.end();
  2570. cvIterator++ )
  2571. {
  2572. PROPDETMAP::iterator tempIterator = NULL;
  2573. if ( !Find(pdmPropDetMap, *cvIterator, tempIterator) )
  2574. {
  2575. if ( lCount == 0)
  2576. {
  2577. bstrMsg += _bstr_t(*cvIterator);
  2578. }
  2579. else
  2580. {
  2581. bstrMsg += _bstr_t(L", ") + _bstr_t(*cvIterator);
  2582. }
  2583. lCount++;
  2584. }
  2585. }
  2586. DisplayString(IDS_I_NEWLINE);
  2587. if (bSetVerb)
  2588. DisplayString(IDS_I_INVALID_NOWRITE_PROS,
  2589. TRUE, (LPWSTR)bstrMsg);
  2590. else
  2591. DisplayString(IDS_I_INVALID_PROS, TRUE, (LPWSTR)bstrMsg);
  2592. }
  2593. }
  2594. catch(_com_error& e)
  2595. {
  2596. _com_issue_error(e.Error());
  2597. }
  2598. }
  2599. /*------------------------------------------------------------------------
  2600. Name :DisplayLargeString
  2601. Synopsis :Displays the large string line by line. And respond
  2602. to Ctr+C event.
  2603. Type :Member Function
  2604. Input parameter(s):
  2605. rParsedInfo - CParsedInfo object, input information.
  2606. strLargeString - reference to STRING object.
  2607. Output parameter(s):None
  2608. Return Type :void
  2609. Global Variables :None
  2610. Calling Syntax :DisplayLargeString(rParsedInfo, stroutput)
  2611. Notes :None
  2612. ------------------------------------------------------------------------*/
  2613. void CFormatEngine::DisplayLargeString(CParsedInfo& rParsedInfo,
  2614. STRING& strLargeString)
  2615. {
  2616. size_t nLineStart = 0;
  2617. size_t nLineEnd = 0;
  2618. while ( TRUE )
  2619. {
  2620. if ( g_wmiCmd.GetBreakEvent() == TRUE )
  2621. {
  2622. DisplayString(IDS_I_NEWLINE);
  2623. break;
  2624. }
  2625. nLineEnd = strLargeString.find(_T("\n"), nLineStart);
  2626. if ( nLineEnd == STRING::npos )
  2627. {
  2628. //
  2629. // string may not be terminated by \n
  2630. // check for NULL terminator
  2631. //
  2632. nLineEnd = strLargeString.find(_T("\0"), nLineStart);
  2633. }
  2634. if ( nLineEnd != STRING::npos )
  2635. {
  2636. DisplayString( (LPTSTR) strLargeString.substr ( nLineStart, ( nLineEnd - nLineStart + 1 ) ).data() ) ;
  2637. nLineStart = nLineEnd + 1;
  2638. }
  2639. else
  2640. {
  2641. DisplayString(IDS_I_NEWLINE);
  2642. break;
  2643. }
  2644. }
  2645. }
  2646. /*------------------------------------------------------------------------
  2647. Name :TraverseNode
  2648. Synopsis :Travese through XML stream node by node and translate
  2649. all nodes
  2650. Type :Member Function
  2651. Input parameter :
  2652. rParsedInfo - CParsedInfo object, input information.
  2653. Output parameters :None
  2654. Return Type :BOOL
  2655. Global Variables :None
  2656. Calling Syntax :TraverseNode(rParsedInfo)
  2657. Notes :None
  2658. ------------------------------------------------------------------------*/
  2659. BOOL CFormatEngine::TraverseNode(CParsedInfo& rParsedInfo)
  2660. {
  2661. HRESULT hr = S_OK;
  2662. IXMLDOMElement *pIXMLDOMElement = NULL;
  2663. IXMLDOMNodeList *pIDOMNodeList = NULL;
  2664. IXMLDOMNode *pIDOMNode = NULL;
  2665. IXMLDOMNode *pIParentNode = NULL;
  2666. IXMLDOMNode *pINewNode = NULL;
  2667. LONG lValue = 0;
  2668. BSTR bstrItemText = NULL;
  2669. BOOL bRet = TRUE;
  2670. DWORD dwThreadId = GetCurrentThreadId();
  2671. try
  2672. {
  2673. if(m_pIXMLDoc != NULL)
  2674. {
  2675. _bstr_t bstrTemp = rParsedInfo.GetCmdSwitchesObject().
  2676. GetXMLResultSet();
  2677. // Load the XML stream
  2678. VARIANT_BOOL varBool;
  2679. hr = m_pIXMLDoc->loadXML(bstrTemp, &varBool);
  2680. if (m_bTrace || m_eloErrLogOpt)
  2681. {
  2682. WMITRACEORERRORLOG(hr, __LINE__,
  2683. __FILE__, _T("IXMLDOMDocument::loadXML(-, -)"),
  2684. dwThreadId, rParsedInfo, m_bTrace);
  2685. }
  2686. ONFAILTHROWERROR(hr);
  2687. if(varBool == VARIANT_TRUE)
  2688. {
  2689. // Get the document element.
  2690. hr = m_pIXMLDoc->get_documentElement(&pIXMLDOMElement);
  2691. if (m_bTrace || m_eloErrLogOpt)
  2692. {
  2693. WMITRACEORERRORLOG(hr, __LINE__,
  2694. __FILE__, _T("IXMLDOMDocument::get_documentElement(-)"),
  2695. dwThreadId, rParsedInfo, m_bTrace);
  2696. }
  2697. ONFAILTHROWERROR(hr);
  2698. if (pIXMLDOMElement != NULL)
  2699. {
  2700. // Get the Node List named <VALUE> in the current XML doc
  2701. hr = pIXMLDOMElement->getElementsByTagName
  2702. (_bstr_t(L"VALUE"), &pIDOMNodeList);
  2703. if (m_bTrace || m_eloErrLogOpt)
  2704. {
  2705. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2706. _T("IXMLDOMElement::getElementsByTagName"
  2707. L"(L\"VALUE\", -)"), dwThreadId, rParsedInfo,
  2708. m_bTrace);
  2709. }
  2710. ONFAILTHROWERROR(hr);
  2711. // Get the length of the node list
  2712. hr = pIDOMNodeList->get_length(&lValue);
  2713. if (m_bTrace || m_eloErrLogOpt)
  2714. {
  2715. WMITRACEORERRORLOG(hr, __LINE__,
  2716. __FILE__, _T("IXMLDOMNodeList::get_length(-)"),
  2717. dwThreadId, rParsedInfo, m_bTrace);
  2718. }
  2719. ONFAILTHROWERROR(hr);
  2720. // Traverse through full node list and apply
  2721. // translate table on each node
  2722. for(WMICLIINT ii = 0; ii < lValue; ii++)
  2723. {
  2724. // Get a node from node list
  2725. hr = pIDOMNodeList->get_item(ii, &pIDOMNode);
  2726. if (m_bTrace || m_eloErrLogOpt)
  2727. {
  2728. WMITRACEORERRORLOG(hr, __LINE__,
  2729. __FILE__, _T("IXMLDOMNodeList::get_item(-,-)"),
  2730. dwThreadId, rParsedInfo, m_bTrace);
  2731. }
  2732. ONFAILTHROWERROR(hr);
  2733. if (pIDOMNode == NULL)
  2734. continue;
  2735. // Get the value stored in the node
  2736. hr = pIDOMNode->get_text(&bstrItemText);
  2737. if (m_bTrace || m_eloErrLogOpt)
  2738. {
  2739. WMITRACEORERRORLOG(hr, __LINE__,
  2740. __FILE__, _T("IXMLDOMNode::get_text(-)"),
  2741. dwThreadId, rParsedInfo, m_bTrace);
  2742. }
  2743. ONFAILTHROWERROR(hr);
  2744. // Get the parent node of the current node to store
  2745. // the translated value in the current node
  2746. hr = pIDOMNode->get_parentNode(&pIParentNode);
  2747. if (m_bTrace || m_eloErrLogOpt)
  2748. {
  2749. WMITRACEORERRORLOG(hr, __LINE__,
  2750. __FILE__, _T("IXMLDOMNode::get_parentNode(-)"),
  2751. dwThreadId, rParsedInfo, m_bTrace);
  2752. }
  2753. ONFAILTHROWERROR(hr);
  2754. // Create a clone node of current node
  2755. VARIANT_BOOL vBool = VARIANT_FALSE;
  2756. hr = pIDOMNode->cloneNode(vBool, &pINewNode);
  2757. if (m_bTrace || m_eloErrLogOpt)
  2758. {
  2759. WMITRACEORERRORLOG(hr, __LINE__,
  2760. __FILE__, _T("IXMLDOMNode::cloneNode(-,-)"),
  2761. dwThreadId, rParsedInfo, m_bTrace);
  2762. }
  2763. ONFAILTHROWERROR(hr);
  2764. if (pINewNode != NULL && pIParentNode != NULL)
  2765. {
  2766. // If /TRANSLATE:<table> is specified.
  2767. STRING strOutput((_TCHAR*)bstrItemText);
  2768. if ( rParsedInfo.GetCmdSwitchesObject().
  2769. GetTranslateTableName() != NULL )
  2770. {
  2771. // Translate the result
  2772. ApplyTranslateTable(strOutput, rParsedInfo);
  2773. }
  2774. // Reconvert the char string into BSTR string
  2775. _bstr_t bstrTemp =
  2776. _bstr_t((LPTSTR)strOutput.data());
  2777. // Write the translated value into new node
  2778. hr = pINewNode->put_text(bstrTemp);
  2779. if (m_bTrace || m_eloErrLogOpt)
  2780. {
  2781. WMITRACEORERRORLOG(hr, __LINE__,
  2782. __FILE__, _T("IXMLDOMNode::put_text(-)"),
  2783. dwThreadId, rParsedInfo, m_bTrace);
  2784. }
  2785. ONFAILTHROWERROR(hr);
  2786. // Replace current node with translated node
  2787. hr = pIParentNode->replaceChild(pINewNode,
  2788. pIDOMNode, NULL);
  2789. if (m_bTrace || m_eloErrLogOpt)
  2790. {
  2791. WMITRACEORERRORLOG(hr, __LINE__,
  2792. __FILE__,
  2793. _T("IXMLDOMNode::replaceChild(-,-,-)"),
  2794. dwThreadId, rParsedInfo, m_bTrace);
  2795. }
  2796. ONFAILTHROWERROR(hr);
  2797. }
  2798. SAFEBSTRFREE(bstrItemText);
  2799. bstrItemText = NULL;
  2800. SAFEIRELEASE(pINewNode);
  2801. SAFEIRELEASE(pIParentNode);
  2802. SAFEIRELEASE(pIDOMNode);
  2803. }
  2804. SAFEIRELEASE(pIDOMNodeList);
  2805. SAFEIRELEASE(pIXMLDOMElement);
  2806. bRet = TRUE;
  2807. }
  2808. }
  2809. else
  2810. bRet = FALSE;
  2811. }
  2812. else
  2813. bRet = FALSE;
  2814. }
  2815. catch(_com_error& e)
  2816. {
  2817. SAFEIRELEASE(pIParentNode);
  2818. SAFEIRELEASE(pINewNode);
  2819. SAFEIRELEASE(pIDOMNode);
  2820. SAFEIRELEASE(pIDOMNodeList);
  2821. SAFEIRELEASE(pIXMLDOMElement);
  2822. SAFEBSTRFREE(bstrItemText);
  2823. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2824. bRet = FALSE;
  2825. }
  2826. return bRet;
  2827. }
  2828. /*------------------------------------------------------------------------
  2829. Name :DisplayRESULTCLASSHelp
  2830. Synopsis :Displays help for RESULT CLASS switch
  2831. Type :Member Function
  2832. Input parameter :None
  2833. Output parameters :None
  2834. Return Type :void
  2835. Global Variables :None
  2836. Calling Syntax :DisplayRESULTCLASSHelp()
  2837. Notes :None
  2838. ------------------------------------------------------------------------*/
  2839. void CFormatEngine::DisplayRESULTCLASSHelp()
  2840. {
  2841. DisplayString(IDS_I_NEWLINE);
  2842. DisplayString(IDS_I_SWITCH_RESULTCLASS_DESC_FULL);
  2843. DisplayString(IDS_I_USAGE);
  2844. DisplayString(IDS_I_NEWLINE);
  2845. DisplayString(IDS_I_SWITCH_RESULTCLASS_USAGE);
  2846. }
  2847. /*------------------------------------------------------------------------
  2848. Name :DisplayRESULTROLEHelp
  2849. Synopsis :Displays help for RESULT ROLE switch
  2850. Type :Member Function
  2851. Input parameter :None
  2852. Output parameters :None
  2853. Return Type :void
  2854. Global Variables :None
  2855. Calling Syntax :DisplayRESULTROLEHelp()
  2856. Notes :None
  2857. ------------------------------------------------------------------------*/
  2858. void CFormatEngine::DisplayRESULTROLEHelp()
  2859. {
  2860. DisplayString(IDS_I_NEWLINE);
  2861. DisplayString(IDS_I_SWITCH_RESULTROLE_DESC_FULL );
  2862. DisplayString(IDS_I_USAGE);
  2863. DisplayString(IDS_I_NEWLINE);
  2864. DisplayString(IDS_I_SWITCH_RESULTROLE_USAGE);
  2865. }
  2866. /*------------------------------------------------------------------------
  2867. Name :DisplayASSOCCLASSHelp
  2868. Synopsis :Displays help for ASSOCCLASS switch
  2869. Type :Member Function
  2870. Input parameter :None
  2871. Output parameters :None
  2872. Return Type :void
  2873. Global Variables :None
  2874. Calling Syntax :DisplayASSOCCLASSHelp()
  2875. Notes :None
  2876. ------------------------------------------------------------------------*/
  2877. void CFormatEngine::DisplayASSOCCLASSHelp()
  2878. {
  2879. DisplayString(IDS_I_NEWLINE);
  2880. DisplayString(IDS_I_SWITCH_ASSOCCLASS_DESC_FULL);
  2881. DisplayString(IDS_I_USAGE);
  2882. DisplayString(IDS_I_NEWLINE);
  2883. DisplayString(IDS_I_SWITCH_ASSOCCLASS_USAGE);
  2884. }
  2885. /*------------------------------------------------------------------------
  2886. Name :AppendtoOutputString
  2887. Synopsis :Appends the content currently being displayed, to the
  2888. m_chsOutput which will be used for XML logging
  2889. Type :Member Function
  2890. Input parameter :
  2891. pszOutput - output string
  2892. Output parameters :None
  2893. Return Type :void
  2894. Global Variables :None
  2895. Calling Syntax :AppendtoOutputString(pszOutput)
  2896. Notes :None
  2897. ------------------------------------------------------------------------*/
  2898. void CFormatEngine::AppendtoOutputString(_TCHAR* pszOutput)
  2899. {
  2900. m_chsOutput += pszOutput;
  2901. }
  2902. /*------------------------------------------------------------------------
  2903. Name :DoCascadeTransforms
  2904. Synopsis :Does cascading transforms on the XML output obtained
  2905. as result (the intermediate transforms should data
  2906. which is DOM compliant)
  2907. Type :Member Function
  2908. Input parameter :
  2909. rParsedInfo - reference to CParsedInfo object
  2910. Output parameters :
  2911. bstrOutput - transformed output
  2912. Return Type :BOOL
  2913. Global Variables :None
  2914. Calling Syntax :DoCascadeTransforms(rParsedInfo, bstrOutput)
  2915. Notes :None
  2916. ------------------------------------------------------------------------*/
  2917. BOOL CFormatEngine::DoCascadeTransforms(CParsedInfo& rParsedInfo,
  2918. _bstr_t& bstrOutput)
  2919. {
  2920. HRESULT hr = S_OK;
  2921. IXMLDOMDocument2 *pIStyleSheet = NULL;
  2922. IXMLDOMDocument2 *pIObject = NULL;
  2923. IXSLTemplate *pITemplate = NULL;
  2924. IXSLProcessor *pIProcessor = NULL;
  2925. VARIANT varValue, vtOutStream;
  2926. VariantInit(&varValue);
  2927. VariantInit(&vtOutStream);
  2928. VARIANT_BOOL varLoad = VARIANT_FALSE;
  2929. XSLTDETVECTOR vecXSLDetails;
  2930. XSLTDETVECTOR::iterator vecEnd = NULL,
  2931. vecIterator = NULL;
  2932. BSTRMAP::iterator mapItrtr = NULL,
  2933. mapEnd = NULL;
  2934. BOOL bFirst = TRUE;
  2935. DWORD dwCount = 0;
  2936. DWORD dwSize = 0;
  2937. BOOL bRet = TRUE;
  2938. CHString chsMsg;
  2939. DWORD dwThreadId = GetCurrentThreadId();
  2940. CFileOutputStream outStrm;
  2941. vecXSLDetails = rParsedInfo.GetCmdSwitchesObject().GetXSLTDetailsVector();
  2942. try
  2943. {
  2944. // Create single instance of the IXSLTemplate
  2945. hr = CoCreateInstance(CLSID_XSLTemplate, NULL, CLSCTX_SERVER,
  2946. IID_IXSLTemplate, (LPVOID*)(&pITemplate));
  2947. if (m_bTrace || m_eloErrLogOpt)
  2948. {
  2949. chsMsg.Format(L"CoCreateInstance(CLSID_XSLTemplate, NULL,"
  2950. L" CLSCTX_SERVER, IID_IXSLTemplate, -)");
  2951. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2952. dwThreadId, rParsedInfo, m_bTrace);
  2953. }
  2954. ONFAILTHROWERROR(hr);
  2955. if (pITemplate)
  2956. {
  2957. vecIterator = vecXSLDetails.begin();
  2958. vecEnd = vecXSLDetails.end();
  2959. dwSize = vecXSLDetails.size();
  2960. // Loop thru the list of cascading transforms specified.
  2961. while (vecIterator != vecEnd)
  2962. {
  2963. // Create single instance of IXMLDOMDocument2
  2964. hr = CoCreateInstance(CLSID_FreeThreadedDOMDocument, NULL,
  2965. CLSCTX_SERVER, IID_IXMLDOMDocument2,
  2966. (LPVOID*) (&pIStyleSheet));
  2967. if (m_bTrace || m_eloErrLogOpt)
  2968. {
  2969. chsMsg.Format(L"CoCreateInstance("
  2970. L"CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_SERVER,"
  2971. L"IID_IXMLDOMDocument2, -)");
  2972. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2973. dwThreadId, rParsedInfo, m_bTrace);
  2974. }
  2975. ONFAILTHROWERROR(hr);
  2976. if (pIStyleSheet)
  2977. {
  2978. hr = pIStyleSheet->put_async(VARIANT_FALSE);
  2979. if (m_bTrace || m_eloErrLogOpt)
  2980. {
  2981. chsMsg.Format(L"IXSLDOMDocument2::put_async("
  2982. L"VARIANT_FALSE)");
  2983. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2984. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo, m_bTrace);
  2985. }
  2986. ONFAILTHROWERROR(hr);
  2987. dwCount++;
  2988. // Load the transform document (xsl)
  2989. hr = pIStyleSheet->load(_variant_t((*vecIterator)
  2990. .FileName), &varLoad);
  2991. if (m_bTrace || m_eloErrLogOpt)
  2992. {
  2993. chsMsg.Format(L"IXSLDOMDocument2::load("
  2994. L"L\"%s\", -)", (WCHAR*)(*vecIterator).FileName);
  2995. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2996. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo, m_bTrace);
  2997. }
  2998. ONFAILTHROWERROR(hr);
  2999. if (varLoad == VARIANT_TRUE)
  3000. {
  3001. // Add the reference of the stylesheet to the
  3002. // IXSLTemplate object
  3003. hr = pITemplate->putref_stylesheet(pIStyleSheet);
  3004. if (m_bTrace || m_eloErrLogOpt)
  3005. {
  3006. chsMsg.Format(L"IXSTemplate::putref_stylesheet("
  3007. L"-)");
  3008. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3009. (LPCWSTR)chsMsg, dwThreadId,
  3010. rParsedInfo, m_bTrace);
  3011. }
  3012. ONFAILTHROWERROR(hr);
  3013. // Create the processor object
  3014. hr = pITemplate->createProcessor(&pIProcessor);
  3015. if (m_bTrace || m_eloErrLogOpt)
  3016. {
  3017. chsMsg.Format(L"IXSTemplate::createProcessor("
  3018. L"-)");
  3019. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3020. (LPCWSTR)chsMsg, dwThreadId,
  3021. rParsedInfo, m_bTrace);
  3022. }
  3023. ONFAILTHROWERROR(hr);
  3024. if (pIProcessor)
  3025. {
  3026. // If parameters are specified
  3027. if ((*vecIterator).ParamMap.size())
  3028. {
  3029. // Add the list of parameters specified to the
  3030. // IXSLProcessor interface object
  3031. hr = AddParameters(rParsedInfo, pIProcessor,
  3032. (*vecIterator).ParamMap);
  3033. ONFAILTHROWERROR(hr);
  3034. }
  3035. // If first tranformation, then feed the XML data
  3036. // loaded into m_pIXMLDoc for transformation
  3037. if (bFirst)
  3038. {
  3039. hr = pIProcessor->put_input(
  3040. _variant_t(m_pIXMLDoc));
  3041. bFirst = FALSE;
  3042. }
  3043. else
  3044. {
  3045. // Intermediate transformation - load the
  3046. // result data obtained in previous
  3047. // transformation
  3048. hr = pIProcessor->put_input(
  3049. _variant_t(pIObject));
  3050. }
  3051. if (m_bTrace || m_eloErrLogOpt)
  3052. {
  3053. chsMsg.Format(L"IXSProcessor::put_input("
  3054. L"-)");
  3055. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3056. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  3057. m_bTrace);
  3058. }
  3059. ONFAILTHROWERROR(hr);
  3060. // if last transform then direct output to file
  3061. // Streaming of output is done only if output
  3062. // redirection is specified or in case inline
  3063. // /output command
  3064. if (dwCount == dwSize)
  3065. {
  3066. // Set output stream i.e output file or
  3067. // redirection file.
  3068. // This function
  3069. if ( SetOutputStream(outStrm, vtOutStream)
  3070. == TRUE )
  3071. {
  3072. // Put output stream in IXSLProcessor
  3073. // so that when transform() is executed
  3074. // output goes directly to the stream
  3075. // i.e output file or redirection file
  3076. hr = pIProcessor->put_output(vtOutStream);
  3077. if (m_bTrace || m_eloErrLogOpt)
  3078. {
  3079. chsMsg.Format(L"IXSProcessor::put_output("
  3080. L"-)");
  3081. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3082. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  3083. m_bTrace);
  3084. }
  3085. ONFAILTHROWERROR(hr);
  3086. }
  3087. }
  3088. // Transform the content
  3089. hr = pIProcessor->transform(&varLoad);
  3090. if (m_bTrace || m_eloErrLogOpt)
  3091. {
  3092. chsMsg.Format(L"IXSProcessor::tranform("
  3093. L"-)");
  3094. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3095. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  3096. m_bTrace);
  3097. }
  3098. ONFAILTHROWERROR(hr);
  3099. // If last transform is streamed out to stream
  3100. // specified by put_output() then apply again
  3101. // transform to get output in Unicode string
  3102. // which can be used in XML logging and for
  3103. // append file
  3104. if (dwCount == dwSize &&
  3105. m_bOutputGoingToStream == TRUE)
  3106. {
  3107. // Stop streaming output to out files
  3108. V_VT(&vtOutStream) = VT_EMPTY;
  3109. pIProcessor->put_output(vtOutStream);
  3110. // Execute transform again to get output
  3111. // in Unicode string
  3112. hr = pIProcessor->transform(&varLoad);
  3113. if (m_bTrace || m_eloErrLogOpt)
  3114. {
  3115. chsMsg.Format(L"IXSProcessor::tranform("
  3116. L"-)");
  3117. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3118. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  3119. m_bTrace);
  3120. }
  3121. ONFAILTHROWERROR(hr);
  3122. }
  3123. if (varLoad == VARIANT_TRUE)
  3124. {
  3125. // Retrieve the output
  3126. hr = pIProcessor->get_output(&varValue);
  3127. if (m_bTrace || m_eloErrLogOpt)
  3128. {
  3129. chsMsg.Format(L"IXSProcessor::"
  3130. L"get_output(-)");
  3131. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  3132. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  3133. m_bTrace);
  3134. }
  3135. ONFAILTHROWERROR(hr);
  3136. // intermediate transform
  3137. if (dwCount != dwSize)
  3138. {
  3139. if (pIObject == NULL)
  3140. {
  3141. hr = CoCreateInstance(CLSID_FreeThreadedDOMDocument,
  3142. NULL, CLSCTX_SERVER,
  3143. IID_IXMLDOMDocument2,
  3144. (LPVOID*)(&pIObject));
  3145. if (m_bTrace || m_eloErrLogOpt)
  3146. {
  3147. chsMsg.Format(L"CoCreateInstance("
  3148. L"CLSID_FreeThreadedDOMDocument, NULL,"
  3149. L" CLSCTX_INPROC_SERVER, "
  3150. L"IID_IXMLDOMDocument2, -)");
  3151. WMITRACEORERRORLOG(hr, __LINE__,
  3152. __FILE__, (LPCWSTR)chsMsg,
  3153. dwThreadId, rParsedInfo,
  3154. m_bTrace);
  3155. }
  3156. ONFAILTHROWERROR(hr);
  3157. }
  3158. hr = pIObject->loadXML(
  3159. varValue.bstrVal, &varLoad);
  3160. if (m_bTrace || m_eloErrLogOpt)
  3161. {
  3162. chsMsg.Format(L"IXMLDOMDocument2::"
  3163. L"loadXML(-, -)");
  3164. WMITRACEORERRORLOG(hr, __LINE__,
  3165. __FILE__, (LPCWSTR)chsMsg, dwThreadId,
  3166. rParsedInfo, m_bTrace);
  3167. }
  3168. ONFAILTHROWERROR(hr);
  3169. if (varLoad == VARIANT_FALSE)
  3170. {
  3171. // Invalid XML content.
  3172. rParsedInfo.GetCmdSwitchesObject().
  3173. SetErrataCode(
  3174. IDS_E_INVALID_XML_CONTENT);
  3175. bRet = FALSE;
  3176. break;
  3177. }
  3178. }
  3179. // last transform - print the result.
  3180. else
  3181. {
  3182. bstrOutput = _bstr_t(varValue);
  3183. }
  3184. VariantClear(&varValue);
  3185. }
  3186. SAFEIRELEASE(pIProcessor);
  3187. }
  3188. }
  3189. else
  3190. {
  3191. // Invalid XSL format.
  3192. rParsedInfo.GetCmdSwitchesObject()
  3193. .SetErrataCode(IDS_E_INVALID_FORMAT);
  3194. bRet = FALSE;
  3195. break;
  3196. }
  3197. SAFEIRELEASE(pIStyleSheet);
  3198. }
  3199. vecIterator++;
  3200. }
  3201. VariantClear(&vtOutStream);
  3202. SAFEIRELEASE(pIProcessor);
  3203. SAFEIRELEASE(pITemplate);
  3204. SAFEIRELEASE(pIObject);
  3205. SAFEIRELEASE(pITemplate);
  3206. }
  3207. }
  3208. catch(_com_error& e)
  3209. {
  3210. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  3211. VariantClear(&varValue);
  3212. VariantClear(&vtOutStream);
  3213. SAFEIRELEASE(pIProcessor);
  3214. SAFEIRELEASE(pIStyleSheet);
  3215. SAFEIRELEASE(pITemplate);
  3216. SAFEIRELEASE(pIObject);
  3217. bRet = FALSE;
  3218. }
  3219. //trap for CHeap_Exception
  3220. catch(CHeap_Exception)
  3221. {
  3222. VariantClear(&varValue);
  3223. VariantClear(&vtOutStream);
  3224. SAFEIRELEASE(pIProcessor);
  3225. SAFEIRELEASE(pIStyleSheet);
  3226. SAFEIRELEASE(pITemplate);
  3227. SAFEIRELEASE(pIObject);
  3228. bRet = FALSE;
  3229. hr = WBEM_E_OUT_OF_MEMORY;
  3230. _com_issue_error(hr);
  3231. }
  3232. return bRet;
  3233. }
  3234. /*------------------------------------------------------------------------
  3235. Name :AddParameters
  3236. Synopsis :Adds parameters to the IXSLProcessor object
  3237. Type :Member Function
  3238. Input parameter :
  3239. rParsedInfo - reference to CParsedInfo object
  3240. pIProcessor - IXSLProcessor object
  3241. bstrmapParam - parameter map
  3242. Output parameters :None
  3243. Return Type :HRESULT
  3244. Global Variables :None
  3245. Calling Syntax :AddParameters(rParsedInfo, pIProcessor, bstrmapParam)
  3246. Notes :None
  3247. ------------------------------------------------------------------------*/
  3248. HRESULT CFormatEngine::AddParameters(CParsedInfo& rParsedInfo,
  3249. IXSLProcessor *pIProcessor,
  3250. BSTRMAP bstrmapParam)
  3251. {
  3252. HRESULT hr = S_OK;
  3253. BSTRMAP::iterator mapItrtr = NULL,
  3254. mapEnd = NULL;
  3255. _bstr_t bstrProp,
  3256. bstrVal;
  3257. CHString chsMsg;
  3258. DWORD dwThreadId = GetCurrentThreadId();
  3259. try
  3260. {
  3261. mapItrtr = bstrmapParam.begin();
  3262. mapEnd = bstrmapParam.end();
  3263. // Loop thru the available parameters
  3264. while (mapItrtr != mapEnd)
  3265. {
  3266. bstrProp = (*mapItrtr).first;
  3267. bstrVal = (*mapItrtr).second;
  3268. // Add the parameter to the IXSLProcessor
  3269. hr = pIProcessor->addParameter(bstrProp, _variant_t(bstrVal));
  3270. if (m_bTrace || m_eloErrLogOpt)
  3271. {
  3272. chsMsg.Format(L"IXSProcessor::addParameter(L\"%s\", -)",
  3273. (WCHAR*) bstrProp);
  3274. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  3275. dwThreadId, rParsedInfo, m_bTrace);
  3276. }
  3277. ONFAILTHROWERROR(hr);
  3278. mapItrtr++;
  3279. }
  3280. }
  3281. catch(_com_error& e)
  3282. {
  3283. hr = e.Error();
  3284. }
  3285. catch(CHeap_Exception)
  3286. {
  3287. hr = WBEM_E_OUT_OF_MEMORY;
  3288. _com_issue_error(hr);
  3289. }
  3290. return hr;
  3291. }
  3292. /*------------------------------------------------------------------------
  3293. Name :SetOutputStream
  3294. Synopsis :Sets the output stream, if /OUTPUT if FILEOUTPUT and
  3295. is inline command i.e /OUTPUT:file command,
  3296. Or output redirection is specified.
  3297. Type :Member Function
  3298. Input parameter :
  3299. Output parameters :
  3300. fosFileOutputStream - CFileOutputStream object, initialized output stream
  3301. vtStream - VARIANT type, holds the stream object
  3302. Return Type :BOOL
  3303. Global Variables :None
  3304. Calling Syntax :SetOutputStream(outStrm, vtOutStream);
  3305. Notes :None
  3306. ------------------------------------------------------------------------*/
  3307. BOOL CFormatEngine::SetOutputStream(CFileOutputStream& fosFileOutputStream,
  3308. VARIANT& vtStream)
  3309. {
  3310. BOOL bRet = TRUE;
  3311. HRESULT hr = S_OK;
  3312. try
  3313. {
  3314. if ( m_bGetOutOpt == TRUE )
  3315. {
  3316. // Get the output option to redirect the output.
  3317. m_opsOutputOpt = g_wmiCmd.GetParsedInfoObject().
  3318. GetGlblSwitchesObject().
  3319. GetOutputOrAppendOption(TRUE);
  3320. m_bGetOutOpt = FALSE;
  3321. }
  3322. // If Output is directed to file and /OUTPUT is appearing in command
  3323. // i.e ( /OUTPUT:<file> command )
  3324. if ( m_opsOutputOpt == FILEOUTPUT &&
  3325. g_wmiCmd.GetParsedInfoObject().GetCmdSwitchesObject().
  3326. GetOutputSwitchFlag() == TRUE )
  3327. {
  3328. // Close the output file which is already opened in text mode.
  3329. if ( CloseOutputFile() == TRUE )
  3330. {
  3331. // Make Out file pointer NULL.
  3332. m_fpOutFile = NULL;
  3333. // Set output file to stream
  3334. hr = fosFileOutputStream.Init(
  3335. g_wmiCmd.
  3336. GetParsedInfoObject().
  3337. GetGlblSwitchesObject().
  3338. GetOutputOrAppendFileName(TRUE));
  3339. ONFAILTHROWERROR(hr);
  3340. }
  3341. m_bOutputGoingToStream = TRUE;
  3342. }
  3343. else if ( IsRedirection() == TRUE ) // If output redirection is specified
  3344. {
  3345. HANDLE hFile = GetStdHandle(STD_OUTPUT_HANDLE);
  3346. BOOL bOutputGoingToStream = FALSE;
  3347. if (FILE_TYPE_DISK == GetFileType(hFile))
  3348. {
  3349. bOutputGoingToStream = TRUE;
  3350. }
  3351. if(bOutputGoingToStream)
  3352. {
  3353. hr = fosFileOutputStream.Init(GetStdHandle(STD_OUTPUT_HANDLE));
  3354. ONFAILTHROWERROR(hr);
  3355. m_bOutputGoingToStream = TRUE;
  3356. }
  3357. }
  3358. if ( m_bOutputGoingToStream == TRUE )
  3359. {
  3360. V_VT(&vtStream) = VT_UNKNOWN;
  3361. V_UNKNOWN(&vtStream) = &fosFileOutputStream;
  3362. }
  3363. else
  3364. bRet = FALSE;
  3365. }
  3366. catch(_com_error& e)
  3367. {
  3368. g_wmiCmd.GetParsedInfoObject().GetCmdSwitchesObject().SetCOMError(e);
  3369. bRet = FALSE;
  3370. }
  3371. return bRet;
  3372. }