Exemplo n.º 1
0
        private bool NO_ARG(OptionEntry entry)
        {
            switch (entry.arg)
            {
            case OptionArg.NONE:
            case OptionArg.CALLBACK:
                return(true);

            default:
                return(entry.flags.HasFlag(OptionFlags.NO_ARG));
            }
        }
Exemplo n.º 2
0
        private bool parse_arg(
            OptionGroup group,
            OptionEntry entry,
            string value,
            string option_name
            )
        {
            Debug.Assert(value != null || OPTIONAL_ARG(entry) || NO_ARG(entry));

            switch (entry.arg)
            {
            case OptionArg.NONE: {
                OptionEntry <bool> centry = entry as OptionEntry <bool>;
                centry.arg_data = !centry.flags.HasFlag(OptionFlags.REVERSE);
                break;
            }

            case OptionArg.STRING:
            case OptionArg.FILENAME: {
                OptionEntry <string> centry = entry as OptionEntry <string>;
                centry.arg_data = value;
                break;
            }

            case OptionArg.STRING_ARRAY:
            case OptionArg.FILENAME_ARRAY: {
                OptionEntry <IList <string> > centry = entry as OptionEntry <IList <string> >;
                if (centry.arg_data == null)
                {
                    centry.arg_data = new List <string>();
                }
                centry.arg_data.Add(value);
                break;
            }

            case OptionArg.INT: {
                OptionEntry <int> centry = entry as OptionEntry <int>;
                centry.arg_data = int.Parse(value);
                break;
            }

            case OptionArg.CALLBACK: {
                OptionEntry <OptionArgFunc> centry = entry as OptionEntry <OptionArgFunc>;
                string data = null;
                if (
                    centry.flags.HasFlag(OptionFlags.OPTIONAL_ARG) ||
                    centry.flags.HasFlag(OptionFlags.NO_ARG)
                    )
                {
                    data = null;
                }
                else if (centry.flags.HasFlag(OptionFlags.FILENAME))
                {
                    data = value;
                }
                if (centry.flags.HasFlag(OptionFlags.NO_ARG | OptionFlags.OPTIONAL_ARG) && data == null)
                {
                    return(false);
                }

                bool retval = centry.arg_data(option_name, data, group.user_data);
                if (!retval)
                {
                    throw new Exception("Error parsing option " + option_name);
                }
                return(retval);
            }

            case OptionArg.DOUBLE: {
                OptionEntry <double> centry = entry as OptionEntry <double>;
                centry.arg_data = double.Parse(value);
                break;
            }

            case OptionArg.INT64: {
                OptionEntry <Int64> centry = entry as OptionEntry <Int64>;
                centry.arg_data = Int64.Parse(value);
                break;
            }

            default:
                Debug.Assert(false);
                break;
            }
            return(true);
        }
Exemplo n.º 3
0
 private bool OPTIONAL_ARG(OptionEntry entry)
 {
     return(entry.arg == OptionArg.CALLBACK && entry.flags.HasFlag(OptionFlags.OPTIONAL_ARG));
 }