Esempio n. 1
0
        public override bool Execute(string command, TSRPStack stack)
        {
            if (command == "open_file")
            {
                if (stack.Top is StackString)
                {
                    StackString s = (StackString)stack.Pop();

                    stack.Push(new StackFile(s.Value));
                }
            }
            else if (command == "call_windows")
            {
                if (stack.Top is StackString)
                {
                    StackString s = (StackString)stack.Pop();

                    System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    startInfo.FileName    = "cmd.exe";
                    startInfo.Arguments   = "/C " + s.Value;
                    process.StartInfo     = startInfo;
                    process.Start();
                    return(true);
                }
            }
            else if (command == "call_program")
            {
                if (stack.Top is StackString && stack.FromTop(1) is StackString)
                {
                    StackString args         = (StackString)stack.Pop();
                    StackString program_name = (StackString)stack.Pop();


                    System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    startInfo.FileName  = program_name.Value;
                    startInfo.Arguments = args.Value;
                    process.StartInfo   = startInfo;
                    process.Start();
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
 public StackString(StackString copy) : this(copy.value)
 {
 }
Esempio n. 3
0
        public override bool Execute(string command, TSRPStack stack)
        {
            if (closed)
            {
                return(false);
            }
            if (command == "CheckLine")
            {
                stack.Push(reader.Peek() >= 0);
                return(true);
            }
            else
            if (command == "Check")
            {
                stack.Push(file.Position < file.Length);
                return(true);
            }
            else
            if (command == "Close")
            {
                Dispose();
                closed = true;
                return(true);
            }
            else
            if (command == "Write")
            {
                if (stack.Top is StackString)
                {
                    StackString s = (StackString)stack.Pop();
                    writer.Write(s.Value);
                    return(true);
                }
            }
            else
            if (command == "ReadByte")
            {
                stack.Push((byte)file.ReadByte());
                return(true);
            }
            else
            if (command == "Read")
            {
                stack.Push("" + (char)reader.Read());
                return(true);
            }
            else
            if (command == "WriteLine")
            {
                StackString s = (StackString)stack.Pop();
                writer.WriteLine(s.Value);
                return(true);
            }
            else
            if (command == "ReadLine")
            {
                stack.Push(reader.ReadLine());
                return(true);
            }
            else
            if (command == "ReadToEnd")
            {
                stack.Push(reader.ReadToEnd());
                return(true);
            }
            else
            if (command == "WriteByte")
            {
                if (stack.Top is StackNumber)
                {
                    StackNumber s = (StackNumber)stack.Pop();
                    file.WriteByte(s.ToByte());
                    return(true);
                }
            }
            else
            if (command == "ReadBytes")
            {
                if (stack.Top is StackNumber)
                {
                    int    x   = ((StackNumber)stack.Pop()).ToInt();
                    byte[] buf = new byte[x];
                    file.Read(buf, 0, x);
                    TSRPStack s = new TSRPStack();
                    foreach (byte b in buf)
                    {
                        s.Push(b);
                    }
                    stack.Push(new StackArray(s));
                    return(true);
                }
            }
            else
            if (command == "WriteBytes")
            {
                if (stack.Top is StackArray)
                {
                    StackElement[] els = ((StackArray)stack.Pop()).Elements;
                    foreach (StackNumber n in els)
                    {
                        file.WriteByte(n.ToByte());
                    }
                    return(true);
                }
            }
            else
            if (command == "ReadWord")
            {
                StringBuilder b = new StringBuilder();
                while (reader.Peek() >= 0 && ((char)reader.Peek() != ' ') && ((char)reader.Peek() != '\n') && ((char)reader.Peek() != '\t') && ((char)reader.Peek() != '\r'))
                {
                    b.Append((char)reader.Read());
                }


                if (reader.Peek() >= 0)
                {
                    b.Append((char)reader.Read());
                }

                stack.Push(b.ToString());
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        public override bool Execute(string command, TSRPStack stack)
        {
            if (command.EndsWith("*") && (stack.Top == this || command.EndsWith("**")))
            {
                int k = 1;
                if (command.EndsWith("**"))
                {
                    k = 2;
                }
                bool j = Execute(command.Substring(0, command.Length - k), stack);

                int counter = 0;

                while (stack.Top != this)
                {
                    counter++;
                    elements.Push(stack.Pop());
                }

                stack.Pop();

                for (int i = 0; i < counter; i++)
                {
                    stack.Push(elements.Pop());
                }
            }
            else
            if (command == "size")
            {
                stack.Push(Count);
                return(true);
            }
            else
            if (command == "at")
            {
                if (stack.Top is StackNumber)
                {
                    int n = ((StackNumber)stack.Pop()).ToInt();
                    if (n < Count)
                    {
                        stack.Push(((StackElement)elements.FromTop(Count - n - 1).Clone()));
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                return(false);
            }
            else
            if (command == "push" || command == "array_push")
            {
                if (stack.Count != 0)
                {
                    elements.Push(stack.Pop());
                }
                return(true);
            }
            else
            if (command == "array_pop")
            {
                if (elements.Count > 0)
                {
                    stack.Push(elements.Pop());
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            if (command == "set")
            {
                if (stack.Top is StackNumber)
                {
                    int          n  = ((StackNumber)stack.Pop()).ToInt();
                    StackElement el = stack.Pop();
                    var          x  = Elements;
                    if (n < Count)
                    {
                        x[n] = el;
                        elements.Elements = x;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(false);
            }
            else if (command == "chars2str")
            {
                var           x = Elements;
                StringBuilder b = new StringBuilder();
                for (int i = 0; i < x.Length; i++)
                {
                    StackNumber y = null;
                    if (x[i] is StackNumber)
                    {
                        y = (StackNumber)x[i];
                    }
                    else
                    {
                        continue;
                    }
                    b.Append((char)y.ToUnsignedShort());
                }
                stack.Push(b.ToString());
                return(true);
            }
            else if (command == "concatstr")
            {
                var           x = Elements;
                StringBuilder b = new StringBuilder();
                for (int i = 0; i < x.Length; i++)
                {
                    StackString y = null;
                    if (x[i] is StackString)
                    {
                        y = (StackString)x[i];
                    }
                    else
                    {
                        continue;
                    }
                    b.Append(y.Value);
                }
                stack.Push(b.ToString());
                return(true);
            }
            else if (command == "array_clear" || command == "empty")
            {
                elements.Clear();
                return(true);
            }
            else if (command == "release")
            {
                stack.Pop();
                var els = elements.Elements;
                //Array.Reverse(els);
                foreach (StackElement el in els)
                {
                    stack.Push(el);
                }
                elements.Clear();

                return(true);
            }
            else if (command == "clone")
            {
                stack.Push(new StackArray(this));
                return(true);
            }
            else if (command == "reverse")
            {
                var x = elements.Elements;

                elements.Clear();
                for (var i = x.Length - 1; i >= 0; i--)
                {
                    elements.Push(x[i]);
                }

                return(true);
            }


            return(false);
        }
Esempio n. 5
0
 public StackArray(StackString ss, bool dig = false) : this(ss.Value, dig)
 {
 }