view defical-sharp/defical-cli/argumentparser.cs @ 1:758381a85d76 default tip

Incorrect printf format.
author Edho Prima Arief <me@myconan.net>
date Mon, 28 Jun 2010 14:52:19 +0700
parents ebed2bd0d300
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;
            }

        }
    }
}