Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using TestWindow1;
- namespace TestWindow1
- {
- public partial class CommandPrompt : Form
- {
- private TextBox textBox1;
- private TextBox textBox2;
- private Button button1;
- private Label label1;
- private TextBox textBox3;
- private Label label2;
- private readonly object hScrollBar1;
- private TextBox textBox4;
- private Label label3;
- public int num = default(int);
- public double num1 = default(double);
- public float num2 = default(float);
- public decimal num3 = default(decimal);
- public byte num4 = default(byte);
- public long num5 = default(long);
- public short num6 = default(short);
- public string[] Command = { "^p^", "cls", "Hello, World!", "speak ^p^", "view ", "looprun"};
- public string[] Type = { "int", "double" };
- public string[] CpCommand = { "mode default", "1"};
- private object d = null;
- private float s = 0;
- private Label label4;
- private ComboBox comboBox1;
- enum Logtype {NOAMAL_LOG_TYPE,
- EDIT_LOG_TYPE };
- public bool editmodec = false;
- public CommandPrompt()
- {
- InitializeComponent();
- }
- private void InitializeComponent()
- {
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.button1 = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.SuspendLayout();
- //
- // textBox1
- //
- this.textBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.textBox1.ForeColor = System.Drawing.Color.AliceBlue;
- this.textBox1.Location = new System.Drawing.Point(7, 49);
- this.textBox1.Multiline = true;
- this.textBox1.Name = "textBox1";
- this.textBox1.ReadOnly = true;
- this.textBox1.Size = new System.Drawing.Size(1251, 763);
- this.textBox1.TabIndex = 0;
- this.textBox1.Text = ">";
- this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
- //
- // textBox2
- //
- this.textBox2.BackColor = System.Drawing.SystemColors.WindowFrame;
- this.textBox2.ForeColor = System.Drawing.Color.AliceBlue;
- this.textBox2.Location = new System.Drawing.Point(7, 12);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(542, 19);
- this.textBox2.TabIndex = 1;
- this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
- //
- // button1
- //
- this.button1.BackColor = System.Drawing.SystemColors.ControlLight;
- this.button1.Location = new System.Drawing.Point(555, 12);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(71, 19);
- this.button1.TabIndex = 2;
- this.button1.Text = "Run";
- this.button1.UseVisualStyleBackColor = false;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.BackColor = System.Drawing.SystemColors.Control;
- this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.label1.Location = new System.Drawing.Point(12, 34);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(23, 12);
- this.label1.TabIndex = 4;
- this.label1.Text = "Log";
- //
- // textBox3
- //
- this.textBox3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.textBox3.ForeColor = System.Drawing.Color.AliceBlue;
- this.textBox3.Location = new System.Drawing.Point(1264, 577);
- this.textBox3.Multiline = true;
- this.textBox3.Name = "textBox3";
- this.textBox3.ReadOnly = true;
- this.textBox3.Size = new System.Drawing.Size(539, 383);
- this.textBox3.TabIndex = 5;
- this.textBox3.Text = ">";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(1262, 562);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(69, 12);
- this.label2.TabIndex = 6;
- this.label2.Text = "宣言された型";
- //
- // textBox4
- //
- this.textBox4.BackColor = System.Drawing.SystemColors.InactiveCaption;
- this.textBox4.Location = new System.Drawing.Point(1264, 24);
- this.textBox4.Multiline = true;
- this.textBox4.Name = "textBox4";
- this.textBox4.ReadOnly = true;
- this.textBox4.Size = new System.Drawing.Size(539, 535);
- this.textBox4.TabIndex = 7;
- this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(1262, 9);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(26, 12);
- this.label3.TabIndex = 8;
- this.label3.Text = "help";
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(13, 839);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(112, 12);
- this.label4.TabIndex = 12;
- this.label4.Text = "LogBackGroundColor";
- //
- // comboBox1
- //
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Items.AddRange(new object[] {
- "Black",
- "White"});
- this.comboBox1.Location = new System.Drawing.Point(15, 854);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(111, 20);
- this.comboBox1.TabIndex = 13;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // CommandPrompt
- //
- this.AutoSize = true;
- this.ClientSize = new System.Drawing.Size(1806, 960);
- this.Controls.Add(this.comboBox1);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.textBox4);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.textBox3);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.textBox2);
- this.Controls.Add(this.textBox1);
- this.Name = "CommandPrompt";
- this.Text = "CommandPrompt++";
- this.Load += new System.EventHandler(this.Form1_Load);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- System.IO.StreamReader file =
- new System.IO.StreamReader("CommandDescription(ReadOnly).txt", System.Text.Encoding.GetEncoding("shift_jis"));
- public void nn()
- {
- string line1;
- while ((line1 = file.ReadLine()) != null)
- {
- textBox4.AppendText(line1 + "\n");
- }
- file.Close();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string s;
- s = ">";
- commandline();
- textBox1.AppendText(s);
- }
- public new string Text
- {
- get
- {
- return textBox2.Text;
- }
- set
- {
- value = textBox2.Text;
- }
- }
- public void put(String str)
- {
- textBox1.AppendText(str);
- }
- public void put4(String str1)
- {
- textBox3.AppendText(str1);
- }
- public void commandline()
- {
- Regex rs = new Regex("^(<#=/)");
- Regex rf = new Regex("(/=#>)$");
- Regex rsf1 = new Regex("^(#)");
- Regex rsf2 = new Regex("(#)$");
- Regex rsf1l = new Regex("^(l#)");
- Regex rsf2l = new Regex("(#l)$");
- Regex rsf1b = new Regex("^(b#)");
- Regex rsf2b = new Regex("(#b)$");
- Regex rsf1s = new Regex("^(s#)");
- Regex rsf2s = new Regex("(#s)$");
- Regex rsf3 = new Regex("^(~)");
- Regex rsf4 = new Regex("(~)$");
- Regex rsf1f = new Regex("^(f~)");
- Regex rsf2f = new Regex("(~f)$");
- Regex rsf1m = new Regex("^(m~)");
- Regex rsf2m = new Regex("(~m)$");
- Regex llp = new Regex("(:)$");
- if (!editmodec)
- {
- if (Text == cm(0))
- {
- put("^p^<コポォ\n");
- }
- else if (Text == cm(1))
- {
- textBox1.Clear();
- put("[Console]クリアしました。\n");
- textBox3.Clear();
- put4("[Console]クリアしました。\n");
- }
- else if (Text == cm(2))
- {
- put("Hello, World!\n");
- }
- else if (Text == "Textedi")
- {
- }
- else
- {
- if (Text == "")
- {
- put(
- "error : コマンドが入力されていません。\n");
- }
- else
- {
- put("\n");
- string[] pause = Text.Split('>');
- var r = new Regex(">");
- if (r.Match(Text).Success && pause[0] == "int")
- {
- put4("if (r.Match(Text).Success && pause[0] == 'int')=true\n");
- Regex re = new Regex(@"[^0-9]");
- put4(">文字の除外と代入 > 処理中 ");
- try
- {
- num = int.Parse(re.Replace(pause[1], ""));
- put4("> 完了\n");
- put4(">intに" + num + "が代入されました\n");
- put("宣言された型>" + num + "\n");
- put4(">pause(String[])の初期化 > 処理中 ");
- pause = Enumerable.Repeat<string>("", pause.Length).ToArray();
- put4("> 完了\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put4("\n" + err + "\n");
- }
- }
- else if (r.Match(Text).Success && pause[0] == "double")
- {
- put4("if (r.Match(Text).Success && pause[0] == 'int')=true\n");
- Regex re = new Regex(@"[^0-9,.,E]");
- put4(">文字の除外と代入 > 処理中 ");
- try
- {
- num1 = double.Parse(re.Replace(pause[1], ""));
- put4("> 完了\n");
- put4(">doubleに" + num1 + "が代入されました\n");
- put("宣言された型>" + num1 + "\n");
- put4(">pause(String[])の初期化 > 処理中 ");
- pause = Enumerable.Repeat<string>("", pause.Length).ToArray();
- put4("> 完了\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put4("\n" + err + "\n");
- }
- }
- else if (rs.IsMatch(Text) && rf.IsMatch(Text))
- {
- String[] pause1 = Text.Split('/');
- put("comment>>" + pause1[1] + "\n");
- pause1 = Enumerable.Repeat<string>("", pause1.Length).ToArray();
- }
- else if (rsf3.IsMatch(Text) && rsf4.IsMatch(Text))
- {
- String[] pause2 = Text.Split('~');
- Regex de = new Regex(@"[^0-9,.,e,E,-]");
- try
- {
- double i = double.Parse(de.Replace(pause2[1], ""));
- double j = double.Parse(de.Replace(pause2[3], ""));
- if (pause2[2] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause2[2] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause2[2] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause2[2] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause2[2] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause2 = Enumerable.Repeat<string>("", pause2.Length).ToArray();
- }
- else if (rsf1f.IsMatch(Text) && rsf1f.IsMatch(Text))
- {
- String[] pause3 = Text.Split('f','~');
- Regex de = new Regex(@"[^0-9,-,.,e,E,f]");
- try
- {
- float i = float.Parse(de.Replace(pause3[1], ""));
- float j = float.Parse(de.Replace(pause3[4], ""));
- if (pause3[4] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause3[4] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause3[4] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause3[4] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause3[4] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause3 = Enumerable.Repeat<string>("", pause3.Length).ToArray();
- }
- else if (rsf1f.IsMatch(Text) && rsf1f.IsMatch(Text))
- {
- String[] pause3 = Text.Split('m', '~');
- Regex de = new Regex(@"[^0-9,-,.,e,E,m]");
- try
- {
- decimal i = decimal.Parse(de.Replace(pause3[1], ""));
- decimal j = decimal.Parse(de.Replace(pause3[4], ""));
- if (pause3[4] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause3[4] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause3[4] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause3[4] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause3[4] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause3 = Enumerable.Repeat<string>("", pause3.Length).ToArray();
- }
- else if (rsf1.IsMatch(Text) && rsf2.IsMatch(Text))
- {
- String[] pause3 = Text.Split('#');
- Regex de = new Regex(@"[^0-9,-,.,]");
- try
- {
- int i = int.Parse(de.Replace(pause3[1], ""));
- int j = int.Parse(de.Replace(pause3[3], ""));
- if (pause3[2] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause3[2] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause3[2] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause3[2] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause3[2] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause3 = Enumerable.Repeat<string>("", pause3.Length).ToArray();
- }
- else if (rsf1l.IsMatch(Text) && rsf2l.IsMatch(Text))
- {
- String[] pause4 = Text.Split('l', '#');
- Regex de = new Regex(@"[^0-9,-,.,l]");
- try
- {
- long i = long.Parse(de.Replace(pause4[2], ""));
- long j = long.Parse(de.Replace(pause4[4], ""));
- if (pause4[3] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause4[3] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause4[3] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause4[3] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause4[3] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause4 = Enumerable.Repeat<string>("", pause4.Length).ToArray();
- }
- else if (rsf1b.IsMatch(Text) && rsf2b.IsMatch(Text))
- {
- String[] pause4 = Text.Split('b', '#');
- Regex de = new Regex(@"[^0-9,-,.]");
- try
- {
- byte i = byte.Parse(de.Replace(pause4[2], ""));
- byte j = byte.Parse(de.Replace(pause4[4], ""));
- if (pause4[3] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause4[3] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause4[3] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause4[3] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause4[3] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause4 = Enumerable.Repeat<string>("", pause4.Length).ToArray();
- }
- else if (rsf1s.IsMatch(Text) && rsf2s.IsMatch(Text))
- {
- String[] pause4 = Text.Split('s', '#');
- Regex de = new Regex(@"[^0-9,-,.]");
- try
- {
- short i = short.Parse(de.Replace(pause4[2], ""));
- short j = short.Parse(de.Replace(pause4[4], ""));
- if (pause4[3] == "+")
- {
- put("Resalt : " + (i + j) + "\n");
- }
- else if (pause4[3] == "-")
- {
- put("Resalt : " + (i - j) + "\n");
- }
- else if (pause4[3] == "*")
- {
- put("Resalt : " + (i * j) + "\n");
- }
- else if (pause4[3] == "/")
- {
- put("Resalt : " + (i / j) + "\n");
- }
- else if (pause4[3] == "%")
- {
- put("Resalt : " + (i % j) + "\n");
- }
- else
- {
- put("演算記号が間違っています。");
- }
- }
- catch (System.FormatException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- catch (System.OverflowException e)
- {
- string err;
- err = e.ToString();
- put(err + "\n");
- }
- pause4 = Enumerable.Repeat<string>("", pause4.Length).ToArray();
- }
- else if (Text == cm(4) + cm2(0))
- {
- put4("intに代入されている数値は、" + num + "です。\n");
- }
- else if (Text == cm(4) + cm2(1))
- {
- put4("doubleに代入されている数値は、" + num1 + "です。\n");
- }
- else if (Text == cm(1) + " " + cm2(0))
- {
- num = 0;
- }
- else if (Text == cm(1) + " " + cm2(1))
- {
- num1 = 0;
- }
- else if (Text == "modec method")
- {
- put("change mode method\n");
- put("back to nomal mode 'modec nomal()'\n");
- editmodec = true;
- }
- else
- {
- put(
- "error : '" + Text + "'" + "は、\n"
- + "実行可能なファイル又は、\n"
- + "コマンドとして認識、定義されていません。\n");
- }
- }
- }
- }
- else if (editmodec)
- {
- if (Text == "modec nomal()")
- {
- editmodec = false;
- put("\n");
- }
- else
- {
- put("error : There is no method called '" + Text + "'.\n");
- }
- }
- }
- public String cm(int e)
- {
- return Command[e];
- }
- public String cm2(int e)
- {
- return Type[e];
- }
- public String cm1(int e)
- {
- return CpCommand[e];
- }
- public bool rexs(String str)
- {
- return System.Text.RegularExpressions.Regex.IsMatch(Text, @"^(str)");
- }
- public bool rexf(String str)
- {
- return System.Text.RegularExpressions.Regex.IsMatch(Text, @"$(str)");
- }
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- nn();
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- textBox1.ForeColor = System.Drawing.Color.AliceBlue;
- textBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- int seleItem = comboBox1.SelectedIndex;
- if (seleItem == 0)
- {
- textBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- textBox1.ForeColor = System.Drawing.Color.AliceBlue;
- textBox3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- textBox3.ForeColor = System.Drawing.Color.AliceBlue;
- }
- else if (seleItem == 1)
- {
- textBox1.BackColor = System.Drawing.SystemColors.InactiveCaption;
- textBox1.ForeColor = System.Drawing.Color.Black;
- textBox3.BackColor = System.Drawing.SystemColors.InactiveCaption;
- textBox3.ForeColor = System.Drawing.Color.Black;
- }
- }
- }
- //function
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement