Example #1
0
        /// <summary>
        /// peek and return specified length of bytes from current position in Bytes
        /// array. If length exceeds remaining length then shorten the peek length.
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        public byte[] PeekBytesLenient(int Length)
        {
            int lx  = IntExt.Min(this.RemainingLength, Length);
            var buf = this.Bytes.SubArray(this.Index, lx);

            return(buf);
        }
Example #2
0
        private static void LogFile_WriteRawBytes(byte[] Buffer, string FilePath)
        {
            int ix = 0;

            while (ix < Buffer.Length)
            {
                int remLx = Buffer.Length - ix;
                int lx    = 1;

                if ((Buffer[ix] == 0x1b) && (remLx > 1))
                {
                    var fx = Buffer.IndexOf(ix + 1, new byte[] { 0x1b });
                    if (fx == -1)
                    {
                        lx = remLx;
                    }
                    else
                    {
                        lx = fx - ix;
                    }
                }
                else
                {
                    lx = IntExt.Min(remLx, 15);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToHex(ix, lx, ' '));
                    System.IO.File.AppendAllText(
                        FilePath, sb.ToString() + Environment.NewLine);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToAscii(ix, lx, "  "));
                    System.IO.File.AppendAllText(
                        FilePath, sb.ToString() + Environment.NewLine);
                }

                ix += lx;
            }
        }
        private static void LogFile_WriteRawBytes(byte[] Buffer, List <string> Lines)
        {
            int ix = 0;

            while (ix < Buffer.Length)
            {
                int remLx = Buffer.Length - ix;
                int lx    = 1;

                if ((Buffer[ix] == 0x1b) && (remLx > 1))
                {
                    var fx = Buffer.IndexOf(ix + 1, new byte[] { 0x1b });
                    if (fx == -1)
                    {
                        lx = remLx;
                    }
                    else
                    {
                        lx = fx - ix;
                    }
                }
                else
                {
                    lx = IntExt.Min(remLx, 15);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToHex(ix, lx, ' '));
                    Lines.Add(sb.ToString());
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToAscii(ix, lx, "  "));
                    Lines.Add(sb.ToString());
                }

                ix += lx;
            }
        }
Example #4
0
        private static TerminalVt100Statement Factory_FromStmtText(string StmtText)
        {
            Vt100Command?          cmd  = null;
            TerminalVt100Statement stmt = null;
            string text1  = "";
            string text2  = "";
            string text3  = "";
            string text4  = "";
            string text20 = "";
            int    rx     = 0;

            if (StmtText.Length >= 1)
            {
                text1 = StmtText.Substring(0, 1);
            }
            if (StmtText.Length >= 2)
            {
                text2 = StmtText.Substring(0, 2);
            }
            if (StmtText.Length >= 3)
            {
                text3 = StmtText.Substring(0, 3);
            }
            if (StmtText.Length >= 4)
            {
                text4 = StmtText.Substring(0, 4);
            }

            int lx = IntExt.Min(StmtText.Length, 20);

            text20 = StmtText.Substring(0, lx);

            if (text4 == "[?3l")
            {
                cmd  = Vt100Command.SetCol80;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }
            else if (text4 == "[?7h")
            {
                cmd  = Vt100Command.SetAutoWrap;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }

            else if (text3 == "[0m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.CharAttrOff);
            }

            else if (text3 == "[1m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.BoldModeOn);
            }

            else if (text3 == "[4m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.UnderlineModeOn);
            }

            else if (text3 == "[2J")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.ClearScreen);
            }

            else if ((text1 == "[") && (StmtText.Length >= 5) &&
                     ((rx = StmtText.MatchRegExp(REGEXPCURSORPOSITION)) > 0))
            {
                stmt = new Vt100PosCursor(StmtText.Substring(0, rx));
            }

            else
            {
                stmt = new TerminalVt100Statement(StmtText, null);
            }


            return(stmt);
        }