示例#1
0
        internal static void  create(Interp interp, Interp slaveInterp, Interp masterInterp, TclObject name, TclObject targetName, int objIx, TclObject[] objv)
        {
            string inString = name.ToString();

            InterpAliasCmd alias = new InterpAliasCmd();

            alias.name = name;
            name.preserve();

            alias.slaveInterp  = slaveInterp;
            alias.targetInterp = masterInterp;

            alias.prefix = TclList.newInstance();
            alias.prefix.preserve();
            TclList.append(interp, alias.prefix, targetName);
            TclList.insert(interp, alias.prefix, 1, objv, objIx, objv.Length - 1);

            slaveInterp.createCommand(inString, alias);
            alias.slaveCmd = NamespaceCmd.findCommand(slaveInterp, inString, null, 0);

            try
            {
                interp.preventAliasLoop(slaveInterp, alias.slaveCmd);
            }
            catch (TclException e)
            {
                // Found an alias loop!  The last call to Tcl_CreateObjCommand made
                // the alias point to itself.  Delete the command and its alias
                // record.  Be careful to wipe out its client data first, so the
                // command doesn't try to delete itself.

                slaveInterp.deleteCommandFromToken(alias.slaveCmd);
                throw;
            }

            // Make an entry in the alias table. If it already exists delete
            // the alias command. Then retry.

            if (slaveInterp.aliasTable.ContainsKey(inString))
            {
                InterpAliasCmd oldAlias = (InterpAliasCmd)slaveInterp.aliasTable[inString];
                slaveInterp.deleteCommandFromToken(oldAlias.slaveCmd);
            }

            alias.aliasEntry = inString;
            SupportClass.PutElement(slaveInterp.aliasTable, inString, alias);

            // Create the new command. We must do it after deleting any old command,
            // because the alias may be pointing at a renamed alias, as in:
            //
            // interp alias {} foo {} bar		# Create an alias "foo"
            // rename foo zop				# Now rename the alias
            // interp alias {} foo {} zop		# Now recreate "foo"...

            SupportClass.PutElement(masterInterp.targetTable, alias.slaveCmd, slaveInterp);

            interp.setResult(name);
        }
示例#2
0
        internal static Interp getTargetInterp(Interp slaveInterp, string aliasName)
        {
            if (!slaveInterp.aliasTable.ContainsKey(aliasName))
            {
                return(null);
            }

            InterpAliasCmd alias = (InterpAliasCmd)slaveInterp.aliasTable[aliasName];

            return(alias.targetInterp);
        }
示例#3
0
        internal static void  list(Interp interp, Interp slaveInterp)
        {
            TclObject result = TclList.newInstance();

            interp.setResult(result);

            IEnumerator aliases = slaveInterp.aliasTable.Values.GetEnumerator();

            while (aliases.MoveNext())
            {
                InterpAliasCmd alias = (InterpAliasCmd)aliases.Current;
                TclList.append(interp, result, alias.name);
            }
        }
示例#4
0
        internal static void  describe(Interp interp, Interp slaveInterp, TclObject name)
        {
            // If the alias has been renamed in the slave, the master can still use
            // the original name (with which it was created) to find the alias to
            // describe it.


            string inString = name.ToString();

            if (slaveInterp.aliasTable.ContainsKey(inString))
            {
                InterpAliasCmd alias = (InterpAliasCmd)slaveInterp.aliasTable[inString];
                interp.setResult(alias.prefix);
            }
        }
示例#5
0
        internal static void  delete(Interp interp, Interp slaveInterp, TclObject name)
        {
            // If the alias has been renamed in the slave, the master can still use
            // the original name (with which it was created) to find the alias to
            // delete it.


            string inString = name.ToString();

            if (!slaveInterp.aliasTable.ContainsKey(inString))
            {
                throw new TclException(interp, "alias \"" + inString + "\" not found");
            }

            InterpAliasCmd alias = (InterpAliasCmd)slaveInterp.aliasTable[inString];

            slaveInterp.deleteCommandFromToken(alias.slaveCmd);
        }
示例#6
0
    internal static void create( Interp interp, Interp slaveInterp, Interp masterInterp, TclObject name, TclObject targetName, int objIx, TclObject[] objv )
    {

      string inString = name.ToString();

      InterpAliasCmd alias = new InterpAliasCmd();

      alias.name = name;
      name.preserve();

      alias.slaveInterp = slaveInterp;
      alias.targetInterp = masterInterp;

      alias.prefix = TclList.newInstance();
      alias.prefix.preserve();
      TclList.append( interp, alias.prefix, targetName );
      TclList.insert( interp, alias.prefix, 1, objv, objIx, objv.Length - 1 );

      slaveInterp.createCommand( inString, alias );
      alias.slaveCmd = NamespaceCmd.findCommand( slaveInterp, inString, null, 0 );

      try
      {
        interp.preventAliasLoop( slaveInterp, alias.slaveCmd );
      }
      catch ( TclException e )
      {
        // Found an alias loop!  The last call to Tcl_CreateObjCommand made
        // the alias point to itself.  Delete the command and its alias
        // record.  Be careful to wipe out its client data first, so the
        // command doesn't try to delete itself.

        slaveInterp.deleteCommandFromToken( alias.slaveCmd );
        throw;
      }

      // Make an entry in the alias table. If it already exists delete
      // the alias command. Then retry.

      if ( slaveInterp.aliasTable.ContainsKey( inString ) )
      {
        InterpAliasCmd oldAlias = (InterpAliasCmd)slaveInterp.aliasTable[inString];
        slaveInterp.deleteCommandFromToken( oldAlias.slaveCmd );
      }

      alias.aliasEntry = inString;
      SupportClass.PutElement( slaveInterp.aliasTable, inString, alias );

      // Create the new command. We must do it after deleting any old command,
      // because the alias may be pointing at a renamed alias, as in:
      //
      // interp alias {} foo {} bar		# Create an alias "foo"
      // rename foo zop				# Now rename the alias
      // interp alias {} foo {} zop		# Now recreate "foo"...

      SupportClass.PutElement( masterInterp.targetTable, alias.slaveCmd, slaveInterp );

      interp.setResult( name );
    }
示例#7
0
        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv)
        {
            if (objv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, objv, "cmd ?arg ...?");
            }
            int cmd = TclIndex.get(interp, objv[1], options, "option", 0);

            switch (cmd)
            {
            case OPT_ALIAS:
            {
                if (objv.Length >= 4)
                {
                    Interp slaveInterp = getInterp(interp, objv[2]);

                    if (objv.Length == 4)
                    {
                        InterpAliasCmd.describe(interp, slaveInterp, objv[3]);
                        return(TCL.CompletionCode.RETURN);
                    }

                    if ((objv.Length == 5) && ("".Equals(objv[4].ToString())))
                    {
                        InterpAliasCmd.delete(interp, slaveInterp, objv[3]);
                        return(TCL.CompletionCode.RETURN);
                    }
                    if (objv.Length > 5)
                    {
                        Interp masterInterp = getInterp(interp, objv[4]);

                        if ("".Equals(objv[5].ToString()))
                        {
                            if (objv.Length == 6)
                            {
                                InterpAliasCmd.delete(interp, slaveInterp, objv[3]);
                                return(TCL.CompletionCode.RETURN);
                            }
                        }
                        else
                        {
                            InterpAliasCmd.create(interp, slaveInterp, masterInterp, objv[3], objv[5], 6, objv);
                            return(TCL.CompletionCode.RETURN);
                        }
                    }
                }
                throw new TclNumArgsException(interp, 2, objv, "slavePath slaveCmd ?masterPath masterCmd? ?args ..?");
            }

            case OPT_ALIASES:
            {
                Interp slaveInterp = getInterp(interp, objv);
                InterpAliasCmd.list(interp, slaveInterp);
                break;
            }

            case OPT_CREATE:
            {
                // Weird historical rules: "-safe" is accepted at the end, too.

                bool safe = interp.isSafe;

                TclObject slaveNameObj = null;
                bool      last         = false;
                for (int i = 2; i < objv.Length; i++)
                {
                    if ((!last) && (objv[i].ToString()[0] == '-'))
                    {
                        int index = TclIndex.get(interp, objv[i], createOptions, "option", 0);
                        if (index == OPT_CREATE_SAFE)
                        {
                            safe = true;
                            continue;
                        }
                        i++;
                        last = true;
                    }
                    if (slaveNameObj != null)
                    {
                        throw new TclNumArgsException(interp, 2, objv, "?-safe? ?--? ?path?");
                    }
                    slaveNameObj = objv[i];
                }
                if (slaveNameObj == null)
                {
                    // Create an anonymous interpreter -- we choose its name and
                    // the name of the command. We check that the command name
                    // that we use for the interpreter does not collide with an
                    // existing command in the master interpreter.

                    int i = 0;
                    while (interp.getCommand("interp" + i) != null)
                    {
                        i++;
                    }
                    slaveNameObj = TclString.newInstance("interp" + i);
                }
                InterpSlaveCmd.create(interp, slaveNameObj, safe);
                interp.setResult(slaveNameObj);
                break;
            }

            case OPT_DELETE:
            {
                for (int i = 2; i < objv.Length; i++)
                {
                    Interp slaveInterp = getInterp(interp, objv[i]);

                    if (slaveInterp == interp)
                    {
                        throw new TclException(interp, "cannot delete the current interpreter");
                    }
                    InterpSlaveCmd slave = slaveInterp.slave;
                    slave.masterInterp.deleteCommandFromToken(slave.interpCmd);
                }
                break;
            }

            case OPT_EVAL:
            {
                if (objv.Length < 4)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path arg ?arg ...?");
                }
                Interp slaveInterp = getInterp(interp, objv[2]);
                InterpSlaveCmd.eval(interp, slaveInterp, 3, objv);
                break;
            }

            case OPT_EXISTS:
            {
                bool exists = true;

                try
                {
                    getInterp(interp, objv);
                }
                catch (TclException e)
                {
                    if (objv.Length > 3)
                    {
                        throw;
                    }
                    exists = false;
                }
                interp.setResult(exists);
                break;
            }

            case OPT_EXPOSE:
            {
                if (objv.Length < 4 || objv.Length > 5)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path hiddenCmdName ?cmdName?");
                }
                Interp slaveInterp = getInterp(interp, objv[2]);
                InterpSlaveCmd.expose(interp, slaveInterp, 3, objv);
                break;
            }

            case OPT_HIDE:
            {
                if (objv.Length < 4 || objv.Length > 5)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path cmdName ?hiddenCmdName?");
                }
                Interp slaveInterp = getInterp(interp, objv[2]);
                InterpSlaveCmd.hide(interp, slaveInterp, 3, objv);
                break;
            }

            case OPT_HIDDEN:
            {
                Interp slaveInterp = getInterp(interp, objv);
                InterpSlaveCmd.hidden(interp, slaveInterp);
                break;
            }

            case OPT_ISSAFE:
            {
                Interp slaveInterp = getInterp(interp, objv);
                interp.setResult(slaveInterp.isSafe);
                break;
            }

            case OPT_INVOKEHIDDEN:
            {
                bool global = false;
                int  i;
                for (i = 3; i < objv.Length; i++)
                {
                    if (objv[i].ToString()[0] != '-')
                    {
                        break;
                    }
                    int index = TclIndex.get(interp, objv[i], hiddenOptions, "option", 0);
                    if (index == OPT_HIDDEN_GLOBAL)
                    {
                        global = true;
                    }
                    else
                    {
                        i++;
                        break;
                    }
                }
                if (objv.Length - i < 1)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path ?-global? ?--? cmd ?arg ..?");
                }
                Interp slaveInterp = getInterp(interp, objv[2]);
                InterpSlaveCmd.invokeHidden(interp, slaveInterp, global, i, objv);
                break;
            }

            case OPT_MARKTRUSTED:
            {
                if (objv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path");
                }
                Interp slaveInterp = getInterp(interp, objv[2]);
                InterpSlaveCmd.markTrusted(interp, slaveInterp);
                break;
            }

            case OPT_SLAVES:
            {
                Interp slaveInterp = getInterp(interp, objv);

                TclObject result = TclList.newInstance();
                interp.setResult(result);

                IEnumerator keys = slaveInterp.slaveTable.Keys.GetEnumerator();
                while (keys.MoveNext())
                {
                    string inString = (string)keys.Current;
                    TclList.append(interp, result, TclString.newInstance(inString));
                }

                break;
            }

            case OPT_SHARE:
            {
                if (objv.Length != 5)
                {
                    throw new TclNumArgsException(interp, 2, objv, "srcPath channelId destPath");
                }
                Interp masterInterp = getInterp(interp, objv[2]);


                Channel chan = TclIO.getChannel(masterInterp, objv[3].ToString());
                if (chan == null)
                {
                    throw new TclException(interp, "can not find channel named \"" + objv[3].ToString() + "\"");
                }

                Interp slaveInterp = getInterp(interp, objv[4]);
                TclIO.registerChannel(slaveInterp, chan);
                break;
            }

            case OPT_TARGET:
            {
                if (objv.Length != 4)
                {
                    throw new TclNumArgsException(interp, 2, objv, "path alias");
                }

                Interp slaveInterp = getInterp(interp, objv[2]);

                string aliasName    = objv[3].ToString();
                Interp targetInterp = InterpAliasCmd.getTargetInterp(slaveInterp, aliasName);
                if (targetInterp == null)
                {
                    throw new TclException(interp, "alias \"" + aliasName + "\" in path \"" + objv[2].ToString() + "\" not found");
                }
                if (!getInterpPath(interp, targetInterp))
                {
                    throw new TclException(interp, "target interpreter for alias \"" + aliasName + "\" in path \"" + objv[2].ToString() + "\" is not my descendant");
                }
                break;
            }

            case OPT_TRANSFER:
            {
                if (objv.Length != 5)
                {
                    throw new TclNumArgsException(interp, 2, objv, "srcPath channelId destPath");
                }
                Interp masterInterp = getInterp(interp, objv[2]);


                Channel chan = TclIO.getChannel(masterInterp, objv[3].ToString());
                if (chan == null)
                {
                    throw new TclException(interp, "can not find channel named \"" + objv[3].ToString() + "\"");
                }

                Interp slaveInterp = getInterp(interp, objv[4]);
                TclIO.registerChannel(slaveInterp, chan);
                TclIO.unregisterChannel(masterInterp, chan);
                break;
            }
            }
            return(TCL.CompletionCode.RETURN);
        }
        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv)
        {
            if (objv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, objv, "cmd ?arg ...?");
            }
            int cmd = TclIndex.get(interp, objv[1], options, "option", 0);

            switch (cmd)
            {
            case OPT_ALIAS:
                if (objv.Length == 3)
                {
                    InterpAliasCmd.describe(interp, slaveInterp, objv[2]);
                    return(TCL.CompletionCode.RETURN);
                }

                if ("".Equals(objv[3].ToString()))
                {
                    if (objv.Length == 4)
                    {
                        InterpAliasCmd.delete(interp, slaveInterp, objv[2]);
                        return(TCL.CompletionCode.RETURN);
                    }
                }
                else
                {
                    InterpAliasCmd.create(interp, slaveInterp, interp, objv[2], objv[3], 4, objv);
                    return(TCL.CompletionCode.RETURN);
                }
                throw new TclNumArgsException(interp, 2, objv, "aliasName ?targetName? ?args..?");

            case OPT_ALIASES:
                InterpAliasCmd.list(interp, slaveInterp);
                break;

            case OPT_EVAL:
                if (objv.Length < 3)
                {
                    throw new TclNumArgsException(interp, 2, objv, "arg ?arg ...?");
                }
                eval(interp, slaveInterp, 2, objv);
                break;

            case OPT_EXPOSE:
                if (objv.Length < 3 || objv.Length > 4)
                {
                    throw new TclNumArgsException(interp, 2, objv, "hiddenCmdName ?cmdName?");
                }
                expose(interp, slaveInterp, 2, objv);
                break;

            case OPT_HIDE:
                if (objv.Length < 3 || objv.Length > 4)
                {
                    throw new TclNumArgsException(interp, 2, objv, "cmdName ?hiddenCmdName?");
                }
                hide(interp, slaveInterp, 2, objv);
                break;

            case OPT_HIDDEN:
                if (objv.Length != 2)
                {
                    throw new TclNumArgsException(interp, 2, objv, null);
                }
                InterpSlaveCmd.hidden(interp, slaveInterp);
                break;

            case OPT_ISSAFE:
                interp.setResult(slaveInterp.isSafe);
                break;

            case OPT_INVOKEHIDDEN:
                bool global = false;
                int  i;
                for (i = 2; i < objv.Length; i++)
                {
                    if (objv[i].ToString()[0] != '-')
                    {
                        break;
                    }
                    int index = TclIndex.get(interp, objv[i], hiddenOptions, "option", 0);
                    if (index == OPT_HIDDEN_GLOBAL)
                    {
                        global = true;
                    }
                    else
                    {
                        i++;
                        break;
                    }
                }
                if (objv.Length - i < 1)
                {
                    throw new TclNumArgsException(interp, 2, objv, "?-global? ?--? cmd ?arg ..?");
                }
                InterpSlaveCmd.invokeHidden(interp, slaveInterp, global, i, objv);
                break;

            case OPT_MARKTRUSTED:
                if (objv.Length != 2)
                {
                    throw new TclNumArgsException(interp, 2, objv, null);
                }
                markTrusted(interp, slaveInterp);
                break;
            }
            return(TCL.CompletionCode.RETURN);
        }