view defical-sharp/defical-cli/argumentparser.cs @ 0:ebed2bd0d300

Initial import from svn. History be damned.
author Edho P. Arief <me@myconan.net>
date Fri, 02 Apr 2010 23:11:57 +0700
parents
children
line wrap: on
line source

namespace defical_cli
{
    public partial class Program
    {
        private partial class main
        {
            private bool getArguments(string[] args)
            {
                bool ret = true;
                int numArgs = args.Length;
                for (int i = 0; i < numArgs; i++)
               {
                    switch (args[i].Substring(0, 1))
                    {
                        case "-":
                            {
                                switch (args[i].Substring(1, 1))
                                {
                                    case "g":
                                        {
                                            args[i] = "--graph";
                                            i--;
                                            break;
                                        }
                                    case "n":
                                        {
                                            args[i] = "--numver";
                                            i--;
                                            break;
                                        }
                                    case "d":
                                        {
                                            args[i] = "--numdef";
                                            i--;
                                            break;
                                        }
                                    case "a":
                                        {
                                            args[i] = "--algorithm";
                                            i--;
                                            break;
                                        }
                                    case "-":
                                        {
                                            if (i < numArgs - 1)
                                            {
                                                switch (args[i].Substring(2))
                                                {
                                                    case "graph":
                                                        #region graphparser
                                                        {
                                                            switch (args[i + 1])
                                                            {
                                                                case "wheel":
                                                                case "fan":
                                                                case "doublefan":
                                                                    {
                                                                        this.graphType = args[i + 1];
                                                                        break;
                                                                    }
                                                                default:
                                                                    {
                                                                        ret = false;
                                                                        break;
                                                                    }
                                                            }
                                                            break;
                                                        }
                                                        #endregion
                                                    case "numver":
                                                        #region numverparser
                                                        {
                                                            int tempNumVer = -1;
                                                            if (parseNum(args[i + 1], 5, 10, out tempNumVer))
                                                            {
                                                                this.numVer = tempNumVer;
                                                            }
                                                            else { ret = false; }
                                                            break;
                                                        }
                                                        #endregion
                                                    case "numdef":
                                                        #region numdefparser
                                                        {
                                                            int tempNumDef = -1;
                                                            if (parseNum(args[i + 1], 0, 10, out tempNumDef))
                                                            {
                                                                this.numDef = tempNumDef;
                                                            }
                                                            else { ret = false; }
                                                            break;
                                                        }
                                                        #endregion
                                                    case "algorithm":
                                                        #region algorithmparser
                                                        {
                                                            switch (args[i + 1])
                                                            {
                                                                case "backtrack":
                                                                    this.algorithm = args[i + 1];
                                                                    break;
                                                                default:
                                                                    ret = false;
                                                                    break;
                                                            }
                                                            break;
                                                        }
                                                        #endregion
                                                }
                                                i++;
                                            }
                                            else { ret = false; }
                                            break;
                                        }
                                }
                                break;
                            }
                        default:
                            {
                                ret = false;
                                break;
                            }
                    }
                }
                //TODO
                return ret;
            }

        }
    }
}