예제 #1
0
        private void ProcessByte(byte b)
        {
            if (_terminal.State == ProcessCharResult.Escaping)
            {
                _terminal.ProcessChar((char)b);
            }
            else
            {
                if (_state == State.Normal && !IsControlChar(b) && _encoding.IsInterestingByte(b))
                {
                    PutMBCSByte(b);
                }
                else
                {
                    switch (_state)
                    {
                    case State.Normal:
                        if (b == 0x1B)                              //ESC
                        {
                            _state = State.ESC;
                        }
                        else if (b == 14)                              //SO
                        {
                            ChangeProcessor(_G1ByteProcessor);
                        }
                        else if (b == 15)                              //SI
                        {
                            ChangeProcessor(_G0ByteProcessor);
                        }
                        else
                        {
                            ConsumeByte(b);
                        }
                        break;

                    case State.ESC:
                        if (b == (byte)'$')
                        {
                            _state = State.ESC_DOLLAR;
                        }
                        else if (b == (byte)'(')
                        {
                            _state = State.ESC_BRACKET;
                        }
                        else if (b == (byte)')')
                        {
                            _state = State.ESC_ENDBRACKET;
                        }
                        else
                        {
                            ConsumeByte(0x1B);
                            ConsumeByte(b);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_BRACKET:
                        if (b == (byte)'0')
                        {
                            _G0ByteProcessor = _DECLineByteProcessor;
                        }
                        else if (b == (byte)'B' || b == (byte)'J' || b == (byte)'~')                          //!!lessでssh2architecture.txtを見ていたら来た。詳細はまだ調べていない。
                        {
                            _G0ByteProcessor = null;
                        }
                        else
                        {
                            _terminal.UnsupportedCharSetDetected((char)b);
                        }
                        ChangeProcessor(_G0ByteProcessor);
                        break;

                    case State.ESC_ENDBRACKET:
                        if (b == (byte)'0')
                        {
                            _G1ByteProcessor = _DECLineByteProcessor;
                        }
                        else if (b == (byte)'B' || b == (byte)'J' || b == (byte)'~')                          //!!lessでssh2architecture.txtを見ていたら来た。詳細はまだ調べていない。
                        {
                            _G1ByteProcessor = null;
                        }
                        _state = State.Normal;
                        break;

                    case State.ESC_DOLLAR:
                        if (b == (byte)'B' || b == (byte)'@')
                        {
                            ChangeProcessor(_iso2022jpByteProcessor);
                        }
                        else
                        {
                            _terminal.ProcessChar((char)0x1B);
                            _terminal.ProcessChar('$');
                            _terminal.ProcessChar((char)b);
                            _state = State.Normal;
                        }
                        break;

                    default:
                        Debug.Assert(false, "unexpected state transition");
                        break;
                    }
                }
            }
        }
예제 #2
0
        private void ProcessByte(byte b)
        {
            if (_processor.State == ProcessCharResult.Escaping)
            {
                _processor.ProcessChar((char)b);
            }
            else
            {
                if (_state == State.Normal && !IsControlChar(b) && _encoding.IsInterestingByte(b))
                {
                    PutMBCSByte(b);
                }
                else
                {
                    switch (_state)
                    {
                    case State.Normal:
                        if (b == 0x1B)                                //ESC
                        {
                            _escseq.Reset();
                            _escseq.Append(b);
                            _state = State.ESC;
                        }
                        else if (b == 14)                              //SO
                        {
                            ChangeProcessor(_G1ByteProcessor);
                        }
                        else if (b == 15)                              //SI
                        {
                            ChangeProcessor(_G0ByteProcessor);
                        }
                        else
                        {
                            ConsumeByte(b);
                        }
                        break;

                    case State.ESC:
                        _escseq.Append(b);
                        if (b == (byte)'$')
                        {
                            _state = State.ESC_DOLLAR;
                        }
                        else if (b == (byte)'(')
                        {
                            _state = State.ESC_BRACKET;
                        }
                        else if (b == (byte)')')
                        {
                            _state = State.ESC_ENDBRACKET;
                        }
                        else
                        {
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_BRACKET:
                        _escseq.Append(b);
                        if (b == (byte)'0')
                        {
                            _G0ByteProcessor = GetDECLineByteProcessor();
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else if (b == (byte)'B' || b == (byte)'J' || b == (byte)'~')                            //!!lessでssh2architecture.txtを見ていたら来た。詳細はまだ調べていない。
                        {
                            _G0ByteProcessor = _asciiByteProcessor;
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else
                        {
                            _processor.UnsupportedCharSetDetected((char)b);
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_ENDBRACKET:
                        _escseq.Append(b);
                        if (b == (byte)'0')
                        {
                            _G1ByteProcessor = GetDECLineByteProcessor();
                            _state           = State.Normal;
                        }
                        else if (b == (byte)'B' || b == (byte)'J' || b == (byte)'~')                            //!!lessでssh2architecture.txtを見ていたら来た。詳細はまだ調べていない。
                        {
                            _G1ByteProcessor = _asciiByteProcessor;
                            _state           = State.Normal;
                        }
                        else
                        {
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_DOLLAR:
                        _escseq.Append(b);
                        if (b == (byte)'(')
                        {
                            _state = State.ESC_DOLLAR_BRACKET;
                        }
                        else if (b == (byte)')')
                        {
                            _state = State.ESC_DOLLAR_ENDBRACKET;
                        }
                        else if (b == (byte)'B' || b == (byte)'@')
                        {
                            _G0ByteProcessor = GetISO2022JPByteProcessor();
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else
                        {
                            _processor.UnsupportedCharSetDetected((char)b);
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_DOLLAR_BRACKET:
                        _escseq.Append(b);
                        if (b == (byte)'C')
                        {
                            _G0ByteProcessor = GetISO2022KRByteProcessor();
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else if (b == (byte)'D')
                        {
                            _G0ByteProcessor = GetISO2022JPByteProcessor();
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else if (b == (byte)'I')
                        {
                            _G0ByteProcessor = GetISO2022JPKanaByteProcessor();
                            ChangeProcessor(_G0ByteProcessor);
                            _state = State.Normal;
                        }
                        else
                        {
                            _processor.UnsupportedCharSetDetected((char)b);
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    case State.ESC_DOLLAR_ENDBRACKET:
                        _escseq.Append(b);
                        if (b == (byte)'C')
                        {
                            _G1ByteProcessor = GetISO2022KRByteProcessor();
                            _state           = State.Normal;
                        }
                        else
                        {
                            ConsumeBytes(_escseq.Buffer, _escseq.Length);
                            _state = State.Normal;
                        }
                        break;

                    default:
                        Debug.Assert(false, "unexpected state transition");
                        break;
                    }
                }
            }
        }