Exemplo n.º 1
0
        static TabData ConsoleHelpTab(string line)
        {
            string[] split   = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string   subLine = "";

            if (split.Length > 2)
            {
                return(TabData.Failue());
            }
            if (split.Length == 2)
            {
                subLine = split[1];
            }

            TabData data = TabInput(subLine);

            //Data.Line = split[0] + " " + data.Line;
            return(data);
        }
Exemplo n.º 2
0
        public static TabData TabInput(string line)
        {
            string[] matches;
            string[] split = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


            lock (_varables)
            {
                line = line.TrimStart();
                if (line.Contains(" "))
                {
                    TabData subResponse;
                    string  trimline = split[0];

                    //Get possible results from module.
                    if (_varables.Contains(trimline))
                    {
                        if (_varables[trimline].TabFunction == null)
                        {
                            return(TabData.Failue());
                        }
                        else
                        {
                            subResponse = _varables[trimline].TabFunction(line);
                        }
                    }
                    else if (_functions.Contains(trimline))
                    {
                        if (_functions[trimline].TabFunction == null)
                        {
                            return(TabData.Failue());
                        }
                        else
                        {
                            subResponse = _functions[trimline].TabFunction(line);
                        }
                    }
                    else
                    {
                        return(TabData.Failue());
                    }

                    if (subResponse.Result == false)
                    {
                        return(TabData.Failue());
                    }

                    line = subResponse.Line;

                    if (subResponse.TabStrings == null || subResponse.TabStrings.Length == 0)
                    {
                        return new TabData()
                               {
                                   Result = true, Line = trimline + " " + line
                               }
                    }
                    ;
                    if (subResponse.TabStrings.Length == 1)
                    {
                        return new TabData()
                               {
                                   Result = true, Line = trimline + " " + subResponse.TabStrings[0]
                               }
                    }
                    ;

                    matches = subResponse.TabStrings;
                }
                else
                {
                    SortedList <string> sortedMatches = new SortedList <string>(StringComparer.CurrentCultureIgnoreCase);
                    foreach (string name in _varables.Keys)
                    {
                        if (name.StartsWith(line))
                        {
                            sortedMatches.Add(name);
                        }
                    }
                    foreach (string name in _functions.Keys)
                    {
                        if (name.StartsWith(line))
                        {
                            sortedMatches.Add(name);
                        }
                    }

                    if (sortedMatches.Count == 0)
                    {
                        return new TabData()
                               {
                                   Result = false
                               }
                    }
                    ;
                    if (sortedMatches.Count == 1)
                    {
                        return new TabData()
                               {
                                   Result = true, Line = sortedMatches[0]
                               }
                    }
                    ;;

                    // Expand it out to match the closest match of any.
                    matches = sortedMatches.ToArray();
                }
            }

            if (split.Length > 0)
            {
                int length = split[split.Length - 1].Length;

                char c;
                while (matches[0].Length > length)
                {
                    // Length is always 1 more than the index,
                    // This means a length of 1 will attempt to grab an index of 2;
                    c = matches[0][length];
                    foreach (string entry in matches)
                    {
                        if (entry.Length == length || (entry.Length > length && entry[length] != c))
                        {
                            goto @break; // No point in continuing
                        }
                    }
                    line += c;
                    length++;
                }
                @break :;
            }

            return(new TabData()
            {
                Result = true, Line = line, TabStrings = matches
            });
        }