Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1257 lines
32 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusCfgCommands
  7. //
  8. // Abstract:
  9. // This file contains functions for handling commands passed to cluscfg.exe
  10. // either via a command line option of via entries in an answer file.
  11. //
  12. // Author:
  13. // C. Brent Thomas a-brentt
  14. //
  15. // Revision History:
  16. // 30 Sep 1998 original
  17. //
  18. // Notes:
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include <windows.h>
  22. #include <setupapi.h>
  23. #include <tchar.h>
  24. #include "ClusCfgCommands.h"
  25. /////////////////////////////////////////////////////////////////////////////
  26. //++
  27. //
  28. // CClusCfgCommand
  29. //
  30. // Routine Description:
  31. // This is the default constructor for the CClusCfgConnand class.
  32. //
  33. // Arguments:
  34. // None
  35. //
  36. // Return Value:
  37. // None
  38. //
  39. //--
  40. /////////////////////////////////////////////////////////////////////////////
  41. CClusCfgCommand::CClusCfgCommand( void )
  42. {
  43. m_pNextCommand = NULL;
  44. m_dwCommandStringId = 0L;
  45. m_ptszCommandString = NULL;
  46. m_dwCommandSubStringId = 0L;
  47. m_ptszCommandSubString = NULL;
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. //++
  51. //
  52. // CClusCfgCommand
  53. //
  54. // Routine Description:
  55. // This constructor initializes the string Id data members of a CClusCfgCommand object.
  56. //
  57. // Arguments:
  58. // dwStringId - the string Id of the command string
  59. // dwSubStringId - the string Id of the minimum substring of a command
  60. //
  61. // Return Value:
  62. // None
  63. //
  64. //--
  65. /////////////////////////////////////////////////////////////////////////////
  66. CClusCfgCommand::CClusCfgCommand( DWORD dwStringId, DWORD dwSubStringId )
  67. {
  68. m_pNextCommand = NULL;
  69. m_dwCommandStringId = dwStringId;
  70. m_ptszCommandString = NULL;
  71. m_dwCommandSubStringId = dwSubStringId;
  72. m_ptszCommandSubString = NULL;
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. //++
  76. //
  77. // ~CClusCfgCommand
  78. //
  79. // Routine Description:
  80. // This is the destructor for the CClusCfgCommand class.
  81. //
  82. // Arguments:
  83. // None
  84. //
  85. // Return Value:
  86. // None
  87. //
  88. //--
  89. /////////////////////////////////////////////////////////////////////////////
  90. CClusCfgCommand::~CClusCfgCommand( void )
  91. {
  92. if ( m_pNextCommand != NULL )
  93. {
  94. delete m_pNextCommand;
  95. }
  96. if ( m_ptszCommandString != NULL )
  97. {
  98. delete m_ptszCommandString;
  99. }
  100. if ( m_ptszCommandSubString != NULL )
  101. {
  102. delete m_ptszCommandSubString;
  103. }
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. //++
  107. //
  108. // InitializeCommandSubString
  109. //
  110. // Routine Description:
  111. // This function sets the m_dwCommandSubStringId and m_ptszCommandSubString members
  112. // of a CClusCfgCommand object.
  113. //
  114. // Arguments:
  115. // hInstance = the instance handle of the executable image
  116. // dwCommandSubStringId = the string Id of the command Sub string
  117. //
  118. //
  119. // Return Value:
  120. // TRUE - indicates success
  121. // FALSE - indicates that an error occured
  122. //
  123. //--
  124. /////////////////////////////////////////////////////////////////////////////
  125. BOOL CClusCfgCommand::InitializeCommandSubString( HINSTANCE hInstance, DWORD dwCommandSubStringId )
  126. {
  127. BOOL fReturnValue;
  128. // Assume that no valid command will be longer than the maximum length of an answer file entry.
  129. TCHAR tszString[MAX_INF_STRING_LENGTH];
  130. // Is the command string Id meaningfull?
  131. if ( dwCommandSubStringId != 0L )
  132. {
  133. // Set the command string Id.
  134. SetCommandSubStringId( dwCommandSubStringId );
  135. // Read the command string from the STRINGTABLE.
  136. if ( LoadString( hInstance,
  137. m_dwCommandSubStringId,
  138. tszString,
  139. MAX_INF_STRING_LENGTH ) > 0 )
  140. {
  141. // tszString is the command string.
  142. // Allocate memory for the string and save its' address.
  143. SetCommandSubStringPointer( new TCHAR[_tcslen( tszString ) +1] );
  144. // Store the command string.
  145. _tcscpy( GetCommandSubStringPointer(), tszString );
  146. fReturnValue = TRUE;
  147. }
  148. else
  149. {
  150. // Set the command string to empty.
  151. if ( GetCommandSubStringPointer() != NULL )
  152. {
  153. delete GetCommandSubStringPointer();
  154. }
  155. SetCommandSubStringPointer( NULL );
  156. fReturnValue = FALSE;
  157. } // string loaded from STRINGTABLE?
  158. }
  159. else
  160. {
  161. // Set the command string to empty.
  162. if ( GetCommandSubStringPointer() != NULL )
  163. {
  164. delete GetCommandSubStringPointer();
  165. }
  166. SetCommandSubStringPointer( NULL );
  167. fReturnValue = FALSE;
  168. } // String Id meaningfull?
  169. return ( fReturnValue );
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. //++
  173. //
  174. // InitializeCommandSubString
  175. //
  176. // Routine Description:
  177. // This function sets the m_ptszCommandSubString member of a CClusCfgCommand object
  178. // based on the contents of the m_dwCommandSubStringId member.
  179. //
  180. // Arguments:
  181. // hInstance = the instance handle of the executable image
  182. //
  183. // Return Value:
  184. // TRUE - indicates success
  185. // FALSE - indicates that an error occured
  186. //
  187. //--
  188. /////////////////////////////////////////////////////////////////////////////
  189. BOOL CClusCfgCommand::InitializeCommandSubString( HINSTANCE hInstance )
  190. {
  191. BOOL fReturnValue;
  192. // Assume that no valid command will be longer than the maximum length of an answer file entry.
  193. TCHAR tszString[MAX_INF_STRING_LENGTH];
  194. // Is the command string Id meaningfull?
  195. if ( GetCommandSubStringId() != 0L )
  196. {
  197. // Read the command string from the STRINGTABLE.
  198. if ( LoadString( hInstance,
  199. m_dwCommandSubStringId,
  200. tszString,
  201. MAX_INF_STRING_LENGTH ) > 0 )
  202. {
  203. // tszString is the command string.
  204. // Allocate memory for the string and save its' address.
  205. SetCommandSubStringPointer( new TCHAR[_tcslen(tszString) + 1] );
  206. // Store the command string.
  207. _tcscpy( GetCommandSubStringPointer(), tszString );
  208. fReturnValue = TRUE;
  209. }
  210. else
  211. {
  212. // Set the command string to empty.
  213. if ( GetCommandSubStringPointer() != NULL )
  214. {
  215. delete GetCommandSubStringPointer();
  216. }
  217. SetCommandSubStringPointer( NULL );
  218. fReturnValue = FALSE;
  219. } // string loaded from STRINGTABLE?
  220. }
  221. else
  222. {
  223. // Set the command string to empty.
  224. if ( GetCommandSubStringPointer() != NULL )
  225. {
  226. delete GetCommandSubStringPointer();
  227. }
  228. SetCommandSubStringPointer( NULL );
  229. fReturnValue = FALSE;
  230. } // String Id meaningfull?
  231. return ( fReturnValue );
  232. }
  233. /////////////////////////////////////////////////////////////////////////////
  234. //++
  235. //
  236. // InitializeCommandString
  237. //
  238. // Routine Description:
  239. // This function sets the m_dwCommandStringId and m_ptszCommandString members
  240. // of a CClusCfgCommand object.
  241. //
  242. // Arguments:
  243. // hInstance = the instance handle of the executable image
  244. // dwCommandStringId = the string Id of the command string
  245. //
  246. //
  247. // Return Value:
  248. // TRUE - indicates success
  249. // FALSE - indicates that an error occured
  250. //
  251. //--
  252. /////////////////////////////////////////////////////////////////////////////
  253. BOOL CClusCfgCommand::InitializeCommandString( HINSTANCE hInstance, DWORD dwCommandStringId )
  254. {
  255. BOOL fReturnValue;
  256. // Assume that no valid command will be longer than the maximum length of an answer file entry.
  257. TCHAR tszString[MAX_INF_STRING_LENGTH];
  258. // Is the command string Id meaningfull?
  259. if ( dwCommandStringId != 0L )
  260. {
  261. // Set the command string Id.
  262. SetCommandStringId( dwCommandStringId );
  263. // Read the command string from the STRINGTABLE.
  264. if ( LoadString( hInstance,
  265. m_dwCommandStringId,
  266. tszString,
  267. MAX_INF_STRING_LENGTH ) > 0 )
  268. {
  269. // tszString is the command string.
  270. // Allocate memory for the string and save its' address.
  271. SetCommandStringPointer( new TCHAR[_tcslen(tszString) + 1] );
  272. // Store the command string.
  273. _tcscpy( GetCommandStringPointer(), tszString );
  274. fReturnValue = TRUE;
  275. }
  276. else
  277. {
  278. // Set the command string to empty.
  279. if ( GetCommandStringPointer() != NULL )
  280. {
  281. delete GetCommandStringPointer();
  282. }
  283. SetCommandStringPointer( NULL );
  284. fReturnValue = FALSE;
  285. } // string loaded from STRINGTABLE?
  286. }
  287. else
  288. {
  289. // Set the command string to empty.
  290. if ( GetCommandStringPointer() != NULL )
  291. {
  292. delete GetCommandStringPointer();
  293. }
  294. SetCommandStringPointer( NULL );
  295. fReturnValue = FALSE;
  296. } // String Id meaningfull?
  297. return ( fReturnValue );
  298. }
  299. /////////////////////////////////////////////////////////////////////////////
  300. //++
  301. //
  302. // InitializeCommandString
  303. //
  304. // Routine Description:
  305. // This function sets the m_ptszCommandString member of a CClusCfgCommand object
  306. // based on the contents of the m_dwCommandStringId member.
  307. //
  308. // Arguments:
  309. // hInstance = the instance handle of the executable image
  310. //
  311. // Return Value:
  312. // TRUE - indicates success
  313. // FALSE - indicates that an error occured
  314. //
  315. //--
  316. /////////////////////////////////////////////////////////////////////////////
  317. BOOL CClusCfgCommand::InitializeCommandString( HINSTANCE hInstance )
  318. {
  319. BOOL fReturnValue;
  320. // Assume that no valid command will be longer than the maximum length of an answer file entry.
  321. TCHAR tszString[MAX_INF_STRING_LENGTH];
  322. // Is the command string Id meaningfull?
  323. if ( GetCommandStringId() != 0L )
  324. {
  325. // Read the command string from the STRINGTABLE.
  326. if ( LoadString( hInstance,
  327. m_dwCommandStringId,
  328. tszString,
  329. MAX_INF_STRING_LENGTH ) > 0 )
  330. {
  331. // tszString is the command string.
  332. // Allocate memory for the string and save its' address.
  333. SetCommandStringPointer( new TCHAR[_tcslen(tszString) + 1] );
  334. // Store the command string.
  335. _tcscpy( GetCommandStringPointer(), tszString );
  336. fReturnValue = TRUE;
  337. }
  338. else
  339. {
  340. // Set the command string to empty.
  341. if ( GetCommandStringPointer() != NULL )
  342. {
  343. delete GetCommandStringPointer();
  344. }
  345. SetCommandStringPointer( NULL );
  346. fReturnValue = FALSE;
  347. } // string loaded from STRINGTABLE?
  348. }
  349. else
  350. {
  351. // Set the command string to empty.
  352. if ( GetCommandStringPointer() != NULL )
  353. {
  354. delete GetCommandStringPointer();
  355. }
  356. SetCommandStringPointer( NULL );
  357. fReturnValue = FALSE;
  358. } // String Id meaningfull?
  359. return ( fReturnValue );
  360. }
  361. /////////////////////////////////////////////////////////////////////////////
  362. //++
  363. //
  364. // SetNextCommandPointer
  365. //
  366. // Routine Description:
  367. // This function sets the m_pNextCommand member of a CClusCfgCommand object.
  368. //
  369. // Arguments:
  370. // pNextCommand - points to a CClusCfgCommand object
  371. //
  372. // Return Value:
  373. // TRUE - indicates success
  374. // FALSE - indicates that an error occured
  375. //
  376. //--
  377. /////////////////////////////////////////////////////////////////////////////
  378. BOOL CClusCfgCommand::SetNextCommandPointer( CClusCfgCommand * pNextCommand )
  379. {
  380. BOOL fReturnValue;
  381. m_pNextCommand = pNextCommand;
  382. fReturnValue = TRUE;
  383. return ( fReturnValue );
  384. }
  385. /////////////////////////////////////////////////////////////////////////////
  386. //++
  387. //
  388. // GetNextCommandPointer
  389. //
  390. // Routine Description:
  391. // This function returns the m_pNextCommand member of a CClusCfgCommand object.
  392. //
  393. // Arguments:
  394. // None
  395. //
  396. // Return Value:
  397. // The contents of the m_pNextCommand member.
  398. //
  399. //--
  400. /////////////////////////////////////////////////////////////////////////////
  401. CClusCfgCommand * CClusCfgCommand::GetNextCommandPointer( void )
  402. {
  403. return ( m_pNextCommand );
  404. }
  405. /////////////////////////////////////////////////////////////////////////////
  406. //++
  407. //
  408. // BuildClusCfgCommandList
  409. //
  410. // Routine Description:
  411. // This function builds a singly linked list of CClusCfgCommand objects
  412. // and initializes the elements of the list based on the entries in a
  413. // table of CLUSCFG_COMMAND_IDS structures.
  414. //
  415. // Arguments:
  416. // hInstance - the instance handle of the executable
  417. // pClusCfgCommandIds - points to a table of CLUSCFG_COMMAND_IDS structures.
  418. //
  419. // Return Value:
  420. // A pointer to the head of a singly linked list of CClusCfgCommand objects.
  421. //
  422. //--
  423. /////////////////////////////////////////////////////////////////////////////
  424. BOOL CClusCfgCommand::BuildClusCfgCommandList( HINSTANCE hInstance,
  425. CLUSCFG_COMMAND_IDS * pClusCfgCommandIds )
  426. {
  427. BOOL fReturnValue;
  428. // Is the pointer to the table of string resource IDs meaningfull?
  429. if ( pClusCfgCommandIds != NULL )
  430. {
  431. // Is the table non-empty?
  432. if ( (pClusCfgCommandIds->dwCommandStringId != 0L) &&
  433. (pClusCfgCommandIds->dwCommandSubStringId != 0L) )
  434. {
  435. // Initialize the first CClusCfgCommand object.
  436. if ( (InitializeCommandString( hInstance, pClusCfgCommandIds->dwCommandStringId ) == TRUE) &&
  437. (InitializeCommandSubString( hInstance, pClusCfgCommandIds->dwCommandSubStringId ) == TRUE) )
  438. {
  439. // Initialize the parameter counts.
  440. SetNumRequiredParameters( pClusCfgCommandIds->xNumRequiredParameters );
  441. SetNumOptionalParameters( pClusCfgCommandIds->xNumOptionalParameters );
  442. // Point to the next element in the table.
  443. pClusCfgCommandIds++;
  444. // Create and initialize the rest of the list.
  445. CClusCfgCommand * pClusCfgCommand;
  446. pClusCfgCommand = this;
  447. BOOL fError = FALSE;
  448. while ( (pClusCfgCommandIds->dwCommandStringId != 0L) &&
  449. (pClusCfgCommandIds->dwCommandSubStringId != 0L) &&
  450. (fError == FALSE) )
  451. {
  452. // Create an object.
  453. pClusCfgCommand->SetNextCommandPointer( new CClusCfgCommand( pClusCfgCommandIds->dwCommandStringId,
  454. pClusCfgCommandIds->dwCommandSubStringId ) );
  455. // Adjust the pointer to the new command object.
  456. pClusCfgCommand = pClusCfgCommand->GetNextCommandPointer();
  457. // Initialize it.
  458. if ( (pClusCfgCommand != NULL ) &&
  459. (pClusCfgCommand->InitializeCommandString( hInstance ) == TRUE) &&
  460. (pClusCfgCommand->InitializeCommandSubString( hInstance ) == TRUE) )
  461. {
  462. // Initialize the parameter counts.
  463. pClusCfgCommand->SetNumRequiredParameters( pClusCfgCommandIds->xNumRequiredParameters );
  464. pClusCfgCommand->SetNumOptionalParameters( pClusCfgCommandIds->xNumOptionalParameters );
  465. // Point to the next entry in the table.
  466. pClusCfgCommandIds++;
  467. }
  468. else
  469. {
  470. // Could not initialize the object. Terminate the loop.
  471. fError = TRUE;
  472. } // Current object initialized?
  473. } // end of "while" loop
  474. // Was the list built and initialized successfully?
  475. if ( fError == FALSE )
  476. {
  477. fReturnValue = TRUE;
  478. }
  479. else
  480. {
  481. // An error occured. Delete the list.
  482. delete GetNextCommandPointer();
  483. SetNextCommandPointer( NULL );
  484. fReturnValue = FALSE;
  485. }
  486. }
  487. else
  488. {
  489. // The first CClusCfgCommand object could not be initialized.
  490. delete GetNextCommandPointer();
  491. SetNextCommandPointer( NULL );
  492. fReturnValue = FALSE;
  493. } // First string initialized succesfully?
  494. }
  495. else
  496. {
  497. // The table of string resource Ids is empty.
  498. fReturnValue = FALSE;
  499. } // Is the table empty
  500. }
  501. else
  502. {
  503. // The table of string resource Ids does not exist.
  504. fReturnValue = FALSE;
  505. } // table of string ids meaningfull?
  506. return ( fReturnValue );
  507. }
  508. /////////////////////////////////////////////////////////////////////////////
  509. //++
  510. //
  511. // GetCommandString
  512. //
  513. // Routine Description:
  514. // This function returns the contents of the m_ptszCommandString member of
  515. // a CClusCfgCommand object.
  516. //
  517. // Arguments:
  518. // None
  519. //
  520. // Return Value:
  521. // A pointer to a string that represents a command that can be passed to
  522. // ClusCfg.exe.
  523. //
  524. //--
  525. /////////////////////////////////////////////////////////////////////////////
  526. LPTSTR CClusCfgCommand::GetCommandString( void )
  527. {
  528. return ( m_ptszCommandString );
  529. }
  530. /////////////////////////////////////////////////////////////////////////////
  531. //++
  532. //
  533. // GetCommandSubString
  534. //
  535. // Routine Description:
  536. // This function returns the contents of the m_ptszCommandSubString member of
  537. // a CClusCfgCommand object.
  538. //
  539. // Arguments:
  540. // None
  541. //
  542. // Return Value:
  543. // A pointer to a string that represents the smallest substring that can be
  544. // recognized as a command that can be passed to ClusCfg.exe.
  545. //
  546. //--
  547. /////////////////////////////////////////////////////////////////////////////
  548. LPTSTR CClusCfgCommand::GetCommandSubString( void )
  549. {
  550. return ( m_ptszCommandSubString );
  551. }
  552. /////////////////////////////////////////////////////////////////////////////
  553. //++
  554. //
  555. // RecognizeCommandToken
  556. //
  557. // Routine Description:
  558. // This routine attempts to recognize a token as a command that may be
  559. // passed to cluscfg.exe.
  560. //
  561. // Arguments:
  562. // ptszToken - points to the token to be recognized
  563. // pClusCfgCommandList - points to the singly linked list of CClusCfgCommand
  564. // objects that describe the set of valid commands that
  565. // may be passed to cluscfg.exe
  566. //
  567. // Return Value:
  568. // TRUE - indicates that the token was recognized as a command
  569. // FALSE - indicates that the token was not recognized as a command
  570. //
  571. //--
  572. /////////////////////////////////////////////////////////////////////////////
  573. BOOL CClusCfgCommand::RecognizeCommandToken( LPCTSTR ptszToken,
  574. CClusCfgCommand * pClusCfgCommandList )
  575. {
  576. BOOL fReturnValue = FALSE;
  577. // Are the parameters meaningfull?
  578. if ( (ptszToken != NULL) &&
  579. (*ptszToken != TEXT('\0')) &&
  580. (pClusCfgCommandList != NULL) )
  581. {
  582. BOOL fTokenRecognized = FALSE;
  583. CClusCfgCommand * pTempCommand;
  584. // Starting at the head of the list compare the token to the command strings
  585. // and command sub-strings.
  586. pTempCommand = pClusCfgCommandList;
  587. // The token will be "recognized" if it is a sub-string of the "command string"
  588. // and the command sub-string is a sub-string of the token. This must be a case
  589. // insensitive comparison.
  590. LPTSTR ptszUpperCaseTokenCopy;
  591. // Allocate memory for an upper case copy of the token.
  592. ptszUpperCaseTokenCopy = new TCHAR[_tcslen( ptszToken ) + 1];
  593. _tcscpy( ptszUpperCaseTokenCopy, ptszToken );
  594. // Convert it to upper case.
  595. _tcsupr( ptszUpperCaseTokenCopy );
  596. // Starting at the head of the list compare the token to the command strings.
  597. do
  598. {
  599. // Allocate memory for an upper case copy of the command string.
  600. LPTSTR ptszUpperCaseCommandStringCopy;
  601. ptszUpperCaseCommandStringCopy = new TCHAR[_tcslen( pTempCommand->GetCommandString() ) +1];
  602. _tcscpy( ptszUpperCaseCommandStringCopy, pTempCommand->GetCommandString() );
  603. // Convert it to upper case.
  604. _tcsupr( ptszUpperCaseCommandStringCopy );
  605. // Is the token a sub-string of the command string?
  606. if ( _tcsstr( ptszUpperCaseCommandStringCopy, ptszUpperCaseTokenCopy ) == ptszUpperCaseCommandStringCopy )
  607. {
  608. // The token is a sub-string of the command string. Now determine whether
  609. // the command sub-string is a sub-string of the token.
  610. // Allocate memory for a upper case copy of the command sub-string.
  611. LPTSTR ptszUpperCaseCommandSubStringCopy;
  612. ptszUpperCaseCommandSubStringCopy = new TCHAR[_tcslen( pTempCommand->GetCommandSubString() ) +1];
  613. _tcscpy( ptszUpperCaseCommandSubStringCopy, pTempCommand->GetCommandSubString() );
  614. // Convert it to upper case.
  615. _tcsupr( ptszUpperCaseCommandSubStringCopy );
  616. // Is the command sub-string a sub-string of the token?
  617. if ( _tcsstr( ptszUpperCaseTokenCopy, ptszUpperCaseCommandSubStringCopy ) == ptszUpperCaseTokenCopy )
  618. {
  619. LPTSTR string;
  620. // The token is recognized. Make a copy of the all the contents
  621. // so we don't try to free the same chunk of memory
  622. // twice. Technically, we should check to see memory is already
  623. // allocated and free it.
  624. SetCommandStringId( pTempCommand->GetCommandStringId() );
  625. string = pTempCommand->GetCommandString();
  626. if ( string != NULL ) {
  627. // Allocate space for the copy
  628. SetCommandStringPointer( new TCHAR[_tcslen( string ) +1] );
  629. // Store the command string.
  630. _tcscpy( GetCommandStringPointer(), string );
  631. }
  632. SetCommandSubStringId( pTempCommand->GetCommandSubStringId() );
  633. string = pTempCommand->GetCommandSubString();
  634. if ( string != NULL ) {
  635. // Allocate space for the copy
  636. SetCommandSubStringPointer( new TCHAR[_tcslen( string ) +1] );
  637. // Store the command string.
  638. _tcscpy( GetCommandSubStringPointer(), string );
  639. }
  640. SetNumRequiredParameters( pTempCommand->GetNumRequiredParameters() );
  641. SetNumOptionalParameters( pTempCommand->GetNumOptionalParameters() );
  642. SetNextCommandPointer( NULL );
  643. fTokenRecognized = TRUE;
  644. fReturnValue = TRUE;
  645. }
  646. else
  647. {
  648. // Test the next command.
  649. pTempCommand = pTempCommand->GetNextCommandPointer();
  650. }
  651. // Free the upper case copy of the command sub-string.
  652. delete ptszUpperCaseCommandSubStringCopy;
  653. }
  654. else
  655. {
  656. // Test the next command.
  657. pTempCommand = pTempCommand->GetNextCommandPointer();
  658. } // Is the token a sub-string of the command string?
  659. // Free the upper case copy of the command string.
  660. delete ptszUpperCaseCommandStringCopy;
  661. } while ( (pTempCommand != NULL) &&
  662. (fTokenRecognized == FALSE) );
  663. // Free the memory for the upper case copy of the token.
  664. delete ptszUpperCaseTokenCopy;
  665. }
  666. else
  667. {
  668. // At least one parameter was invalid.
  669. fReturnValue = FALSE;
  670. } // parameters meaningfull?
  671. return ( fReturnValue );
  672. }
  673. /////////////////////////////////////////////////////////////////////////////
  674. //++
  675. //
  676. // SetNumRequiredParameters
  677. //
  678. // Routine Description:
  679. // This function sets the m_xNumRequiredParameters member of a CClusCfgCommand
  680. // object.
  681. //
  682. // Arguments:
  683. // xNumRequiredParameters - the number of parameters required by the command
  684. // which is described by the CClusCfgCommand object.
  685. //
  686. // Return Value:
  687. // None
  688. //
  689. //--
  690. /////////////////////////////////////////////////////////////////////////////
  691. void CClusCfgCommand::SetNumRequiredParameters( int xNumRequiredParameters )
  692. {
  693. m_xNumRequiredParameters = xNumRequiredParameters;
  694. }
  695. /////////////////////////////////////////////////////////////////////////////
  696. //++
  697. //
  698. // GetNumRequiredParameters
  699. //
  700. // Routine Description:
  701. // This function returns the contents of the m_xNumRequiredParameters
  702. // member of a CClusCfgCommand object.
  703. //
  704. // Arguments:
  705. // None
  706. //
  707. // Return Value:
  708. // the number of parameters required by the command which is described by the
  709. // CClusCfgCommand object.
  710. //
  711. //--
  712. /////////////////////////////////////////////////////////////////////////////
  713. int CClusCfgCommand::GetNumRequiredParameters( void )
  714. {
  715. return ( m_xNumRequiredParameters );
  716. }
  717. /////////////////////////////////////////////////////////////////////////////
  718. //++
  719. //
  720. // SetNumOptionalParameters
  721. //
  722. // Routine Description:
  723. // This function sets the m_xNumOptionalParameters member of a CClusCfgCommand
  724. // object.
  725. //
  726. // Arguments:
  727. // xNumOptionalParameters - the number of parameters accepted by the command
  728. // which is described by the CClusCfgCommand object.
  729. //
  730. // Return Value:
  731. // None
  732. //
  733. //--
  734. /////////////////////////////////////////////////////////////////////////////
  735. void CClusCfgCommand::SetNumOptionalParameters( int xNumOptionalParameters )
  736. {
  737. m_xNumOptionalParameters = xNumOptionalParameters;
  738. }
  739. /////////////////////////////////////////////////////////////////////////////
  740. //++
  741. //
  742. // GetNumOptionalParameters
  743. //
  744. // Routine Description:
  745. // This function returns the contents of the m_xNumOptionalParameters
  746. // member of a CClusCfgCommand object.
  747. //
  748. // Arguments:
  749. // None
  750. //
  751. // Return Value:
  752. // the number of parameters accepted by the command which is described by the
  753. // CClusCfgCommand object.
  754. //
  755. //--
  756. /////////////////////////////////////////////////////////////////////////////
  757. int CClusCfgCommand::GetNumOptionalParameters( void )
  758. {
  759. return ( m_xNumOptionalParameters );
  760. }
  761. /////////////////////////////////////////////////////////////////////////////
  762. //++
  763. //
  764. // Reset
  765. //
  766. // Routine Description:
  767. // This function sets all datamembers of a CClusCfgCommand object to zero.
  768. //
  769. // Arguments:
  770. // None
  771. //
  772. // Return Value:
  773. // None
  774. //
  775. //--
  776. /////////////////////////////////////////////////////////////////////////////
  777. void CClusCfgCommand::Reset( void )
  778. {
  779. SetNextCommandPointer( NULL );
  780. SetCommandStringId( 0L );
  781. SetCommandStringPointer( NULL );
  782. SetCommandSubStringId( 0L );
  783. SetCommandSubStringPointer( NULL );
  784. SetNumRequiredParameters( 0 );
  785. SetNumOptionalParameters( 0 );
  786. }
  787. /////////////////////////////////////////////////////////////////////////////
  788. //++
  789. //
  790. // GetCommandStringId
  791. //
  792. // Routine Description:
  793. // This function returns the m_dwCommandStringId member of a CClusCfgCommand object.
  794. //
  795. // Arguments:
  796. // None
  797. //
  798. // Return Value:
  799. // A DWORD indicating the string resource ID of the command string.
  800. //
  801. //--
  802. /////////////////////////////////////////////////////////////////////////////
  803. DWORD CClusCfgCommand::GetCommandStringId( void )
  804. {
  805. return ( m_dwCommandStringId );
  806. }
  807. /////////////////////////////////////////////////////////////////////////////
  808. //++
  809. //
  810. // SetCommandStringId
  811. //
  812. // Routine Description:
  813. // This function sets the m_dwCommandStringId member of a CClusCfgCommand object.
  814. //
  815. // Arguments:
  816. // dwCommandStringId - the string resource ID of the command string.
  817. //
  818. // Return Value:
  819. // TRUE - indicates success
  820. //
  821. //--
  822. /////////////////////////////////////////////////////////////////////////////
  823. BOOL CClusCfgCommand::SetCommandStringId( DWORD dwCommandStringId )
  824. {
  825. BOOL fReturnValue = TRUE;
  826. m_dwCommandStringId = dwCommandStringId;
  827. return ( fReturnValue );
  828. }
  829. /////////////////////////////////////////////////////////////////////////////
  830. //++
  831. //
  832. // GetCommandSubStringId
  833. //
  834. // Routine Description:
  835. // This function returns the m_dwCommandSubStringId member of a CClusCfgCommand object.
  836. //
  837. // Arguments:
  838. // None
  839. //
  840. // Return Value:
  841. // A DWORD indicating the string resource ID of the command sub-string.
  842. //
  843. //--
  844. /////////////////////////////////////////////////////////////////////////////
  845. DWORD CClusCfgCommand::GetCommandSubStringId( void )
  846. {
  847. return ( m_dwCommandSubStringId );
  848. }
  849. /////////////////////////////////////////////////////////////////////////////
  850. //++
  851. //
  852. // SetCommandSubStringId
  853. //
  854. // Routine Description:
  855. // This function sets the m_dwCommandSubStringId member of a CClusCfgCommand object.
  856. //
  857. // Arguments:
  858. // dwCommandSubStringId - the string resource ID of the command string.
  859. //
  860. // Return Value:
  861. // TRUE - indicates success
  862. //
  863. //--
  864. /////////////////////////////////////////////////////////////////////////////
  865. BOOL CClusCfgCommand::SetCommandSubStringId( DWORD dwCommandSubStringId )
  866. {
  867. BOOL fReturnValue = TRUE;
  868. m_dwCommandSubStringId = dwCommandSubStringId;
  869. return ( fReturnValue );
  870. }
  871. /////////////////////////////////////////////////////////////////////////////
  872. //++
  873. //
  874. // SetCommandStringPointer
  875. //
  876. // Routine Description:
  877. // This function sets the m_ptszCommandString member of a CClusCfgCommand object.
  878. //
  879. // Arguments:
  880. // pAddress - the value to which the command string pointer should be set.
  881. //
  882. // Return Value:
  883. // TRUE - indicates success
  884. //
  885. // Note:
  886. // IT IS THE CALLER'S RESPONSIBILITY TO AVOID MEMORY LEAKS WHEN USING THIS FUNCTION!
  887. //
  888. //--
  889. /////////////////////////////////////////////////////////////////////////////
  890. BOOL CClusCfgCommand::SetCommandStringPointer( LPTSTR pAddress )
  891. {
  892. BOOL fReturnValue = TRUE;
  893. m_ptszCommandString = pAddress;
  894. return ( fReturnValue );
  895. }
  896. /////////////////////////////////////////////////////////////////////////////
  897. //++
  898. //
  899. // SetCommandSubStringPointer
  900. //
  901. // Routine Description:
  902. // This function sets the m_ptszCommandSubString member of a CClusCfgCommand object.
  903. //
  904. // Arguments:
  905. // pAddress - the value to which the command sub-string pointer should be set.
  906. //
  907. // Return Value:
  908. // TRUE - indicates success
  909. //
  910. // Note:
  911. // IT IS THE CALLER'S RESPONSIBILITY TO AVOID MEMORY LEAKS WHEN USING THIS FUNCTION!
  912. //
  913. //--
  914. /////////////////////////////////////////////////////////////////////////////
  915. BOOL CClusCfgCommand::SetCommandSubStringPointer( LPTSTR pAddress )
  916. {
  917. BOOL fReturnValue = TRUE;
  918. m_ptszCommandSubString = pAddress;
  919. return ( fReturnValue );
  920. }
  921. /////////////////////////////////////////////////////////////////////////////
  922. //++
  923. //
  924. // GetCommandSubStringPointer
  925. //
  926. // Routine Description:
  927. // This function returns the m_ptszCommandSubString member of a CClusCfgCommand object.
  928. //
  929. // Arguments:
  930. // None
  931. //
  932. // Return Value:
  933. // The contents of the m_ptszCommandSubString member
  934. //
  935. //--
  936. /////////////////////////////////////////////////////////////////////////////
  937. LPTSTR CClusCfgCommand::GetCommandSubStringPointer( void )
  938. {
  939. return ( m_ptszCommandSubString );
  940. }
  941. /////////////////////////////////////////////////////////////////////////////
  942. //++
  943. //
  944. // GetCommandStringPointer
  945. //
  946. // Routine Description:
  947. // This function returns the m_ptszCommandString member of a CClusCfgCommand object.
  948. //
  949. // Arguments:
  950. // None
  951. //
  952. // Return Value:
  953. // The contents of the m_ptszCommandString member
  954. //
  955. //--
  956. /////////////////////////////////////////////////////////////////////////////
  957. LPTSTR CClusCfgCommand::GetCommandStringPointer( void )
  958. {
  959. return ( m_ptszCommandString );
  960. }