public void Append (SpObject obj) { if (IsTable () == false) { mType = ArgType.Table; mValue = new Dictionary<object, SpObject> (); } Insert (AsTable ().Count, obj); }
// Constructor public NotifyArgs(string newEventItem, object newObjectItem, EventArgs newEventArgsItem, ArgType newArgsType) { eventItem = newEventItem; objectItem = newObjectItem; eventArgsItem = newEventArgsItem; argsType = newArgsType; }
public void Insert (object key, SpObject obj) { if (IsTable () == false) { mType = ArgType.Table; mValue = new Dictionary<object, SpObject> (); } AsTable ()[key] = obj; }
public Parameter(int lineNum, int colNum, int charIndex, VariableDeclaration varDec, ArgType argType) : base(lineNum, colNum, charIndex) { this.TypeMark = varDec.TypeMark; this.VariableName = varDec.VariableName; this.ArraySize = varDec.ArraySize; Type = argType; }
public void Insert(object key, SpObject obj) { if (IsTable() == false) { mType = ArgType.Table; mValue = new Dictionary <object, SpObject>(); } AsTable()[key] = obj; }
// constructor NAME + DESCRIPTION internal AzmiArgument(string name, [DisallowNull] string description, ArgType type = ArgType.str, bool required = false) : this( name, name[0], description, required, type) { }
// constructor NAME + ALIAS? + DESCRIPTION internal AzmiArgument(string name, char?alias, string description, ArgType type = ArgType.str, bool required = false) : this( name, alias, description, required, type) { }
// constructor NAME with one string internal AzmiArgument(string name, ArgType type = ArgType.str, bool required = false) : this( name, name[0], $"Description for {name}", required, type) { }
public override int GetHashCode() { unchecked { var hashCode = (Key != null ? Key.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ArgType != null ? ArgType.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Position; return(hashCode); } }
public void Append(SpObject obj) { if (IsTable() == false) { mType = ArgType.Table; mValue = new Dictionary <object, SpObject>(); } Insert(AsTable().Count, obj); }
// constructor NAME with one string internal AzmiArgument(string name, ArgType type = defaultType, bool required = defaultRequired, bool multiValued = defaultMultiValued) : this( name, name[0], $"Description for {name}", required, type, multiValued) { }
// constructor NAME + ALIAS? + DESCRIPTION internal AzmiArgument(string name, char?alias, string description, ArgType type = defaultType, bool required = defaultRequired, bool multiValued = defaultMultiValued) : this( name, alias, description, required, type, multiValued) { }
public static @string GoString(this ArgType t) { var s = t.String(); if (t > 0L && t < TypeLast) { return("Type" + s); } return(s); }
// constructor NAME + DESCRIPTION internal AzmiArgument(string name, [DisallowNull] string description, ArgType type = defaultType, bool required = defaultRequired, bool multiValued = defaultMultiValued) : this( name, name[0], description, required, type, multiValued) { }
private Win32API/*!*/ Reinitialize(IntPtr function, ArgType[] signature, ArgType returnType) { if (IntPtr.Size != 4) { throw new NotSupportedException("Win32API is not supported in 64-bit process"); } Debug.Assert(function != IntPtr.Zero && signature != null); _function = function; _signature = signature; _returnType = returnType; _version = Interlocked.Increment(ref _Version); return this; }
private static Type /*!*/ ToNativeType(ArgType argType) { switch (argType) { case ArgType.Buffer: return(typeof(byte[])); case ArgType.Int32: return(typeof(int)); case ArgType.None: return(typeof(void)); } throw Assert.Unreachable; }
public static object MatchArgToType(Character self, string arg, ArgType type) { object result; int nresult; if (type.HasFlag(ArgType.Int) && int.TryParse(arg, out nresult)) { return(nresult); } if (type.HasFlag(ArgType.String)) { return(arg); } if (type.HasFlag(ArgType.ObjEq) && (result = self.Eq.Items.ToList().Find(obj => obj.MatchNames(arg))) != null) { return(result); } if (type.HasFlag(ArgType.ObjInv) && (result = self.Inventory.Find(obj => obj.MatchNames(arg))) != null) { return(result); } if (type.HasFlag(ArgType.ObjRoom) && (result = self.Room.Items.Find(obj => obj.MatchNames(arg))) != null) { return(result); } if (type.HasFlag(ArgType.ChRoom) && (result = self.Room.Characters.Find(vch => vch.MatchNames(arg))) != null) { return(result); } if (type.HasFlag(ArgType.ExitRoom) && (result = self.Room.Exits[arg]) != null) { return(result); } /*if( type.HasFlag( ArgType.ChWorld ) * && ( result = World.ActivePlayers.Find( * player => player.Model.ShortDescr.StartsWith( arg, StringComparison.CurrentCultureIgnoreCase ) ) ) != null ) * return result;*/// TODO fix return(null); }
private void SetArgument(ref Argument sop, ref ArgType argType, ParameterInfo[] infos, int paramNum, int wid) { //インスタンスがObject型に変換可能であれば引数に代入し、引数のTypeを決める if (infos[paramNum].ParameterType.IsSubclassOf(typeof(UnityEngine.Object))) { GUILayout.Label("Object"); sop.object_Arg = (UnityEngine.Object)EditorGUILayout.ObjectField(sop.object_Arg, infos[paramNum].ParameterType, true, GUILayout.Width(wid)); argType = ArgType.UnityObject; } //int型 else if (infos[paramNum].ParameterType == typeof(int)) { GUILayout.Label("int"); sop.int_Arg = EditorGUILayout.IntField(sop.int_Arg, GUILayout.Width(wid)); argType = ArgType.Int; } //string型 else if (infos[paramNum].ParameterType == typeof(string)) { GUILayout.Label("string"); sop.string_Arg = EditorGUILayout.TextField(sop.string_Arg, GUILayout.Width(wid - 20)); argType = ArgType.String; } //float型 else if (infos[paramNum].ParameterType == typeof(float)) { GUILayout.Label("float"); sop.float_Arg = EditorGUILayout.FloatField(sop.float_Arg, GUILayout.Width(wid)); argType = ArgType.Float; } //bool型 else if (infos[paramNum].ParameterType == typeof(bool)) { GUILayout.Label("bool"); sop.bool_Arg = EditorGUILayout.Toggle(sop.bool_Arg, GUILayout.Width(wid)); argType = ArgType.Bool; } else if (infos[paramNum].ParameterType.IsEnum) { GUILayout.Label("Enum"); Enum em = (Enum)infos[paramNum].ParameterType.GetField(Enum.GetName(infos[paramNum].ParameterType, sop.enum_Arg)).GetValue(null); em = EditorGUILayout.EnumPopup(em); sop.enum_Arg = em.GetHashCode(); sop.enum_Name = infos[paramNum].ParameterType.FullName; sop.assembly_Name = infos[paramNum].ParameterType.Assembly.FullName; argType = ArgType.Enum; } else { GUILayout.Label("未対応の引数です、エラーが起こります"); } }
public CodeArg(string src) { if (src.StartsWith("\"")) { _ArgType = ArgType.TEXT; _Value = TextUtil.unescapeText(src); } else { _ArgType = ArgType.ENUM; _Value = src; } }
public Argument(Argument otherArg) { Type = otherArg.Type; Name = otherArg.Name; Init(); if (otherArg.Arguments == null || otherArg.Arguments.Count <= 0) { return; } foreach (var arg in otherArg.Arguments) { Arguments.Add(new Argument(arg)); } }
private Win32API /*!*/ Reinitialize(IntPtr function, ArgType[] signature, ArgType returnType) { if (IntPtr.Size != 4) { throw new NotSupportedException("Win32API is not supported in 64-bit process"); } Debug.Assert(function != IntPtr.Zero && signature != null); _function = function; _signature = signature; _returnType = returnType; _version = Interlocked.Increment(ref _Version); return(this); }
static void Main(string[] args) { try { //assume the first arg to be the input file currentArgType = ArgType.Action; //then look for other args for (int index = 0; index < args.Length; index++) { if (args[index].StartsWith("-")) //an attribute { if (args[index] == "--action" || args[index] == "-a") { currentArgType = ArgType.Action; } else if (args[index] == "--data" || args[index] == "-d") { currentArgType = ArgType.Data; } } else //a value { commandLineArgs.Add(currentArgType, args[index]); } } if (commandLineArgs[ArgType.Action] == "add-activity") { AddActivity(commandLineArgs[ArgType.Data]); } else if (commandLineArgs[ArgType.Action] == "enroll") { Enroll(commandLineArgs[ArgType.Data]); } else if (commandLineArgs[ArgType.Action] == "get") { Get(commandLineArgs[ArgType.Data]); } else if (commandLineArgs[ArgType.Action] == "identify") { Identify(commandLineArgs[ArgType.Data]); } } catch (Exception ex) { Console.WriteLine($">> Error : {ex.Message}"); } Console.Read(); }
public SpObject (ArgType type, params object[] args) { mType = ArgType.Null; switch (type) { case ArgType.Array: for (int i = 0; i < args.Length; i++) { Insert (i, args[i]); } break; case ArgType.Table: for (int i = 0; i < args.Length; i += 2) { Insert (args[i], args[i + 1]); } break; } }
public Dictionary <uint, string> GetArgList(ArgType argType, bool IsTran = false) { if (ArgDic.ContainsKey(argType)) { if (IsTran) { return(TranArgDic[argType]); } else { return(ArgDic[argType]); } } return(null); }
private bool TryGetArg(string str, ArgType type, out object arg) { try { arg = GetArg(str, type); return(true); } catch { } arg = null; return(false); }
/// <summary> /// If <see cref="ArgType"/> is not null, returns a new default instance of <see cref="ArgType"/>. /// Otherwise, returns null. /// </summary> public object CreateArguments() { if (ArgType == null) { return(null); } var ctor = ArgType.GetConstructor(Type.EmptyTypes); if (ctor == null) { throw Contracts.Except("Loadable class '{0}' has ArgType '{1}', which has no suitable constructor", UserName, ArgType); } return(ctor.Invoke(null)); }
public CmdArgument(string names, ArgType type, string help = "", string parameter_help = "", bool required = false, bool anonymous = false, Action <dynamic> assign = default(Action <dynamic>)) { _type = type; _value = NewArgType(type); _names = names.Split(','); _required = required; _assign = assign; _help = help; _parameter_help = parameter_help; _matched = false; _anonymous = anonymous; }
public static Type RealType(ArgType type) { switch (type) { case ArgType.Bool: return(typeof(bool)); case ArgType.Int: return(typeof(int)); case ArgType.Float: return(typeof(float)); case ArgType.String: return(typeof(string)); case ArgType.Object: return(typeof(Object)); case ArgType.GameObject: return(typeof(GameObject)); case ArgType.StringVariable: return(typeof(StringVariable)); case ArgType.ScriptableObject: return(typeof(ScriptableObject)); case ArgType.KeyValuePairsArrayVariable: return(typeof(KeyValuePairsArrayVariable)); case ArgType.FloatVariable: return(typeof(FloatVariable)); case ArgType.InputKey: return(typeof(AdvancedUnityPlugin.Input.Key)); case ArgType.AnimationClip: return(typeof(AnimationClip)); default: return(null); } }
public object GetValue(ArgType type) { switch (type) { case ArgType.Bool: return(boolValue); case ArgType.Int: return(intValue); case ArgType.Float: return(floatValue); case ArgType.String: return(stringValue); case ArgType.Object: return(objectValue); case ArgType.GameObject: return(gameObjectValue); case ArgType.StringVariable: return(stringVariableValue); case ArgType.ScriptableObject: return(scriptableObjectValue); case ArgType.KeyValuePairsArrayVariable: return(keyValuePairsArrayVariable); case ArgType.FloatVariable: return(floatVariable); case ArgType.InputKey: return(inputKeyVariable); case ArgType.AnimationClip: return(clipVariable); default: return(null); } }
// generate a new dynamic object with type suitable for ArgType private dynamic NewArgType(ArgType type) { switch (type) { case ArgType.Int: case ArgType.Counter: return(new int()); case ArgType.Double: return(new double()); case ArgType.String: return(String.Empty); case ArgType.Flag: return(new bool()); } return(null); }
private object GetArg(string str, ArgType type) { object arg; switch (type) { case ArgType.Int: arg = long.Parse(str); break; default: arg = str; break; } return(arg); }
int ReadArg(Track track, ArgType type) { switch (type) { case ArgType.Byte: // GetByte { return(sseq.Data[track.DataOffset++]); } case ArgType.Short: // GetShort { return(sseq.Data[track.DataOffset++] | (sseq.Data[track.DataOffset++] << 8)); } case ArgType.VarLen: // GetVariableLengthInt { int read = 0, val = 0; byte b; do { b = sseq.Data[track.DataOffset++]; val = (val << 7) | (b & 0x7F); read++; }while (read < 4 && (b & 0x80) != 0); return(val); } case ArgType.Rand: // GetRandomShort { short min = (short)(sseq.Data[track.DataOffset++] | (sseq.Data[track.DataOffset++] << 8)); short max = (short)(sseq.Data[track.DataOffset++] | (sseq.Data[track.DataOffset++] << 8)); return(Utils.RNG.Next(min, max + 1)); } case ArgType.SoundVar: // GetSoundVarShort { byte varIndex = sseq.Data[track.DataOffset++]; return(soundVars[varIndex].Value); } default: throw new Exception(); } }
private Command(Xml::XmlElement elem) { this.name = elem.GetAttribute("name"); this.size = int.Parse(elem.GetAttribute("size")); this.mask = int.Parse(elem.GetAttribute("mask")); this.code = int.Parse(elem.GetAttribute("code")); string sbits = elem.GetAttribute("bits"); if (sbits != "00") { bits = (Bits)System.Enum.Parse(typeof(Bits), sbits); } else { bits = Bits.None; } this.type = default(CmdType); string[] types = elem.GetAttribute("type").Split('|'); foreach (string stype in types) { if ('0' <= stype[0] && stype[0] <= '9') { this.type |= (CmdType)int.Parse(stype); } else { this.type |= (CmdType)System.Enum.Parse(typeof(CmdType), stype); } } Gen::List <ArgType> list = new System.Collections.Generic.List <ArgType>(); foreach (Xml::XmlElement earg in elem.SelectNodes("/operand")) { string stype = earg.GetAttribute("type"); ArgType type = (ArgType)System.Enum.Parse(typeof(ArgType), stype); list.Add(type); } this.args = list.ToArray(); }
private void SetArgument(ref Argument sop, ref ArgType argType, ParameterInfo[] infos, int paramNum, int wid) { //インスタンスがObject型に変換可能であれば引数に代入し、引数のTypeを決める if (infos[paramNum].ParameterType.IsSubclassOf(typeof(UnityEngine.Object))) { GUILayout.Label("Object"); sop.object_Arg = (UnityEngine.Object)EditorGUILayout.ObjectField(sop.object_Arg, infos[paramNum].ParameterType, true, GUILayout.Width(wid)); argType = ArgType.UnityObject; } //int型 else if (infos[paramNum].ParameterType == typeof(int)) { GUILayout.Label("int"); sop.int_Arg = EditorGUILayout.IntField(sop.int_Arg, GUILayout.Width(wid)); argType = ArgType.Int; } //string型 else if (infos[paramNum].ParameterType == typeof(string)) { GUILayout.Label("string"); sop.string_Arg = EditorGUILayout.TextField(sop.string_Arg, GUILayout.Width(wid - 20)); argType = ArgType.String; } //float型 else if (infos[paramNum].ParameterType == typeof(float)) { GUILayout.Label("float"); sop.float_Arg = EditorGUILayout.FloatField(sop.float_Arg, GUILayout.Width(wid)); argType = ArgType.Float; } //bool型 else if (infos[paramNum].ParameterType == typeof(bool)) { GUILayout.Label("bool"); sop.bool_Arg = EditorGUILayout.Toggle(sop.bool_Arg, GUILayout.Width(wid)); argType = ArgType.Bool; } else { GUILayout.Label("未対応の引数です、エラーが起こります"); } }
public System.Type RealType(ArgType type) { switch (type) { case ArgType.CurrentGenericParam0: return(System.Type.GetType(genericType0)); case ArgType.CurrentGenericParam1: return(System.Type.GetType(genericType1)); case ArgType.CurrentGenericParam2: return(System.Type.GetType(genericType2)); case ArgType.CurrentGenericParam3: return(System.Type.GetType(genericType3)); default: return(null); } }
public SpObject (object arg) { mValue = arg; mType = ArgType.Null; if (mValue != null) { Type t = mValue.GetType (); if (t == typeof (long)) { mType = ArgType.Long; } else if (t == typeof (int)) { mType = ArgType.Int; } else if (t == typeof (string)) { mType = ArgType.String; } else if (t == typeof (bool)) { mType = ArgType.Boolean; } } }
private static ArgType[] /*!*/ MakeSignature(int size, Func <int, byte> /*!*/ getByte) { ArgType[] signature = new ArgType[size]; int j = 0; for (int i = 0; i < size; i++) { var argType = ToArgType(getByte(i)); if (argType != ArgType.None) { signature[j++] = argType; } } if (j != signature.Length) { Array.Resize(ref signature, j); } return(signature); }
public Arg(string arg, bool containsLabel, bool allowSixBit) { if (arg.Contains('(')) { Type = ArgType.HasParaenthesis; var args = arg.Split('('); args[0] = args[0].Replace("(", ""); args[0] = args[0].Replace(")", ""); args[0] = args[0].Replace("$", ""); args[1] = args[1].Replace("(", ""); args[1] = args[1].Replace(")", ""); args[1] = args[1].Replace("$", ""); OutsideValue = Int32.Parse(args[0]); Value = Int32.Parse(args[1]); } else if (arg.Contains('$')) { Type = ArgType.HasDollarSign; arg = arg.Replace("$", ""); Value = Int32.Parse(arg); } else { if (!containsLabel) { Type = ArgType.JustAValue; Value = Int32.Parse(arg); } else { Label = arg; IsLabel = true; } } var maxValue = allowSixBit ? 63 : 7; if (!IsLabel && (Value > maxValue || OutsideValue > 63)) { throw new ValueTooLargeException(); } }
public Argument(string data, ArgType type = ArgType.NONE) { Name = data.Split(' ')[0]; Description = data.Substring(data.IndexOf(" ") + 1); Type = type; }
public IEnumerable<string> GetArgs(ArgType type) { return _argDatas[type].Args; }
public string GetArg(ArgType type) { return _argDatas[type].Args.First(); }
private string GetFormattedArg(double argVal, ArgType type) { // beware, you have to cast to correct type for X to work (it will throw exception on floating types etc) switch (type) { case ArgType.Byte: return string.Format("0x{0:X2}", (byte)argVal); case ArgType.Word: return string.Format("0x{0:X4}", (ushort)argVal); case ArgType.Dword: return string.Format("0x{0:X8}", (uint)argVal); case ArgType.Qword: return string.Format("0x{0:X16}", (ulong)argVal); case ArgType.Token: return string.Format("0x{0:X8}", (uint)argVal); // beware: branches use relative logic that is not straightforward to print case ArgType.SmallBranch: byte b = (byte) argVal; if (b <= 127) return string.Format("0x{0:X8}", Offset + 2 + b); else return string.Format("0x{0:X8}", Offset + 2 - (0 - b)); case ArgType.Branch: uint dword = (uint) argVal; if (dword <= 0x7FFFFFFF) return string.Format("0x{0:X8}", Offset + 5 +dword); else return string.Format("0x{0:X8}", Offset + 5 - (0 - dword)); case ArgType.Char: case ArgType.Short: return string.Format("{0}", (short) argVal); case ArgType.UChar: case ArgType.UShort: return string.Format("{0}", (ushort) argVal); case ArgType.Int: return string.Format("{0}", (int) argVal); case ArgType.UInt: return string.Format("{0}", (uint) argVal); case ArgType.Int64: return string.Format("{0}", (ulong) argVal); case ArgType.Float: case ArgType.Double: return argVal.ToString("F"); default: return string.Empty; } }
public Arg(ArgType type, string param) { Type = type; Param = param; }
private static ArgType[]/*!*/ MakeSignature(int size, Func<int, byte>/*!*/ getByte) { ArgType[] signature = new ArgType[size]; int j = 0; for (int i = 0; i < size; i++) { var argType = ToArgType(getByte(i)); if (argType != ArgType.None) { signature[j++] = argType; } } if (j != signature.Length) { Array.Resize(ref signature, j); } return signature; }
public SpObject () { mValue = null; mType = ArgType.Null; }
private void _PushLocalVar(int byteOffset, ArgType argType) { String argName = null; if (_excelFunction != null) { argName = (from arg in _excelFunction.Args where arg.ByteOffset == byteOffset select arg.Name).FirstOrDefault(); } if (argName == null) { StackObject localVar = (from varObj in _vars where varObj.ByteOffset == byteOffset select varObj).FirstOrDefault(); Debug.Assert(localVar != null); int index = byteOffset / 4; argName = "var" + index; } Debug.Assert(argName != null); _stack.Push(new StackObject { Value = argName, Type = argType }); }
public Args(ArgType type) { this.type=type; }
private static void SetInstruction(DisassembledInstruction dec, Instruction instr, byte[] chunks, ArgType type) { dec.Instruction = instr; ReadParameter(dec, chunks, type, false); }
private static void SetPrefix(DisassembledInstruction dec, Prefix prefix, byte[] chunks, ArgType type) { dec.PrefixType = type; dec.Prefix = prefix; ReadParameter(dec, chunks, type, true); }
public Argument(ArgType type, string str) { this.type = type; this.str = str; this.param = null; }
private static Type/*!*/ ToNativeType(ArgType argType) { switch (argType) { case ArgType.Buffer: return typeof(byte[]); case ArgType.Int32: return typeof(int); case ArgType.None: return typeof(void); } throw Assert.Unreachable; }
public RegisterArguments(Type t, ArgType argType) { this.Type = t; this.ArgType = argType; }
private Expression/*!*/ MarshalArgument(MetaObjectBuilder/*!*/ metaBuilder, DynamicMetaObject/*!*/ arg, ArgType parameterType) { object value = arg.Value; if (value == null) { metaBuilder.AddRestriction(Ast.Equal(arg.Expression, AstUtils.Constant(null))); } else { metaBuilder.AddTypeRestriction(value.GetType(), arg.Expression); } switch (parameterType) { case ArgType.Buffer: if (value == null) { return AstUtils.Constant(null, typeof(byte[])); } if (value is int && (int)value == 0) { metaBuilder.AddRestriction(Ast.Equal(AstUtils.Convert(arg.Expression, typeof(int)), AstUtils.Constant(0))); return AstUtils.Constant(null, typeof(byte[])); } if (value.GetType() == typeof(MutableString)) { return Methods.GetMutableStringBytes.OpCall( AstUtils.Convert(arg.Expression, typeof(MutableString)) ); } return Methods.GetMutableStringBytes.OpCall( AstUtils.LightDynamic(ConvertToStrAction.Make(_context), typeof(MutableString), arg.Expression) ); case ArgType.Int32: if (value is int) { return AstUtils.Convert(arg.Expression, typeof(int)); } return Ast.Convert( Ast.Call( AstUtils.LightDynamic(ConvertToIntAction.Make(_context), typeof(IntegerValue), arg.Expression), Methods.IntegerValue_ToUInt32Unchecked ), typeof(int) ); } throw Assert.Unreachable; }
private static void ReadParameter(DisassembledInstruction dec, byte[] chunks, ArgType type, bool isPrefixVal) { if (isPrefixVal) dec.PrefixType = type; else dec.ArgType = type; if (type == ArgType.None) return; int curIdx = dec.RollingByteIndex; double? parsedVal = null; switch (type) { case ArgType.SmallBranch: case ArgType.Byte: case ArgType.Char: case ArgType.UChar: if (type != ArgType.UChar) parsedVal = chunks[curIdx]; else parsedVal = ((sbyte)chunks[curIdx]); ++curIdx; break; case ArgType.Short: if (EnsureRoom(chunks, curIdx, 2)) { parsedVal = BitConverter.ToInt16(chunks, curIdx); curIdx += 2; } break; case ArgType.UShort: if (EnsureRoom(chunks, curIdx, 2)) { parsedVal = BitConverter.ToUInt16(chunks, curIdx); curIdx += 2; } break; case ArgType.Token: case ArgType.UInt: case ArgType.Branch: case ArgType.Dword: if (EnsureRoom(chunks, curIdx, 4)) { parsedVal = BitConverter.ToUInt32(chunks, curIdx); curIdx += 4; } break; case ArgType.Int: if (EnsureRoom(chunks, curIdx, 4)) { parsedVal = BitConverter.ToInt32(chunks, curIdx); curIdx += 4; } break; case ArgType.Qword: if (EnsureRoom(chunks, curIdx, 8)) { parsedVal = BitConverter.ToUInt64(chunks, curIdx); curIdx += 8; } break; case ArgType.Int64: if (EnsureRoom(chunks, curIdx, 8)) { parsedVal = BitConverter.ToInt64(chunks, curIdx); curIdx += 8; } break; case ArgType.Switch: // first uint -> # of uints follow it, its an array of switch offsets // [dword #1] ([dword] [dword] .... ) x #1 if (EnsureRoom(chunks, curIdx, 4)) { int switchOffsetsCount = BitConverter.ToInt32(chunks, curIdx); curIdx += 4; // TODO: does the array of offsets need to be saved? int switchByteSize = 4 * switchOffsetsCount; if (EnsureRoom(chunks, curIdx, switchByteSize)) curIdx += switchByteSize; } break; } if (parsedVal != null) { if (isPrefixVal) dec.PrefixValue = parsedVal.Value; else dec.ArgValue = parsedVal.Value; } // dont forget to update this, wups dec.RollingByteIndex = curIdx; }
/// <summary> /// Gets the string associated with the expected argument type. /// </summary> /// <param name="argType">The argument type.</param> /// <returns>The string describing the argument type.</returns> internal static string ValueMessage(ArgType argType) { return valueMessage[(int)argType]; }
public ArgDef(string name, ArgType type) : this(name, type, false) { }
static void Main(string[] args) { if (!initialized) { Console.WriteLine("Quic Command Line Interface"); Console.WriteLine(); Messenger.Prompted += Messenger_Prompted; Messenger.Notified += Messenger_Notified; Messenger.NotificationsCleared += Messenger_NotificationsCleared; initialized = true; } try { //assume the first arg to be the input file currentArgType = ArgType.InputFile; //then look for other args for (int index = 0; index < args.Length; index++) { if (args[index].StartsWith("-")) //an attribute { if (args[index] == "--input-file" || args[index] == "-i") { currentArgType = ArgType.InputFile; } else if (args[index] == "--output-dir" || args[index] == "-o") { currentArgType = ArgType.OutputDirectory; } else if (args[index] == "--done" || args[index] == "-d") { currentArgType = ArgType.Done; } } else //a value { commandLineArgs.Add(currentArgType, args[index]); } } //if there are missing command line args, ask for them if (!commandLineArgs.ContainsKey(ArgType.InputFile)) { Console.WriteLine("Specify the path to the input file:"); string inputFile = Console.ReadLine(); commandLineArgs.Add(ArgType.InputFile, inputFile); } if (!commandLineArgs.ContainsKey(ArgType.OutputDirectory)) { Console.WriteLine("Specify the path to the output directory:"); string outputDirectory = Console.ReadLine(); commandLineArgs.Add(ArgType.OutputDirectory, outputDirectory); } string sourceFile = commandLineArgs[ArgType.InputFile]; string outputDir = commandLineArgs[ArgType.OutputDirectory]; if (!string.IsNullOrWhiteSpace(sourceFile) && !string.IsNullOrWhiteSpace(outputDir)) { Messenger.ClearNotifications(); QuicDocument doc = QuicDocument.Load(sourceFile); doc.Render(outputDir); //a success notif if (Messenger.Notifications.Length == 0) { Messenger.Notify( new QuicException("Build complete.", sourceFile) { MessageType = MessageType.Success }); } if (commandLineArgs.ContainsKey(ArgType.Done)) { string done = commandLineArgs[ArgType.Done]; if (done.Equals("open-dir", StringComparison.InvariantCultureIgnoreCase)) { if (Directory.Exists(outputDir)) Process.Start(outputDir); } } } } catch (ArgumentException) { Messenger.Prompt("A command line option appears more than once.", MessageType.Error); } catch (QuicException ex) { Messenger.Notify(ex); } catch (Exception ex) { //MessageBox.Show(ex.Message, "Quic"); Messenger.Prompt(ex.Message, MessageType.Error); } Console.WriteLine(); Console.WriteLine("Press Enter to exit"); Console.Read(); }
public ArgDef(string name, ArgType type, bool optional) { Name = name; Type = type; Optional = optional; }
/// <summary> /// Check one of the arguments /// </summary> /// <param name="arg">An argument passed to the primitive.</param> /// <param name="argType">The expected argument type.</param> private void CheckArgType(SchemeObject arg, ArgType argType) { if (ArgTypeTester.Ok(arg, argType)) { return; } var msg = string.Format( @"Primitive ""{0}"" invalid argument ""{1}"". Got type: {2}. Expected type: {3}", this.ProcedureName, arg.ToString(true), arg.GetType().Name, ArgTypeTester.ValueMessage(argType)); ErrorHandlers.SemanticError(msg, arg); }
/// <summary> /// Tests the argument against the expected argument type. /// </summary> /// <param name="arg">The actual argument.</param> /// <param name="argType">The expected argument type.</param> /// <returns>True if OK.</returns> internal static bool Ok(SchemeObject arg, ArgType argType) { return argType <= ArgType.Undefined && argPredicates[(int)argType](arg); }