Esempio n. 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 );
    }
Esempio n. 2
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 );
    }
Esempio n. 3
0
		/*
		*----------------------------------------------------------------------
		*
		* Tcl_ForgetImport -> forgetImport
		*
		*	Deletes previously imported commands. Given a pattern that may
		*	include the name of an exporting namespace, this procedure first
		*	finds all matching exported commands. It then looks in the namespace
		*	specified by namespace for any corresponding previously imported
		*	commands, which it deletes. If namespace is null, commands are
		*	deleted from the current namespace.
		*
		* Results:
		*  Returns if successful, raises TclException if something goes wrong.
		*
		* Side effects:
		*	May delete commands. 
		*
		*----------------------------------------------------------------------
		*/
		
		internal static void  forgetImport(Interp interp, Namespace namespace_Renamed, string pattern)
		{
			Namespace ns, importNs, actualCtx;
			string simplePattern, cmdName;
			IEnumerator search;
			WrappedCommand cmd;
			
			// If the specified namespace is null, use the current namespace.
			
			if (namespace_Renamed == null)
			{
				ns = getCurrentNamespace(interp);
			}
			else
			{
				ns = namespace_Renamed;
			}
			
			// From the pattern, find the namespace from which we are importing
			// and get the simple pattern (no namespace qualifiers or ::'s) at
			// the end.
			
			// Java does not support passing an address so we pass
			// an array of size 1 and then assign arr[0] to the value
			Namespace[] importNsArr = new Namespace[1];
			Namespace[] dummyArr = new Namespace[1];
			Namespace[] actualCtxArr = new Namespace[1];
			string[] simplePatternArr = new string[1];
			
			getNamespaceForQualName(interp, pattern, ns, TCL.VarFlag.LEAVE_ERR_MSG, importNsArr, dummyArr, actualCtxArr, simplePatternArr);
			
			// get the values out of the arrays
			importNs = importNsArr[0];
			actualCtx = actualCtxArr[0];
			simplePattern = simplePatternArr[0];
			
			// FIXME : the above call passes TCL.VarFlag.LEAVE_ERR_MSG, but
			// it seems like this will be a problem when exception is raised!
			if (importNs == null)
			{
				throw new TclException(interp, "unknown namespace in namespace forget pattern \"" + pattern + "\"");
			}
			
			// Scan through the command table in the source namespace and look for
			// exported commands that match the string pattern. If the current
			// namespace has an imported command that refers to one of those real
			// commands, delete it.
			
			
			for (search = importNs.cmdTable.Keys.GetEnumerator(); search.MoveNext(); )
			{
				
				cmdName = ((string) search.Current);
				if (Util.stringMatch(cmdName, simplePattern))
				{
					cmd = (WrappedCommand) ns.cmdTable[cmdName];
					if (cmd != null)
					{
						// cmd of same name in current namespace
						if (cmd.cmd is ImportedCmdData)
						{
							interp.deleteCommandFromToken(cmd);
						}
					}
				}
			}
			return ;
		}