public override void ProcessChar(char ch) { if (_processCharResult != ProcessCharResult.Escaping) { if (ch == ControlCode.ESC) { _processCharResult = ProcessCharResult.Escaping; } else { if (_currentCharacterTask != null) //マクロなど、charを取るタイプ { _currentCharacterTask.ProcessChar(ch); } this.LogService.XmlLogger.Write(Unicode.ToOriginal(ch)); if (Unicode.IsControlCharacter(ch)) { _processCharResult = ProcessControlChar(ch); } else { _processCharResult = ProcessNormalChar(ch); } } } else { if (ch == ControlCode.NUL) { return; //シーケンス中にNULL文字が入っているケースが確認された なお今はXmlLoggerにもこのデータは行かない。 } if (ch == ControlCode.ESC) { // escape sequence restarted ? // save log silently RuntimeUtil.SilentReportException(new UnknownEscapeSequenceException("Incomplete escape sequence: ESC " + _escapeSequence.ToString())); _escapeSequence.Remove(0, _escapeSequence.Length); return; } _escapeSequence.Append(ch); bool end_flag = false; //escape sequenceの終わりかどうかを示すフラグ if (_escapeSequence.Length == 1) //ESC+1文字である場合 { end_flag = ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '>' || ch == '=' || ch == '|' || ch == '}' || ch == '~'; } else if (_escapeSequence[0] == ']') //OSCの終端はBELかST(String Terminator) { end_flag = (ch == ControlCode.BEL) || (ch == ControlCode.ST); // Note: The conversion from "ESC \" to ST would be done in XTerm.ProcessChar(char). } else if (this._escapeSequence[0] == '@') { end_flag = (ch == '0') || (ch == '1'); } else { end_flag = ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '@' || ch == '~' || ch == '|' || ch == '{'; } if (end_flag) //シーケンスのおわり { char[] seq = _escapeSequence.ToString().ToCharArray(); this.LogService.XmlLogger.EscapeSequence(seq); try { char code = seq[0]; _processCharResult = ProcessCharResult.Unsupported; //ProcessEscapeSequenceで例外が来た後で状態がEscapingはひどい結果を招くので _processCharResult = ProcessEscapeSequence(code, seq, 1); if (_processCharResult == ProcessCharResult.Unsupported) { throw new UnknownEscapeSequenceException("Unknown escape sequence: ESC " + new string(seq)); } } catch (UnknownEscapeSequenceException ex) { CharDecodeError(GEnv.Strings.GetString("Message.EscapesequenceTerminal.UnsupportedSequence") + ex.Message); RuntimeUtil.SilentReportException(ex); } finally { _escapeSequence.Remove(0, _escapeSequence.Length); } } else { _processCharResult = ProcessCharResult.Escaping; } } }
public override void ProcessChar(char ch) { if (_processCharResult != ProcessCharResult.Escaping) { if (ch == 0x1B) { _processCharResult = ProcessCharResult.Escaping; } else { if (_currentCharacterTask != null) //マクロなど、charを取るタイプ { _currentCharacterTask.ProcessChar(ch); } this.LogService.XmlLogger.Write(ch); if (ch < 0x20 || (ch >= 0x80 && ch < 0xA0)) { _processCharResult = ProcessControlChar(ch); } else { _processCharResult = ProcessNormalChar(ch); } } } else { if (ch == '\0') { return; //シーケンス中にNULL文字が入っているケースが確認された なお今はXmlLoggerにもこのデータは行かない。 } _escapeSequence.Append(ch); bool end_flag = false; //escape sequenceの終わりかどうかを示すフラグ if (_escapeSequence.Length == 1) //ESC+1文字である場合 { end_flag = ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '>' || ch == '=' || ch == '|' || ch == '}' || ch == '~'; } else if (_escapeSequence[0] == ']') //OSCの終端はBELかST(String Terminator) { end_flag = ch == 0x07 || ch == 0x9c; if (ch == '\\' && _escapeSequence[_escapeSequence.Length - 2] == 0x1b) { // ESC \ も OSC の終端 _escapeSequence.Remove(_escapeSequence.Length - 1, 1); end_flag = true; } } else if (this._escapeSequence[0] == '@') { end_flag = (ch == '0') || (ch == '1'); } else { end_flag = ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '@' || ch == '~' || ch == '|' || ch == '{'; } if (end_flag) //シーケンスのおわり { char[] seq = _escapeSequence.ToString().ToCharArray(); this.LogService.XmlLogger.EscapeSequence(seq); try { char code = seq[0]; _processCharResult = ProcessCharResult.Unsupported; //ProcessEscapeSequenceで例外が来た後で状態がEscapingはひどい結果を招くので _processCharResult = ProcessEscapeSequence(code, seq, 1); if (_processCharResult == ProcessCharResult.Unsupported) { throw new UnknownEscapeSequenceException(String.Format("ESC {0}", new string(seq))); } } catch (UnknownEscapeSequenceException ex) { CharDecodeError(GEnv.Strings.GetString("Message.EscapesequenceTerminal.UnsupportedSequence") + ex.Message); RuntimeUtil.SilentReportException(ex); } finally { _escapeSequence.Remove(0, _escapeSequence.Length); } } else { _processCharResult = ProcessCharResult.Escaping; } } }