Пример #1
0
        ///////////////////////////////////////////////////////////////////////

        bool IDictionary <string, T> .ContainsKey(
            string key
            )
        {
            return(base.ContainsKey(
                       PathOps.TranslatePath(key, translationType)));
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////

        public new bool ContainsKey(
            string key
            )
        {
            return(base.ContainsKey(
                       PathOps.TranslatePath(key, translationType)));
        }
Пример #3
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public static bool MatchFileName(
            Interpreter interpreter,
            IScriptLocation location1,
            IScriptLocation location2,
            bool exact
            )
        {
            if ((location1 == null) && (location2 == null))
            {
                return(true);
            }
            else if ((location1 == null) || (location2 == null))
            {
                return(false);
            }
            else if (exact)
            {
                if (PathOps.HasPathWildcard(location1.FileName) ||
                    PathOps.HasPathWildcard(location2.FileName))
                {
                    return(false);
                }
            }

            return(MatchFileName(interpreter, location1.FileName, location2.FileName));
        }
Пример #4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public override int GetHashCode()
        {
            return(CommonOps.HashCodes.Combine(
                       PathOps.GetHashCode(fileName),
                       startLine.GetHashCode(),
                       endLine.GetHashCode()));
        }
Пример #5
0
        ///////////////////////////////////////////////////////////////////////

        void IDictionary <string, T> .Add(
            string key,
            T value
            )
        {
            base.Add(PathOps.TranslatePath(key, translationType), value);
        }
Пример #6
0
        ///////////////////////////////////////////////////////////////////////

        public new void Add(
            string key,
            T value
            )
        {
            base.Add(PathOps.TranslatePath(key, translationType), value);
        }
Пример #7
0
        ///////////////////////////////////////////////////////////////////////

        bool IDictionary <string, T> .TryGetValue(
            string key,
            out T value
            )
        {
            return(base.TryGetValue(
                       PathOps.TranslatePath(key, translationType), out value));
        }
Пример #8
0
        ///////////////////////////////////////////////////////////////////////

        public new bool TryGetValue(
            string key,
            out T value
            )
        {
            return(base.TryGetValue(
                       PathOps.TranslatePath(key, translationType), out value));
        }
Пример #9
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public StringPairList ToList(bool scrub)
        {
            StringPairList list = new StringPairList();

            list.Add("FileName", scrub ? PathOps.ScrubPath(
                         GlobalState.GetBasePath(), fileName) : fileName);

            list.Add("StartLine", startLine.ToString());
            list.Add("EndLine", endLine.ToString());
            list.Add("ViaSource", viaSource.ToString());

            return(list);
        }
Пример #10
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region Public Static Methods
        public static string NormalizeFileName(
            Interpreter interpreter,
            string fileName
            )
        {
            if (!PathOps.HasPathWildcard(fileName) &&
                PathOps.HasDirectory(fileName))
            {
                return(PathOps.GetUnixPath(PathOps.ResolveFullPath(
                                               interpreter, fileName)));
            }

            return(fileName);
        }
Пример #11
0
        ///////////////////////////////////////////////////////////////////////

        public StringPairList ToList(
            bool scrub
            )
        {
            StringPairList list = new StringPairList();

            list.Add("type", type);
            list.Add("text", text);

            list.Add("fileName", scrub ? PathOps.ScrubPath(
                         GlobalState.GetBasePath(), fileName) : fileName);

            list.Add("startLine", startLine.ToString());
            list.Add("endLine", endLine.ToString());
            list.Add("viaSource", viaSource.ToString());

            list.Add("engineMode", engineMode.ToString());
            list.Add("scriptFlags", scriptFlags.ToString());
            list.Add("engineFlags", engineFlags.ToString());
            list.Add("substitutionFlags", substitutionFlags.ToString());
            list.Add("eventFlags", eventFlags.ToString());
            list.Add("expressionFlags", expressionFlags.ToString());

#if XML
            list.Add("blockType", blockType.ToString());
            list.Add("timeStamp", timeStamp.ToString());
            list.Add("publicKeyToken", publicKeyToken);
            list.Add("signature", ArrayOps.ToHexadecimalString(signature));
#endif

#if CAS_POLICY
            if (!scrub)
            {
                list.Add("evidence", (evidence != null) ?
                         evidence.ToString() : null);

                list.Add("hashValue", ArrayOps.ToHexadecimalString(hashValue));

                list.Add("hashAlgorithm", (hashAlgorithm != null) ?
                         hashAlgorithm.ToString() : null);
            }
#endif

            return(list);
        }
Пример #12
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetCertificate2(
            string fileName,
            ref X509Certificate2 certificate2,
            ref Result error
            )
        {
            X509Certificate certificate = null;

            if (GetCertificate(fileName, ref certificate,
                               ref error) == ReturnCode.Ok)
            {
                if (certificate != null)
                {
                    try
                    {
                        certificate2 = new X509Certificate2(certificate);
                        return(ReturnCode.Ok);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                else
                {
                    error = "invalid certificate";
                }
            }

#if DEBUG
            if (!PathOps.IsSameFile(
                    Interpreter.GetActive(), fileName,
                    GlobalState.GetAssemblyLocation()))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate2: file {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(fileName),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(CertificateOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
Пример #13
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public static bool MatchFileName(
            Interpreter interpreter,
            string path1,
            string path2
            )
        {
            //
            // BUGBUG: This might be too slow?
            //
            if (PathOps.HasPathWildcard(path2))
            {
                return(StringOps.Match(
                           interpreter, StringOps.DefaultMatchMode,
                           path1, path2, PathOps.NoCase));
            }
            else
            {
                return(PathOps.IsSameFile(interpreter, path1, path2));
            }
        }
Пример #14
0
        ///////////////////////////////////////////////////////////////////////

        #region IPlugin Members
        public override Stream GetStream(
            Interpreter interpreter,
            string name,
            ref Result error
            )
        {
            if (String.IsNullOrEmpty(name))
            {
                error = "invalid stream name";
                return(null);
            }

            Assembly assembly = this.Assembly;

            if (assembly == null)
            {
                error = "plugin assembly not available";
                return(null);
            }

            try
            {
                Stream stream = assembly.GetManifestResourceStream(
                    PathOps.MakeRelativePath(name, true));

                if (stream != null)
                {
                    return(stream);
                }
                else
                {
                    error = "stream not found";
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(null);
        }
Пример #15
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Certificate Methods
        public static ReturnCode GetCertificate(
            string fileName,
            ref X509Certificate certificate,
            ref Result error
            )
        {
            if (!String.IsNullOrEmpty(fileName))
            {
                try
                {
                    certificate = X509Certificate.CreateFromSignedFile(
                        fileName);

                    return(ReturnCode.Ok);
                }
                catch (Exception e)
                {
                    error = e;
                }
            }
            else
            {
                error = "invalid file name";
            }

#if DEBUG
            if (!PathOps.IsSameFile(
                    Interpreter.GetActive(), fileName,
                    GlobalState.GetAssemblyLocation()))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate: file {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(fileName),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(CertificateOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
Пример #16
0
        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 == 1)
                    {
                        result = PathOps.GetUnixPath(Directory.GetCurrentDirectory());
                    }
                    else
                    {
                        result = "wrong # args: should be \"pwd\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
Пример #17
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IComparer<IScriptLocation> Members
        public int Compare(
            IScriptLocation x,
            IScriptLocation y
            )
        {
            if ((x == null) && (y == null))
            {
                return(0);
            }
            else if (x == null)
            {
                return(-1);
            }
            else if (y == null)
            {
                return(1);
            }
            else
            {
                int result = PathOps.CompareFileNames(x.FileName,
                                                      y.FileName);

                if (result != 0)
                {
                    return(result);
                }

                result = LogicOps.Compare(x.StartLine, y.StartLine);

                if (result != 0)
                {
                    return(result);
                }

                return(LogicOps.Compare(x.EndLine, y.EndLine));
            }
        }
Пример #18
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode LoadFile(
            string fileName,
            ref XmlDocument document,
            ref Result error
            )
        {
            if (String.IsNullOrEmpty(fileName))
            {
                error = "invalid file name";
                return(ReturnCode.Error);
            }

            bool remoteUri = PathOps.IsRemoteUri(fileName);

            if (!remoteUri && !File.Exists(fileName))
            {
                error = String.Format(
                    "couldn't read file \"{0}\": no such file or directory",
                    fileName);

                return(ReturnCode.Error);
            }

            try
            {
                document = new XmlDocument();
                document.Load(fileName); /* throw */

                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }
Пример #19
0
        ///////////////////////////////////////////////////////////////////////

        #region Generic Xml Handling Methods
        public static bool CouldBeDocument(
            string path
            )
        {
            if (String.IsNullOrEmpty(path))
            {
                return(false);
            }

            string extension = PathOps.GetExtension(path);

            if (String.IsNullOrEmpty(extension))
            {
                return(false);
            }

            if (String.Equals(extension,
                              FileExtension.Markup, PathOps.ComparisonType))
            {
                return(true);
            }

            return(false);
        }
Пример #20
0
        ///////////////////////////////////////////////////////////////////////

        #region System.Collections.Generic.IDictionary<string, TValue> Overrides
        T IDictionary <string, T> .this[string key]
        {
            get { return(base[PathOps.TranslatePath(key, translationType)]); }
            set { base[PathOps.TranslatePath(key, translationType)] = value; }
        }
Пример #21
0
        ///////////////////////////////////////////////////////////////////////

        private static AppDomainSetup CreateSetup(
            Interpreter interpreter, /* OPTIONAL */
            string baseDirectory,
            string packagePath,
            bool useBasePath,
            ref Result error
            )
        {
            string basePath = baseDirectory;

            if (useBasePath && (basePath == null) && (interpreter != null))
            {
                basePath = interpreter.PluginBaseDirectory;
            }

            Result localError = null;

            if (useBasePath && (basePath == null))
            {
                basePath = GetBasePath(
                    interpreter, packagePath, ref localError);
            }

            if (!useBasePath || (basePath != null))
            {
                //
                // NOTE: Check if the package path is located under the base
                //       path.
                //
                bool packageUnderBasePath = (packagePath != null) ?
                                            PathOps.IsUnderPath(interpreter, packagePath,
                                                                basePath) : false;

                //
                // NOTE: Verify that the package path is either usable or
                //       superfluous.
                //
                if ((packagePath == null) ||
                    !useBasePath || packageUnderBasePath)
                {
                    //
                    // NOTE: Grab the full path for the Eagle core library
                    //       assembly.
                    //
                    string assemblyPath = GetAssemblyPath();

                    //
                    // NOTE: Check if the assembly path is located under
                    //       the base path.
                    //
                    bool assemblyUnderBasePath = (assemblyPath != null) ?
                                                 PathOps.IsUnderPath(interpreter, assemblyPath,
                                                                     basePath) : false;

                    //
                    // NOTE: Verify that the assembly path is either usable
                    //       or superfluous.
                    //
                    if ((assemblyPath == null) ||
                        !useBasePath || assemblyUnderBasePath)
                    {
                        AppDomainSetup appDomainSetup = new AppDomainSetup();

                        //
                        // NOTE: Use the base directory of the Eagle install
                        //       as the base directory for the new isolated
                        //       application domain.
                        //
                        appDomainSetup.ApplicationBase = useBasePath ?
                                                         basePath : (packagePath != null) ?
                                                         packagePath : assemblyPath;

                        //
                        // NOTE: If we are using the base path of the Eagle
                        //       core library assembly, then we need to modify
                        //       the private binary path so that it includes
                        //       both the directory containing that assembly
                        //       and the directory containing the package;
                        //       otherwise, we can simply skip this step.
                        //
                        if (useBasePath)
                        {
                            //
                            // TODO: May need to add more options here.
                            //
                            string relativeAssemblyPath =
                                (assemblyPath != null) && assemblyUnderBasePath?
                                assemblyPath.Remove(0, basePath.Length).Trim(
                                    PathOps.DirectoryChars) : null;

                            string privateBinPath = relativeAssemblyPath;

                            string relativePackagePath =
                                (packagePath != null) && packageUnderBasePath?
                                packagePath.Remove(0, basePath.Length).Trim(
                                    PathOps.DirectoryChars) : null;

                            if (!String.IsNullOrEmpty(relativePackagePath))
                            {
                                if (!String.IsNullOrEmpty(privateBinPath))
                                {
                                    privateBinPath += Characters.SemiColon;
                                }

                                privateBinPath += relativePackagePath;
                            }

                            appDomainSetup.PrivateBinPath = privateBinPath;
                        }

                        return(appDomainSetup);
                    }
                    else
                    {
                        error = "assembly path is not under base path";
                    }
                }
                else
                {
                    error = "package path is not under base path";
                }
            }
            else if (localError == null)
            {
                error = "invalid base path";
            }
            else
            {
                error = localError;
            }

            return(null);
        }
Пример #22
0
        ///////////////////////////////////////////////////////////////////////

#if APPDOMAINS || ISOLATED_INTERPRETERS || ISOLATED_PLUGINS
        private static string GetBasePath(
            Interpreter interpreter, /* OPTIONAL */
            string packagePath,
            ref Result error
            )
        {
            //
            // NOTE: Fetch the raw base directory for the currently executing
            //       application binary.  It is now possible to override the
            //       value used here via the environment.
            //
            string path0 = AssemblyOps.GetAnchorPath();

            if (path0 == null)
            {
                path0 = GlobalState.GetRawBinaryBasePath();
            }

            //
            // NOTE: First, try to use the effective path to the core library
            //       assembly.  This is used to verify that this candidate
            //       application domain base path contains the core library
            //       assembly somewhere underneath it.
            //
            string path1 = GetAssemblyPath();

            if (PathOps.IsUnderPath(interpreter, path1, path0))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path0))
                {
                    return(path0);
                }
            }

            //
            // NOTE: Second, try to use the raw base path for the assembly.
            //       This is used to verify that this candidate application
            //       domain base path contains the core library assembly
            //       somewhere underneath it.
            //
            string path2 = GlobalState.GetRawBasePath();

            if (PathOps.IsUnderPath(interpreter, path1, path2))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path2))
                {
                    return(path2);
                }
            }

            //
            // NOTE: At this point, we have failed to figure out a base path
            //       for the application domain to be created that actually
            //       contains the core library assembly.
            //
            error = String.Format(
                "cannot determine usable base path for the new application " +
                "domain for interpreter {0}, with the raw binary base path " +
                "{1}, assembly path {2}, and raw base path {3}",
                FormatOps.InterpreterNoThrow(interpreter),
                FormatOps.DisplayPath(path0), FormatOps.DisplayPath(path1),
                FormatOps.DisplayPath(path2));

            return(null);
        }
Пример #23
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 >= 2)
                    {
                        string subCommand = arguments[1];
                        bool   tried      = false;

                        code = ScriptOps.TryExecuteSubCommandFromEnsemble(
                            interpreter, this, clientData, arguments, true,
                            false, ref subCommand, ref tried, ref result);

                        if ((code == ReturnCode.Ok) && !tried)
                        {
                            switch (subCommand)
                            {
                            case "forget":
                            {
                                if (arguments.Count >= 2)
                                {
                                    code = interpreter.PkgForget(
                                        new StringList(arguments, 2), ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package forget ?package package ...?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "ifneeded":
                            {
                                if ((arguments.Count == 4) || (arguments.Count == 5))
                                {
                                    Version version = null;

                                    code = Value.GetVersion(
                                        arguments[3], interpreter.CultureInfo,
                                        ref version, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        string text = null;

                                        if (arguments.Count == 5)
                                        {
                                            text = arguments[4];
                                        }

                                        code = interpreter.PkgIfNeeded(
                                            arguments[2], version, text, interpreter.PackageFlags,
                                            ref result);
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package ifneeded package version ?script?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "indexes":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    string pattern = null;

                                    if (arguments.Count == 3)
                                    {
                                        pattern = arguments[2];
                                    }

                                    code = interpreter.PkgIndexes(
                                        pattern, false, ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package indexes ?pattern?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "info":
                            {
                                if (arguments.Count == 3)
                                {
                                    IPackage package = null;

                                    code = interpreter.GetPackage(
                                        arguments[2], LookupFlags.Default,
                                        ref package, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        bool         scrub = interpreter.IsSafe();
                                        PackageFlags flags = package.Flags;
                                        Guid         id    = AttributeOps.GetObjectId(package);

                                        result = StringList.MakeList(
                                            "kind", package.Kind,
                                            "id", package.Id.Equals(Guid.Empty) ? id : package.Id,
                                            "name", package.Name,
                                            "description", package.Description,
                                            "indexFileName", scrub ? PathOps.ScrubPath(
                                                GlobalState.GetBasePath(), package.IndexFileName) :
                                            package.IndexFileName,
                                            "provideFileName", scrub ? PathOps.ScrubPath(
                                                GlobalState.GetBasePath(), package.ProvideFileName) :
                                            package.ProvideFileName,
                                            "flags", flags,
                                            "loaded", (package.Loaded != null) ? package.Loaded : null,
                                            "ifNeeded", (!scrub && (package.IfNeeded != null)) ?
                                            package.IfNeeded.KeysAndValuesToString(null, false) :
                                            null);
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package info name\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "loaded":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    string pattern = null;

                                    if (arguments.Count == 3)
                                    {
                                        pattern = arguments[2];
                                    }

                                    code = interpreter.PkgLoaded(
                                        pattern, false, false, ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package loaded ?pattern?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "names":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    string pattern = null;

                                    if (arguments.Count == 3)
                                    {
                                        pattern = arguments[2];
                                    }

                                    code = interpreter.PkgNames(
                                        pattern, false, ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package names ?pattern?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "present":
                            {
                                if (arguments.Count >= 3)
                                {
                                    OptionDictionary options = new OptionDictionary(
                                        new IOption[] {
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-exact", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null)
                                        });

                                    int argumentIndex = Index.Invalid;

                                    code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, false, ref argumentIndex, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        if ((argumentIndex != Index.Invalid) &&
                                            ((argumentIndex + 2) >= arguments.Count))
                                        {
                                            bool exact = false;

                                            if (options.IsPresent("-exact"))
                                            {
                                                exact = true;
                                            }

                                            Version version = null;

                                            if ((argumentIndex + 1) < arguments.Count)
                                            {
                                                code = Value.GetVersion(
                                                    arguments[argumentIndex + 1], interpreter.CultureInfo,
                                                    ref version, ref result);
                                            }

                                            if (code == ReturnCode.Ok)
                                            {
                                                code = interpreter.PresentPackage(
                                                    arguments[argumentIndex], version, exact, ref result);
                                            }
                                        }
                                        else
                                        {
                                            if ((argumentIndex != Index.Invalid) &&
                                                Option.LooksLikeOption(arguments[argumentIndex]))
                                            {
                                                result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                            }
                                            else
                                            {
                                                result = "wrong # args: should be \"package present ?-exact? package ?version?\"";
                                            }

                                            code = ReturnCode.Error;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package present ?-exact? package ?version?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "provide":
                            {
                                if ((arguments.Count == 3) || (arguments.Count == 4))
                                {
                                    PackageFlags flags = interpreter.PackageFlags;

                                    if (!FlagOps.HasFlags(flags, PackageFlags.NoProvide, true))
                                    {
                                        Version version = null;

                                        if (arguments.Count == 4)
                                        {
                                            code = Value.GetVersion(arguments[3], interpreter.CultureInfo, ref version, ref result);
                                        }

                                        if (code == ReturnCode.Ok)
                                        {
                                            code = interpreter.PkgProvide(arguments[2], version, flags, ref result);
                                        }
                                    }
                                    else
                                    {
                                        //
                                        // HACK: Do nothing, provide no package, and return nothing.
                                        //
                                        result = String.Empty;
                                        code   = ReturnCode.Ok;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package provide package ?version?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "relativefilename":
                            {
                                if ((arguments.Count == 3) || (arguments.Count == 4))
                                {
                                    PathComparisonType pathComparisonType = PathComparisonType.Default;

                                    if (arguments.Count == 4)
                                    {
                                        object enumValue = EnumOps.TryParseFlagsEnum(
                                            interpreter, typeof(PathComparisonType),
                                            pathComparisonType.ToString(), arguments[3],
                                            interpreter.CultureInfo, true, true, true,
                                            ref result);

                                        if (enumValue is EventFlags)
                                        {
                                            pathComparisonType = (PathComparisonType)enumValue;
                                        }
                                        else
                                        {
                                            code = ReturnCode.Error;
                                        }
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        string fileName = null;

                                        code = PackageOps.GetRelativeFileName(
                                            interpreter, arguments[2], pathComparisonType,
                                            ref fileName, ref result);

                                        if (code == ReturnCode.Ok)
                                        {
                                            result = fileName;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package relativefilename fileName ?type?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "require":
                            {
                                if (arguments.Count >= 3)
                                {
                                    OptionDictionary options = new OptionDictionary(
                                        new IOption[] {
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-exact", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null)
                                        });

                                    int argumentIndex = Index.Invalid;

                                    code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, false, ref argumentIndex, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        if ((argumentIndex != Index.Invalid) && ((argumentIndex + 2) >= arguments.Count))
                                        {
                                            bool exact = false;

                                            if (options.IsPresent("-exact"))
                                            {
                                                exact = true;
                                            }

                                            Version version = null;

                                            if ((argumentIndex + 1) < arguments.Count)
                                            {
                                                code = Value.GetVersion(
                                                    arguments[argumentIndex + 1], interpreter.CultureInfo,
                                                    ref version, ref result);
                                            }

                                            if (code == ReturnCode.Ok)
                                            {
                                                code = interpreter.RequirePackage(
                                                    arguments[argumentIndex], version, exact, ref result);
                                            }

                                            //
                                            // NOTE: This is a new feature.  If the initial attempt to
                                            //       require a package fails, call the package fallback
                                            //       delegate for the interpreter and then try requiring
                                            //       the package again.
                                            //
                                            if ((code != ReturnCode.Ok) && !ScriptOps.HasFlags(
                                                    interpreter, InterpreterFlags.NoPackageFallback, true))
                                            {
                                                PackageCallback packageFallback = interpreter.PackageFallback;

                                                if (packageFallback != null)
                                                {
                                                    code = packageFallback(
                                                        interpreter, arguments[argumentIndex], version, null,
                                                        interpreter.PackageFlags, exact, ref result);

                                                    if (code == ReturnCode.Ok)
                                                    {
                                                        code = interpreter.RequirePackage(
                                                            arguments[argumentIndex], version, exact, ref result);
                                                    }
                                                }
                                            }

                                            //
                                            // BUGFIX: This is really a new feature.  In the event of a failure
                                            //         here, we now fallback to the "unknown package handler",
                                            //         just like Tcl does.
                                            //
                                            if ((code != ReturnCode.Ok) && !ScriptOps.HasFlags(
                                                    interpreter, InterpreterFlags.NoPackageUnknown, true))
                                            {
                                                string text = interpreter.PackageUnknown + Characters.Space +
                                                              Parser.Quote(arguments[argumentIndex]);

                                                if (version != null)
                                                {
                                                    text += Characters.Space + Parser.Quote(version.ToString());
                                                }

                                                code = interpreter.EvaluateScript(text, ref result);         /* EXEMPT */

                                                if (code == ReturnCode.Ok)
                                                {
                                                    code = interpreter.RequirePackage(
                                                        arguments[argumentIndex], version, exact, ref result);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((argumentIndex != Index.Invalid) &&
                                                Option.LooksLikeOption(arguments[argumentIndex]))
                                            {
                                                result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                            }
                                            else
                                            {
                                                result = "wrong # args: should be \"package require ?-exact? package ?version?\"";
                                            }

                                            code = ReturnCode.Error;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package require ?-exact? package ?version?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "reset":
                            {
                                if (arguments.Count == 2)
                                {
                                    code = interpreter.ResetPkgIndexes(ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = String.Empty;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package reset\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "scan":
                            {
                                if (arguments.Count >= 2)
                                {
                                    OptionDictionary options = new OptionDictionary(
                                        new IOption[] {
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-interpreter", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-preferfilesystem", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-preferhost", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-host", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-normal", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-nonormal", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-recursive", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-resolve", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-refresh", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-autopath", null),
                                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null)
                                        });

                                    int argumentIndex = Index.Invalid;

                                    if (arguments.Count > 2)
                                    {
                                        code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, true, ref argumentIndex, ref result);
                                    }
                                    else
                                    {
                                        code = ReturnCode.Ok;
                                    }

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

                                            if (options.IsPresent("-interpreter"))
                                            {
                                                flags = interpreter.PackageIndexFlags;
                                            }
                                            else
                                            {
                                                flags = PackageIndexFlags.Default;
                                            }

                                            if (options.IsPresent("-preferfilesystem"))
                                            {
                                                flags |= PackageIndexFlags.PreferFileSystem;
                                            }

                                            if (options.IsPresent("-preferhost"))
                                            {
                                                flags |= PackageIndexFlags.PreferHost;
                                            }

                                            if (options.IsPresent("-host"))
                                            {
                                                flags |= PackageIndexFlags.Host;
                                            }

                                            if (options.IsPresent("-normal"))
                                            {
                                                flags |= PackageIndexFlags.Normal;
                                            }

                                            if (options.IsPresent("-nonormal"))
                                            {
                                                flags |= PackageIndexFlags.NoNormal;
                                            }

                                            if (options.IsPresent("-recursive"))
                                            {
                                                flags |= PackageIndexFlags.Recursive;
                                            }

                                            if (options.IsPresent("-refresh"))
                                            {
                                                flags |= PackageIndexFlags.Refresh;
                                            }

                                            if (options.IsPresent("-resolve"))
                                            {
                                                flags |= PackageIndexFlags.Resolve;
                                            }

                                            bool autoPath = false;

                                            if (options.IsPresent("-autopath"))
                                            {
                                                autoPath = true;
                                            }

                                            StringList paths;

                                            if (argumentIndex != Index.Invalid)
                                            {
                                                //
                                                // NOTE: Refresh the specified path list.
                                                //
                                                paths = new StringList(arguments, argumentIndex);
                                            }
                                            else
                                            {
                                                //
                                                // NOTE: Refresh the default path list.
                                                //
                                                paths = GlobalState.GetAutoPathList(interpreter, autoPath);

                                                //
                                                // NOTE: Did they request the auto-path be rebuilt?
                                                //
                                                if (autoPath)
                                                {
                                                    //
                                                    // NOTE: Since the actual auto-path may have changed,
                                                    //       update the variable now.  We disable traces
                                                    //       here because we manually rescan, if necessary,
                                                    //       below.
                                                    //
                                                    code = interpreter.SetLibraryVariableValue(
                                                        VariableFlags.SkipTrace, TclVars.AutoPath,
                                                        (paths != null) ? paths.ToString() : null,
                                                        ref result);
                                                }
                                            }

                                            if (code == ReturnCode.Ok)
                                            {
                                                PackageIndexDictionary packageIndexes = interpreter.CopyPackageIndexes();

                                                if (code == ReturnCode.Ok)
                                                {
                                                    code = PackageOps.FindAll(
                                                        interpreter, paths, flags, ref packageIndexes,
                                                        ref result);
                                                }

                                                if (code == ReturnCode.Ok)
                                                {
                                                    interpreter.PackageIndexes = packageIndexes;
                                                    result = String.Empty;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package scan ?options? ?dir dir ...?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "unknown":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    if (arguments.Count == 3)
                                    {
                                        interpreter.PackageUnknown = arguments[2];
                                        result = String.Empty;
                                    }
                                    else
                                    {
                                        result = interpreter.PackageUnknown;
                                    }

                                    code = ReturnCode.Ok;
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package unknown ?command?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "vcompare":
                            {
                                if (arguments.Count == 4)
                                {
                                    Version version1 = null;

                                    code = Value.GetVersion(
                                        arguments[2], interpreter.CultureInfo,
                                        ref version1, ref result);

                                    Version version2 = null;

                                    if (code == ReturnCode.Ok)
                                    {
                                        code = Value.GetVersion(
                                            arguments[3], interpreter.CultureInfo,
                                            ref version2, ref result);
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = PackageOps.VersionCompare(version1, version2);
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package vcompare version1 version2\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "versions":
                            {
                                if (arguments.Count == 3)
                                {
                                    code = interpreter.PkgVersions(
                                        arguments[2], ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package versions package\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "vloaded":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    string pattern = null;

                                    if (arguments.Count == 3)
                                    {
                                        pattern = arguments[2];
                                    }

                                    code = interpreter.PkgLoaded(
                                        pattern, false, true, ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package vloaded ?pattern?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "vsatisfies":
                            {
                                if (arguments.Count == 4)
                                {
                                    PackageFlags flags = interpreter.PackageFlags;

                                    if (!FlagOps.HasFlags(flags, PackageFlags.AlwaysSatisfy, true))
                                    {
                                        Version version1 = null;

                                        code = Value.GetVersion(arguments[2], interpreter.CultureInfo, ref version1, ref result);

                                        Version version2 = null;

                                        if (code == ReturnCode.Ok)
                                        {
                                            code = Value.GetVersion(
                                                arguments[3], interpreter.CultureInfo,
                                                ref version2, ref result);
                                        }

                                        if (code == ReturnCode.Ok)
                                        {
                                            result = PackageOps.VersionSatisfies(
                                                version1, version2, false);
                                        }
                                    }
                                    else
                                    {
                                        //
                                        // HACK: Always fake that this was a satisfied package request.
                                        //
                                        result = true;
                                        code   = ReturnCode.Ok;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package vsatisfies version1 version2\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "withdraw":
                            {
                                if ((arguments.Count == 3) || (arguments.Count == 4))
                                {
                                    Version version = null;

                                    if (arguments.Count == 4)
                                    {
                                        code = Value.GetVersion(
                                            arguments[3], interpreter.CultureInfo,
                                            ref version, ref result);
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        code = interpreter.WithdrawPackage(
                                            arguments[2], version, ref result);
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"package withdraw package ?version?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            default:
                            {
                                result = ScriptOps.BadSubCommand(
                                    interpreter, null, null, subCommand, this, null, null);

                                code = ReturnCode.Error;
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"package arg ?arg ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
Пример #24
0
        ///////////////////////////////////////////////////////////////////////

        private static string GetNativeLibraryFileName(
            Interpreter interpreter /* NOT USED */
            )
        {
            string path = CommonOps.Environment.GetVariable(
                EnvVars.UtilityPath);

            if (!String.IsNullOrEmpty(path))
            {
                if (File.Exists(path))
                {
                    return(path);
                }

                if (Directory.Exists(path))
                {
                    string fileName = PathOps.CombinePath(
                        null, path, DllName.Utility);

                    if (File.Exists(fileName))
                    {
                        return(fileName);
                    }

                    //
                    // TODO: Is this strictly necessary here?  It is known
                    //       at this point that this file does not exist.
                    //       Setting the path here only controls the result
                    //       returned in non-strict mode (below).
                    //
                    path = fileName;
                }

                //
                // NOTE: If the environment variable was set and the utility
                //       library could not be found, force an invalid result
                //       to be returned.  This ends up skipping the standard
                //       automatic utility library detection logic.
                //
                lock (syncRoot)
                {
                    return(strictPath ? null : path);
                }
            }

            //
            // HACK: If the processor architecture ends up being "AMD64", we
            //       want it to be "x64" instead, to match the platform name
            //       used by the native utility library project itself.
            //
            string processorName = PlatformOps.GetAlternateProcessorName(
                RuntimeOps.GetProcessorArchitecture(), true, false);

            if (processorName != null)
            {
                path = PathOps.CombinePath(
                    null, GlobalState.GetAssemblyPath(), processorName,
                    DllName.Utility);

                if (File.Exists(path))
                {
                    return(path);
                }
            }

            path = PathOps.CombinePath(
                null, GlobalState.GetAssemblyPath(), DllName.Utility);

            if (File.Exists(path))
            {
                return(path);
            }

            lock (syncRoot)
            {
                return(strictPath ? null : path);
            }
        }
Пример #25
0
        ///////////////////////////////////////////////////////////////////////

        bool IDictionary <string, T> .Remove(
            string key
            )
        {
            return(base.Remove(PathOps.TranslatePath(key, translationType)));
        }
Пример #26
0
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-nocommands", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-nofunctions", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-nopolicies", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-notraces", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-noprovide", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-noresources", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-verifiedonly", null),
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-trustedonly", null),
#if ISOLATED_PLUGINS
                            new Option(null, OptionFlags.Unsafe, Index.Invalid, Index.Invalid, "-noisolated", null),
#else
                            new Option(null, OptionFlags.Unsafe | OptionFlags.Unsupported, Index.Invalid, Index.Invalid,
                                       "-noisolated", null),
#endif
                            new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-clientdata", null),
                            new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-data", null),
                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null)
                        });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 1, Index.Invalid, false, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            //
                            // NOTE: There should be a minimum of one and a maximum
                            //       of three arguments after the final option.
                            //
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 3) >= arguments.Count))
                            {
                                string path = ((argumentIndex + 2) < arguments.Count) ?
                                              (string)arguments[argumentIndex + 2] : String.Empty;

                                Interpreter slaveInterpreter = null;

                                code = interpreter.GetNestedSlaveInterpreter(
                                    path, LookupFlags.Interpreter, false,
                                    ref slaveInterpreter, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    Variant     value           = null;
                                    IClientData localClientData = clientData;

                                    if (options.IsPresent("-clientdata", ref value))
                                    {
                                        IObject @object = (IObject)value.Value;

                                        if ((@object.Value == null) ||
                                            (@object.Value is IClientData))
                                        {
                                            localClientData = (IClientData)@object.Value;
                                        }
                                        else
                                        {
                                            result = "option value has invalid clientData";
                                            code   = ReturnCode.Error;
                                        }
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        if (options.IsPresent("-data", ref value))
                                        {
                                            IObject @object = (IObject)value.Value;

                                            if (@object != null)
                                            {
                                                localClientData = _Public.ClientData.WrapOrReplace(
                                                    localClientData, @object.Value);
                                            }
                                            else
                                            {
                                                result = "option value has invalid data";
                                                code   = ReturnCode.Error;
                                            }
                                        }

                                        if (code == ReturnCode.Ok)
                                        {
                                            //
                                            // NOTE: All plugins loaded by this command are considered
                                            //       as having been loaded "on demand".
                                            //
                                            PluginFlags pluginFlags = PluginFlags.Demand;

                                            //
                                            // NOTE: Add the plugin flags for the target interpreter.
                                            //
                                            pluginFlags |= slaveInterpreter.PluginFlags;

#if ISOLATED_PLUGINS
                                            //
                                            // NOTE: Disable loading this plugin into an isolated
                                            //       application domain (i.e. load it into the default
                                            //       application domain for the target interpreter).
                                            //
                                            if (options.IsPresent("-noisolated"))
                                            {
                                                pluginFlags &= ~PluginFlags.Isolated;
                                            }
#endif

                                            if (options.IsPresent("-nocommands"))
                                            {
                                                pluginFlags |= PluginFlags.NoCommands;
                                            }

                                            if (options.IsPresent("-nofunctions"))
                                            {
                                                pluginFlags |= PluginFlags.NoFunctions;
                                            }

                                            if (options.IsPresent("-nopolicies"))
                                            {
                                                pluginFlags |= PluginFlags.NoPolicies;
                                            }

                                            if (options.IsPresent("-notraces"))
                                            {
                                                pluginFlags |= PluginFlags.NoTraces;
                                            }

                                            if (options.IsPresent("-noprovide"))
                                            {
                                                pluginFlags |= PluginFlags.NoProvide;
                                            }

                                            if (options.IsPresent("-noresources"))
                                            {
                                                pluginFlags |= PluginFlags.NoResources;
                                            }

                                            if (options.IsPresent("-verifiedonly"))
                                            {
                                                pluginFlags |= PluginFlags.VerifiedOnly;
                                            }

                                            if (options.IsPresent("-trustedonly"))
                                            {
                                                pluginFlags |= PluginFlags.TrustedOnly;
                                            }

                                            string fileName = PathOps.ResolveFullPath(
                                                interpreter, arguments[argumentIndex]);

                                            if (!String.IsNullOrEmpty(fileName))
                                            {
                                                string typeName = null;

                                                if ((argumentIndex + 1) < arguments.Count)
                                                {
                                                    typeName = arguments[argumentIndex + 1];
                                                }

                                                IPlugin plugin = null;
                                                long    token  = 0;

                                                try
                                                {
                                                    code = slaveInterpreter.LoadPlugin(
                                                        fileName,
#if CAS_POLICY
                                                        null, null, AssemblyHashAlgorithm.None,
#endif
                                                        typeName, localClientData, pluginFlags,
                                                        ref plugin, ref result);

                                                    if (code == ReturnCode.Ok)
                                                    {
                                                        code = slaveInterpreter.AddPlugin(
                                                            plugin, localClientData, ref token,
                                                            ref result);
                                                    }
                                                }
                                                finally
                                                {
                                                    if (code != ReturnCode.Ok)
                                                    {
                                                        if (token != 0)
                                                        {
                                                            //
                                                            // NOTE: Terminate and remove the plugin now.
                                                            //       This does not unload the associated
                                                            //       AppDomain, if any.
                                                            //
                                                            ReturnCode removeCode;
                                                            Result     removeResult = null;

                                                            removeCode = slaveInterpreter.RemovePlugin(
                                                                token, localClientData, ref removeResult);

                                                            if (removeCode != ReturnCode.Ok)
                                                            {
                                                                DebugOps.Complain(
                                                                    slaveInterpreter, removeCode,
                                                                    removeResult);
                                                            }
                                                        }

                                                        if (plugin != null)
                                                        {
                                                            //
                                                            // NOTE: Unload the plugin.  This basically does
                                                            //       "nothing" unless the plugin was isolated.
                                                            //       In that case, it unloads the associated
                                                            //       AppDomain.
                                                            //
                                                            ReturnCode unloadCode;
                                                            Result     unloadResult = null;

                                                            unloadCode = slaveInterpreter.UnloadPlugin(
                                                                plugin, localClientData, pluginFlags |
                                                                PluginFlags.SkipTerminate, ref unloadResult);

                                                            if (unloadCode != ReturnCode.Ok)
                                                            {
                                                                DebugOps.Complain(
                                                                    slaveInterpreter, unloadCode,
                                                                    unloadResult);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                result = "invalid file name";
                                                code   = ReturnCode.Error;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"load ?options? fileName ?packageName? ?interp?\"";
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"load ?options? fileName ?packageName? ?interp?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
Пример #27
0
        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 >= 2)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-debug", null),                  // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-commandline", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-dequote", null),                // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-quoteall", null),               // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-unicode", null),                // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-ignorestderr", null),           // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-killonerror", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-keepnewline", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-noexitcode", null),             // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-nocapture", null),              // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-shell", null),                  // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-nocarriagereturns", null),      // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-trimall", null),                // simple switch
                            new Option(typeof(ExitCode), OptionFlags.MustHaveEnumValue,
                                       Index.Invalid, Index.Invalid, "-success", null), // success exit code
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-domainname", null),
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-username", null),
                            new Option(null, OptionFlags.MustHaveSecureStringValue, Index.Invalid,
                                       Index.Invalid, "-password", null),
                            new Option(null, OptionFlags.MustHaveListValue, Index.Invalid,
                                       Index.Invalid, "-preprocessarguments", null), // command
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-directory", null),           // directory name
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-processid", null),           // varName for processId
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-exitcode", null),            // varName for exitCode
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stdin", null),               // varName for StdIn input
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stdout", null),              // varName for StdOut output
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stderr", null),              // varName for StdErr output
                            new Option(typeof(EventFlags), OptionFlags.MustHaveEnumValue,
                                       Index.Invalid, Index.Invalid, "-eventflags",
                                       new Variant(interpreter.EngineEventFlags)),
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, Option.EndOfOptions, null)
                        });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 1,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if (argumentIndex != Index.Invalid)
                            {
                                bool debug = false;

                                if (options.IsPresent("-debug"))
                                {
                                    debug = true;
                                }

                                bool commandLine = false;

                                if (options.IsPresent("-commandline"))
                                {
                                    commandLine = true;
                                }

                                bool dequote = false;

                                if (options.IsPresent("-dequote"))
                                {
                                    dequote = true;
                                }

                                bool quoteAll = false;

                                if (options.IsPresent("-quoteall"))
                                {
                                    quoteAll = true;
                                }

                                bool captureExitCode = true;

                                if (options.IsPresent("-noexitcode"))
                                {
                                    captureExitCode = false;
                                }

                                bool captureInput  = true;
                                bool captureOutput = true;

                                if (options.IsPresent("-nocapture"))
                                {
                                    captureInput  = false;
                                    captureOutput = false;
                                }

                                bool useUnicode = false;

                                if (options.IsPresent("-unicode"))
                                {
                                    useUnicode = true;
                                }

                                bool ignoreStdErr = false;

                                if (options.IsPresent("-ignorestderr"))
                                {
                                    ignoreStdErr = true;
                                }

                                bool killOnError = false;

                                if (options.IsPresent("-killonerror"))
                                {
                                    killOnError = true;
                                }

                                bool keepNewLine = false;

                                if (options.IsPresent("-keepnewline"))
                                {
                                    keepNewLine = true;
                                }

                                bool carriageReturns = true;

                                if (options.IsPresent("-nocarriagereturns"))
                                {
                                    carriageReturns = false;
                                }

                                bool trimAll = false;

                                if (options.IsPresent("-trimall"))
                                {
                                    trimAll = true;
                                }

                                bool useShellExecute = false;

                                if (options.IsPresent("-shell"))
                                {
                                    useShellExecute = true;
                                }

                                Variant  value           = null;
                                ExitCode?successExitCode = null;

                                if (options.IsPresent("-success", ref value))
                                {
                                    successExitCode = (ExitCode)value.Value;
                                }

                                string domainName = null;

                                if (options.IsPresent("-domainname", ref value))
                                {
                                    domainName = value.ToString();
                                }

                                string userName = null;

                                if (options.IsPresent("-username", ref value))
                                {
                                    userName = value.ToString();
                                }

                                SecureString password = null;

                                if (options.IsPresent("-password", ref value))
                                {
                                    password = (SecureString)value.Value;
                                }

                                string directory = null;

                                if (options.IsPresent("-directory", ref value))
                                {
                                    directory = value.ToString();
                                }

                                string processIdVarName = null;

                                if (options.IsPresent("-processid", ref value))
                                {
                                    processIdVarName = value.ToString();
                                }

                                string exitCodeVarName = null;

                                if (options.IsPresent("-exitcode", ref value))
                                {
                                    exitCodeVarName = value.ToString();
                                }

                                string stdInVarName = null;

                                if (options.IsPresent("-stdin", ref value))
                                {
                                    stdInVarName = value.ToString();
                                }

                                string stdOutVarName = null;

                                if (options.IsPresent("-stdout", ref value))
                                {
                                    stdOutVarName = value.ToString();
                                }

                                string stdErrVarName = null;

                                if (options.IsPresent("-stderr", ref value))
                                {
                                    stdErrVarName = value.ToString();
                                }

                                EventFlags eventFlags = interpreter.EngineEventFlags;

                                if (options.IsPresent("-eventflags", ref value))
                                {
                                    eventFlags = (EventFlags)value.Value;
                                }

                                StringList list = null;

                                if (options.IsPresent("-preprocessarguments", ref value))
                                {
                                    list = (StringList)value.Value;
                                }

                                int  argumentStopIndex = arguments.Count - 1;
                                bool background        = false;

                                if (arguments[arguments.Count - 1] ==
                                    Characters.Ampersand.ToString())
                                {
                                    argumentStopIndex--;
                                    background = true;
                                }

                                string execFileName = arguments[argumentIndex];

                                if (!PathOps.IsRemoteUri(execFileName))
                                {
                                    execFileName = PathOps.GetNativePath(execFileName);
                                }

                                string execArguments = null;

                                if ((argumentIndex + 1) < arguments.Count)
                                {
                                    if (commandLine)
                                    {
                                        execArguments = RuntimeOps.BuildCommandLine(
                                            ArgumentList.GetRangeAsStringList(arguments,
                                                                              argumentIndex + 1, argumentStopIndex,
                                                                              dequote),
                                            quoteAll);
                                    }
                                    else
                                    {
                                        execArguments = ListOps.Concat(arguments,
                                                                       argumentIndex + 1, argumentStopIndex);
                                    }
                                }

                                Result input = null;

                                if ((code == ReturnCode.Ok) && !useShellExecute &&
                                    captureInput && (stdInVarName != null))
                                {
                                    code = interpreter.GetVariableValue(VariableFlags.None,
                                                                        stdInVarName, ref input, ref result);
                                }

                                if (debug)
                                {
                                    TraceOps.DebugTrace(String.Format(
                                                            "Execute: interpreter = {0}, domainName = {1}, userName = {2}, " +
                                                            "password = {3}, execFileName = {4}, execArguments = {5}, " +
                                                            "directory = {6}, input = {7}, eventFlags = {8}, debug = {9}, " +
                                                            "commandLine = {10}, dequote = {11}, quoteAll = {12}, " +
                                                            "useShellExecute = {13}, captureExitCode = {14}, " +
                                                            "captureInput = {15}, captureOutput = {16}, useUnicode = {17}, " +
                                                            "ignoreStdErr = {18}, killOnError = {19}, keepNewLine = {20}, " +
                                                            "carriageReturns = {21}, trimAll = {22}, background = {23}, " +
                                                            "successExitCode = {24}, processIdVarName = {25}, exitCodeVarName = {26}, " +
                                                            "stdInVarName = {27}, stdOutVarName = {28}, stdErrVarName = {29}",
                                                            FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(domainName),
                                                            FormatOps.WrapOrNull(userName), FormatOps.WrapOrNull(password),
                                                            FormatOps.WrapOrNull(execFileName), FormatOps.WrapOrNull(execArguments),
                                                            FormatOps.WrapOrNull(directory), FormatOps.WrapOrNull(input),
                                                            FormatOps.WrapOrNull(eventFlags), debug, commandLine, dequote, quoteAll,
                                                            useShellExecute, captureExitCode, captureInput, captureOutput, useUnicode,
                                                            ignoreStdErr, killOnError, keepNewLine, carriageReturns, trimAll, background,
                                                            FormatOps.WrapOrNull(successExitCode), FormatOps.WrapOrNull(processIdVarName),
                                                            FormatOps.WrapOrNull(exitCodeVarName), FormatOps.WrapOrNull(stdInVarName),
                                                            FormatOps.WrapOrNull(stdOutVarName), FormatOps.WrapOrNull(stdErrVarName)),
                                                        typeof(Exec).Name, TracePriority.Command);
                                }

                                int      processId = 0;
                                ExitCode exitCode  = ResultOps.SuccessExitCode();
                                Result   error     = null;

                                if (code == ReturnCode.Ok)
                                {
                                    if (list != null)
                                    {
                                        list.Add(execFileName);
                                        list.Add(directory);
                                        list.Add(execArguments);

                                        code = interpreter.EvaluateScript(list.ToString(), ref result);

                                        if (code == ReturnCode.Return)
                                        {
                                            execArguments = result;
                                            code          = ReturnCode.Ok;
                                        }
                                        else if (code == ReturnCode.Continue)
                                        {
                                            code = ReturnCode.Ok;
                                            goto done;
                                        }
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        code = ProcessOps.ExecuteProcess(
                                            interpreter, domainName, userName, password, execFileName,
                                            execArguments, directory, input, eventFlags, useShellExecute,
                                            captureExitCode, captureOutput, useUnicode, ignoreStdErr,
                                            killOnError, keepNewLine, background, !background,
                                            ref processId, ref exitCode, ref result, ref error);
                                    }
                                }

done:

                                if (debug)
                                {
                                    TraceOps.DebugTrace(String.Format(
                                                            "Execute: interpreter = {0}, domainName = {1}, userName = {2}, " +
                                                            "password = {3}, execFileName = {4}, execArguments = {5}, " +
                                                            "directory = {6}, input = {7}, eventFlags = {8}, debug = {9}, " +
                                                            "commandLine = {10}, dequote = {11}, quoteAll = {12}, " +
                                                            "useShellExecute = {13}, captureExitCode = {14}, " +
                                                            "captureInput = {15}, captureOutput = {16}, useUnicode = {17}, " +
                                                            "ignoreStdErr = {18}, killOnError = {19}, keepNewLine = {20}, " +
                                                            "carriageReturns = {21}, trimAll = {22}, background = {23}, " +
                                                            "successExitCode = {24}, processIdVarName = {25}, exitCodeVarName = {26}, " +
                                                            "stdInVarName = {27}, stdOutVarName = {28}, stdErrVarName = {29}, " +
                                                            "processId = {30}, exitCode = {31}, result = {32}, error = {33}",
                                                            FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(domainName),
                                                            FormatOps.WrapOrNull(userName), FormatOps.WrapOrNull(password),
                                                            FormatOps.WrapOrNull(execFileName), FormatOps.WrapOrNull(execArguments),
                                                            FormatOps.WrapOrNull(directory), FormatOps.WrapOrNull(input),
                                                            FormatOps.WrapOrNull(eventFlags), debug, commandLine, dequote, quoteAll,
                                                            useShellExecute, captureExitCode, captureInput, captureOutput, useUnicode,
                                                            ignoreStdErr, killOnError, keepNewLine, carriageReturns, trimAll, background,
                                                            FormatOps.WrapOrNull(successExitCode), FormatOps.WrapOrNull(processIdVarName),
                                                            FormatOps.WrapOrNull(exitCodeVarName), FormatOps.WrapOrNull(stdInVarName),
                                                            FormatOps.WrapOrNull(stdOutVarName), FormatOps.WrapOrNull(stdErrVarName),
                                                            processId, exitCode, FormatOps.WrapOrNull(true, true, result),
                                                            FormatOps.WrapOrNull(true, true, error)), typeof(Exec).Name,
                                                        TracePriority.Command);
                                }

                                //
                                // NOTE: Even upon failure, always set the variable to contain
                                //       process Id, if applicable.
                                //
                                if (processIdVarName != null)
                                {
                                    /* IGNORED */
                                    interpreter.SetVariableValue( /* EXEMPT */
                                        VariableFlags.NoReady, processIdVarName,
                                        processId.ToString(), null);
                                }

                                if (code == ReturnCode.Ok)
                                {
                                    //
                                    // NOTE: Remove all carriage returns from output (leaving
                                    //       only line feeds as line separators)?
                                    //
                                    if (!carriageReturns)
                                    {
                                        if (!String.IsNullOrEmpty(result))
                                        {
                                            result = result.Replace(
                                                Characters.CarriageReturnString,
                                                String.Empty);
                                        }

                                        if (!String.IsNullOrEmpty(error))
                                        {
                                            error = error.Replace(
                                                Characters.CarriageReturnString,
                                                String.Empty);
                                        }
                                    }

                                    //
                                    // NOTE: Remove all surrounding whitespace from the output?
                                    //
                                    if (trimAll)
                                    {
                                        if (!String.IsNullOrEmpty(result))
                                        {
                                            result = result.Trim();
                                        }

                                        if (!String.IsNullOrEmpty(error))
                                        {
                                            error = error.Trim();
                                        }
                                    }

                                    //
                                    // NOTE: Now, "result" contains any StdOut output and "error"
                                    //        contains any StdErr output.
                                    //
                                    if ((code == ReturnCode.Ok) && !background &&
                                        captureExitCode && (exitCodeVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            exitCodeVarName, exitCode.ToString(), null, ref error);
                                    }

                                    if ((code == ReturnCode.Ok) && !useShellExecute &&
                                        !background && captureOutput && (stdOutVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            stdOutVarName, result, null, ref error);
                                    }

                                    if ((code == ReturnCode.Ok) && !useShellExecute &&
                                        !background && captureOutput && (stdErrVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            stdErrVarName, error, null, ref error);
                                    }

                                    //
                                    // NOTE: If they specified a "success" exit code, make sure
                                    //       that is the same as the exit code we actually got
                                    //       from the process.
                                    //
                                    if ((code == ReturnCode.Ok) && !background && captureExitCode &&
                                        (successExitCode != null) && (exitCode != successExitCode))
                                    {
                                        /* IGNORED */
                                        interpreter.SetVariableValue( /* EXEMPT */
                                            Engine.ErrorCodeVariableFlags, TclVars.ErrorCode,
                                            StringList.MakeList(
                                                "CHILDSTATUS", processId, exitCode),
                                            null);

                                        Engine.SetErrorCodeSet(interpreter, true);

                                        error = "child process exited abnormally";
                                        code  = ReturnCode.Error;
                                    }

                                    if (code != ReturnCode.Ok)
                                    {
                                        //
                                        // NOTE: Transfer error to command result.
                                        //
                                        result = error;
                                    }
                                }
                                else
                                {
                                    //
                                    // NOTE: Transfer error to command result.
                                    //
                                    result = error;
                                }
                            }
                            else
                            {
                                result = "wrong # args: should be \"exec ?options? arg ?arg ...?\"";
                                code   = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"exec ?options? arg ?arg ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
Пример #28
0
        ///////////////////////////////////////////////////////////////////////

        public new bool Remove(
            string key
            )
        {
            return(base.Remove(PathOps.TranslatePath(key, translationType)));
        }
Пример #29
0
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                            new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-clientdata", null),
                            new Option(null, OptionFlags.MustHaveObjectValue, Index.Invalid, Index.Invalid, "-data", null),
                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-nocase", null),
                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-keeplibrary", null),
                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, "-nocomplain", null),
                            new Option(null, OptionFlags.MustHaveMatchModeValue, Index.Invalid, Index.Invalid, "-match",
                                       new Variant(StringOps.DefaultUnloadMatchMode)),
                            new Option(null, OptionFlags.None, Index.Invalid, Index.Invalid, Option.EndOfOptions, null)
                        });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 1, Index.Invalid, false, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            //
                            // NOTE: There should be a minimum of one and a maximum
                            //       of three arguments after the final option.
                            //
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 3) >= arguments.Count))
                            {
                                string path = ((argumentIndex + 2) < arguments.Count) ?
                                              (string)arguments[argumentIndex + 2] : String.Empty;

                                Interpreter slaveInterpreter = null;

                                code = interpreter.GetNestedSlaveInterpreter(
                                    path, LookupFlags.Interpreter, false,
                                    ref slaveInterpreter, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    Variant     value           = null;
                                    IClientData localClientData = clientData;

                                    if (options.IsPresent("-clientdata", ref value))
                                    {
                                        IObject @object = (IObject)value.Value;

                                        if ((@object.Value == null) ||
                                            (@object.Value is IClientData))
                                        {
                                            localClientData = (IClientData)@object.Value;
                                        }
                                        else
                                        {
                                            result = "option value has invalid clientData";
                                            code   = ReturnCode.Error;
                                        }
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        if (options.IsPresent("-data", ref value))
                                        {
                                            IObject @object = (IObject)value.Value;

                                            localClientData = _Public.ClientData.WrapOrReplace(
                                                localClientData, @object.Value);
                                        }

                                        MatchMode mode = StringOps.DefaultUnloadMatchMode;

                                        if (options.IsPresent("-match", ref value))
                                        {
                                            mode = (MatchMode)value.Value;
                                        }

                                        bool noCase = false;

                                        if (options.IsPresent("-nocase"))
                                        {
                                            noCase = true;
                                        }

                                        if (slaveInterpreter.HasPlugins(ref result))
                                        {
                                            string fileName = PathOps.ResolveFullPath(
                                                interpreter, arguments[argumentIndex]);

                                            if (!String.IsNullOrEmpty(fileName))
                                            {
                                                string typeName = null;

                                                if ((argumentIndex + 1) < arguments.Count)
                                                {
                                                    typeName = arguments[argumentIndex + 1];
                                                }

                                                //
                                                // NOTE: Grab the plugin flags to match from the target
                                                //       interpreter and add the Demand flag to them.
                                                //
                                                PluginFlags pluginFlags =
                                                    slaveInterpreter.PluginFlags | PluginFlags.Demand;

                                                //
                                                // FIXME: PRI 4: Threading.
                                                //
                                                bool       unload = false;
                                                StringList list   = slaveInterpreter.CopyPluginKeys();

                                                foreach (string name in list)
                                                {
                                                    IPluginData pluginData = slaveInterpreter.GetPluginData(name);

                                                    //
                                                    // NOTE: Check that this plugin represents a loaded
                                                    //       assembly.
                                                    //
                                                    if (pluginData != null)
                                                    {
                                                        if ((pluginData.FileName != null) &&
                                                            PathOps.IsSameFile(interpreter,
                                                                               pluginData.FileName, fileName))
                                                        {
                                                            if (String.IsNullOrEmpty(typeName) ||
                                                                StringOps.Match(interpreter, mode,
                                                                                pluginData.TypeName, typeName, noCase) ||
                                                                StringOps.Match(interpreter, mode,
                                                                                pluginData.Name, typeName, noCase))
                                                            {
                                                                code = slaveInterpreter.UnloadPlugin(
                                                                    name, localClientData, pluginFlags,
                                                                    ref result);

                                                                if (code == ReturnCode.Ok)
                                                                {
                                                                    unload = true;
                                                                }

                                                                //
                                                                // NOTE: Stop as soon as we match and
                                                                //       attempt to unload a plugin,
                                                                //       whether or not we actually
                                                                //       unloaded it.  We always halt
                                                                //       on errors and since we only
                                                                //       support unloading a single
                                                                //       plugin at a time (even if
                                                                //       there are multiple plugins
                                                                //       contained in a particular
                                                                //       assembly file), we know it
                                                                //       is safe to stop now.
                                                                //
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }

                                                if ((code == ReturnCode.Ok) && !unload)
                                                {
                                                    if (typeName != null)
                                                    {
                                                        result = String.Format(
                                                            "type \"{0}\" and file \"{1}\" have never been loaded",
                                                            typeName, fileName);
                                                    }
                                                    else
                                                    {
                                                        result = String.Format(
                                                            "file \"{0}\" has never been loaded",
                                                            fileName);
                                                    }

                                                    code = ReturnCode.Error;
                                                }
                                            }
                                            else
                                            {
                                                result = "invalid file name";
                                                code   = ReturnCode.Error;
                                            }
                                        }
                                        else
                                        {
                                            code = ReturnCode.Error;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"unload ?options? fileName ?packageName? ?interp?\"";
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"unload ?options? fileName ?packageName? ?interp?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
Пример #30
0
        ///////////////////////////////////////////////////////////////////////

        #region System.Collections.Generic.Dictionary<string, TValue> Overrides
        public new T this[string key]
        {
            get { return(base[PathOps.TranslatePath(key, translationType)]); }
            set { base[PathOps.TranslatePath(key, translationType)] = value; }
        }