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.

174 lines
4.7 KiB

  1. // LCDManDoc.cpp : implementation of the CLCDManDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "LCDMan.h"
  5. #include "LCDManDoc.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CLCDManDoc
  13. IMPLEMENT_DYNCREATE(CLCDManDoc, CDocument)
  14. BEGIN_MESSAGE_MAP(CLCDManDoc, CDocument)
  15. //{{AFX_MSG_MAP(CLCDManDoc)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. // DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CLCDManDoc construction/destruction
  22. CLCDManDoc::CLCDManDoc() : m_List(10), m_cstrState(_T("")), m_iDocTimeIntrval(0),
  23. m_ptFileBuffer(NULL), m_ptBufferStart(NULL), m_ptBufferEnd(NULL)
  24. {
  25. // TODO: add one-time construction code here
  26. }
  27. CLCDManDoc::~CLCDManDoc()
  28. {
  29. if (m_ptBufferStart)
  30. free(m_ptBufferStart);
  31. }
  32. BOOL CLCDManDoc::OnNewDocument()
  33. {
  34. if (!CDocument::OnNewDocument())
  35. return FALSE;
  36. InitDocument(NULL);
  37. return TRUE;
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CLCDManDoc serialization
  41. void CLCDManDoc::Serialize(CArchive& ar)
  42. {
  43. if (ar.IsStoring())
  44. {
  45. // TODO: add storing code here
  46. }
  47. else
  48. {
  49. // TODO: add loading code here
  50. }
  51. m_List.Serialize(ar);
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CLCDManDoc diagnostics
  55. #ifdef _DEBUG
  56. void CLCDManDoc::AssertValid() const
  57. {
  58. CDocument::AssertValid();
  59. }
  60. void CLCDManDoc::Dump(CDumpContext& dc) const
  61. {
  62. CDocument::Dump(dc);
  63. }
  64. #endif //_DEBUG
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CLCDManDoc commands
  67. BOOL CLCDManDoc::OnOpenDocument(LPCTSTR lpszPathName)
  68. {
  69. // if (!CDocument::OnOpenDocument(lpszPathName)) Do not use the archive
  70. // return FALSE;
  71. if (lpszPathName)
  72. {
  73. CFile CFSource(lpszPathName, CFile::modeRead);
  74. if (CFSource)
  75. InitDocument(&CFSource);
  76. }
  77. return TRUE;
  78. }
  79. void CLCDManDoc::InitDocument(CFile *pCFSource)
  80. {
  81. if (pCFSource)
  82. {
  83. m_List.RemoveAll();
  84. // Red the file and build m_List
  85. DWORD dwLength = pCFSource->GetLength();
  86. m_ptFileBuffer = (LPTSTR)malloc(dwLength);
  87. m_ptBufferStart = m_ptFileBuffer;
  88. if (m_ptFileBuffer)
  89. {
  90. pCFSource->Read(m_ptFileBuffer, dwLength);
  91. m_ptFileBuffer++; // Notepad places 0xFF 0xFE codes at the beginig of the file
  92. m_ptBufferEnd = m_ptFileBuffer + dwLength;
  93. }
  94. }
  95. else if (!m_ptFileBuffer)
  96. return; // No file, no document, no nothing
  97. while (m_ptFileBuffer < m_ptBufferEnd)
  98. {
  99. LPTSTR ptEndString = _tcschr(m_ptFileBuffer, _T('\r'));
  100. if (!ptEndString)
  101. break;
  102. *ptEndString = _T('\0');
  103. if (_tcsstr(m_ptFileBuffer, _T("TIME:")))
  104. {
  105. // Set the timer for the message set
  106. m_ptFileBuffer += _tcsclen(_T("TIME:"));
  107. _stscanf(m_ptFileBuffer, _T("%d"), &m_iDocTimeIntrval);
  108. POSITION posView = GetFirstViewPosition();
  109. CView *pView = GetNextView(posView);
  110. pView->SetTimer(2, m_iDocTimeIntrval * 1000, NULL);
  111. }
  112. else if (_tcsstr(m_ptFileBuffer, _T("STATE:")))
  113. {
  114. // Set the state
  115. m_ptFileBuffer += _tcsclen(_T("STATE:"));
  116. m_cstrState = m_ptFileBuffer;
  117. }
  118. else if (_tcsstr(m_ptFileBuffer, _T("ADDMSG:")))
  119. {
  120. // Add message to the list
  121. m_ptFileBuffer += _tcsclen(_T("ADDMSG:"));
  122. m_List.AddTail(m_ptFileBuffer);
  123. }
  124. else if (_tcsstr(m_ptFileBuffer, _T("REMOVEMSG:")))
  125. {
  126. // Remove message from the list
  127. m_ptFileBuffer += _tcsclen(_T("REMOVEMSG:"));
  128. CString cstr(TEXT(""));
  129. CString cstrMsg(m_ptFileBuffer);
  130. for (POSITION pos = m_List.GetHeadPosition(); pos != NULL; m_List.GetNext(pos) )
  131. {
  132. cstr = m_List.GetAt(pos);
  133. if (cstr == cstrMsg)
  134. {
  135. m_List.RemoveAt(pos);
  136. break;
  137. }
  138. }
  139. }
  140. else if (_tcsstr(m_ptFileBuffer, _T("END:")))
  141. {
  142. // End of the document
  143. m_ptFileBuffer = ptEndString + 2;
  144. break;
  145. }
  146. m_ptFileBuffer = ptEndString + 2;
  147. }
  148. }