コード例 #1
0
ファイル: VwaitCmd.cs プロジェクト: Belxjander/Asuna
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if (argv.Length != 2)
			{
				throw new TclNumArgsException(interp, 1, argv, "name");
			}
			
			VwaitTrace trace = new VwaitTrace();
			Var.traceVar(interp, argv[1], TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_UNSETS, trace);
			
			int foundEvent = 1;
			while (!trace.done && (foundEvent != 0))
			{
				foundEvent = interp.getNotifier().doOneEvent(TCL.ALL_EVENTS);
			}
			
			Var.untraceVar(interp, argv[1], TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_UNSETS, trace);
			
			// Clear out the interpreter's result, since it may have been set
			// by event handlers.
			
			interp.resetResult();
			
			if (foundEvent == 0)
			{
				
				throw new TclException(interp, "can't wait for variable \"" + argv[1] + "\":  would wait forever");
			}
      return TCL.CompletionCode.RETURN;
    }
コード例 #2
0
ファイル: UpdateCmd.cs プロジェクト: Jaden-J/csharp-sqlite
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      int flags;

      if ( argv.Length == 1 )
      {
        flags = TCL.ALL_EVENTS | TCL.DONT_WAIT;
      }
      else if ( argv.Length == 2 )
      {
        TclIndex.get( interp, argv[1], validOpts, "option", 0 );

        /*
        * Since we just have one valid option, if the above call returns
        * without an exception, we've got "idletasks" (or abreviations).
        */

        flags = TCL.IDLE_EVENTS | TCL.DONT_WAIT;
      }
      else
      {
        throw new TclNumArgsException( interp, 1, argv, "?idletasks?" );
      }

      while ( interp.getNotifier().doOneEvent( flags ) != 0 )
      {
        /* Empty loop body */
      }

      /*
      * Must clear the interpreter's result because event handlers could
      * have executed commands.
      */

      interp.resetResult();
      return TCL.CompletionCode.RETURN;
    }
コード例 #3
0
ファイル: AfterCmd.cs プロジェクト: R4P3NET/TS3SRV-ASE
        public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
        {
            int i;
              Notifier notifier = (Notifier)interp.getNotifier();
              Object info;

              if ( assocData == null )
              {
            /*
            * Create the "after" information associated for this
            * interpreter, if it doesn't already exist.
            */

            assocData = (AfterAssocData)interp.getAssocData( "tclAfter" );
            if ( assocData == null )
            {
              assocData = new AfterAssocData( this );
              interp.setAssocData( "tclAfter", assocData );
            }
              }

              if ( argv.Length < 2 )
              {
            throw new TclNumArgsException( interp, 1, argv, "option ?arg arg ...?" );
              }

              /*
              * First lets see if the command was passed a number as the first argument.
              */

              bool isNumber = false;
              int ms = 0;

              if ( argv[1].InternalRep is TclInteger )
              {
            ms = TclInteger.get( interp, argv[1] );
            isNumber = true;
              }
              else
              {
            string s = argv[1].ToString();
            if ( ( s.Length > 0 ) && ( System.Char.IsDigit( s[0] ) ) )
            {
              ms = TclInteger.get( interp, argv[1] );
              isNumber = true;
            }
              }

              if ( isNumber )
              {
            if ( ms < 0 )
            {
              ms = 0;
            }
            if ( argv.Length == 2 )
            {
              /*
              * Sleep for at least the given milliseconds and return.
              */

              long endTime = System.DateTime.Now.Ticks / 10000 + ms;
              while ( true )
              {
            try
            {
              System.Threading.Thread.Sleep( ms );
              return TCL.CompletionCode.RETURN;
            }
            catch ( System.Threading.ThreadInterruptedException e )
            {
              /*
              * We got interrupted. Sleep again if we havn't slept
              * long enough yet.
              */

              long sysTime = System.DateTime.Now.Ticks / 10000;
              if ( sysTime >= endTime )
              {
                return TCL.CompletionCode.RETURN;
              }
              ms = (int)( endTime - sysTime );
              continue;
            }
              }
            }

            TclObject cmd = getCmdObject( argv );
            cmd.preserve();

            assocData.lastAfterId++;
            TimerInfo timerInfo = new TimerInfo( this, notifier, ms );
            timerInfo.interp = interp;
            timerInfo.command = cmd;
            timerInfo.id = assocData.lastAfterId;

            assocData.handlers.Add( timerInfo );

            interp.setResult( "after#" + timerInfo.id );

            return TCL.CompletionCode.RETURN;
              }

              /*
              * If it's not a number it must be a subcommand.
              */

              int index;

              try
              {
            index = TclIndex.get( interp, argv[1], validOpts, "option", 0 );
              }
              catch ( TclException e )
              {
            throw new TclException( interp, "bad argument \"" + argv[1] + "\": must be cancel, idle, info, or a number" );
              }

              switch ( index )
              {

            case OPT_CANCEL:
              if ( argv.Length < 3 )
              {
            throw new TclNumArgsException( interp, 2, argv, "id|command" );
              }

              TclObject arg = getCmdObject( argv );
              arg.preserve();

              /*
              * Search the timer/idle handler by id or by command.
              */

              info = null;
              for ( i = 0; i < assocData.handlers.Count; i++ )
              {
            Object obj = assocData.handlers[i];
            if ( obj is TimerInfo )
            {
              TclObject cmd = ( (TimerInfo)obj ).command;

              if ( ( cmd == arg ) || cmd.ToString().Equals( arg.ToString() ) )
              {
                info = obj;
                break;
              }
            }
            else
            {
              TclObject cmd = ( (IdleInfo)obj ).command;

              if ( ( cmd == arg ) || cmd.ToString().Equals( arg.ToString() ) )
              {
                info = obj;
                break;
              }
            }
              }
              if ( info == null )
              {

            info = getAfterEvent( arg.ToString() );
              }
              arg.release();

              /*
              * Cancel the handler.
              */

              if ( info != null )
              {
            if ( info is TimerInfo )
            {
              ( (TimerInfo)info ).cancel();
              ( (TimerInfo)info ).command.release();
            }
            else
            {
              ( (IdleInfo)info ).cancel();
              ( (IdleInfo)info ).command.release();
            }

            SupportClass.VectorRemoveElement( assocData.handlers, info );
              }
              break;

            case OPT_IDLE:
              if ( argv.Length < 3 )
              {
            throw new TclNumArgsException( interp, 2, argv, "script script ..." );
              }

              TclObject cmd2 = getCmdObject( argv );
              cmd2.preserve();
              assocData.lastAfterId++;

              IdleInfo idleInfo = new IdleInfo( this, notifier );
              idleInfo.interp = interp;
              idleInfo.command = cmd2;
              idleInfo.id = assocData.lastAfterId;

              assocData.handlers.Add( idleInfo );

              interp.setResult( "after#" + idleInfo.id );
              break;

            case OPT_INFO:
              if ( argv.Length == 2 )
              {
            /*
            * No id is given. Return a list of current after id's.
            */

            TclObject list = TclList.newInstance();
            for ( i = 0; i < assocData.handlers.Count; i++ )
            {
              int id;
              Object obj = assocData.handlers[i];
              if ( obj is TimerInfo )
              {
                id = ( (TimerInfo)obj ).id;
              }
              else
              {
                id = ( (IdleInfo)obj ).id;
              }
              TclList.append( interp, list, TclString.newInstance( "after#" + id ) );
            }
            interp.resetResult();
            interp.setResult( list );
            return TCL.CompletionCode.RETURN;
              }
              if ( argv.Length != 3 )
              {
            throw new TclNumArgsException( interp, 2, argv, "?id?" );
              }

              /*
              * Return command and type of the given after id.
              */

              info = getAfterEvent( argv[2].ToString() );
              if ( info == null )
              {

            throw new TclException( interp, "event \"" + argv[2] + "\" doesn't exist" );
              }
              TclObject list2 = TclList.newInstance();
              TclList.append( interp, list2, ( ( info is TimerInfo ) ? ( (TimerInfo)info ).command : ( (IdleInfo)info ).command ) );
              TclList.append( interp, list2, TclString.newInstance( ( info is TimerInfo ) ? "timer" : "idle" ) );

              interp.resetResult();
              interp.setResult( list2 );
              break;
              }
              return TCL.CompletionCode.RETURN;
        }
コード例 #4
0
ファイル: csTCL.cs プロジェクト: Jaden-J/csharp-sqlite
  /*
  ** 2009 July 17
  **
  ** The author disclaims copyright to this source code.  In place of
  ** a legal notice, here is a blessing:
  **
  **    May you do good and not evil.
  **    May you find forgiveness for yourself and forgive others.
  **    May you share freely, never taking more than you give.
  **
  *************************************************************************
  ** This file contains code to implement the "sqlite" test harness
  ** which runs TCL commands for testing the C#-SQLite port.
  **
  ** $Header$
  */
  public static void Main(string[] args)
  {
    // Array of command-line argument strings.
    {
      string fileName = null;

      // Create the interpreter. This will also create the built-in
      // Tcl commands.

      Interp interp = new Interp();

      // Make command-line arguments available in the Tcl variables "argc"
      // and "argv".  If the first argument doesn't start with a "-" then
      // strip it off and use it as the name of a script file to process.
      // We also set the argv0 and TCL.Tcl_interactive vars here.

      if ((args.Length > 0) && !(args[0].StartsWith("-")))
      {
        fileName = args[0];
      }

      TclObject argv = TclList.newInstance();
      argv.preserve();
      try
      {
        int i = 0;
        int argc = args.Length;
        if ((System.Object)fileName == null)
        {
          interp.setVar("argv0", "tcl.lang.Shell", TCL.VarFlag.GLOBAL_ONLY);
          interp.setVar("tcl_interactive", "1", TCL.VarFlag.GLOBAL_ONLY);
        }
        else
        {
          interp.setVar("argv0", fileName, TCL.VarFlag.GLOBAL_ONLY);
          interp.setVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY);
          i++;
          argc--;
        }
        for (; i < args.Length; i++)
        {
          TclList.append(interp, argv, TclString.newInstance(args[i]));
        }
        interp.setVar("argv", argv, TCL.VarFlag.GLOBAL_ONLY);
        interp.setVar("argc", System.Convert.ToString(argc), TCL.VarFlag.GLOBAL_ONLY);
      }
      catch (TclException e)
      {
        throw new TclRuntimeError("unexpected TclException: " + e.Message);
      }
      finally
      {
        argv.release();
      }

      // Normally we would do application specific initialization here.
      // However, that feature is not currently supported.
      // If a script file was specified then just source that file
      // and quit.

      Console.WriteLine("C#-TCL version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
      Console.WriteLine("==============================================================");
      Console.WriteLine("");

      if ((System.Object)fileName != null)
      {
        try
        {
          interp.evalFile(fileName);
        }
        catch (TclException e)
        {
          TCL.CompletionCode code = e.getCompletionCode();
          if (code == TCL.CompletionCode.RETURN)
          {
            code = interp.updateReturnInfo();
            if (code != TCL.CompletionCode.OK)
            {
              System.Console.Error.WriteLine("command returned bad code: " + code);
              if (tcl.lang.ConsoleThread.debug) System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
            }
          }
          else if (code == TCL.CompletionCode.ERROR)
          {
            System.Console.Error.WriteLine(interp.getResult().ToString());
            if (tcl.lang.ConsoleThread.debug) System.Diagnostics.Debug.WriteLine(interp.getResult().ToString());
            System.Diagnostics.Debug.Assert(false, interp.getResult().ToString());
          }
          else
          {
            System.Console.Error.WriteLine("command returned bad code: " + code);
            if (tcl.lang.ConsoleThread.debug) System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
          }
        }

        // Note that if the above interp.evalFile() returns the main
        // thread will exit.  This may bring down the VM and stop
        // the execution of Tcl.
        //
        // If the script needs to handle events, it must call
        // vwait or do something similar.
        //
        // Note that the script can create AWT widgets. This will
        // start an AWT event handling thread and keep the VM up. However,
        // the interpreter thread (the same as the main thread) would
        // have exited and no Tcl scripts can be executed.

        interp.dispose();

        System.Environment.Exit(0);
      }

      if ((System.Object)fileName == null)
      {
        // We are running in interactive mode. Start the ConsoleThread
        // that loops, grabbing stdin and passing it to the interp.

        ConsoleThread consoleThread = new ConsoleThread(interp);
        consoleThread.IsBackground = true;
        consoleThread.Start();

        // Loop forever to handle user input events in the command line.

        Notifier notifier = interp.getNotifier();
        while (true)
        {
          // process events until "exit" is called.

          notifier.doOneEvent(TCL.ALL_EVENTS);
        }
      }
    }
  }