public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      // Create the call frame and parameter bindings

      CallFrame frame = interp.newCallFrame( this, argv );

      // Execute the body

      interp.pushDebugStack( srcFileName, srcLineNumber );
      try
      {
        Parser.eval2( interp, body.array, body.index, body_length, 0 );
      }
      catch ( TclException e )
      {
        TCL.CompletionCode code = e.getCompletionCode();
        if ( code == TCL.CompletionCode.RETURN )
        {
          TCL.CompletionCode realCode = interp.updateReturnInfo();
          if ( realCode != TCL.CompletionCode.OK )
          {
            e.setCompletionCode( realCode );
            throw;
          }
        }
        else if ( code == TCL.CompletionCode.ERROR )
        {

          interp.addErrorInfo( "\n    (procedure \"" + argv[0] + "\" line " + interp.errorLine + ")" );
          throw;
        }
        else if ( code == TCL.CompletionCode.BREAK )
        {
          throw new TclException( interp, "invoked \"break\" outside of a loop" );
        }
        else if ( code == TCL.CompletionCode.CONTINUE )
        {
          throw new TclException( interp, "invoked \"continue\" outside of a loop" );
        }
        else
        {
          throw;
        }
      }
      finally
      {
        interp.popDebugStack();

        // The check below is a hack.  The problem is that there
        // could be unset traces on the variables, which cause
        // scripts to be evaluated.  This will clear the
        // errInProgress flag, losing stack trace information if
        // the procedure was exiting with an error.  The code
        // below preserves the flag.  Unfortunately, that isn't
        // really enough: we really should preserve the errorInfo
        // variable too (otherwise a nested error in the trace
        // script will trash errorInfo).  What's really needed is
        // a general-purpose mechanism for saving and restoring
        // interpreter state.

        if ( interp.errInProgress )
        {
          frame.dispose();
          interp.errInProgress = true;
        }
        else
        {
          frame.dispose();
        }
      }
      return TCL.CompletionCode.RETURN;
    }
Beispiel #2
0
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			string fileName = null;
			bool url = false;
			
			if (argv.Length == 2)
			{
				
				fileName = argv[1].ToString();
			}
			else if (argv.Length == 3)
			{
				
				if (argv[1].ToString().Equals("-url"))
				{
					url = true;
					
					fileName = argv[2].ToString();
				}
			}
			
			if ((System.Object) fileName == null)
			{
				throw new TclNumArgsException(interp, 1, argv, "?-url? fileName");
			}
			
			try
			{
				if (url)
				{
					if (fileName.StartsWith("resource:/"))
					{
						interp.evalResource(fileName.Substring(9));
					}
					else
					{
						interp.evalURL(null, fileName);
					}
				}
				else
				{
					interp.evalFile(fileName);
				}
			}
			catch (TclException e)
			{
				TCL.CompletionCode code = e.getCompletionCode();
				
				if (code == TCL.CompletionCode.RETURN)
				{
					TCL.CompletionCode realCode = interp.updateReturnInfo();
					if (realCode != TCL.CompletionCode.OK)
					{
						e.setCompletionCode(realCode);
						throw ;
					}
				}
				else if (code == TCL.CompletionCode.ERROR)
				{
					/*
					* Record information telling where the error occurred.
					*/
					
					interp.addErrorInfo("\n    (file line " + interp.errorLine + ")");
					throw ;
				}
				else
				{
					throw ;
				}
			}
      return TCL.CompletionCode.RETURN;
    }
Beispiel #3
0
  /*
  ** 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);
        }
      }
    }
  }