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.

950 lines
21 KiB

  1. /*
  2. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  3. * All rights reserved
  4. *
  5. * $Revision: 6 $
  6. * $Date: 7/08/02 6:38p $
  7. */
  8. #include <windows.h>
  9. #pragma hdrstop
  10. #define ARRAYSIZE(rg) (sizeof(rg)/sizeof((rg)[0]))
  11. // #define DEBUGSTR 1
  12. #define DO_RAW_MODE 1
  13. #include <string.h>
  14. #include "stdtyp.h"
  15. #include "mc.h"
  16. #include "sf.h"
  17. #include <tdll\assert.h>
  18. #include "file_io.h"
  19. #include "globals.h"
  20. #include "session.h"
  21. #include "sess_ids.h"
  22. #include "tdll.h"
  23. #include "htchar.h"
  24. #include "open_msc.h"
  25. #include <term\res.h>
  26. #include "capture.h"
  27. #include "capture.hh"
  28. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. * FUNCTION:
  30. * CreateCaptureFileHandle
  31. *
  32. * DESCRIPTION:
  33. * This function is called to create a capture file handle and fill it with
  34. * some reasonable set of defaults.
  35. *
  36. * PARAMETERS:
  37. * hSession -- the session handle
  38. *
  39. * RETURNS:
  40. * A capture file handle or ZERO if there was an error.
  41. *
  42. */
  43. HCAPTUREFILE CreateCaptureFileHandle(const HSESSION hSession)
  44. {
  45. int nRet;
  46. STCAPTURE *pST = NULL; // REV 8/27/98
  47. pST = (STCAPTURE *)malloc(sizeof(STCAPTURE));
  48. if (pST == (STCAPTURE *)0)
  49. goto CCFHexit;
  50. memset(pST, 0, sizeof(STCAPTURE));
  51. nRet = InitializeCaptureFileHandle(hSession, (HCAPTUREFILE)pST);
  52. if (nRet == 0)
  53. return (HCAPTUREFILE)pST;
  54. CCFHexit:
  55. if (pST != (STCAPTURE *)0)
  56. {
  57. if (pST->pszInternalCaptureName != (LPTSTR)0)
  58. {
  59. free(pST->pszInternalCaptureName);
  60. pST->pszInternalCaptureName = NULL;
  61. }
  62. if (pST->pszDefaultCaptureName != (LPTSTR)0)
  63. {
  64. free(pST->pszDefaultCaptureName);
  65. pST->pszDefaultCaptureName = NULL;
  66. }
  67. if (pST->pszTempCaptureName != (LPTSTR)0)
  68. {
  69. free(pST->pszTempCaptureName);
  70. pST->pszTempCaptureName = NULL;
  71. }
  72. free(pST);
  73. pST = NULL;
  74. }
  75. return (HCAPTUREFILE)0;
  76. }
  77. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  78. * FUNCTION:
  79. * DestroyCaptureFileHandle
  80. *
  81. * DESCRIPTION:
  82. * This function is called to free up all the resources that are associated
  83. * with the capture file handle. After this, it is GONE.
  84. *
  85. * PARAMETERS:
  86. * hCapt -- the capture handle
  87. *
  88. * RETURNS:
  89. * Nothing.
  90. *
  91. */
  92. void DestroyCaptureFileHandle(HCAPTUREFILE hCapt)
  93. {
  94. STCAPTURE *pST = NULL;
  95. pST = (STCAPTURE *)hCapt;
  96. assert(pST);
  97. if (pST != (STCAPTURE *)0)
  98. {
  99. if (pST->hCaptureFile != NULL)
  100. {
  101. fio_close(pST->hCaptureFile);
  102. }
  103. pST->hCaptureFile = NULL;
  104. if (pST->pszDefaultCaptureName != (LPTSTR)0)
  105. {
  106. free(pST->pszDefaultCaptureName);
  107. pST->pszDefaultCaptureName = NULL;
  108. }
  109. if (pST->pszInternalCaptureName != (LPTSTR)0)
  110. {
  111. free(pST->pszInternalCaptureName);
  112. pST->pszInternalCaptureName = NULL;
  113. }
  114. if (pST->pszTempCaptureName != (LPTSTR)0)
  115. {
  116. free(pST->pszTempCaptureName);
  117. pST->pszTempCaptureName = NULL;
  118. }
  119. if (pST->hMenu)
  120. {
  121. /* We only destroy it if it is not in use */
  122. switch (pST->nState)
  123. {
  124. case CPF_CAPTURE_ON:
  125. case CPF_CAPTURE_PAUSE:
  126. case CPF_CAPTURE_RESUME:
  127. DestroyMenu(pST->hMenu);
  128. break;
  129. case CPF_CAPTURE_OFF:
  130. default:
  131. break;
  132. }
  133. }
  134. free(pST);
  135. pST = NULL;
  136. }
  137. }
  138. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  139. * FUNCTION:
  140. * InitializeCaptureFileHandle
  141. *
  142. * DESCRIPTION:
  143. * This function is called to set the capture file handle to a known state
  144. *
  145. * PARAMETERS:
  146. * hSession -- the session handle
  147. *
  148. * RETURNS:
  149. * ZERO if everything was OK, otherwise an error code
  150. */
  151. int InitializeCaptureFileHandle(const HSESSION hSession, HCAPTUREFILE hCapt)
  152. {
  153. STCAPTURE *pST = (STCAPTURE *)hCapt;
  154. int nLen;
  155. LPTSTR pszStr;
  156. TCHAR acBuffer[FNAME_LEN];
  157. assert(pST);
  158. TCHAR_Fill(acBuffer, TEXT('\0'), sizeof(acBuffer) / sizeof(TCHAR)); // REV 8/27/98
  159. pST->hSession = hSession;
  160. /* Put together a reasonable default for the capture file */
  161. //Changed to remember the working folder path - mpt 8-18-99
  162. if ( !GetWorkingDirectory(acBuffer, sizeof(acBuffer) / sizeof(TCHAR)) )
  163. {
  164. GetCurrentDirectory(sizeof(acBuffer) / sizeof(TCHAR), acBuffer);
  165. }
  166. pszStr = StrCharLast(acBuffer);
  167. if (*pszStr != TEXT('\\'))
  168. StrCharCat(pszStr, TEXT("\\"));
  169. /* Decide if this should be in the resource strings */
  170. // StrCharCat(acBuffer, TEXT("CAPTURE.TXT"));
  171. pszStr = StrCharEnd(acBuffer);
  172. LoadString(glblQueryDllHinst(),
  173. IDS_CPF_CAP_FILE,
  174. pszStr,
  175. (int)(sizeof(acBuffer) - (pszStr - acBuffer) / sizeof(TCHAR)));
  176. nLen = StrCharGetByteCount(acBuffer) + 1;
  177. if (pST->pszInternalCaptureName != (LPTSTR)0)
  178. {
  179. free(pST->pszInternalCaptureName);
  180. pST->pszInternalCaptureName = NULL;
  181. }
  182. pST->pszInternalCaptureName = (LPTSTR)malloc((unsigned int)nLen * sizeof(TCHAR));
  183. if (pST->pszInternalCaptureName == (LPTSTR)0)
  184. goto ICFHexit;
  185. StrCharCopyN(pST->pszInternalCaptureName, acBuffer, nLen * sizeof(TCHAR));
  186. if (pST->pszDefaultCaptureName != (LPTSTR)0)
  187. free(pST->pszDefaultCaptureName);
  188. pST->pszDefaultCaptureName = (LPTSTR)0;
  189. if (pST->pszTempCaptureName != (LPTSTR)0)
  190. free(pST->pszTempCaptureName);
  191. pST->pszTempCaptureName = (LPTSTR)0;
  192. #if defined(DO_RAW_MODE)
  193. pST->nDefaultCaptureMode = CPF_MODE_RAW;
  194. pST->nTempCaptureMode = CPF_MODE_RAW;
  195. #else
  196. pST->nDefaultCaptureMode = CPF_MODE_LINE;
  197. pST->nTempCaptureMode = CPF_MODE_LINE;
  198. #endif
  199. pST->nDefaultFileMode = CPF_FILE_APPEND;
  200. pST->nTempFileMode = CPF_FILE_APPEND;
  201. pST->nState = CPF_CAPTURE_OFF;
  202. return 0;
  203. ICFHexit:
  204. if (pST != (STCAPTURE *)0)
  205. {
  206. if (pST->pszInternalCaptureName != (LPTSTR)0)
  207. {
  208. free(pST->pszInternalCaptureName);
  209. pST->pszInternalCaptureName = NULL;
  210. }
  211. }
  212. return CPF_NO_MEMORY;
  213. }
  214. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  215. * FUNCTION:
  216. * LoadCaptureFileHandle
  217. *
  218. * DESCRIPTION:
  219. * This function is called to load the capture file settings from the system
  220. * file.
  221. *
  222. * PARAMETERS:
  223. * hSession -- the session handle
  224. *
  225. * RETURNS:
  226. * ZERO if everythis was OK, otherwise an error code.
  227. *
  228. */
  229. int LoadCaptureFileHandle(HCAPTUREFILE hCapt)
  230. {
  231. int nRet = 0;
  232. long lSize;
  233. STCAPTURE *pOld;
  234. pOld = (STCAPTURE *)hCapt;
  235. assert(pOld);
  236. if (pOld->hCaptureFile != NULL)
  237. {
  238. fio_close(pOld->hCaptureFile);
  239. }
  240. pOld->hCaptureFile = NULL;
  241. pOld->nState = CPF_CAPTURE_OFF;
  242. nRet = InitializeCaptureFileHandle(pOld->hSession, hCapt);
  243. if (nRet)
  244. return nRet;
  245. lSize = 0;
  246. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  247. SFID_CPF_MODE,
  248. &lSize, NULL);
  249. if (lSize)
  250. {
  251. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  252. SFID_CPF_MODE,
  253. &lSize,
  254. &pOld->nDefaultCaptureMode);
  255. if (pOld->nDefaultCaptureMode == 0)
  256. #if defined(DO_RAW_MODE)
  257. pOld->nDefaultCaptureMode = CPF_MODE_RAW;
  258. #else
  259. pOld->nDefaultCaptureMode = CPF_MODE_LINE;
  260. #endif
  261. pOld->nTempCaptureMode = pOld->nDefaultCaptureMode;
  262. }
  263. lSize = 0;
  264. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  265. SFID_CPF_FILE,
  266. &lSize, NULL);
  267. if (lSize)
  268. {
  269. lSize = sizeof(int);
  270. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  271. SFID_CPF_FILE,
  272. &lSize,
  273. &pOld->nDefaultFileMode);
  274. if (pOld->nDefaultFileMode == 0)
  275. pOld->nDefaultFileMode = CPF_FILE_APPEND;
  276. pOld->nTempFileMode = pOld->nDefaultFileMode;
  277. }
  278. lSize = 0;
  279. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  280. SFID_CPF_FILENAME,
  281. &lSize, NULL);
  282. if (lSize)
  283. {
  284. LPTSTR pszName;
  285. pszName = (LPTSTR)0;
  286. pszName = malloc((unsigned int)lSize);
  287. if (!pszName)
  288. {
  289. return CPF_NO_MEMORY;
  290. }
  291. sfGetSessionItem(sessQuerySysFileHdl(pOld->hSession),
  292. SFID_CPF_FILENAME,
  293. &lSize, pszName);
  294. if (pOld->pszDefaultCaptureName)
  295. {
  296. free(pOld->pszDefaultCaptureName);
  297. pOld->pszDefaultCaptureName = NULL;
  298. }
  299. pOld->pszDefaultCaptureName = pszName;
  300. if (pOld->pszTempCaptureName)
  301. free(pOld->pszTempCaptureName);
  302. pOld->pszTempCaptureName = (LPTSTR)0;
  303. }
  304. return 0;
  305. }
  306. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  307. * FUNCTION:
  308. * SaveCaptureFileHandle
  309. *
  310. * DESCRIPTION:
  311. * This function is called to save whatever has been changed in the capture
  312. * file handle out to the system file.
  313. *
  314. * PARAMETERS:
  315. * hCapt -- the capture handle
  316. *
  317. * RETURNS:
  318. * ZERO if everything is OK, otherwise an error code
  319. *
  320. */
  321. int SaveCaptureFileHandle(HCAPTUREFILE hCapt)
  322. {
  323. STCAPTURE *pST;
  324. long lSize;
  325. pST = (STCAPTURE *)hCapt;
  326. assert(pST);
  327. if (pST != (STCAPTURE *)0)
  328. {
  329. /* Need to save the new value */
  330. if (pST->pszDefaultCaptureName)
  331. {
  332. lSize = StrCharGetByteCount(pST->pszDefaultCaptureName);
  333. if (lSize > 0)
  334. {
  335. lSize += 1;
  336. lSize *= sizeof(TCHAR);
  337. sfPutSessionItem(sessQuerySysFileHdl(pST->hSession),
  338. SFID_CPF_FILENAME,
  339. (unsigned long)lSize,
  340. pST->pszDefaultCaptureName);
  341. }
  342. }
  343. /* Need to save the new value */
  344. sfPutSessionItem(sessQuerySysFileHdl(pST->hSession),
  345. SFID_CPF_MODE,
  346. sizeof(int),
  347. &pST->nDefaultCaptureMode);
  348. /* Need to save the new value */
  349. sfPutSessionItem(sessQuerySysFileHdl(pST->hSession),
  350. SFID_CPF_FILE,
  351. sizeof(int),
  352. &pST->nDefaultFileMode);
  353. }
  354. return 0;
  355. }
  356. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  357. * FUNCTION:
  358. * cpfGetCaptureFilename
  359. *
  360. * DESCRIPTION:
  361. * This function is used to get the default capture file name from the
  362. * handle in order to load it into the dialog box.
  363. *
  364. * PARAMETERS:
  365. * hCapt -- the capture handle
  366. * pszName -- pointer to where to copy the file name
  367. * nLen -- size of the buffer
  368. *
  369. * RETURNS:
  370. * ZERO if everything is OK, otherwise an error code
  371. *
  372. */
  373. int cpfGetCaptureFilename(HCAPTUREFILE hCapt,
  374. LPTSTR pszName,
  375. const int nLen)
  376. {
  377. STCAPTURE *pST;
  378. LPTSTR pszStr;
  379. pST = (STCAPTURE *)hCapt;
  380. assert(pST);
  381. if (pST != (STCAPTURE *)0)
  382. {
  383. if ((pszStr = pST->pszTempCaptureName) == (LPTSTR)0)
  384. {
  385. if ((pszStr = pST->pszDefaultCaptureName) == (LPTSTR)0)
  386. pszStr = pST->pszInternalCaptureName;
  387. }
  388. if (StrCharGetByteCount(pszStr) >= nLen)
  389. return CPF_SIZE_ERROR;
  390. StrCharCopyN(pszName, pszStr, nLen);
  391. }
  392. return 0;
  393. }
  394. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  395. * FUNCTION:
  396. * cpfSetCaptureFilename
  397. *
  398. * DESCRIPTION:
  399. * This function is called to set the name of the capture file. If the mode
  400. * flag is FALSE, only the temporary name is set. If the mode file is TRUE,
  401. * both the temporary and default names are set.
  402. *
  403. * PARAMETERS:
  404. * hCapt -- the capture handle
  405. * pszName -- the file name
  406. * nMode -- the mode flag, see above
  407. *
  408. * RETURNS:
  409. * ZERO if everything is OK, otherwise an error code
  410. *
  411. */
  412. int cpfSetCaptureFilename(HCAPTUREFILE hCapt,
  413. LPCTSTR pszName,
  414. const int nMode)
  415. {
  416. int nRet = 0;
  417. int nLen;
  418. LPTSTR pszTemp;
  419. LPTSTR pszDefault;
  420. STCAPTURE *pST;
  421. pST = (STCAPTURE *)hCapt;
  422. assert(pST);
  423. if (pST != (STCAPTURE *)0)
  424. {
  425. nLen = StrCharGetByteCount(pszName) + 1;
  426. pszTemp = (LPTSTR)0;
  427. pszDefault = (LPTSTR)0;
  428. pszTemp = (LPTSTR)malloc((unsigned int)nLen * sizeof(TCHAR));
  429. if (pszTemp == (LPTSTR)0)
  430. {
  431. nRet = CPF_NO_MEMORY;
  432. goto SCFexit;
  433. }
  434. StrCharCopyN(pszTemp, pszName, nLen);
  435. if (nMode)
  436. {
  437. pszDefault = (LPTSTR)malloc((unsigned int)nLen * sizeof(TCHAR));
  438. if (pszDefault == (LPTSTR)0)
  439. {
  440. nRet = CPF_NO_MEMORY;
  441. goto SCFexit;
  442. }
  443. StrCharCopyN(pszDefault, pszName, nLen);
  444. }
  445. /* Got the memory that we need */
  446. if (pST->pszTempCaptureName)
  447. {
  448. free(pST->pszTempCaptureName);
  449. pST->pszTempCaptureName = NULL;
  450. }
  451. pST->pszTempCaptureName = pszTemp;
  452. if (nMode)
  453. {
  454. if (pST->pszDefaultCaptureName)
  455. {
  456. free(pST->pszDefaultCaptureName);
  457. pST->pszDefaultCaptureName = NULL;
  458. }
  459. pST->pszDefaultCaptureName = pszDefault;
  460. }
  461. }
  462. return nRet;
  463. SCFexit:
  464. if (pszTemp)
  465. {
  466. free(pszTemp);
  467. pszTemp = NULL;
  468. }
  469. if (pszDefault)
  470. {
  471. free(pszDefault);
  472. pszDefault = NULL;
  473. }
  474. return nRet;
  475. }
  476. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  477. * FUNCTION:
  478. * cpfGetCaptureMode
  479. *
  480. * DESCRIPTION:
  481. * This function returns the current default capture mode.
  482. *
  483. * PARAMETERS:
  484. * hCapt -- the capture handle
  485. *
  486. * RETURNS:
  487. * The current capture mode.
  488. *
  489. */
  490. int cpfGetCaptureMode(HCAPTUREFILE hCapt)
  491. {
  492. STCAPTURE *pST;
  493. pST = (STCAPTURE *)hCapt;
  494. assert(pST);
  495. if (pST != (STCAPTURE *)0)
  496. {
  497. return pST->nDefaultCaptureMode;
  498. }
  499. return 0;
  500. }
  501. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  502. * FUNCTION:
  503. * cpfSetCaptureMode
  504. *
  505. * DESCRIPTION:
  506. * This function changes the capture mode. If the mode flag is set to FALSE,
  507. * only the temporary mode is set. If the mode flag is set to TRUE, both the
  508. * temporary and default mode flags are set.
  509. *
  510. * PARAMETERS:
  511. * hCapt -- the capture handle
  512. * nCaptMode -- the capture mode
  513. * nModeFlag -- the mode flag
  514. *
  515. * RETURNS:
  516. * ZERO of everything is OK, otherwise an error code
  517. *
  518. */
  519. int cpfSetCaptureMode(HCAPTUREFILE hCapt,
  520. const int nCaptMode,
  521. const int nModeFlag)
  522. {
  523. STCAPTURE *pST;
  524. pST = (STCAPTURE *)hCapt;
  525. assert(pST);
  526. if (pST != (STCAPTURE *)0)
  527. {
  528. pST->nTempCaptureMode = nCaptMode;
  529. if (nModeFlag)
  530. pST->nDefaultCaptureMode = nCaptMode;
  531. }
  532. return 0;
  533. }
  534. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  535. * FUNCTION:
  536. * cpfGetCaptureFileflag
  537. *
  538. * DESCRIPTION:
  539. * This function is called to get the file save flags for capture to file.
  540. *
  541. * PARAMETERS:
  542. * hCapt -- the capture handle
  543. *
  544. * RETURNS:
  545. * The file save flags.
  546. *
  547. */
  548. int cpfGetCaptureFileflag(HCAPTUREFILE hCapt)
  549. {
  550. STCAPTURE *pST;
  551. pST = (STCAPTURE *)hCapt;
  552. assert(pST);
  553. if (pST != (STCAPTURE *)0)
  554. {
  555. return pST->nDefaultFileMode;
  556. }
  557. return 0;
  558. }
  559. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  560. * FUNCTION:
  561. * cpfSetCaptureFileflag
  562. *
  563. * DESCRIPTION:
  564. * This function is called to set the file save mode flag. If the mode flag
  565. * is set to FALSE, only the temporary value is changed, if the mode flag is
  566. * TRUE, both the temporary and default values are changed.
  567. *
  568. * PARAMETERS:
  569. * hCapt -- the capture handle
  570. * nSaveMode -- the new file save mode value
  571. * nModeFlag -- the mode flag, see above
  572. *
  573. * RETURNS:
  574. * ZERO if everything is OK, otherwise an error code.
  575. *
  576. */
  577. int cpfSetCaptureFileflag(HCAPTUREFILE hCapt,
  578. const int nSaveMode,
  579. const int nModeFlag)
  580. {
  581. STCAPTURE *pST;
  582. pST = (STCAPTURE *)hCapt;
  583. assert(pST);
  584. if (pST != (STCAPTURE *)0)
  585. {
  586. pST->nTempFileMode = nSaveMode;
  587. if (nModeFlag)
  588. pST->nDefaultFileMode = nSaveMode;
  589. }
  590. return 0;
  591. }
  592. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  593. * FUNCTION:
  594. * cpfGetCaptureState
  595. *
  596. * DESCRIPTION:
  597. * This function returns a value that reflects the state of capturing. It can
  598. * be on, off, or paused. See "capture.h" for the actual values.
  599. *
  600. * PARAMETERS:
  601. * hCapt -- the capture handle
  602. *
  603. * RETURNS:
  604. * The current state of capturing.
  605. *
  606. */
  607. int cpfGetCaptureState(HCAPTUREFILE hCapt)
  608. {
  609. STCAPTURE *pST;
  610. pST = (STCAPTURE *)hCapt;
  611. assert(pST);
  612. if (pST != (STCAPTURE *)0)
  613. {
  614. return pST->nState;
  615. }
  616. return 0;
  617. }
  618. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  619. * FUNCTION:
  620. * cpfSetCaptureState
  621. *
  622. * DESCRIPTION:
  623. * This function changes the state of capturing. It can turn it on, off,
  624. * pause capturing or resume capturing.
  625. *
  626. * PARAMETERS:
  627. * hCapt -- the capture handle
  628. * nState -- the new state to change to
  629. *
  630. * RETURNS:
  631. * The previous state of capturing.
  632. *
  633. */
  634. int cpfSetCaptureState(HCAPTUREFILE hCapt, int nState)
  635. {
  636. int nOldState = 0;
  637. STCAPTURE *pST;
  638. LPTSTR pszStr;
  639. pST = (STCAPTURE *)hCapt;
  640. assert(pST);
  641. if (pST != (STCAPTURE *)0)
  642. {
  643. switch (nState)
  644. {
  645. case CPF_CAPTURE_ON:
  646. /* Open the capture file */
  647. if (pST->hCaptureFile)
  648. {
  649. /*
  650. * We get here one of two ways. The first and expected
  651. * way is by selecting "Resume" from the menu. This is
  652. * not a problem. the other way is that there is still
  653. * a problem with the menus. Go figure.
  654. */
  655. break;
  656. }
  657. if ((pszStr = pST->pszTempCaptureName) == (LPTSTR)0)
  658. {
  659. if ((pszStr = pST->pszDefaultCaptureName) == (LPTSTR)0)
  660. pszStr = pST->pszInternalCaptureName;
  661. }
  662. switch (pST->nTempFileMode)
  663. {
  664. default:
  665. case CPF_FILE_OVERWRITE:
  666. pST->hCaptureFile = fio_open(pszStr,
  667. FIO_CREATE | FIO_WRITE);
  668. assert(pST->hCaptureFile);
  669. break;
  670. case CPF_FILE_APPEND:
  671. pST->hCaptureFile = fio_open(pszStr,
  672. FIO_WRITE | FIO_APPEND);
  673. assert(pST->hCaptureFile);
  674. break;
  675. case CPF_FILE_REN_SEQ:
  676. assert(TRUE);
  677. break;
  678. case CPF_FILE_REN_DATE:
  679. assert(TRUE);
  680. break;
  681. }
  682. break;
  683. case CPF_CAPTURE_OFF:
  684. /* Close the capture file */
  685. assert(pST->hCaptureFile);
  686. fio_close(pST->hCaptureFile);
  687. pST->hCaptureFile = NULL;
  688. break;
  689. default:
  690. break;
  691. }
  692. nOldState = pST->nState;
  693. pST->nState = nState;
  694. }
  695. return nOldState;
  696. }
  697. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  698. * FUNCTION:
  699. *
  700. * DESCRIPTION:
  701. *
  702. * PARAMETERS:
  703. *
  704. * RETURNS:
  705. *
  706. */
  707. HMENU cpfGetCaptureMenu(HCAPTUREFILE hCapt)
  708. {
  709. HMENU hRet = (HMENU)0;
  710. STCAPTURE *pST;
  711. pST = (STCAPTURE *)hCapt;
  712. assert(pST);
  713. if (pST != (STCAPTURE *)0)
  714. {
  715. // The SetMenuItemInfo() call will destroy this submenu whenever
  716. // its replaced by something else (like a plain menu item). The
  717. // result was you could go into capture once, but the second time
  718. // you activated the menu it wouldn't load because the handle was
  719. // no longer valid. So I moved the code to load the menu here. - mrw
  720. //
  721. if (!IsMenu(pST->hMenu))
  722. pST->hMenu = LoadMenu(glblQueryDllHinst(), TEXT("MenuCapture"));
  723. assert(pST->hMenu);
  724. hRet = pST->hMenu;
  725. }
  726. return hRet;
  727. }
  728. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  729. * FUNCTION:
  730. * CaptureChar
  731. *
  732. * DESCRIPTION:
  733. * This function is called whenever the emulators have a character that might
  734. * need to be capture.
  735. *
  736. * PARAMETERS:
  737. * hCapt -- the capture handle
  738. * nFlags -- capture flags (must match the capture state we are in)
  739. * cData -- the character to be captured
  740. *
  741. * RETURNS:
  742. *
  743. */
  744. void CaptureChar(HCAPTUREFILE hCapt, int nFlags, ECHAR cData)
  745. {
  746. STCAPTURE *pST = (STCAPTURE *)hCapt;
  747. int nLen = 0;
  748. int i = 0;
  749. TCHAR cChar[3];
  750. if (pST == NULL)
  751. {
  752. assert(pST);
  753. return;
  754. }
  755. /* Check the state */
  756. if (pST->nState == CPF_CAPTURE_OFF)
  757. return;
  758. if (pST->nState == CPF_CAPTURE_PAUSE)
  759. return;
  760. /* Check the file next */
  761. if (pST->hCaptureFile == NULL)
  762. return;
  763. /* Check the mode */
  764. if (pST->nTempCaptureMode != nFlags)
  765. return;
  766. DbgOutStr("Cc 0x%x %c (0x%x)\r\n", nFlags, cData, cData, 0,0);
  767. CnvrtECHARtoTCHAR(cChar, ARRAYSIZE(cChar), cData);
  768. /* Write out the character */
  769. // fio_putc(cChar, pST->hCaptureFile);
  770. // nLen = StrCharGetByteCount(cChar);
  771. // for (i = 0; i < nLen; i++)
  772. // fio_putc(cChar[i], pST->hCaptureFile);
  773. fio_putc(cChar[0], pST->hCaptureFile);
  774. if (cChar[1])
  775. fio_putc(cChar[1], pST->hCaptureFile);
  776. }
  777. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  778. * FUNCTION:
  779. * CaptureLine
  780. *
  781. * DESCRIPTION:
  782. * This function is called whenever the emulators have a line that might need
  783. * to be captured.
  784. *
  785. * PARAMETERS:
  786. * hCapt -- the capture handle
  787. * nFlags -- capture flags (must match the capture state we are in)
  788. * pszStr -- pointer to line to capture (sans <cr/lf>)
  789. *
  790. * RETURNS:
  791. *
  792. */
  793. void CaptureLine(HCAPTUREFILE hCapt, int nFlags, ECHAR *achStr, int nLen)
  794. {
  795. STCAPTURE *pST = (STCAPTURE *)hCapt;
  796. LPTSTR pchEnd = NULL;
  797. TCHAR *pszStr = NULL;
  798. if (pST == NULL)
  799. {
  800. assert(pST);
  801. return;
  802. }
  803. /* Check the state */
  804. if (pST->nState == CPF_CAPTURE_OFF)
  805. return;
  806. if (pST->nState == CPF_CAPTURE_PAUSE)
  807. return;
  808. /* Check the file next */
  809. if (pST->hCaptureFile == NULL)
  810. return;
  811. /* Check the mode */
  812. if (pST->nTempCaptureMode != nFlags)
  813. return;
  814. // Allocate space assuming every character is double byte
  815. pszStr = (TCHAR *)malloc(((unsigned int)StrCharGetEcharLen(achStr) +
  816. sizeof(ECHAR)) * sizeof(ECHAR));
  817. if (pszStr == NULL)
  818. {
  819. assert(FALSE);
  820. return;
  821. }
  822. CnvrtECHARtoMBCS(pszStr, ((unsigned long)StrCharGetEcharLen(achStr) + 1)
  823. * sizeof(ECHAR), achStr,
  824. StrCharGetEcharByteCount(achStr) + sizeof(ECHAR)); // mrw:5/17/95
  825. pchEnd = pszStr + (StrCharGetByteCount(pszStr) - 1);
  826. /* Write out the string */
  827. while (pszStr <= pchEnd)
  828. fio_putc(*pszStr++, pST->hCaptureFile);
  829. free(pszStr);
  830. pszStr = NULL;
  831. fio_putc(TEXT('\r'), pST->hCaptureFile);
  832. fio_putc(TEXT('\n'), pST->hCaptureFile);
  833. }
  834. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  835. * FUNCTION:
  836. *
  837. * DESCRIPTION:
  838. *
  839. * PARAMETERS:
  840. *
  841. * RETURNS:
  842. *
  843. */