예제 #1
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode ToList(
            ProcedureFlags hasFlags,
            ProcedureFlags notHasFlags,
            bool hasAll,
            bool notHasAll,
            string pattern,
            bool noCase,
            ref StringList list,
            ref Result error
            )
        {
            StringList inputList;

            //
            // NOTE: If no flags were supplied, we do not bother filtering on
            //       them.
            //
            if ((hasFlags == ProcedureFlags.None) &&
                (notHasFlags == ProcedureFlags.None))
            {
                inputList = new StringList(this.Keys);
            }
            else
            {
                inputList = new StringList();

                foreach (KeyValuePair <string, _Wrappers.Lambda> pair in this)
                {
                    if (pair.Value != null)
                    {
                        if (((hasFlags == ProcedureFlags.None) ||
                             FlagOps.HasFlags(
                                 pair.Value.Flags, hasFlags, hasAll)) &&
                            ((notHasFlags == ProcedureFlags.None) ||
                             !FlagOps.HasFlags(
                                 pair.Value.Flags, notHasFlags, notHasAll)))
                        {
                            inputList.Add(pair.Key);
                        }
                    }
                }
            }

            if (list == null)
            {
                list = new StringList();
            }

            return(GenericOps <string> .FilterList(
                       inputList, list, Index.Invalid, Index.Invalid,
                       ToStringFlags.None, pattern, noCase, ref error));
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            ProcedureFlags flags,
            ProcedureFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != ProcedureFlags.None);
            }
        }
예제 #3
0
 public ProcedureData(
     string name,
     string group,
     string description,
     ProcedureFlags flags,
     ArgumentList arguments,
     string body,
     IScriptLocation location,
     IClientData clientData,
     long token
     )
 {
     this.kind        = IdentifierKind.ProcedureData;
     this.id          = AttributeOps.GetObjectId(this);
     this.name        = name;
     this.group       = group;
     this.description = description;
     this.flags       = flags;
     this.clientData  = clientData;
     this.arguments   = arguments;
     this.body        = body;
     this.location    = location;
     this.token       = token;
 }
예제 #4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count == 4)
                    {
                        string     name = arguments[1];
                        StringList list = null;

                        code = Parser.SplitList(
                            interpreter, arguments[2], 0,
                            Length.Invalid, true, ref list,
                            ref result);

                        if (code == ReturnCode.Ok)
                        {
                            StringPairList list2 = new StringPairList();

                            for (int argumentIndex = 0; argumentIndex < list.Count; argumentIndex++)
                            {
                                StringList list3 = null;

                                code = Parser.SplitList(
                                    interpreter, list[argumentIndex], 0,
                                    Length.Invalid, true, ref list3,
                                    ref result);

                                if (code != ReturnCode.Ok)
                                {
                                    break;
                                }

                                if (list3.Count > 2)
                                {
                                    result = String.Format(
                                        "too many fields in argument specifier \"{0}\"",
                                        list[argumentIndex]);

                                    code = ReturnCode.Error;
                                    break;
                                }
                                else if ((list3.Count == 0) || String.IsNullOrEmpty(list3[0]))
                                {
                                    result = "argument with no name";
                                    code   = ReturnCode.Error;
                                    break;
                                }
                                else if (!Parser.IsSimpleScalarVariableName(list3[0],
                                                                            String.Format(Interpreter.ArgumentNotSimpleError, list3[0]),
                                                                            String.Format(Interpreter.ArgumentNotScalarError, list3[0]), ref result))
                                {
                                    code = ReturnCode.Error;
                                    break;
                                }

                                string argName    = list3[0];
                                string argDefault = (list3.Count >= 2) ? list3[1] : null;

                                list2.Add(new StringPair(argName, argDefault));
                            }

                            if (code == ReturnCode.Ok)
                            {
                                lock (interpreter.SyncRoot) /* TRANSACTIONAL */
                                {
                                    ProcedureFlags procedureFlags = interpreter.ProcedureFlags;

                                    IProcedure procedure = RuntimeOps.NewCoreProcedure(
                                        interpreter, interpreter.AreNamespacesEnabled() ?
                                        NamespaceOps.MakeQualifiedName(interpreter, name) :
                                        ScriptOps.MakeCommandName(name), null, null,
                                        procedureFlags, new ArgumentList(list2,
                                                                         ArgumentFlags.NameOnly), arguments[3],
                                        ScriptLocation.Create(arguments[3]), clientData);

                                    code = interpreter.AddOrUpdateProcedureWithReplace(
                                        procedure, clientData, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = String.Empty;
                                    }
                                }
                            }
                        }

                        if (code == ReturnCode.Error)
                        {
                            Engine.AddErrorInformation(interpreter, result,
                                                       String.Format("{0}    (creating proc \"{1}\")",
                                                                     Environment.NewLine, name));
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"proc name args body\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }