Exemplo n.º 1
0
    /// <summary> This procedure is invoked to process the "eval" Tcl command.
    /// See the user documentation for details on what it does.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="argv">command arguments.
    /// </param>
    /// <exception cref=""> TclException if script causes error.
    /// </exception>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      if ( argv.Length < 2 )
      {
        throw new TclNumArgsException( interp, 1, argv, "arg ?arg ...?" );
      }

      try
      {
        if ( argv.Length == 2 )
        {
          interp.eval( argv[1], 0 );
        }
        else
        {
          string s = Util.concat( 1, argv.Length - 1, argv );
          interp.eval( s, 0 );
        }
      }
      catch ( TclException e )
      {
        if ( e.getCompletionCode() == TCL.CompletionCode.ERROR )
        {
          interp.addErrorInfo( "\n    (\"eval\" body line " + interp.errorLine + ")" );
        }
        throw;
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 2
0
    /// <summary> Evaluates a Tcl expression. See Tcl user documentation for
    /// details.
    /// </summary>
    /// <exception cref=""> TclException If malformed expression.
    /// </exception>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      if ( argv.Length < 2 )
      {
        throw new TclNumArgsException( interp, 1, argv, "arg ?arg ...?" );
      }

      if ( argv.Length == 2 )
      {

        interp.setResult( interp.expr.eval( interp, argv[1].ToString() ) );
      }
      else
      {
        StringBuilder sbuf = new StringBuilder();

        sbuf.Append( argv[1].ToString() );
        for ( int i = 2; i < argv.Length; i++ )
        {
          sbuf.Append( ' ' );

          sbuf.Append( argv[i].ToString() );
        }
        interp.setResult( interp.expr.eval( interp, sbuf.ToString() ) );
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 3
0
		/// <summary> This procedure is invoked to process the "seek" Tcl command.
		/// See the user documentation for details on what it does.
		/// </summary>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			
			Channel chan; /* The channel being operated on this method */
			int mode; /* Stores the search mode, either beg, cur or end
			* of file.  See the TclIO class for more info */
			
			if (argv.Length != 3 && argv.Length != 4)
			{
				throw new TclNumArgsException(interp, 1, argv, "channelId offset ?origin?");
			}
			
			// default is the beginning of the file
			
			mode = TclIO.SEEK_SET;
			if (argv.Length == 4)
			{
				int index = TclIndex.get(interp, argv[3], validOrigins, "origin", 0);
				
				switch (index)
				{
					
					case OPT_START:  {
							mode = TclIO.SEEK_SET;
							break;
						}
					
					case OPT_CURRENT:  {
							mode = TclIO.SEEK_CUR;
							break;
						}
					
					case OPT_END:  {
							mode = TclIO.SEEK_END;
							break;
						}
					}
			}
			
			
			chan = TclIO.getChannel(interp, argv[1].ToString());
			if (chan == null)
			{
				
				throw new TclException(interp, "can not find channel named \"" + argv[1].ToString() + "\"");
			}
			long offset = TclInteger.get(interp, argv[2]);
			
			try
			{
				chan.seek(interp, offset, mode);
			}
			catch (System.IO.IOException e)
			{
				// FIXME: Need to figure out Tcl specific error conditions.
				// Should we also wrap an IOException in a ReflectException?
				throw new TclRuntimeError("SeekCmd.cmdProc() Error: IOException when seeking " + chan.ChanName + ":" + e.Message);
			}
      return TCL.CompletionCode.RETURN;
    }
    internal Procedure( Interp interp, NamespaceCmd.Namespace ns, string name, TclObject args, TclObject b, string sFileName, int sLineNumber )
    {
      this.ns = ns;
      srcFileName = sFileName;
      srcLineNumber = sLineNumber;

      // Break up the argument list into argument specifiers, then process
      // each argument specifier.

      int numArgs = TclList.getLength( interp, args );
      argList = new TclObject[numArgs][];
      for ( int i = 0; i < numArgs; i++ )
      {
        argList[i] = new TclObject[2];
      }

      for ( int i = 0; i < numArgs; i++ )
      {
        // Now divide the specifier up into name and default.

        TclObject argSpec = TclList.index( interp, args, i );
        int specLen = TclList.getLength( interp, argSpec );

        if ( specLen == 0 )
        {
          throw new TclException( interp, "procedure \"" + name + "\" has argument with no name" );
        }
        if ( specLen > 2 )
        {

          throw new TclException( interp, "too many fields in argument " + "specifier \"" + argSpec + "\"" );
        }

        argList[i][0] = TclList.index( interp, argSpec, 0 );
        argList[i][0].preserve();
        if ( specLen == 2 )
        {
          argList[i][1] = TclList.index( interp, argSpec, 1 );
          argList[i][1].preserve();
        }
        else
        {
          argList[i][1] = null;
        }
      }


      if ( numArgs > 0 && ( argList[numArgs - 1][0].ToString().Equals( "args" ) ) )
      {
        isVarArgs = true;
      }
      else
      {
        isVarArgs = false;
      }


      body = new CharPointer( b.ToString() );
      body_length = body.length();
    }
Exemplo n.º 5
0
        /// <summary> This procedure is invoked to process the "flush" Tcl command.
        /// See the user documentation for details on what it does.
        /// 
        /// </summary>
        /// <param name="interp">the current interpreter.
        /// </param>
        /// <param name="argv">command arguments.
        /// </param>
        public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
        {
            Channel chan; /* The channel being operated on this method */

              if ( argv.Length != 2 )
              {
            throw new TclNumArgsException( interp, 1, argv, "channelId" );
              }

              chan = TclIO.getChannel( interp, argv[1].ToString() );
              if ( chan == null )
              {

            throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" );
              }

              try
              {
            chan.flush( interp );
              }
              catch ( IOException e )
              {
            throw new TclRuntimeError( "FlushCmd.cmdProc() Error: IOException when flushing " + chan.ChanName );
              }
              return TCL.CompletionCode.RETURN;
        }
Exemplo n.º 6
0
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
    {
      TclObject varValue = null;

      if ( objv.Length < 2 )
      {
        throw new TclNumArgsException( interp, 1, objv, "varName ?value value ...?" );
      }
      else if ( objv.Length == 2 )
      {
        interp.resetResult();
        interp.setResult( interp.getVar( objv[1], 0 ) );
      }
      else
      {
        for ( int i = 2; i < objv.Length; i++ )
        {
          varValue = interp.setVar( objv[1], objv[i], TCL.VarFlag.APPEND_VALUE );
        }

        if ( varValue != null )
        {
          interp.resetResult();
          interp.setResult( varValue );
        }
        else
        {
          interp.resetResult();
        }
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 7
0
        /// <summary> Creates a TclException with the appropiate Tcl error
        /// message for having the wring number of arguments to a Tcl command.
        /// <p>
        /// Example: <pre>
        /// 
        /// if (argv.length != 3) {
        /// throw new TclNumArgsException(interp, 1, argv, "option name");
        /// }
        /// </pre>
        /// 
        /// </summary>
        /// <param name="interp">current Interpreter.
        /// </param>
        /// <param name="argc">the number of arguments to copy from the offending
        /// command to put into the error message.
        /// </param>
        /// <param name="argv">the arguments of the offending command.
        /// </param>
        /// <param name="message">extra message to appear in the error message that
        /// explains the proper usage of the command.
        /// </param>
        /// <exception cref=""> TclException is always thrown.
        /// </exception>
        public TclNumArgsException( Interp interp, int argc, TclObject[] argv, string message )
            : base(TCL.CompletionCode.ERROR)
        {
            if ( interp != null )
              {
            StringBuilder buff = new StringBuilder( 50 );
            buff.Append( "wrong # args: should be \"" );

            for ( int i = 0; i < argc; i++ )
            {
              if ( argv[i].InternalRep is TclIndex )
              {
            buff.Append( argv[i].InternalRep.ToString() );
              }
              else
              {
            buff.Append( argv[i].ToString() );
              }
              if ( i < ( argc - 1 ) )
              {
            buff.Append( " " );
              }
            }
            if ( ( message != null ) )
            {
              buff.Append( " " + message );
            }
            buff.Append( "\"" );
            interp.setResult( buff.ToString() );
              }
        }
Exemplo n.º 8
0
    /// <summary> This procedure is invoked to process the "tell" Tcl command.
    /// See the user documentation for details on what it does.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="argv">command arguments.
    /// </param>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {

      Channel chan; /* The channel being operated on this method */

      if ( argv.Length != 2 )
      {
        throw new TclNumArgsException( interp, 1, argv, "channelId" );
      }


      chan = TclIO.getChannel( interp, argv[1].ToString() );
      if ( chan == null )
      {

        throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" );
      }

      try
      {
        interp.setResult( TclInteger.newInstance( (int)chan.tell() ) );
      }
      catch ( IOException e )
      {
        throw new TclException( interp, "Error in TellCmd" );
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 9
0
		/// <summary> See Tcl user documentation for details.</summary>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if ((argv.Length < 2) || (argv.Length > 3))
			{
				throw new TclNumArgsException(interp, 1, argv, "script ?count?");
			}
			
			int count;
			if (argv.Length == 2)
			{
				count = 1;
			}
			else
			{
				count = TclInteger.get(interp, argv[2]);
			}
			
			long startTime = System.DateTime.Now.Ticks;
			for (int i = 0; i < count; i++)
			{
				interp.eval(argv[1], 0);
			}
			long endTime = System.DateTime.Now.Ticks;
			long uSecs = (((endTime - startTime) / 10) / count);
			if (uSecs == 1)
			{
				interp.setResult(TclString.newInstance("1 microsecond per iteration"));
			}
			else
			{
				interp.setResult(TclString.newInstance(uSecs + " microseconds per iteration"));
			}
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 10
0
        /*
        ** 2007 May 05
        **
        ** 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.
        **
        *************************************************************************
        ** Code for testing the btree.c module in SQLite.  This code
        ** is not included in the SQLite library.  It is used for automated
        ** testing of the SQLite library.
        *************************************************************************
        **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
        **  C#-SQLite is an independent reimplementation of the SQLite software library
        **
        **  SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
        **
        *************************************************************************
        */
        //#include "btreeInt.h"
        //#include <tcl.h>

        /*
        ** Usage: sqlite3_shared_cache_report
        **
        ** Return a list of file that are shared and the number of
        ** references to each file.
        */
        static int sqlite3BtreeSharedCacheReport(
            object clientData,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
Exemplo n.º 11
0
		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;
    }
Exemplo n.º 12
0
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if (argv.Length < 2 || argv.Length > 4)
			{
				throw new TclNumArgsException(interp, 1, argv, "message ?errorInfo? ?errorCode?");
			}
			
			if (argv.Length >= 3)
			{
				
				string errorInfo = argv[2].ToString();
				
				if (!errorInfo.Equals(""))
				{
					interp.addErrorInfo(errorInfo);
					interp.errAlreadyLogged = true;
				}
			}
			
			if (argv.Length == 4)
			{
				interp.setErrorCode(argv[3]);
			}
			
			interp.setResult(argv[1]);
			throw new TclException(TCL.CompletionCode.ERROR);
		}
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      string dirName;

      if ( argv.Length > 2 )
      {
        throw new TclNumArgsException( interp, 1, argv, "?dirName?" );
      }

      if ( argv.Length == 1 )
      {
        dirName = "~";
      }
      else
      {

        dirName = argv[1].ToString();
      }
      if ( ( JACL.PLATFORM == JACL.PLATFORM_WINDOWS ) && ( dirName.Length == 2 ) && ( dirName[1] == ':' ) )
      {
        dirName = dirName + "/";
      }

      // Set the interp's working dir.

      interp.setWorkingDir( dirName );
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 14
0
    /*
    ** 2007 May 05
    **
    ** 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.
    **
    *************************************************************************
    ** Code for testing the btree.c module in SQLite.  This code
    ** is not included in the SQLite library.  It is used for automated
    ** testing of the SQLite library.
    *************************************************************************
    **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
    **  C#-SQLite is an independent reimplementation of the SQLite software library
    **
    **  SQLITE_SOURCE_ID: 2009-12-07 16:39:13 1ed88e9d01e9eda5cbc622e7614277f29bcc551c
    **
    **  $Header$
    *************************************************************************
    */
    //#include "btreeInt.h"
    //#include <tcl.h>

    /*
    ** Usage: sqlite3_shared_cache_report
    **
    ** Return a list of file that are shared and the number of
    ** references to each file.
    */
    static int sqlite3BtreeSharedCacheReport(
    object clientData,
    Tcl_Interp interp,
    int objc,
    Tcl_Obj[] objv
    )
    {
    /// <summary> This procedure is invoked to process the "gets" Tcl command.
    /// See the user documentation for details on what it does.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="argv">command arguments.
    /// </param>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {

      bool writeToVar = false; // If true write to var passes as arg
      string varName = ""; // The variable to write value to
      Channel chan; // The channel being operated on
      int lineLen;
      TclObject line;

      if ( ( argv.Length < 2 ) || ( argv.Length > 3 ) )
      {
        throw new TclNumArgsException( interp, 1, argv, "channelId ?varName?" );
      }

      if ( argv.Length == 3 )
      {
        writeToVar = true;

        varName = argv[2].ToString();
      }


      chan = TclIO.getChannel( interp, argv[1].ToString() );
      if ( chan == null )
      {

        throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" );
      }

      try
      {
        line = TclString.newInstance( new StringBuilder( 64 ) );
        lineLen = chan.read( interp, line, TclIO.READ_LINE, 0 );
        if ( lineLen < 0 )
        {
          // FIXME: Need more specific posix error codes!
          if ( !chan.eof() && !chan.isBlocked( interp ) )
          {

            throw new TclPosixException( interp, TclPosixException.EIO, true, "error reading \"" + argv[1].ToString() + "\"" );
          }
          lineLen = -1;
        }
        if ( writeToVar )
        {
          interp.setVar( varName, line, 0 );
          interp.setResult( lineLen );
        }
        else
        {
          interp.setResult( line );
        }
      }
      catch ( IOException e )
      {
        throw new TclRuntimeError( "GetsCmd.cmdProc() Error: IOException when getting " + chan.ChanName + ": " + e.Message );
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 16
0
		/// <summary> This procedure is invoked to process the "break" Tcl command.
		/// See the user documentation for details on what it does.
		/// </summary>
		/// <exception cref=""> TclException is always thrown.
		/// </exception>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if (argv.Length != 1)
			{
				throw new TclNumArgsException(interp, 1, argv, null);
			}
			throw new TclException(interp, null, TCL.CompletionCode.BREAK);
		}
Exemplo n.º 17
0
        public static int Sqlitetest2_Init(Tcl_Interp interp)
        {
            //extern int sqlite3_io_error_persist;
            //extern int sqlite3_io_error_pending;
            //extern int sqlite3_io_error_hit;
            //extern int sqlite3_io_error_hardhit;
            //extern int sqlite3_diskfull_pending;
            //extern int sqlite3_diskfull;
            //extern int sqlite3_pager_n_sort_bucket;
            //static struct {
            //  char *zName;
            //  Tcl_CmdProc *xProc;
            //} aCmd[] = {
            _aCmd[] aCmd = new _aCmd[] {
//new _aCmd( "pager_open",              (Tcl_CmdProc)pager_open          ),
//new _aCmd( "pager_close",             (Tcl_CmdProc)pager_close         ),
//    { "pager_commit",            (Tcl_CmdProc*)pager_commit        },
//    { "pager_rollback",          (Tcl_CmdProc*)pager_rollback      },
//    { "pager_stmt_begin",        (Tcl_CmdProc*)pager_stmt_begin    },
//    { "pager_stmt_commit",       (Tcl_CmdProc*)pager_stmt_commit   },
//    { "pager_stmt_rollback",     (Tcl_CmdProc*)pager_stmt_rollback },
//    { "pager_stats",             (Tcl_CmdProc*)pager_stats         },
//    { "pager_pagecount",         (Tcl_CmdProc*)pager_pagecount     },
//    { "page_get",                (Tcl_CmdProc*)page_get            },
//    { "page_lookup",             (Tcl_CmdProc*)page_lookup         },
//    { "page_unref",              (Tcl_CmdProc*)page_unref          },
//    { "page_read",               (Tcl_CmdProc*)page_read           },
//    { "page_write",              (Tcl_CmdProc*)page_write          },
//    { "page_number",             (Tcl_CmdProc*)page_number         },
//    { "pager_truncate",          (Tcl_CmdProc*)pager_truncate      },
#if !SQLITE_OMIT_DISKIO
//    { "fake_big_file",           (Tcl_CmdProc*)fake_big_file       },
#endif
                new _aCmd("sqlite3BitvecBuiltinTest", (Tcl_CmdProc)testBitvecBuiltinTest),
                new _aCmd("sqlite3_test_control_pending_byte", (Tcl_CmdProc)testPendingByte),
            };
            int i;
            for (i = 0; i < aCmd.Length; i++)
            {//sizeof(aCmd)/sizeof(aCmd[0]); i++){
                TCL.Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, null, null);
            }
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_pending",
                            sqlite3_io_error_pending, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_persist",
                            sqlite3_io_error_persist, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_hit",
                            sqlite3_io_error_hit, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_hardhit",
                            sqlite3_io_error_hardhit, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_diskfull_pending",
                            sqlite3_diskfull_pending, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_diskfull",
                            sqlite3_diskfull, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_pending_byte",
                            TCLsqlite3PendingByte, VarFlags.SQLITE3_LINK_INT);
            TCLsqlite3PendingByte.iValue = sqlite3PendingByte;
            return(TCL.TCL_OK);
        }
Exemplo n.º 18
0
    internal static ParseResult parseVar( Interp interp, string inString, int index, int length )
    {
      ParseResult result;

      index--;
      result = Parser.parseVar( interp, inString.Substring( index, ( length ) - ( index ) ) );
      result.nextIndex += index;
      return ( result );
    }
Exemplo n.º 19
0
    /// <summary> Tcl_UpvarObjCmd -> UpvarCmd.cmdProc
    /// 
    /// This procedure is invoked to process the "upvar" Tcl command.
    /// See the user documentation for details on what it does.
    /// </summary>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
    {
      CallFrame frame;
      string frameSpec, otherVarName, myVarName;
      int p;
      int objc = objv.Length, objv_index;
      int result;

      if ( objv.Length < 3 )
      {
        throw new TclNumArgsException( interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?" );
      }

      // Find the call frame containing each of the "other variables" to be
      // linked to. 


      frameSpec = objv[1].ToString();
      // Java does not support passing a reference by refernece so use an array
      CallFrame[] frameArr = new CallFrame[1];
      result = CallFrame.getFrame( interp, frameSpec, frameArr );
      frame = frameArr[0];
      objc -= ( result + 1 );
      if ( ( objc & 1 ) != 0 )
      {
        throw new TclNumArgsException( interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?" );
      }
      objv_index = result + 1;


      // Iterate over each (other variable, local variable) pair.
      // Divide the other variable name into two parts, then call
      // MakeUpvar to do all the work of linking it to the local variable.

      for ( ; objc > 0; objc -= 2, objv_index += 2 )
      {

        myVarName = objv[objv_index + 1].ToString();

        otherVarName = objv[objv_index].ToString();

        int otherLength = otherVarName.Length;
        p = otherVarName.IndexOf( (System.Char)'(' );
        if ( ( p != -1 ) && ( otherVarName[otherLength - 1] == ')' ) )
        {
          // This is an array variable name
          Var.makeUpvar( interp, frame, otherVarName.Substring( 0, ( p ) - ( 0 ) ), otherVarName.Substring( p + 1, ( otherLength - 1 ) - ( p + 1 ) ), 0, myVarName, 0 );
        }
        else
        {
          // This is a scalar variable name
          Var.makeUpvar( interp, frame, otherVarName, null, 0, myVarName, 0 );
        }
      }
      interp.resetResult();
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 20
0
 static int Tcl_GetIndexFromObjStruct( Interp interp, TclObject to, BackupSubCommand[] table, int len, string msg, int flags, ref int index )
 {
   string zCmd = to.ToString();
   for ( index = 0 ; index < len ; index++ )
   {
     if ( zCmd == table[index].zCmd ) return 0;
   }
   return 1;
 }
Exemplo n.º 21
0
		/// <summary> See Tcl user documentation for details.</summary>
		/// <exception cref=""> TclException If incorrect number of arguments.
		/// </exception>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if (argv.Length != 2)
			{
				throw new TclNumArgsException(interp, 1, argv, "list");
			}
			interp.setResult(TclInteger.newInstance(TclList.getLength(interp, argv[1])));
      return TCL.CompletionCode.RETURN;
    }
    internal BgErrorMgr( Interp i )
    {
      InitBlock();
      interp = i;
      bgerrorCmdObj = TclString.newInstance( "bgerror" );
      bgerrorCmdObj.preserve();

      errors = new ArrayList( 10 );
    }
Exemplo n.º 23
0
// static void sqlite3_reset_auto_extension() { }
#endif //* SQLITE_OMIT_LOAD_EXTENSION */


        /*
        ** tclcmd:   sqlite3_reset_auto_extension
        **
        ** Reset all auto-extensions
        */
        static int resetAutoExtObjCmd(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            sqlite3_reset_auto_extension();
            return(SQLITE_OK);
        }
    internal static void registerChannel( Interp interp, Channel chan )
    {

      if ( interp != null )
      {
        Hashtable chanTable = getInterpChanTable( interp );
        SupportClass.PutElement( chanTable, chan.ChanName, chan );
        chan.refCount++;
      }
    }
Exemplo n.º 25
0
        //static void *crash_malloc(int nByte){
        //  return (void *)Tcl_Alloc((size_t)nByte);
        //}
        //static void crash_free(void *p){
        //  Tcl_Free(p);
        //}
        //static void *crash_realloc(void *p, int n){
        //  return (void *)Tcl_Realloc(p, (size_t)n);
        //}

        /*
        ** Wrapper around the sqlite3OsWrite() function that avoids writing to the
        ** 512 byte block begining at offset PENDING_BYTE.
        */
        //static int writeDbFile(CrashFile *p, u8 *z, i64 iAmt, i64 iOff){
        //  int rc;
        //  int iSkip = 0;
        //  if( iOff==PENDING_BYTE && (p.flags&SQLITE_OPEN_MAIN_DB) ){
        //    iSkip = 512;
        //  }
        //  if( (iAmt-iSkip)>0 ){
        //    rc = sqlite3OsWrite(p.pRealFile, &z[iSkip], iAmt-iSkip, iOff+iSkip);
        //  }
        //  return rc;
        //}

        /*
        ** Flush the write-list as if xSync() had been called on file handle
        ** pFile. If isCrash is true, simulate a crash.
        */
        //static int writeListSync(CrashFile *pFile, int isCrash){
        //  int rc = SQLITE_OK;
        //  int iDc = g.iDeviceCharacteristics;

        //  WriteBuffer *pWrite;
        //  WriteBuffer **ppPtr;

        //  /* If this is not a crash simulation, set pFinal to point to the
        //  ** last element of the write-list that is associated with file handle
        //  ** pFile.
        //  **
        //  ** If this is a crash simulation, set pFinal to an arbitrarily selected
        //  ** element of the write-list.
        //  */
        //  WriteBuffer *pFinal = 0;
        //  if( !isCrash ){
        //    for(pWrite=g.pWriteList; pWrite; pWrite=pWrite.pNext){
        //      if( pWrite.pFile==pFile ){
        //        pFinal = pWrite;
        //      }
        //    }
        //  }else if( iDc&(SQLITE_IOCAP_SEQUENTIAL|SQLITE_IOCAP_SAFE_APPEND) ){
        //    int nWrite = 0;
        //    int iFinal;
        //    for(pWrite=g.pWriteList; pWrite; pWrite=pWrite.pNext) nWrite++;
        //    sqlite3_randomness(sizeof(int), &iFinal);
        //    iFinal = ((iFinal<0)?-1*iFinal:iFinal)%nWrite;
        //    for(pWrite=g.pWriteList; iFinal>0; pWrite=pWrite.pNext) iFinal--;
        //    pFinal = pWrite;
        //  }

#if TRACE_CRASHTEST
//  printf("Sync %s (is %s crash)\n", pFile.zName, (isCrash?"a":"not a"));
#endif

        //  ppPtr = &g.pWriteList;
        //  for(pWrite=*ppPtr; rc==SQLITE_OK && pWrite; pWrite=*ppPtr){
        //    sqlite3_file *pRealFile = pWrite.pFile.pRealFile;

        //    /* (eAction==1)      . write block out normally,
        //    ** (eAction==2)      . do nothing,
        //    ** (eAction==3)      . trash sectors.
        //    */
        //    int eAction = 0;
        //    if( !isCrash ){
        //      eAction = 2;
        //      if( (pWrite.pFile==pFile || iDc&SQLITE_IOCAP_SEQUENTIAL) ){
        //        eAction = 1;
        //      }
        //    }else{
        //      char random;
        //      sqlite3_randomness(1, &random);

        //      /* Do not select option 3 (sector trashing) if the IOCAP_ATOMIC flag
        //      ** is set or this is an OsTruncate(), not an Oswrite().
        //      */
        //      if( (iDc&SQLITE_IOCAP_ATOMIC) || (pWrite.zBuf==0) ){
        //        random &= 0x01;
        //      }

        //      /* If IOCAP_SEQUENTIAL is set and this is not the final entry
        //      ** in the truncated write-list, always select option 1 (write
        //      ** out correctly).
        //      */
        //      if( (iDc&SQLITE_IOCAP_SEQUENTIAL && pWrite!=pFinal) ){
        //        random = 0;
        //      }

        //      /* If IOCAP_SAFE_APPEND is set and this OsWrite() operation is
        //      ** an append (first byte of the written region is 1 byte past the
        //      ** current EOF), always select option 1 (write out correctly).
        //      */
        //      if( iDc&SQLITE_IOCAP_SAFE_APPEND && pWrite.zBuf ){
        //        i64 iSize;
        //        sqlite3OsFileSize(pRealFile, &iSize);
        //        if( iSize==pWrite.iOffset ){
        //          random = 0;
        //        }
        //      }

        //      if( (random&0x06)==0x06 ){
        //        eAction = 3;
        //      }else{
        //        eAction = ((random&0x01)?2:1);
        //      }
        //    }

        //    switch( eAction ){
        //      case 1: {               /* Write out correctly */
        //        if( pWrite.zBuf ){
        //          rc = writeDbFile(
        //              pWrite.pFile, pWrite.zBuf, pWrite.nBuf, pWrite.iOffset
        //          );
        //        }else{
        //          rc = sqlite3OsTruncate(pRealFile, pWrite.iOffset);
        //        }
        //        *ppPtr = pWrite.pNext;
#if TRACE_CRASHTEST
//        if( isCrash ){
//          printf("Writing %d bytes @ %d (%s)\n",
//            pWrite.nBuf, (int)pWrite.iOffset, pWrite.pFile.zName
//          );
//        }
#endif
        //        crash_free(pWrite);
        //        break;
        //      }
        //      case 2: {               /* Do nothing */
        //        ppPtr = &pWrite.pNext;
#if TRACE_CRASHTEST
//        if( isCrash ){
//          printf("Omiting %d bytes @ %d (%s)\n",
//            pWrite.nBuf, (int)pWrite.iOffset, pWrite.pFile.zName
//          );
//        }
#endif
        //        break;
        //      }
        //      case 3: {               /* Trash sectors */
        //        u8 *zGarbage;
        //        int iFirst = (pWrite.iOffset/g.iSectorSize);
        //        int iLast = (pWrite.iOffset+pWrite.nBuf-1)/g.iSectorSize;

        //        Debug.Assert(pWrite.zBuf);

#if TRACE_CRASHTEST
//        printf("Trashing %d sectors @ sector %d (%s)\n",
//            1+iLast-iFirst, iFirst, pWrite.pFile.zName
//        );
#endif

        //        zGarbage = crash_malloc(g.iSectorSize);
        //        if( zGarbage ){
        //          sqlite3_int64 i;
        //          for(i=iFirst; rc==SQLITE_OK && i<=iLast; i++){
        //            sqlite3_randomness(g.iSectorSize, zGarbage);
        //            rc = writeDbFile(
        //              pWrite.pFile, zGarbage, g.iSectorSize, i*g.iSectorSize
        //            );
        //          }
        //          crash_free(zGarbage);
        //        }else{
        //          rc = SQLITE_NOMEM;
        //        }

        //        ppPtr = &pWrite.pNext;
        //        break;
        //      }

        //      default:
        //        Debug.Assert(!"Cannot happen");
        //    }

        //    if( pWrite==pFinal ) break;
        //  }

        //  if( rc==SQLITE_OK && isCrash ){
        //    exit(-1);
        //  }

        //  for(pWrite=g.pWriteList; pWrite && pWrite.pNext; pWrite=pWrite.pNext);
        //  g.pWriteListEnd = pWrite;

        //  return rc;
        //}

        /*
        ** Add an entry to the end of the write-list.
        */
        //static int writeListAppend(
        //  sqlite3_file *pFile,
        //  sqlite3_int64 iOffset,
        //  const u8 *zBuf,
        //  int nBuf
        //){
        //  WriteBuffer *pNew;

        //  Debug.Assert((zBuf && nBuf) || (!nBuf && !zBuf));

        //  pNew = (WriteBuffer *)crash_malloc(sizeof(WriteBuffer) + nBuf);
        //  if( pNew==0 ){
        //    fprintf(stderr, "out of memory in the crash simulator\n");
        //  }
        //  memset(pNew, 0, sizeof(WriteBuffer)+nBuf);
        //  pNew.iOffset = iOffset;
        //  pNew.nBuf = nBuf;
        //  pNew.pFile = (CrashFile *)pFile;
        //  if( zBuf ){
        //    pNew.zBuf = (u8 *)&pNew[1];
        //    memcpy(pNew.zBuf, zBuf, nBuf);
        //  }

        //  if( g.pWriteList ){
        //    Debug.Assert(g.pWriteListEnd);
        //    g.pWriteListEnd.pNext = pNew;
        //  }else{
        //    g.pWriteList = pNew;
        //  }
        //  g.pWriteListEnd = pNew;

        //  return SQLITE_OK;
        //}

        /*
        ** Close a crash-file.
        */
        //static int cfClose(sqlite3_file *pFile){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  writeListSync(pCrash, 0);
        //  sqlite3OsClose(pCrash.pRealFile);
        //  return SQLITE_OK;
        //}

        ///*
        //** Read data from a crash-file.
        //*/
        //static int cfRead(
        //  sqlite3_file *pFile,
        //  void *zBuf,
        //  int iAmt,
        //  sqlite_int64 iOfst
        //){
        //  CrashFile *pCrash = (CrashFile *)pFile;

        //  /* Check the file-size to see if this is a short-read */
        //  if( pCrash.iSize<(iOfst+iAmt) ){
        //    return SQLITE_IOERR_SHORT_READ;
        //  }

        //  memcpy(zBuf, &pCrash.zData[iOfst], iAmt);
        //  return SQLITE_OK;
        //}

        ///*
        //** Write data to a crash-file.
        //*/
        //static int cfWrite(
        //  sqlite3_file *pFile,
        //  const void *zBuf,
        //  int iAmt,
        //  sqlite_int64 iOfst
        //){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  if( iAmt+iOfst>pCrash.iSize ){
        //    pCrash.iSize = iAmt+iOfst;
        //  }
        //  while( pCrash.iSize>pCrash.nData ){
        //    u8 *zNew;
        //    int nNew = (pCrash.nData*2) + 4096;
        //    zNew = crash_realloc(pCrash.zData, nNew);
        //    if( !zNew ){
        //      return SQLITE_NOMEM;
        //    }
        //    memset(&zNew[pCrash.nData], 0, nNew-pCrash.nData);
        //    pCrash.nData = nNew;
        //    pCrash.zData = zNew;
        //  }
        //  memcpy(&pCrash.zData[iOfst], zBuf, iAmt);
        //  return writeListAppend(pFile, iOfst, zBuf, iAmt);
        //}

        ///*
        //** Truncate a crash-file.
        //*/
        //static int cfTruncate(sqlite3_file *pFile, sqlite_int64 size){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  Debug.Assert(size>=0);
        //  if( pCrash.iSize>size ){
        //    pCrash.iSize = size;
        //  }
        //  return writeListAppend(pFile, size, 0, 0);
        //}

        ///*
        //** Sync a crash-file.
        //*/
        //static int cfSync(sqlite3_file *pFile, int flags){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  int isCrash = 0;

        //  const char *zName = pCrash.zName;
        //  const char *zCrashFile = g.zCrashFile;
        //  int nName = strlen(zName);
        //  int nCrashFile = strlen(zCrashFile);

        //  if( nCrashFile>0 && zCrashFile[nCrashFile-1]=='*' ){
        //    nCrashFile--;
        //    if( nName>nCrashFile ) nName = nCrashFile;
        //  }

        //  if( nName==nCrashFile && 0==memcmp(zName, zCrashFile, nName) ){
        //    if( (--g.iCrash)==0 ) isCrash = 1;
        //  }

        //  return writeListSync(pCrash, isCrash);
        //}

        ///*
        //** Return the current file-size of the crash-file.
        //*/
        //static int cfFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  *pSize = (i64)pCrash.iSize;
        //  return SQLITE_OK;
        //}

        ///*
        //** Calls related to file-locks are passed on to the real file handle.
        //*/
        //static int cfLock(sqlite3_file *pFile, int eLock){
        //  return sqlite3OsLock(((CrashFile *)pFile).pRealFile, eLock);
        //}
        //static int cfUnlock(sqlite3_file *pFile, int eLock){
        //  return sqlite3OsUnlock(((CrashFile *)pFile).pRealFile, eLock);
        //}
        //static int cfCheckReservedLock(sqlite3_file *pFile, int *pResOut){
        //  return sqlite3OsCheckReservedLock(((CrashFile *)pFile).pRealFile, pResOut);
        //}
        //static int cfFileControl(sqlite3_file *pFile, int op, void *pArg){
        //  return sqlite3OsFileControl(((CrashFile *)pFile).pRealFile, op, pArg);
        //}

        ///*
        //** The xSectorSize() and xDeviceCharacteristics() functions return
        //** the global values configured by the [sqlite_crashparams] tcl
        //*  interface.
        //*/
        //static int cfSectorSize(sqlite3_file *pFile){
        //  return g.iSectorSize;
        //}
        //static int cfDeviceCharacteristics(sqlite3_file *pFile){
        //  return g.iDeviceCharacteristics;
        //}

        //static const sqlite3_io_methods CrashFileVtab = {
        //  1,                            /* iVersion */
        //  cfClose,                      /* xClose */
        //  cfRead,                       /* xRead */
        //  cfWrite,                      /* xWrite */
        //  cfTruncate,                   /* xTruncate */
        //  cfSync,                       /* xSync */
        //  cfFileSize,                   /* xFileSize */
        //  cfLock,                       /* xLock */
        //  cfUnlock,                     /* xUnlock */
        //  cfCheckReservedLock,          /* xCheckReservedLock */
        //  cfFileControl,                /* xFileControl */
        //  cfSectorSize,                 /* xSectorSize */
        //  cfDeviceCharacteristics       /* xDeviceCharacteristics */
        //};

        ///*
        //** Application data for the crash VFS
        //*/
        //struct crashAppData {
        //  sqlite3_vfs *pOrig;                   /* Wrapped vfs structure */
        //};

        /*
        ** Open a crash-file file handle.
        **
        ** The caller will have allocated pVfs.szOsFile bytes of space
        ** at pFile. This file uses this space for the CrashFile structure
        ** and allocates space for the "real" file structure using
        ** sqlite3_malloc(). The assumption here is (pVfs.szOsFile) is
        ** equal or greater than sizeof(CrashFile).
        */
        //static int cfOpen(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zName,
        //  sqlite3_file *pFile,
        //  int flags,
        //  int *pOutFlags
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  int rc;
        //  CrashFile *pWrapper = (CrashFile *)pFile;
        //  sqlite3_file *pReal = (sqlite3_file*)&pWrapper[1];

        //  memset(pWrapper, 0, sizeof(CrashFile));
        //  rc = sqlite3OsOpen(pVfs, zName, pReal, flags, pOutFlags);

        //  if( rc==SQLITE_OK ){
        //    i64 iSize;
        //    pWrapper.pMethod = &CrashFileVtab;
        //    pWrapper.zName = (char *)zName;
        //    pWrapper.pRealFile = pReal;
        //    rc = sqlite3OsFileSize(pReal, &iSize);
        //    pWrapper.iSize = (int)iSize;
        //    pWrapper.flags = flags;
        //  }
        //  if( rc==SQLITE_OK ){
        //    pWrapper.nData = (4096 + pWrapper.iSize);
        //    pWrapper.zData = crash_malloc(pWrapper.nData);
        //    if( pWrapper.zData ){
        //      /* os_unix.c contains an Debug.Assert() that fails if the caller attempts
        //      ** to read data from the 512-byte locking region of a file opened
        //      ** with the SQLITE_OPEN_MAIN_DB flag. This region of a database file
        //      ** never contains valid data anyhow. So avoid doing such a read here.
        //      */
        //      const int isDb = (flags&SQLITE_OPEN_MAIN_DB);
        //      i64 iChunk = pWrapper.iSize;
        //      if( iChunk>PENDING_BYTE && isDb ){
        //        iChunk = PENDING_BYTE;
        //      }
        //      memset(pWrapper.zData, 0, pWrapper.nData);
        //      rc = sqlite3OsRead(pReal, pWrapper.zData, iChunk, 0);
        //      if( SQLITE_OK==rc && pWrapper.iSize>(PENDING_BYTE+512) && isDb ){
        //        i64 iOff = PENDING_BYTE+512;
        //        iChunk = pWrapper.iSize - iOff;
        //        rc = sqlite3OsRead(pReal, &pWrapper.zData[iOff], iChunk, iOff);
        //      }
        //    }else{
        //      rc = SQLITE_NOMEM;
        //    }
        //  }
        //  if( rc!=SQLITE_OK && pWrapper.pMethod ){
        //    sqlite3OsClose(pFile);
        //  }
        //  return rc;
        //}

        //static int cfDelete(sqlite3_vfs *pCfVfs, const char *zPath, int dirSync){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDelete(pVfs, zPath, dirSync);
        //}
        //static int cfAccess(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zPath,
        //  int flags,
        //  int *pResOut
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xAccess(pVfs, zPath, flags, pResOut);
        //}
        //static int cfFullPathname(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zPath,
        //  int nPathOut,
        //  char *zPathOut
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xFullPathname(pVfs, zPath, nPathOut, zPathOut);
        //}
        //static void *cfDlOpen(sqlite3_vfs *pCfVfs, const char *zPath){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDlOpen(pVfs, zPath);
        //}
        //static void cfDlError(sqlite3_vfs *pCfVfs, int nByte, char *zErrMsg){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  pVfs.xDlError(pVfs, nByte, zErrMsg);
        //}
        //static void (*cfDlSym(sqlite3_vfs *pCfVfs, void *pH, const char *zSym))(void){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDlSym(pVfs, pH, zSym);
        //}
        //static void cfDlClose(sqlite3_vfs *pCfVfs, void *pHandle){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  pVfs.xDlClose(pVfs, pHandle);
        //}
        //static int cfRandomness(sqlite3_vfs *pCfVfs, int nByte, char *zBufOut){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xRandomness(pVfs, nByte, zBufOut);
        //}
        //static int cfSleep(sqlite3_vfs *pCfVfs, int nMicro){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xSleep(pVfs, nMicro);
        //}
        //static int cfCurrentTime(sqlite3_vfs *pCfVfs, double *pTimeOut){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xCurrentTime(pVfs, pTimeOut);
        //}

        //static int processDevSymArgs(
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[],
        //  int *piDeviceChar,
        //  int *piSectorSize
        //){
        //  struct DeviceFlag {
        //    char *zName;
        //    int iValue;
        //  } aFlag[] = {
        //    { "atomic",      SQLITE_IOCAP_ATOMIC      },
        //    { "atomic512",   SQLITE_IOCAP_ATOMIC512   },
        //    { "atomic1k",    SQLITE_IOCAP_ATOMIC1K    },
        //    { "atomic2k",    SQLITE_IOCAP_ATOMIC2K    },
        //    { "atomic4k",    SQLITE_IOCAP_ATOMIC4K    },
        //    { "atomic8k",    SQLITE_IOCAP_ATOMIC8K    },
        //    { "atomic16k",   SQLITE_IOCAP_ATOMIC16K   },
        //    { "atomic32k",   SQLITE_IOCAP_ATOMIC32K   },
        //    { "atomic64k",   SQLITE_IOCAP_ATOMIC64K   },
        //    { "sequential",  SQLITE_IOCAP_SEQUENTIAL  },
        //    { "safe_append", SQLITE_IOCAP_SAFE_APPEND },
        //    { 0, 0 }
        //  };

        //  int i;
        //  int iDc = 0;
        //  int iSectorSize = 0;
        //  int setSectorsize = 0;
        //  int setDeviceChar = 0;

        //  for(i=0; i<objc; i+=2){
        //    int nOpt;
        //    char *zOpt = Tcl_GetStringFromObj(objv[i], &nOpt);

        //    if( (nOpt>11 || nOpt<2 || strncmp("-sectorsize", zOpt, nOpt))
        //     && (nOpt>16 || nOpt<2 || strncmp("-characteristics", zOpt, nOpt))
        //    ){
        //      Tcl_AppendResult(interp,
        //        "Bad option: \"", zOpt,
        //        "\" - must be \"-characteristics\" or \"-sectorsize\"", 0
        //      );
        //      return TCL.TCL_ERROR;
        //    }
        //    if( i==objc-1 ){
        //      Tcl_AppendResult(interp, "Option requires an argument: \"", zOpt, "\"",0);
        //      return TCL.TCL_ERROR;
        //    }

        //    if( zOpt[1]=='s' ){
        //      if( Tcl_GetIntFromObj(interp, objv[i+1], &iSectorSize) ){
        //        return TCL.TCL_ERROR;
        //      }
        //      setSectorsize = 1;
        //    }else{
        //      int j;
        //      Tcl_Obj **apObj;
        //      int nObj;
        //      if( Tcl_ListObjGetElements(interp, objv[i+1], &nObj, &apObj) ){
        //        return TCL.TCL_ERROR;
        //      }
        //      for(j=0; j<nObj; j++){
        //        int rc;
        //        int iChoice;
        //        Tcl_Obj *pFlag = Tcl_DuplicateObj(apObj[j]);
        //        Tcl_IncrRefCount(pFlag);
        //        Tcl_UtfToLower(Tcl_GetString(pFlag));

        //        rc = Tcl_GetIndexFromObjStruct(
        //            interp, pFlag, aFlag, sizeof(aFlag[0]), "no such flag", 0, &iChoice
        //        );
        //        Tcl_DecrRefCount(pFlag);
        //        if( rc ){
        //          return TCL.TCL_ERROR;
        //        }

        //        iDc |= aFlag[iChoice].iValue;
        //      }
        //      setDeviceChar = 1;
        //    }
        //  }

        //  if( setDeviceChar ){
        //    *piDeviceChar = iDc;
        //  }
        //  if( setSectorsize ){
        //    *piSectorSize = iSectorSize;
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd:   sqlite_crash_enable ENABLE
        **
        ** Parameter ENABLE must be a boolean value. If true, then the "crash"
        ** vfs is added to the system. If false, it is removed.
        */
        //static int crashEnableCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int isEnable;
        //  static sqlite3_vfs crashVfs = {
        //    1,                  /* iVersion */
        //    0,                  /* szOsFile */
        //    0,                  /* mxPathname */
        //    0,                  /* pNext */
        //    "crash",            /* zName */
        //    0,                  /* pAppData */

        //    cfOpen,               /* xOpen */
        //    cfDelete,             /* xDelete */
        //    cfAccess,             /* xAccess */
        //    cfFullPathname,       /* xFullPathname */
        //    cfDlOpen,             /* xDlOpen */
        //    cfDlError,            /* xDlError */
        //    cfDlSym,              /* xDlSym */
        //    cfDlClose,            /* xDlClose */
        //    cfRandomness,         /* xRandomness */
        //    cfSleep,              /* xSleep */
        //    cfCurrentTime         /* xCurrentTime */
        //  };

        //  if( objc!=2 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "ENABLE");
        //    return TCL.TCL_ERROR;
        //  }

        //  if( Tcl_GetBooleanFromObj(interp, objv[1], &isEnable) ){
        //    return TCL.TCL_ERROR;
        //  }

        //  if( (isEnable && crashVfs.pAppData) || (!isEnable && !crashVfs.pAppData) ){
        //    return TCL.TCL_OK;
        //  }

        //  if( crashVfs.pAppData==0 ){
        //    sqlite3_vfs *pOriginalVfs = sqlite3_vfs_find(0);
        //    crashVfs.mxPathname = pOriginalVfs.mxPathname;
        //    crashVfs.pAppData = (void *)pOriginalVfs;
        //    crashVfs.szOsFile = sizeof(CrashFile) + pOriginalVfs.szOsFile;
        //    sqlite3_vfs_register(&crashVfs, 0);
        //  }else{
        //    crashVfs.pAppData = 0;
        //    sqlite3_vfs_unregister(&crashVfs);
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd:   sqlite_crashparams ?OPTIONS? DELAY CRASHFILE
        **
        ** This procedure implements a TCL command that enables crash testing
        ** in testfixture.  Once enabled, crash testing cannot be disabled.
        **
        ** Available options are "-characteristics" and "-sectorsize". Both require
        ** an argument. For -sectorsize, this is the simulated sector size in
        ** bytes. For -characteristics, the argument must be a list of io-capability
        ** flags to simulate. Valid flags are "atomic", "atomic512", "atomic1K",
        ** "atomic2K", "atomic4K", "atomic8K", "atomic16K", "atomic32K",
        ** "atomic64K", "sequential" and "safe_append".
        **
        ** Example:
        **
        **   sqlite_crashparams -sect 1024 -char {atomic sequential} ./test.db 1
        **
        */
        //static int crashParamsObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int iDelay;
        //  const char *zCrashFile;
        //  int nCrashFile, iDc, iSectorSize;

        //  iDc = -1;
        //  iSectorSize = -1;

        //  if( objc<3 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "?OPTIONS? DELAY CRASHFILE");
        //    goto error;
        //  }

        //  zCrashFile = Tcl_GetStringFromObj(objv[objc-1], &nCrashFile);
        //  if( nCrashFile>=sizeof(g.zCrashFile) ){
        //    Tcl_AppendResult(interp, "Filename is too long: \"", zCrashFile, "\"", 0);
        //    goto error;
        //  }
        //  if( Tcl_GetIntFromObj(interp, objv[objc-2], &iDelay) ){
        //    goto error;
        //  }

        //  if( processDevSymArgs(interp, objc-3, &objv[1], &iDc, &iSectorSize) ){
        //    return TCL.TCL_ERROR;
        //  }

        //  if( iDc>=0 ){
        //    g.iDeviceCharacteristics = iDc;
        //  }
        //  if( iSectorSize>=0 ){
        //    g.iSectorSize = iSectorSize;
        //  }

        //  g.iCrash = iDelay;
        //  memcpy(g.zCrashFile, zCrashFile, nCrashFile+1);
        //  sqlite3CrashTestEnable = 1;
        //  return TCL.TCL_OK;

        //error:
        //  return TCL.TCL_ERROR;
        //}

        //static int devSymObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  void devsym_register(int iDeviceChar, int iSectorSize);

        //  int iDc = -1;
        //  int iSectorSize = -1;

        //  if( processDevSymArgs(interp, objc-1, &objv[1], &iDc, &iSectorSize) ){
        //    return TCL.TCL_ERROR;
        //  }
        //  devsym_register(iDc, iSectorSize);

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd: register_jt_vfs ?-default? PARENT-VFS
        */
        //static int jtObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int jt_register(char *, int);
        //  char *zParent = 0;

        //  if( objc!=2 && objc!=3 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "?-default? PARENT-VFS");
        //    return TCL.TCL_ERROR;
        //  }
        //  zParent = Tcl_GetString(objv[1]);
        //  if( objc==3 ){
        //    if( strcmp(zParent, "-default") ){
        //      Tcl_AppendResult(interp,
        //          "bad option \"", zParent, "\": must be -default", 0
        //      );
        //      return TCL.TCL_ERROR;
        //    }
        //    zParent = Tcl_GetString(objv[2]);
        //  }

        //  if( !(*zParent) ){
        //    zParent = 0;
        //  }
        //  if( jt_register(zParent, objc==3) ){
        //    Tcl_AppendResult(interp, "Error in jt_register", 0);
        //    return TCL.TCL_ERROR;
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd: unregister_jt_vfs
        */
        //static int jtUnregisterObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  void jt_unregister(void);

        //  if( objc!=1 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "");
        //    return TCL.TCL_ERROR;
        //  }

        //  jt_unregister();
        //  return TCL.TCL_OK;
        //}
#endif //* SQLITE_OMIT_DISKIO */

        /*
        ** This procedure registers the TCL procedures defined in this file.
        */
        static public int Sqlitetest6_Init(Tcl_Interp interp)
        {
#if !SQLITE_OMIT_DISKIO
            //Tcl_CreateObjCommand(interp, "sqlite3_crash_enable", crashEnableCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "sqlite3_simulate_device", devSymObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "register_jt_vfs", jtObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "unregister_jt_vfs", jtUnregisterObjCmd, 0, 0);
#endif
            return(TCL.TCL_OK);
        }
Exemplo n.º 26
0
    /*
    *----------------------------------------------------------------------
    *
    * initialize --
    *
    *	This method is called to initialize an interpreter with it's 
    *	initial values for the env array.
    *
    * Results:
    *	None.
    *
    * Side effects:
    *	The env array in the interpreter is created and populated.
    *
    *----------------------------------------------------------------------
    */

    internal static void initialize( Interp interp )
    {
      // For a few standrad environment vairables that Tcl users 
      // often assume aways exist (even if they shouldn't), we will
      // try to create those expected variables with the common unix
      // names.

      try
      {
        interp.setVar( "env", "HOME", System.Environment.CurrentDirectory, TCL.VarFlag.GLOBAL_ONLY );
      }
      catch ( TclException e )
      {
        // Ignore errors.
      }

      try
      {
        interp.setVar( "env", "USER", System.Environment.UserName, TCL.VarFlag.GLOBAL_ONLY );
      }
      catch ( TclException e )
      {
        // Ignore errors.
      }

      // Now we will populate the rest of the env array with the
      // properties recieved from the System classes.  This makes for 
      // a nice shortcut for getting to these useful values.

      try
      {


        for ( IDictionaryEnumerator search = System.Environment.GetEnvironmentVariables().GetEnumerator(); search.MoveNext(); )
        {
          interp.setVar( "env", search.Key.ToString(), search.Value.ToString(), TCL.VarFlag.GLOBAL_ONLY );
        }
      }
      catch ( System.Security.SecurityException e2 )
      {
        // We are inside a browser and we can't access the list of
        // property names. That's fine. Life goes on ....
      }
      catch ( System.Exception e3 )
      {
        // We are inside a browser and we can't access the list of
        // property names. That's fine. Life goes on ....

        System.Diagnostics.Debug.WriteLine( "Exception while initializing env array" );
        System.Diagnostics.Debug.WriteLine( e3 );
        System.Diagnostics.Debug.WriteLine( "" );
      }
    }
Exemplo n.º 27
0
        /*
        ** tclcmd:   sqlite3_auto_extension_broken
        **
        ** Register the broken extension to be loaded automatically.
        */
        static int autoExtBrokenObjCmd(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int rc = sqlite3_auto_extension((dxInit)broken_init);

            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(SQLITE_OK);
        }
Exemplo n.º 28
0
		protected internal TclException(Interp interp, string msg, TCL.CompletionCode ccode, int idx):base(msg)
		{
			if (ccode == TCL.CompletionCode.OK)
			{
				throw new TclRuntimeError("The reserved completion code TCL.CompletionCode.OK (0) cannot be used " + "in TclException");
			}
			compCode = ccode;
			errIndex = idx;
			
			if (interp != null && (System.Object) msg != null)
			{
				interp.setResult(msg);
			}
		}
Exemplo n.º 29
0
        /*
        ** This procedure registers the TCL procs defined in this file.
        */
        public static int Sqlitetest_autoext_Init(Tcl_Interp interp)
        {
#if !SQLITE_OMIT_LOAD_EXTENSION
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_sqr",
                                     autoExtSqrObjCmd, null, null);
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_cube",
                                     autoExtCubeObjCmd, null, null);
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken",
                                     autoExtBrokenObjCmd, null, null);
#endif
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension",
                                     resetAutoExtObjCmd, null, null);
            return(TCL.TCL_OK);
        }
Exemplo n.º 30
0
    /// <summary> This procedure is invoked to process the "while" Tcl command.
    /// See the user documentation for details on what it does.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="argv">command arguments.
    /// </param>
    /// <exception cref=""> TclException if script causes error.
    /// </exception>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      if ( argv.Length != 3 )
      {
        throw new TclNumArgsException( interp, 1, argv, "test command" );
      }

      string test = argv[1].ToString();
      TclObject command = argv[2];

      {
        while ( interp.expr.evalBoolean( interp, test ) )
        {
          try
          {
            interp.eval( command, 0 );
          }
          catch ( TclException e )
          {
            switch ( e.getCompletionCode() )
            {

              case TCL.CompletionCode.BREAK:
                goto loop_brk;


              case TCL.CompletionCode.CONTINUE:
                continue;


              case TCL.CompletionCode.ERROR:
                interp.addErrorInfo( "\n    (\"while\" body line " + interp.errorLine + ")" );
                throw;


              default:
                throw;

            }
          }
        }
      }

loop_brk:
      ;


      interp.resetResult();
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 31
0
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      targetInterp.preserve();
      targetInterp.nestLevel++;

      targetInterp.resetResult();
      targetInterp.allowExceptions();

      // Append the arguments to the command prefix and invoke the command
      // in the target interp's global namespace.

      TclObject[] prefv = TclList.getElements( interp, prefix );
      TclObject cmd = TclList.newInstance();
      cmd.preserve();
      TclList.replace( interp, cmd, 0, 0, prefv, 0, prefv.Length - 1 );
      TclList.replace( interp, cmd, prefv.Length, 0, argv, 1, argv.Length - 1 );
      TclObject[] cmdv = TclList.getElements( interp, cmd );

      TCL.CompletionCode result = targetInterp.invoke( cmdv, Interp.INVOKE_NO_TRACEBACK );

      cmd.release();
      targetInterp.nestLevel--;

      // Check if we are at the bottom of the stack for the target interpreter.
      // If so, check for special return codes.

      if ( targetInterp.nestLevel == 0 )
      {
        if ( result == TCL.CompletionCode.RETURN )
        {
          result = targetInterp.updateReturnInfo();
        }
        if ( result != TCL.CompletionCode.OK && result != TCL.CompletionCode.ERROR )
        {
          try
          {
            targetInterp.processUnexpectedResult( result );
          }
          catch ( TclException e )
          {
            result = e.getCompletionCode();
          }
        }
      }

      targetInterp.release();
      interp.transferResult( targetInterp, result );
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 32
0
		/// <summary> Creates an exception with the appropiate Tcl error message to
		/// indicate an error with variable access.
		/// 
		/// </summary>
		/// <param name="interp">currrent interpreter.
		/// </param>
		/// <param name="name1">first part of a variable name.
		/// </param>
		/// <param name="name2">second part of a variable name. May be null.
		/// </param>
		/// <param name="operation">either "read" or "set".
		/// </param>
		/// <param name="reason">a string message to explain why the operation fails..
		/// </param>
		
		internal TclVarException(Interp interp, string name1, string name2, string operation, string reason):base(TCL.CompletionCode.ERROR)
		{
			if (interp != null)
			{
				interp.resetResult();
				if ((System.Object) name2 == null)
				{
					interp.setResult("can't " + operation + " \"" + name1 + "\": " + reason);
				}
				else
				{
					interp.setResult("can't " + operation + " \"" + name1 + "(" + name2 + ")\": " + reason);
				}
			}
		}
Exemplo n.º 33
0
    /// <summary> Constructor - creates a new SocketChannel object with the given
    /// options. Also creates an underlying Socket object, and Input and
    /// Output Streams.
    /// 
    /// </summary>

    public SocketChannel( Interp interp, int mode, string localAddr, int localPort, bool async, string address, int port )
    {
      System.Net.IPAddress localAddress = null;
      System.Net.IPAddress addr = null;

      if ( async )
        throw new TclException( interp, "Asynchronous socket connection not " + "currently implemented" );

      // Resolve addresses
      if ( !localAddr.Equals( "" ) )
      {
        try
        {
          localAddress = System.Net.Dns.GetHostByName( localAddr ).AddressList[0];
        }
        catch ( System.Exception e )
        {
          throw new TclException( interp, "host unknown: " + localAddr );
        }
      }

      try
      {
        addr = System.Net.Dns.GetHostByName( address ).AddressList[0];
      }
      catch ( System.Exception e )
      {
        throw new TclException( interp, "host unknown: " + address );
      }


      // Set the mode of this socket.
      this.mode = mode;

      // Create the Socket object

      //			if ((localAddress != null) && (localPort != 0))
      //			{
      //				
      //				sock = new Socket(addr, port, localAddress, localPort);
      //			}
      //			else
      sock = new System.Net.Sockets.TcpClient( addr.ToString(), port );

      // If we got this far, then the socket has been created.
      // Create the channel name
      ChanName = TclIO.getNextDescriptor( interp, "sock" );
    }
Exemplo n.º 34
0
        /// <summary>----------------------------------------------------------------------
        /// 
        /// Tcl_RenameObjCmd -> RenameCmd.cmdProc
        /// 
        /// This procedure is invoked to process the "rename" Tcl command.
        /// See the user documentation for details on what it does.
        /// 
        /// Results:
        /// A standard Tcl object result.
        /// 
        /// Side effects:
        /// See the user documentation.
        /// 
        /// ----------------------------------------------------------------------
        /// </summary>
        public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
        {
            string oldName, newName;

              if ( objv.Length != 3 )
              {
            throw new TclNumArgsException( interp, 1, objv, "oldName newName" );
              }

              oldName = objv[1].ToString();

              newName = objv[2].ToString();

              interp.renameCommand( oldName, newName );
              return TCL.CompletionCode.RETURN;
        }
Exemplo n.º 35
0
        /*
        ** sqlite3BitvecBuiltinTest SIZE PROGRAM
        **
        ** Invoke the SQLITE_TESTCTRL_BITVEC_TEST operator on test_control.
        ** See comments on sqlite3BitvecBuiltinTest() for additional information.
        */
        static int testBitvecBuiltinTest(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            int sz = 0, rc;
            int nProg = 0;

            int[]  aProg = new int[100];
            string z;

            if (argc != 3)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " SIZE PROGRAM\"");
            }
            if (TCL.Tcl_GetInt(interp, argv[1], out sz))
            {
                return(TCL.TCL_ERROR);
            }
            z = argv[2].ToString() + '\0';
            int iz = 0;

            while (nProg < 99 && z[iz] != 0)
            {
                while (z[iz] != 0 && !sqlite3Isdigit(z[iz]))
                {
                    iz++;
                }
                if (z[iz] == 0)
                {
                    break;
                }
                while (sqlite3Isdigit(z[iz]))
                {
                    aProg[nProg] = aProg[nProg] * 10 + (z[iz] - 48);
                    iz++;
                }
                nProg++;
            }
            aProg[nProg] = 0;
            rc           = sqlite3_test_control(SQLITE_TESTCTRL_BITVEC_TEST, sz, aProg);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
    /// <summary> This procedure is invoked to process the "incr" Tcl command.
    /// See the user documentation for details on what it does.
    /// </summary>
    /// <exception cref=""> TclException if wrong # of args or increment is not an
    /// integer.
    /// </exception>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
    {
      int incrAmount;
      TclObject newValue;

      if ( ( objv.Length != 2 ) && ( objv.Length != 3 ) )
      {
        throw new TclNumArgsException( interp, 1, objv, "varName ?increment?" );
      }

      // Calculate the amount to increment by.

      if ( objv.Length == 2 )
      {
        incrAmount = 1;
      }
      else
      {
        try
        {
          incrAmount = TclInteger.get( interp, objv[2] );
        }
        catch ( TclException e )
        {
          interp.addErrorInfo( "\n    (reading increment)" );
          throw;
        }
      }

      // Increment the variable's value.

      newValue = Var.incrVar( interp, objv[1], null, incrAmount, TCL.VarFlag.LEAVE_ERR_MSG );

      // FIXME: we need to look at this exception throwing problem again
      /*
      if (newValue == null) {
      return TCL_ERROR;
      }
      */

      // Set the interpreter's object result to refer to the variable's new
      // value object.

      interp.setResult( newValue );
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 37
0
    /// <summary> See Tcl user documentation for details.</summary>
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      TclObject list = TclList.newInstance();

      list.preserve();
      try
      {
          for ( int i = 1; i < argv.Length; i++ )
            TclList.append( interp, list, argv[i] );
        interp.setResult( list );
      }
      finally
      {
        list.release();
      }
      return TCL.CompletionCode.RETURN;
    }
Exemplo n.º 38
0
        /*
        ** Usage:   pager_open FILENAME N-PAGE
        **
        ** Open a new pager
        */
        //static int pager_open(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  u16 pageSize;
        //  Pager *pPager;
        //  Pgno nPage;
        //  int rc;
        //  char zBuf[100];
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " FILENAME N-PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  if( Tcl_GetInt(interp, argv[2], nPage) ) return TCL.TCL_ERROR;
        //  rc = sqlite3PagerOpen(sqlite3_vfs_find(0), pPager, argv[1], 0, 0,
        //      SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB,
        // pager_test_reiniter);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3PagerSetCachesize(pPager, nPage);
        //  pageSize = test_pagesize;
        //  sqlite3PagerSetPagesize(pPager, pageSize,-1);
        //  sqlite3_snprintf(100, ref zBuf,"%p",pPager);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_close ID
        **
        ** Close the given pager.
        */
        //static int pager_close(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerClose(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_rollback ID
        **
        ** Rollback changes
        */
        //static int pager_rollback(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerRollback(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_commit ID
        **
        ** Commit all changes
        */
        //static int pager_commit(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerCommitPhaseOne(pPager,  0, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  rc = sqlite3PagerCommitPhaseTwo(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_begin ID
        **
        ** Start a new checkpoint.
        */
        //static int pager_stmt_begin(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerOpenSavepoint(pPager, 1);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_rollback ID
        **
        ** Rollback changes to a checkpoint
        */
        //static int pager_stmt_rollback(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, 0);
        //sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_commit ID
        **
        ** Commit changes to a checkpoint
        */
        //static int pager_stmt_commit(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stats ID
        **
        ** Return pager statistics.
        */
        //static int pager_stats(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int i, *a;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  a = sqlite3PagerStats(pPager);
        //  for(i=0; i<9; i++){
        //    static char *zName[] = {
        //      "ref", "page", "max", "size", "state", "err",
        //      "hit", "miss", "ovfl",
        //    };
        //    char zBuf[100];
        //    Tcl_AppendElement(interp, zName[i]);
        //    sqlite3_snprintf(100, ref zBuf,"%d",a[i]);
        //    Tcl_AppendElement(interp, zBuf);
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_pagecount ID
        **
        ** Return the size of the database file.
        */
        //static int pager_pagecount(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  Pgno nPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3PagerPagecount(pPager, nPage);
        //  sqlite3_snprintf(100, ref zBuf, "%d", nPage);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_get ID PGNO
        **
        ** Return a pointer to a page from the database.
        */
        //static int page_get(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  DbPage *pPage;
        //  int pgno;
        //  int rc;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //rc = sqlite3PagerSharedLock(pPager);
        //if( rc==SQLITE_OK ){
        //  rc = sqlite3PagerGet(pPager, pgno, &pPage);
        //}
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3_snprintf(100, ref zBuf,"%p",pPage);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_lookup ID PGNO
        **
        ** Return a pointer to a page if the page is already in cache.
        ** If not in cache, return an empty string.
        */
        //static int page_lookup(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  DbPage *pPage;
        //  int pgno;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //  pPage = sqlite3PagerLookup(pPager, pgno);
        //  if( pPage ){
        //    sqlite3_snprintf(100, ref zBuf,"%p",pPage);
        //    Tcl_AppendResult(interp, zBuf);
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_truncate ID PGNO
        */
        //static int pager_truncate(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int pgno;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //  sqlite3PagerTruncateImage(pPager, pgno);
        //  return TCL.TCL_OK;
        //}


        /*
        ** Usage:   page_unref PAGE
        **
        ** Drop a pointer to a page.
        */
        //static int page_unref(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3PagerUnref(pPage);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_read PAGE
        **
        ** Return the content of a page
        */
        //static int page_read(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  char zBuf[100];
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  memcpy(zBuf, sqlite3PagerGetData(pPage), sizeof(zBuf));
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_number PAGE
        **
        ** Return the page number for a page.
        */
        //static int page_number(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  char zBuf[100];
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3_snprintf(100, ref zBuf, "%d", sqlite3PagerPagenumber(pPage));
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_write PAGE DATA
        **
        ** Write something into a page.
        */
        //static int page_write(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  DbPage *pPage;
        //  char *pData;
        //  int rc;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE DATA\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerWrite(pPage);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pData = sqlite3PagerGetData(pPage);
        //  strncpy(pData, argv[2], test_pagesize-1);
        //  pData[test_pagesize-1] = 0;
        //  return TCL.TCL_OK;
        //}

#if !SQLITE_OMIT_DISKIO
        /*
        ** Usage:   fake_big_file  N  FILENAME
        **
        ** Write a few bytes at the N megabyte point of FILENAME.  This will
        ** create a large file.  If the file was a valid SQLite database, then
        ** the next time the database is opened, SQLite will begin allocating
        ** new pages after N.  If N is 2096 or bigger, this will test the
        ** ability of SQLite to write to large files.
        */
        //static int fake_big_file(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  sqlite3_vfs *pVfs;
        //  sqlite3_file *fd = 0;
        //  int rc;
        //  int n;
        //  i64 offset;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " N-MEGABYTES FILE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  if( Tcl_GetInt(interp, argv[1], n) ) return TCL.TCL_ERROR;

        //  pVfs = sqlite3_vfs_find(0);
        //  rc = sqlite3OsOpenMalloc(pVfs, argv[2], fd,
        //      (SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB), 0
        //  );
        //  if( rc !=0){
        //    Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  offset = n;
        //  offset *= 1024*1024;
        //  rc = sqlite3OsWrite(fd, "Hello, World!", 14, offset);
        //  sqlite3OsCloseFree(fd);
        //  if( rc !=0){
        //    Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}
#endif


        /*
        ** test_control_pending_byte  PENDING_BYTE
        **
        ** Set the PENDING_BYTE using the sqlite3_test_control() interface.
        */
        static int testPendingByte(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            int pbyte = 0;
            int rc;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " PENDING-BYTE\"");
            }
            if (TCL.Tcl_GetInt(interp, argv[1], ref pbyte))
            {
                return(TCL.TCL_ERROR);
            }
            rc = sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, pbyte);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
Exemplo n.º 39
0
    //static void init_all(Tcl_Interp );
    static int init_all_cmd(
        ClientData cd,
        Tcl_Interp interp,
        int objc,
        Tcl_Obj[] objv
        )
    {
        Tcl_Interp slave;

        if (objc != 2)
        {
            TCL.Tcl_WrongNumArgs(interp, 1, objv, "SLAVE");
            return(TCL.TCL_ERROR);
        }

        slave = TCL.Tcl_GetSlave(interp, TCL.Tcl_GetString(objv[1]));
        if (slave == null)
        {
            return(TCL.TCL_ERROR);
        }

        init_all(slave);
        return(TCL.TCL_OK);
    }