3.4.2 具体实现(6)
⑩ 定义函数ProcessOptions(),用于设置协商的方法,具体代码如下:
- //进行协商
- void CTelnetView::ProcessOptions()
- {
- CString m_strTemp;
- CString m_strOption;
- unsigned char ch;
- int ndx;
- int ldx;
- //将初始扫描完成变量设置为假
- BOOL bScanDone = FALSE;
- //给临时变量赋值为当前行
- m_strTemp = m_strLine;
- //根据状态来判定,当数据在扫描并且还有数据时进行下面的协商
- while(!m_strTemp.IsEmpty() && bScanDone!=TRUE)
- {
- ndx = m_strTemp.Find(IAC);
- if(ndx != -1)
- {
- m_strNormalText += m_strTemp.Left(ndx);
- ch = m_strTemp.GetAt(ndx + 1);
- switch(ch)
- {
- case DO:
- case DONT:
- case WILL:
- case WONT:
- m_strOption = m_strTemp.Mid(ndx, 3);
- m_strTempm_strTemp = m_strTemp.Mid(ndx + 3);
- m_strNormalText = m_strTemp.Left(ndx);
- m_ListOptions.AddTail(m_strOption);
- break;
- case IAC:
- m_strNormalText = m_strTemp.Left(ndx);
- m_strTempm_strTemp = m_strTemp.Mid(ndx + 1);
- break;
- case SB:
- m_strNormalText = m_strTemp.Left(ndx);
- ldx = Find(m_strTemp, SE);
- m_strOption = m_strTemp.Mid(ndx, ldx);
- m_ListOptions.AddTail(m_strOption);
- m_strTempm_strTemp = m_strTemp.Mid(ldx);
- //AfxMessageBox(m_strOption, MB_OK);
- break;
- default:
- bScanDone = TRUE;
- }
- }
- else
- {
- m_strNormalText = m_strTemp;
- bScanDone = TRUE;
- }
- }
- RespondToOptions();
- }