3.4.2 具体实现(6)

2013-10-07 15:56:23 · 作者: · 浏览: 77

3.4.2  具体实现(6)

⑩ 定义函数ProcessOptions(),用于设置协商的方法,具体代码如下:

  1. //进行协商  
  2. void CTelnetView::ProcessOptions()  
  3. {  
  4. CString m_strTemp;  
  5. CString m_strOption;  
  6. unsigned char ch;  
  7. int ndx;  
  8. int ldx;  
  9. //将初始扫描完成变量设置为假  
  10. BOOL bScanDone = FALSE;  
  11. //给临时变量赋值为当前行  
  12. m_strTemp = m_strLine;  
  13. //根据状态来判定,当数据在扫描并且还有数据时进行下面的协商  
  14. while(!m_strTemp.IsEmpty() && bScanDone!=TRUE)  
  15. {  
  16. ndx = m_strTemp.Find(IAC);  
  17. if(ndx != -1)  
  18. {  
  19. m_strNormalText += m_strTemp.Left(ndx);  
  20. ch = m_strTemp.GetAt(ndx + 1);  
  21. switch(ch)  
  22. {  
  23. case DO:  
  24. case DONT:  
  25. case WILL:  
  26. case WONT:  
  27. m_strOption = m_strTemp.Mid(ndx, 3);  
  28. m_strTempm_strTemp       = m_strTemp.Mid(ndx + 3);  
  29. m_strNormalText = m_strTemp.Left(ndx);  
  30. m_ListOptions.AddTail(m_strOption);  
  31. break;  
  32. case IAC:  
  33. m_strNormalText = m_strTemp.Left(ndx);  
  34. m_strTempm_strTemp           = m_strTemp.Mid(ndx + 1);  
  35. break;  
  36. case SB:  
  37. m_strNormalText = m_strTemp.Left(ndx);  
  38. ldx = Find(m_strTemp, SE);  
  39. m_strOption = m_strTemp.Mid(ndx, ldx);  
  40. m_ListOptions.AddTail(m_strOption);  
  41. m_strTempm_strTemp       = m_strTemp.Mid(ldx);  
  42. //AfxMessageBox(m_strOption, MB_OK);  
  43. break;  
  44. default:  
  45. bScanDone = TRUE;  
  46. }  
  47. }  
  48. else  
  49. {  
  50. m_strNormalText = m_strTemp;  
  51. bScanDone = TRUE;  
  52. }  
  53. }   
  54. RespondToOptions();  
  55. }