Beispiel #1
0
        /** Parse a single argument taking things like the double-dash (--) option into consideration. */
        public void Parse(string argument)
        {
            // barf on empty parameters
            if (argument.Length == 0)
                throw new System.ArgumentException(argument);

            // handle -script parameters
            if (_script)
            {
                _arguments.Add(argument);
                return;
            }

            // handle verbatim, and positional parameters
            if (_verbatim || "@-".IndexOf(argument[0]) == -1)
            {
                _sources.Add(argument);
                return;
            }

            // handle response files
            if (argument[0] == '@')
            {
                Load(argument.Substring(1));
                return;
            }

            // handle options aka named parameters
            string name;
            string data;
            int pos = argument.IndexOf(':');
            if (pos == -1)
            {
                name = argument;
                data = null;
            }
            else
            {
                name = argument.Substring(0, pos);
                data = argument.Substring(pos + 1);
            }

            switch (name)
            {
                case "--":              // handy POSIX option: disable further processing
                    _verbatim = true;
                    break;

                case "-entry":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    _entry = data;
                    break;

                case "-h":
                case "-help":
                case "--help":      // GNU compatibility option
                    if (data != null)
                        throw new SetupError("Excess argument in option: " + argument);
                    throw new ShowHelpError();

                case "-license":
                case "--license":   // GNU compatibility option
                    if (data != null)
                        throw new SetupError("Excess argument in option: " + argument);
                    throw new ShowInfoError();

                case "-mode":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    switch (data)
                    {
                        case "ship": _mode = ModeKind.Ship; break;
                        case "test": _mode = ModeKind.Test; break;
                        case "time": _mode = ModeKind.Time; break;
                        default    : throw new SetupError("Invalid argument in option: " + argument);
                    }
                    break;

                case "-name":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    _name = data;
                    break;

                case "-output":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    _output = data;
                    break;

                case "-quiet":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    uint quiet;
                    if (!uint.TryParse(data, out quiet) || quiet > 1)
                        throw new SetupError("Invalid argument in option: " + argument);
                    _quiet = (quiet == 0) ? false : true;
                    break;

                case "-recurse":
                    if (data != null)
                        throw new SetupError("Excess argument in option: " + argument);
                    _recurse = true;
                    break;

                case "-script":
                    _script = true;
                    break;

            #if USED
                case "-target":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    _target = new Target(data);
                    break;
            #endif

                case "-todo":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    switch (data)
                    {
                        case "erase": _todo = TodoKind.Erase; break;
                        case "throw": _todo = TodoKind.Throw; break;
                        case "warn" : _todo = TodoKind.Warn; break;
                        default     : throw new SetupError("Invalid argument in option: " + argument);
                    }
                    break;

                case "-trace":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    uint value;
                    if (!uint.TryParse(data, out value) || value > 6)
                        throw new SetupError("Invalid argument in option: " + argument);
                    _trace = value;
                    break;

                case "-version":
                case "--version":   // GNU compatibility option
                    if (data != null)
                        throw new SetupError("Excess argument in option: " + argument);
                    throw new ShowLogoError();

                case "-writer":
                    if (data == null)
                        throw new SetupError("Argument missing in option: " + argument);
                    switch (data)
                    {
                        case "Braceless0":
                        case "C":
                        case "C++":
                        case "C#":
                        case "D2":
                        case "LLVM":
                        case "MSIL":
                        case "PHP5":
                        case "Python2":
                            break;

                        default:
                            throw new SetupError("Unknown writer (backend) in option: " + argument);
                    }
                    if (_writers.IndexOf(data) != -1)
                        throw new SetupError("Writer already specified once: " + argument);
                    _writers.Add(data);
                    break;

                default:
                    throw new SetupError("Unknown option: " + argument);
            }
        }
Beispiel #2
0
        /** Parse a single command-line parameter. */
        public void Parse(string arg)
        {
            // an empty argument
            if (arg.Length == 0)
                throw new TestError("Empty parameter detected");

            // a response file
            if (arg[0] == '@')
            {
                Load(arg.Substring(1));
                return;
            }

            // a named argument (an option)
            if (arg[0] == '-')
            {
                int pos = arg.IndexOf(':');
                string name;
                string data;
                if (pos == -1)
                {
                    name = arg.Substring(1);
                    data = null;
                }
                else
                {
                    name = arg.Substring(1, pos - 1);
                    data = arg.Substring(pos + 1).TrimEnd();
                }

                switch (name.ToLower())
                {
                    case "bootstrap":
                        if (data != null)
                            throw new TestError("Extranous argument in option: " + arg);
                        _bootstrap = true;
                        break;

                    case "compiler":
                        if (data == null || data.Length == 0)
                            throw new TestError("Missing argument in option: + " + arg);
                        _compiler = data;
                        break;

                    case "?":
                    case "h":
                    case "help":
                    case "-help":
                        throw new ShowHelpError();

                    case "mode":
                        if (data == null || data.Length == 0)
                            throw new TestError("Missing argument in option: + " + arg);
                        switch (data.ToLower())
                        {
                            case "ship":
                                _mode = ModeKind.Ship;
                                break;

                            case "test":
                                _mode = ModeKind.Test;
                                break;

                            default:
                                throw new TestError("Invalid mode in option: " + data);
                        }
                        break;

            #if false
            /* this does not yet work due to hard-coded assumptions about the location of the output path in Bugfind.cs. */
                    case "output":
                        if (data == null || data.Trim().Length == 0)
                            throw new TestError("Missing argument in option: + " + arg);
                        _output = data;
                        if (_output.Length > 1 && _output[_output.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                            _output += System.IO.Path.DirectorySeparatorChar;
                        break;
            #endif

                    case "platform":
                        if (data == null || data.Length == 0)
                            throw new TestError("Missing argument in option: " + arg);
                        switch (data)
                        {
                            case ".NET":
                            case "Mono":
                            case "dotGNU":
                                _platform = data;
                                break;

                            default:
                                throw new TestError("Invalid platform name in option: " + arg);
                        }
                        break;

                    case "target":
                        if (data == null || data.Length == 0)
                            throw new TestError("Missing argument in option: " + arg);
                        try
                        {
                            Target target = new Target(data);
                            _targets.Add(target);
                        }
                        catch (TestError)
                        {
                            throw new TestError("Invalid target specification: " + data);
                        }
                        break;

                    case "trace":
                        if (data == null || data.Length == 0)
                            throw new TestError("Missing argument in option: " + arg);
                        _trace = int.Parse(data);
                        if (_trace < 0 || _trace > 5)
                            throw new TestError("Invalid argument in option (must be between 0 and 5): " + arg);
                        break;

                    case "threads":
                        try
                        {
                            _threads = int.Parse(data);
                        }
                        catch (System.Exception)
                        {
                            throw new TestError("Invalid number of threads in option: " + arg);
                        }
                        break;

                    case "version":
                        throw new ShowInfoError();

                    default:
                        throw new TestError("Unknown option: " + arg);
                }

                return;
            }

            // a positional argument
            _sources.Add(arg);
        }