Windows NT 4.0 source code leak
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.

976 lines
24 KiB

4 years ago
  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include "perfmon.h" // included by all source files
  5. #include "line.h" // external declarations for this file
  6. //#include <tchar.h> // for _tcsncpy
  7. #include "fileutil.h" // for FileRead, FileWrite
  8. #include "pmemory.h" // for MemoryXXX (mallloc-type) routines
  9. #include "perfdata.h" // for UpdateSystemData, et al
  10. #include "perfmops.h" // for InsertLine
  11. #include "system.h" // for SystemAdd
  12. #include "utils.h"
  13. #include "playback.h" // for PlayingBackLog
  14. #include "counters.h" // CounterEntry
  15. #include <string.h> // for strncpy
  16. #ifdef UNICODE
  17. #define _tcsncpy wcsncpy
  18. #else
  19. #define _tcsncpy strncpy
  20. #endif
  21. TCHAR LOCAL_SYS_CODE_NAME[] = TEXT("....") ;
  22. #define sizeofCodeName sizeof(LOCAL_SYS_CODE_NAME) / sizeof(TCHAR) - 1
  23. // Local Function prototype
  24. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  25. PPPERFSYSTEM ppSystemFirst,
  26. PPERFDATA *ppPerfData,
  27. HANDLE hFile,
  28. int LineType,
  29. PDISKLINE *ppDiskLine,
  30. DWORD *pSizeofDiskLine) ;
  31. //==========================================================================//
  32. // Exported Functions //
  33. //==========================================================================//
  34. PLINE LineAllocate (void)
  35. /*
  36. Effect: Allocate and initialize a Line data structure. Lines
  37. are used as the primary elements of both charts and
  38. alerts.
  39. Establish any representation invariants for the Line
  40. type.
  41. Also alllocate another structure, an array of data
  42. elements, iNumDataValues long.
  43. */
  44. { // LineAllocate
  45. PLINE pLine ;
  46. pLine = MemoryAllocate (sizeof (LINESTRUCT)) ;
  47. if (pLine)
  48. {
  49. // don't need to zero these again since MemoryAllocate is using
  50. // GMEM_ZEROPOINT
  51. // pLine->pLineNext = NULL ;
  52. // pLine->pLineCounterNext = NULL ;
  53. // do want to do this since (FLOAT)0.0 is not 0
  54. pLine->lnMinValue =
  55. pLine->lnMaxValue =
  56. pLine->lnAveValue = (FLOAT) 0.0 ;
  57. if (PlayingBackLog())
  58. {
  59. pLine->bFirstTime = FALSE ;
  60. }
  61. else
  62. {
  63. // pLine->bFirstTime = TRUE ;
  64. // we want to take 2 samples before plotting the first data
  65. pLine->bFirstTime = 2 ;
  66. }
  67. } // if
  68. return (pLine) ;
  69. } // LineAllocate
  70. void LineFree (PLINE pLine)
  71. { // LineFree
  72. // free any memory allocated by this line
  73. if (pLine->lnSystemName)
  74. MemoryFree (pLine->lnSystemName) ;
  75. if (pLine->lnObjectName)
  76. MemoryFree (pLine->lnObjectName) ;
  77. if (pLine->lnCounterName)
  78. MemoryFree (pLine->lnCounterName) ;
  79. if (pLine->lnInstanceName)
  80. MemoryFree (pLine->lnInstanceName) ;
  81. if (pLine->lnParentObjName)
  82. MemoryFree (pLine->lnParentObjName) ;
  83. if (pLine->lnPINName)
  84. MemoryFree (pLine->lnPINName) ;
  85. if (pLine->lpszAlertProgram)
  86. MemoryFree (pLine->lpszAlertProgram) ;
  87. if (pLine->hPen)
  88. DeletePen(pLine->hPen);
  89. if (pLine->hBrush)
  90. DeletePen(pLine->hBrush);
  91. if (pLine->lnValues)
  92. MemoryFree (pLine->lnValues) ;
  93. if (pLine->aiLogIndexes)
  94. MemoryFree (pLine->aiLogIndexes) ;
  95. MemoryFree (pLine) ;
  96. } // LineFree
  97. void LineAppend (PPLINE ppLineFirst,
  98. PLINE pLineNew)
  99. {
  100. PLINE pLine ;
  101. if (!*ppLineFirst)
  102. *ppLineFirst = pLineNew ;
  103. else
  104. { // else
  105. for (pLine = *ppLineFirst ;
  106. pLine->pLineNext ;
  107. pLine = pLine->pLineNext)
  108. /* nothing */ ;
  109. pLine->pLineNext = pLineNew ;
  110. } // else
  111. }
  112. BOOL LineRemove (PPLINE ppLineFirst,
  113. PLINE pLineRemove)
  114. {
  115. PLINE pLine ;
  116. if (*ppLineFirst == pLineRemove)
  117. {
  118. *ppLineFirst = (*ppLineFirst)->pLineNext ;
  119. return (TRUE) ;
  120. }
  121. for (pLine = *ppLineFirst ;
  122. pLine->pLineNext ;
  123. pLine = pLine->pLineNext)
  124. { // for
  125. if (pLine->pLineNext == pLineRemove)
  126. {
  127. pLine->pLineNext = pLineRemove->pLineNext ;
  128. return (TRUE) ;
  129. } // if
  130. } // for
  131. return (FALSE) ;
  132. } // LineRemove
  133. int NumLines (PLINE pLineFirst)
  134. { // NumLines
  135. PLINE pLine ;
  136. int iNumLines ;
  137. if (!pLineFirst)
  138. return (0) ;
  139. iNumLines = 0 ;
  140. for (pLine = pLineFirst ;
  141. pLine ;
  142. pLine = pLine->pLineNext)
  143. { // for
  144. iNumLines++ ;
  145. } // for
  146. return (iNumLines) ;
  147. } // NumLines
  148. LPTSTR LineInstanceName (PLINE pLine)
  149. {
  150. if (pLine->lnObject.NumInstances <= 0)
  151. return (NULL) ;
  152. else
  153. return (pLine->lnInstanceName) ;
  154. }
  155. LPTSTR LineParentName (PLINE pLine)
  156. {
  157. if (pLine->lnObject.NumInstances <= 0)
  158. return (NULL) ;
  159. else if (pLine->lnInstanceDef.ParentObjectTitleIndex)
  160. return (pLine->lnPINName) ;
  161. else
  162. return (NULL) ;
  163. }
  164. void LineCounterAppend (PPLINE ppLineFirst,
  165. PLINE pLineNew)
  166. {
  167. PLINE pLine ;
  168. if (!*ppLineFirst)
  169. *ppLineFirst = pLineNew ;
  170. else
  171. { // else
  172. for (pLine = *ppLineFirst ;
  173. pLine->pLineCounterNext ;
  174. pLine = pLine->pLineCounterNext)
  175. /* nothing */ ;
  176. pLine->pLineCounterNext = pLineNew ;
  177. } // else
  178. }
  179. BOOL EquivalentLine (PLINE pLine1,
  180. PLINE pLine2)
  181. { // LineEquivalent
  182. return (pstrsame (pLine1->lnCounterName, pLine2->lnCounterName) &&
  183. pstrsame (pLine1->lnInstanceName, pLine2->lnInstanceName) &&
  184. pstrsame (pLine1->lnPINName, pLine2->lnPINName) &&
  185. pstrsame (pLine1->lnObjectName, pLine2->lnObjectName) &&
  186. pstrsamei (pLine1->lnSystemName, pLine2->lnSystemName)) ;
  187. } // LineEquivalent
  188. PLINE FindEquivalentLine (PLINE pLineToFind,
  189. PLINE pLineFirst)
  190. {
  191. PLINE pLine = NULL;
  192. PLINE pLastEquivLine = NULL;
  193. for (pLine = pLineFirst ;
  194. pLine ;
  195. pLine = pLine->pLineNext) {
  196. if (EquivalentLine (pLine, pLineToFind)) {
  197. if (pLastEquivLine == NULL) {
  198. pLastEquivLine = pLine;
  199. } else {
  200. if (pLine->dwInstanceIndex > pLastEquivLine->dwInstanceIndex) {
  201. pLastEquivLine = pLine;
  202. }
  203. }
  204. }
  205. } // for
  206. return (pLastEquivLine) ;
  207. } // FindEquivalentLine
  208. // This routine is used only to read the system name from a disk string
  209. // It is mainly for performance improvement.
  210. LPTSTR DiskStringReadSys (PDISKSTRING pDS)
  211. { // DiskStringReadSys
  212. LPTSTR lpszText ;
  213. LPTSTR pDiskSysName ;
  214. int iIndex ;
  215. BOOL bLocalSysName = FALSE ;
  216. if (pDS->dwLength == 0)
  217. {
  218. return (NULL) ;
  219. }
  220. if (pDS->dwLength == sizeofCodeName)
  221. {
  222. // check for LOCAL_SYS_CODE_NAME
  223. bLocalSysName = TRUE ;
  224. pDiskSysName = (LPTSTR)((PBYTE) pDS + pDS->dwOffset) ;
  225. for (iIndex = 0 ; iIndex < sizeofCodeName; iIndex++, pDiskSysName++)
  226. {
  227. if (*pDiskSysName != LOCAL_SYS_CODE_NAME[iIndex])
  228. {
  229. bLocalSysName = FALSE ;
  230. break ;
  231. }
  232. }
  233. }
  234. if (bLocalSysName)
  235. {
  236. lpszText =
  237. MemoryAllocate ((lstrlen(LocalComputerName)+1) * sizeof(TCHAR)) ;
  238. if (lpszText)
  239. {
  240. lstrcpy (lpszText, LocalComputerName) ;
  241. }
  242. }
  243. else
  244. {
  245. lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  246. if (lpszText)
  247. {
  248. _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  249. pDS->dwLength) ;
  250. }
  251. }
  252. return (lpszText) ;
  253. } // DiskStringReadSys
  254. LPTSTR DiskStringRead (PDISKSTRING pDS)
  255. { // DiskStringRead
  256. LPTSTR lpszText ;
  257. if (pDS->dwLength == 0)
  258. {
  259. return (NULL) ;
  260. }
  261. lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  262. if (!lpszText)
  263. {
  264. return (NULL) ;
  265. }
  266. _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  267. pDS->dwLength) ;
  268. return (lpszText) ;
  269. } // DiskStringRead
  270. int DiskStringLength (LPTSTR lpszText)
  271. {
  272. if (!lpszText)
  273. return (0) ;
  274. else
  275. return (lstrlen (lpszText)) ;
  276. }
  277. PBYTE DiskStringCopy (PDISKSTRING pDS, LPTSTR lpszText, PBYTE pNextFree)
  278. {
  279. if (!lpszText)
  280. {
  281. pDS->dwOffset = 0 ;
  282. pDS->dwLength = 0 ;
  283. return (pNextFree) ;
  284. }
  285. else
  286. {
  287. pDS->dwOffset = pNextFree - (PBYTE) pDS ;
  288. pDS->dwLength = DiskStringLength (lpszText) ;
  289. _tcsncpy ((WCHAR *)pNextFree, (WCHAR *)lpszText, pDS->dwLength) ;
  290. return (pNextFree + pDS->dwLength * sizeof(TCHAR)) ;
  291. }
  292. } // DiskStringCopy
  293. void CounterName (PPERFSYSTEM pSystem,
  294. PPERFCOUNTERDEF pCounter,
  295. LPTSTR lpszCounter)
  296. { // CounterName
  297. //!! strclr (lpszCounter) ;
  298. lpszCounter [0] = TEXT('\0') ;
  299. QueryPerformanceName (pSystem,
  300. pCounter->CounterNameTitleIndex,
  301. 0, 256,
  302. lpszCounter,
  303. FALSE) ;
  304. } // CounterName
  305. PPERFOBJECT LineFindObject (PPERFSYSTEM pSystem,
  306. PPERFDATA pPerfData,
  307. PLINE pLine)
  308. /*
  309. Effect: Set the lnObject field of pLine to the object with the
  310. name of lnObjectName, and return TRUE. Return FALSE if
  311. there is no such object.
  312. */
  313. { // LineFindObject
  314. PPERFOBJECT pObject ;
  315. pObject = GetObjectDefByName (pSystem, pPerfData, pLine->lnObjectName) ;
  316. if (pObject)
  317. {
  318. pLine->lnObject = *pObject ;
  319. return (pObject) ;
  320. }
  321. else
  322. return (NULL) ;
  323. } // LineFindObject
  324. PPERFCOUNTERDEF LineFindCounter (PPERFSYSTEM pSystem,
  325. PPERFOBJECT pObject,
  326. PPERFDATA pPerfData,
  327. PLINE pLine)
  328. { // LineFindCounter
  329. UINT i ;
  330. PPERFCOUNTERDEF pCounter ;
  331. TCHAR szCounter [256] ;
  332. for (i = 0, pCounter = FirstCounter (pObject) ;
  333. i < pObject->NumCounters ;
  334. i++, pCounter = NextCounter (pCounter))
  335. { // for
  336. CounterName (pSystem, pCounter, szCounter) ;
  337. if (strsame (szCounter, pLine->lnCounterName))
  338. {
  339. pLine->lnCounterDef = *pCounter ;
  340. return (pCounter) ;
  341. } // if
  342. } // for
  343. return (NULL) ;
  344. } // LineFindCounter
  345. PPERFINSTANCEDEF LineFindInstance (PPERFDATA pPerfData,
  346. PPERFOBJECT pObject,
  347. PLINE pLine)
  348. { // LineFindInstance
  349. PPERFINSTANCEDEF pInstance = NULL ;
  350. if ((pObject->NumInstances > 0) && pLine->lnInstanceName)
  351. {
  352. // instances exist, find the right one
  353. if (pLine->lnUniqueID != PERF_NO_UNIQUE_ID)
  354. {
  355. pInstance = GetInstanceByUniqueID(pObject, pLine->lnUniqueID,
  356. pLine->dwInstanceIndex) ;
  357. }
  358. else
  359. {
  360. pInstance = GetInstanceByName(pPerfData, pObject,
  361. pLine->lnInstanceName, pLine->lnPINName,
  362. pLine->dwInstanceIndex) ;
  363. }
  364. }
  365. if (pInstance)
  366. {
  367. pLine->lnInstanceDef = *pInstance ;
  368. }
  369. return (pInstance) ;
  370. } // LineFindInstance
  371. void ReadLines (HANDLE hFile,
  372. DWORD dwNumLines,
  373. PPPERFSYSTEM ppSystemFirst,
  374. PPLINE ppLineFirst,
  375. int LineType)
  376. {
  377. DWORD i ;
  378. PPERFDATA pPerfData ;
  379. PLINE pLine ;
  380. PPERFSYSTEM pSystem ;
  381. PDISKLINE pDiskLine = NULL ;
  382. DWORD SizeofDiskLine = 0 ; // bytes in pDiskLine
  383. pPerfData = AllocatePerfData () ;
  384. pSystem = *ppSystemFirst ;
  385. #if 0
  386. if (!pSystem)
  387. {
  388. pSystem = SystemAdd (ppSystemFirst, LocalComputerName, NULL) ;
  389. pSystem = *ppSystemFirst ; //!!
  390. }
  391. UpdateSystemData (pSystem, &pPerfData) ;
  392. #endif
  393. pDiskLine = MemoryAllocate (FilePathLen) ;
  394. if (!pDiskLine)
  395. {
  396. // no memory to begin with, forget it
  397. DlgErrorBox (hWndMain, ERR_NO_MEMORY) ;
  398. return ;
  399. }
  400. SizeofDiskLine = FilePathLen ;
  401. for (i = 0 ;
  402. i < dwNumLines ;
  403. i++)
  404. {
  405. pLine = ReadLine (&pSystem, ppSystemFirst, &pPerfData, hFile,
  406. LineType, &pDiskLine, &SizeofDiskLine) ;
  407. if (pLine)
  408. {
  409. if (InsertLine (pLine) == FALSE)
  410. {
  411. // no inert occurred due to either line already existed
  412. // or error detected.
  413. LineFree (pLine) ;
  414. }
  415. }
  416. }
  417. if (pDiskLine)
  418. {
  419. MemoryFree (pDiskLine);
  420. }
  421. BuildValueListForSystems (*ppSystemFirst, *ppLineFirst) ;
  422. MemoryFree ((LPMEMORY)pPerfData) ;
  423. } // ReadLines
  424. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  425. PPPERFSYSTEM ppSystemFirst,
  426. PPERFDATA *ppPerfData,
  427. HANDLE hFile,
  428. int LineType,
  429. PDISKLINE *ppDiskLine,
  430. DWORD *pSizeofDiskLine)
  431. /*
  432. Effect: Read in a line from the file hFile, at the current file
  433. position.
  434. Internals: The very first characters are a line signature, then a
  435. length integer. If the signature is correct, then allocate
  436. the length amount, and work with that.
  437. */
  438. { // ReadLine
  439. PLINE pLine ;
  440. struct
  441. {
  442. DWORD dwSignature ;
  443. DWORD dwLength ;
  444. } LineHeader ;
  445. PPERFOBJECT pObject ;
  446. PPERFCOUNTERDEF pCounter ;
  447. PDISKLINE pDiskLine ; // Local copy of the pointer
  448. PPERFINSTANCEDEF pInstance ;
  449. pLine = NULL ;
  450. //=============================//
  451. // read and compare signature //
  452. //=============================//
  453. if (!FileRead (hFile, &LineHeader, sizeof (LineHeader)))
  454. return (NULL) ;
  455. if (LineHeader.dwSignature != dwLineSignature ||
  456. LineHeader.dwLength == 0)
  457. {
  458. SetLastError (ERROR_BAD_FORMAT) ;
  459. return (NULL) ;
  460. }
  461. //=============================//
  462. // read and allocate length //
  463. //=============================//
  464. // if (!FileRead (hFile, &dwLength, sizeof (dwLength)) || dwLength == 0)
  465. // return (NULL) ;
  466. // check if we need a bigger buffer,
  467. // normally, it should be the same except the first time...
  468. if (LineHeader.dwLength > *pSizeofDiskLine)
  469. {
  470. if (*ppDiskLine)
  471. {
  472. // free the previous buffer
  473. MemoryFree (*ppDiskLine);
  474. *pSizeofDiskLine = 0 ;
  475. }
  476. // re-allocate a new buffer
  477. *ppDiskLine = (PDISKLINE) MemoryAllocate (LineHeader.dwLength) ;
  478. if (!(*ppDiskLine))
  479. {
  480. // no memory, should flag an error...
  481. return (NULL) ;
  482. }
  483. *pSizeofDiskLine = LineHeader.dwLength ;
  484. }
  485. pDiskLine = *ppDiskLine ;
  486. //=============================//
  487. // copy diskline, alloc line //
  488. //=============================//
  489. if (!FileRead (hFile, pDiskLine, LineHeader.dwLength))
  490. return (NULL) ;
  491. pLine = LineAllocate () ;
  492. if (!pLine)
  493. {
  494. return (NULL) ;
  495. }
  496. pLine->iLineType = pDiskLine->iLineType ;
  497. //=============================//
  498. // convert system information //
  499. //=============================//
  500. pLine->lnSystemName = DiskStringReadSys (&(pDiskLine->dsSystemName)) ;
  501. if (!pLine->lnSystemName)
  502. goto ErrorBadLine ;
  503. if (!*ppSystem || !strsamei (pLine->lnSystemName, (*ppSystem)->sysName))
  504. {
  505. *ppSystem = SystemAdd (ppSystemFirst, pLine->lnSystemName, NULL) ;
  506. if (!*ppSystem)
  507. {
  508. SetLastError (ERROR_BAD_FORMAT) ;
  509. goto ErrorBadLine ;
  510. }
  511. UpdateSystemData (*ppSystem, ppPerfData) ;
  512. } // if
  513. //=============================//
  514. // convert object information //
  515. //=============================//
  516. pLine->lnObjectName = DiskStringRead (&(pDiskLine->dsObjectName)) ;
  517. if (!pLine->lnObjectName)
  518. goto ErrorBadLine ;
  519. pObject = LineFindObject (*ppSystem, *ppPerfData, pLine) ;
  520. //=============================//
  521. // convert counter information //
  522. //=============================//
  523. pLine->lnCounterName = DiskStringRead (&(pDiskLine->dsCounterName)) ;
  524. if (!pLine->lnCounterName)
  525. goto ErrorBadLine ;
  526. if (pObject)
  527. {
  528. pCounter = LineFindCounter (*ppSystem, pObject, *ppPerfData, pLine) ;
  529. if (!pCounter)
  530. {
  531. SetLastError (ERROR_BAD_FORMAT) ;
  532. goto ErrorBadLine ;
  533. }
  534. }
  535. //=============================//
  536. // convert instance info //
  537. //=============================//
  538. pLine->lnUniqueID = pDiskLine->dwUniqueID ;
  539. pLine->lnInstanceName = DiskStringRead (&(pDiskLine->dsInstanceName)) ;
  540. pLine->lnPINName = DiskStringRead (&(pDiskLine->dsPINName)) ;
  541. if (pObject &&
  542. pLine->lnObject.NumInstances > 0 &&
  543. pLine->lnInstanceName == NULL)
  544. {
  545. goto ErrorBadLine ;
  546. }
  547. if (pObject) {
  548. pInstance = LineFindInstance (*ppPerfData, pObject, pLine) ;
  549. if (pInstance)
  550. {
  551. pLine->lnParentObjName = DiskStringRead (&(pDiskLine->dsParentObjName)) ;
  552. }
  553. }
  554. else {
  555. pLine->lnParentObjName = DiskStringRead (&(pDiskLine->dsParentObjName)) ;
  556. }
  557. //=============================//
  558. // convert chart information //
  559. //=============================//
  560. if (LineType == IDM_VIEWCHART)
  561. {
  562. pLine->Visual = pDiskLine->Visual ;
  563. pLine->hPen = CreatePen (pLine->Visual.iStyle,
  564. pLine->Visual.iWidth,
  565. pLine->Visual.crColor) ;
  566. pLine->iScaleIndex = pDiskLine->iScaleIndex ;
  567. pLine->eScale = pDiskLine->eScale ;
  568. }
  569. //=============================//
  570. // convert alert information //
  571. //=============================//
  572. if (LineType == IDM_VIEWALERT)
  573. {
  574. pLine->Visual = pDiskLine->Visual ;
  575. pLine->hBrush = CreateSolidBrush (pLine->Visual.crColor) ;
  576. pLine->bAlertOver = pDiskLine->bAlertOver ;
  577. pLine->eAlertValue = pDiskLine->eAlertValue ;
  578. pLine->lpszAlertProgram = DiskStringRead (&(pDiskLine->dsAlertProgram)) ;
  579. pLine->bEveryTime = pDiskLine->bEveryTime ;
  580. pLine->bAlerted = FALSE ;
  581. }
  582. //=============================//
  583. // Convert the nasty stuff //
  584. //=============================//
  585. if (pObject) {
  586. pLine->lnCounterType = pCounter->CounterType;
  587. pLine->lnCounterLength = pCounter->CounterSize;
  588. }
  589. return (pLine) ;
  590. ErrorBadLine:
  591. if (!pLine)
  592. {
  593. LineFree (pLine) ;
  594. }
  595. return (NULL) ;
  596. } // ReadLine
  597. BOOL WriteLine (PLINE pLine,
  598. HANDLE hFile)
  599. { // WriteLine
  600. PDISKLINE pDiskLine ;
  601. DWORD dwSignature ;
  602. DWORD dwLength ;
  603. PBYTE pNextFree ;
  604. BOOL bConvertName ;
  605. //=============================//
  606. // write signature //
  607. //=============================//
  608. dwSignature = dwLineSignature ;
  609. if (!FileWrite (hFile, &dwSignature, sizeof (dwSignature)))
  610. return (FALSE) ;
  611. if (IsLocalComputer(pLine->lnSystemName))
  612. {
  613. bConvertName = TRUE ;
  614. }
  615. else
  616. {
  617. bConvertName = FALSE ;
  618. }
  619. //=============================//
  620. // compute and allocate length //
  621. //=============================//
  622. dwLength = sizeof (DISKLINE) ;
  623. if (bConvertName)
  624. {
  625. dwLength += DiskStringLength (LOCAL_SYS_CODE_NAME) * sizeof (TCHAR) ;
  626. }
  627. else
  628. {
  629. dwLength += DiskStringLength (pLine->lnSystemName) * sizeof (TCHAR) ;
  630. }
  631. dwLength += DiskStringLength (pLine->lnObjectName) * sizeof (TCHAR) ;
  632. dwLength += DiskStringLength (pLine->lnCounterName) * sizeof (TCHAR) ;
  633. dwLength += DiskStringLength (pLine->lnInstanceName) * sizeof (TCHAR) ;
  634. dwLength += DiskStringLength (pLine->lnPINName) * sizeof (TCHAR) ;
  635. dwLength += DiskStringLength (pLine->lnParentObjName) * sizeof (TCHAR) ;
  636. dwLength += DiskStringLength (pLine->lpszAlertProgram) * sizeof (TCHAR) ;
  637. if (!FileWrite (hFile, &dwLength, sizeof (dwLength)))
  638. return (FALSE) ;
  639. pDiskLine = (PDISKLINE) MemoryAllocate (dwLength) ;
  640. if (!pDiskLine)
  641. return (FALSE) ;
  642. pNextFree = (PBYTE) pDiskLine + sizeof (DISKLINE) ;
  643. //=============================//
  644. // convert fixed size fields //
  645. //=============================//
  646. pDiskLine->iLineType = pLine->iLineType ;
  647. pDiskLine->dwUniqueID = pLine->lnUniqueID ;
  648. pDiskLine->Visual = pLine->Visual ;
  649. pDiskLine->iScaleIndex = pLine->iScaleIndex ;
  650. pDiskLine->eScale = pLine->eScale ;
  651. pDiskLine->bAlertOver = pLine->bAlertOver ;
  652. pDiskLine->eAlertValue = pLine->eAlertValue ;
  653. pDiskLine->bEveryTime = pLine->bEveryTime ;
  654. //=============================//
  655. // copy disk string fields //
  656. //=============================//
  657. if (bConvertName)
  658. {
  659. pNextFree = DiskStringCopy (&pDiskLine->dsSystemName,
  660. LOCAL_SYS_CODE_NAME,
  661. pNextFree) ;
  662. }
  663. else
  664. {
  665. pNextFree = DiskStringCopy (&pDiskLine->dsSystemName,
  666. pLine->lnSystemName,
  667. pNextFree) ;
  668. }
  669. pNextFree = DiskStringCopy (&pDiskLine->dsObjectName,
  670. pLine->lnObjectName,
  671. pNextFree) ;
  672. pNextFree = DiskStringCopy (&pDiskLine->dsCounterName,
  673. pLine->lnCounterName,
  674. pNextFree) ;
  675. pNextFree = DiskStringCopy (&pDiskLine->dsParentObjName,
  676. pLine->lnParentObjName,
  677. pNextFree) ;
  678. pNextFree = DiskStringCopy (&pDiskLine->dsInstanceName,
  679. pLine->lnInstanceName,
  680. pNextFree) ;
  681. pNextFree = DiskStringCopy (&pDiskLine->dsPINName,
  682. pLine->lnPINName,
  683. pNextFree) ;
  684. pNextFree = DiskStringCopy (&pDiskLine->dsAlertProgram,
  685. pLine->lpszAlertProgram,
  686. pNextFree) ;
  687. FileWrite (hFile, pDiskLine, dwLength) ;
  688. MemoryFree (pDiskLine) ;
  689. return (TRUE) ;
  690. #if 0
  691. //ErrorBadLine:
  692. MemoryFree (pDiskLine) ;
  693. return (FALSE) ;
  694. #endif
  695. } // WriteLine
  696. // we are not doing printing. In case we need this
  697. // later, then define DO_PRINTING
  698. #ifdef DO_PRINTING
  699. int aiPrinterLineStyles [] =
  700. {
  701. PS_SOLID,
  702. PS_DASH,
  703. PS_DOT,
  704. PS_DASHDOT,
  705. PS_DASHDOTDOT
  706. } ;
  707. #define NumPrinterLineStyles() \
  708. (sizeof (aiPrinterLineStyles) / sizeof (aiPrinterLineStyles [0]))
  709. COLORREF acrPrinterLineColors [] =
  710. {
  711. RGB (192, 192, 192),
  712. RGB (128, 128, 128),
  713. RGB (64, 64, 64),
  714. RGB (0, 0, 0)
  715. } ;
  716. #define NumPrinterLineColors() \
  717. (sizeof (acrPrinterLineColors) / sizeof (acrPrinterLineColors [0]))
  718. #endif // DO_PRINTING
  719. HPEN LineCreatePen (HDC hDC,
  720. PLINEVISUAL pVisual,
  721. BOOL bForPrint)
  722. { // LineCreatePen
  723. HPEN hPen ;
  724. #ifdef DO_PRINTING
  725. LOGBRUSH logBrush ;
  726. if (bForPrint)
  727. {
  728. logBrush.lbStyle = PS_SOLID ;
  729. //!! aiPrinterLineStyles [pVisual->iColorIndex % NumPrinterLineStyles ()] ;
  730. logBrush.lbColor =
  731. acrPrinterLineColors [pVisual->iColorIndex % NumPrinterLineColors ()] ;
  732. logBrush.lbHatch = 0 ;
  733. hPen = ExtCreatePen (logBrush.lbStyle |
  734. PS_GEOMETRIC |
  735. PS_ENDCAP_SQUARE |
  736. PS_JOIN_BEVEL,
  737. VertInchPixels (hDC, pVisual->iWidth, 20),
  738. &logBrush,
  739. 0, NULL) ;
  740. }
  741. else
  742. #endif
  743. hPen = CreatePen (pVisual->iStyle,
  744. pVisual->iWidth,
  745. pVisual->crColor) ;
  746. return (hPen) ;
  747. } // LineCreatePen
  748. VOID FreeLines (PLINESTRUCT pLineFirst)
  749. { // FreeLines
  750. PLINESTRUCT pLine,next_line;
  751. for (pLine = pLineFirst; pLine; pLine = next_line)
  752. {
  753. next_line = pLine->pLineNext;
  754. LineFree (pLine) ;
  755. }
  756. } // FreeLines