Beispiel #1
0
        public Commands(LineEditMode lem)
        {
            LEM = lem;
            Cmds = new Dictionary<string, Action<string[], Box<bool>, LineEditMode>>();
            Usages = new Dictionary<string, string>();
            Briefs = new List<string>();

            MethodInfo[] mis = GetType().GetMethods();
            object[] objs;
            CommandNameAttribute nameatr;
            CommandUsageAttribute usageatr;
            CommandBriefAttribute briefatr;
            string brief;
            Action<string[], Box<bool>, LineEditMode> act;

            foreach (MethodInfo mi in mis)
            {
                if ((objs = mi.GetCustomAttributes(typeof(CommandNameAttribute), false)).Length == 0) continue;

                nameatr = objs[0] as CommandNameAttribute;
                usageatr = ((objs = mi.GetCustomAttributes(typeof(CommandUsageAttribute), false)).Length != 0)
                    ? objs[0] as CommandUsageAttribute : null;
                briefatr = ((objs = mi.GetCustomAttributes(typeof(CommandBriefAttribute), false)).Length != 0)
                    ? objs[0] as CommandBriefAttribute : null;

                act = GenerateCommand(mi);

                Cmds.Add(nameatr.Name, act);
                if (usageatr != null) Usages.Add(nameatr.Name, usageatr.Usage);

                foreach (string c in nameatr.Short.Replace(" ", "").Split(','))
                {
                    if (string.IsNullOrEmpty(c)) continue;
                    Cmds.Add(c, act);
                    if (usageatr != null) Usages.Add(c, usageatr.Usage);
                }

                brief = (nameatr.Name + (nameatr.Short != "" ? " (" + nameatr.Short + ")" : "")).PadRight(14, ' ');
                Briefs.Add(brief + (briefatr != null ? " -- " + briefatr.Brief : ""));
            }
        }
Beispiel #2
0
        public static void Tokenize(string[] args, Box<bool> quit, LineEditMode lem)
        {
            string src;
            src = Cty.ToText(lem.Lines);
            SyntaxAnalyzer p = new SyntaxAnalyzer();
            p.Init(src, "");

            ITokenEnumerator tkz = p.Tokens;
            while (tkz.EOF == false)
            {
                lem.CW.WN(tkz.Cur.ToString());
                tkz.Next();
            }
        }
Beispiel #3
0
        public static void WriteLineFormat(int no, LineEditMode lem)
        {
            if (no <= 0 || lem.Lines.Count < no) return;

            lem.CW.WN(string.Format("{0:D"
                + lem.Lines.Count.ToString().Length
                + "}:{1}", no, lem.Lines[no - 1]));
        }
Beispiel #4
0
 public static void Parse(string[] args, Box<bool> quit, LineEditMode lem)
 {
     string src = Cty.ToText(lem.Lines);
     Token t = (new SyntaxAnalyzer()).Run(src, "");
     lem.CW.W(TokenEx.ToTree(t));
 }
Beispiel #5
0
 public static void Quit(string[] args, Box<bool> quit, LineEditMode lem)
 {
     quit.Value = true;
 }
Beispiel #6
0
        public static void Insert(string[] args, Box<bool> quit, LineEditMode lem)
        {
            int no = 0;
            if (args.Length != 1 && args.Length != 2) Usage();
            if (args.Length == 2 && int.TryParse(args[1], out no) == false) Usage();

            if (args.Length == 1) no = lem.Lines.Count + 1;
            VerifyLineNo(no, lem.Lines.Count,/* extra = */ 1);

            if (no > 1) WriteLineFormat(no - 1, lem);

            lem.Row = no;
            lem.Col = 1;
            lem.EditLn = "";
        }
Beispiel #7
0
 public static void List(string[] args, Box<bool> quit, LineEditMode lem)
 {
     for (int i = 1; i <= lem.Lines.Count; i++)
     {
         WriteLineFormat(i, lem);
     }
 }
Beispiel #8
0
        public static void Go(string[] args, Box<bool> quit, LineEditMode lem)
        {
            StringBuilder output = new StringBuilder();
            output.Append(Compile(lem));

            // go
            output.AppendLine("--- go ---");
            Process p;
            string stdoutput;
            p = new Process();
            p.StartInfo.FileName = @"lem_default.exe";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true; // �W���o�͂���_�C���N�g

            p.Start(); // �A�v���̎��s�J�n

            stdoutput = p.StandardOutput.ReadToEnd(); // �W���o�͂̓ǂݎ��
            stdoutput = stdoutput.Replace("\r\r\n", "\n"); // ���s�R�[�h�̏C��

            output.Append(stdoutput);

            lem.CW.WN(output.ToString()); // �m�o�́n�E�B���h�E�ɏo��
        }
Beispiel #9
0
        public static void Help(string[] args, Box<bool> quit, LineEditMode lem)
        {
            if (args.Length >= 2 && lem.Cmds.Usages.ContainsKey(args[1]))
            {
                string s = lem.Cmds.Usages[args[1]];
                lem.CW.WN(s);
                return;
            }

            foreach (string b in lem.Cmds.Briefs)
            {
                lem.CW.WN(b);
            }
        }
Beispiel #10
0
 public static void DelIns(string[] args, Box<bool> quit, LineEditMode lem)
 {
     Delete(args, quit, lem);
     Insert(args, quit, lem);
 }
Beispiel #11
0
        public static void Delete(string[] args, Box<bool> quit, LineEditMode lem)
        {
            if (lem.Lines.Count == 0) throw new Exception("No lines to delete");
            int no = 0, n2 = 0, len;

            if (args.Length != 2 && args.Length != 4) Usage();
            if (int.TryParse(args[1], out no) == false) Usage();
            if (args.Length == 4 && Regex.IsMatch(args[2], @"(-|:)") == false) Usage();
            if (args.Length == 4 && int.TryParse(args[3], out n2) == false) Usage();

            if (args.Length == 4 && args[2] == "-")
            {
                if (n2 < no) { int tmp = no; no = n2; n2 = tmp; }
                len = n2 - no + 1;
            }
            else if (args.Length == 4 && args[2] == ":")
            {
                if (n2 < 0)
                {
                    no = no + n2;
                    n2 = Math.Abs(n2) + 1;
                }
                len = n2;
            }
            else
            {
                len = 1;
            }

            VerifyLineNo(no, lem.Lines.Count,/* extra = */ 0);
            VerifyLineNo(no + len - 1, lem.Lines.Count,/* extra = */ 0);
            lem.Lines.RemoveRange(no - 1, len);
        }
Beispiel #12
0
        public static string Compile(LineEditMode lem)
        {
            Ctrl c = new Ctrl();
            StringBuilder b = new StringBuilder();
            Action<string> trace = delegate(string s) { b.Append(s); };
            c.StdOut = trace;
            c.StdErr = trace;

            c.StartCompile(new string[] { lem.DefaultSrcPath
                , "/xxxil"
                , "/xxxtrace"
            });

            return b.ToString();
        }
Beispiel #13
0
 public static void Compile(string[] args, Box<bool> quit, LineEditMode lem)
 {
     string output = Compile(lem);
     lem.CW.WN(output);
 }
Beispiel #14
0
 public static void List(LineEditMode lem)
 {
     for (int i = 1; i <= lem.Lines.Count; i++)
     {
         WriteLineFormat(i, lem);
     }
 }