コード例 #1
0
ファイル: ErrorCmd.cs プロジェクト: Belxjander/Asuna
		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);
		}
コード例 #2
0
ファイル: Util.cs プロジェクト: Belxjander/Asuna
    internal static double getDouble( Interp interp, string s )
    {
      int len = s.Length;
      bool sign;
      int i = 0;

      // Skip any leading blanks.

      while ( i < len && System.Char.IsWhiteSpace( s[i] ) )
      {
        i++;
      }
      if ( i >= len )
      {
        throw new TclException( interp, "expected floating-point number but got \"" + s + "\"" );
      }

      char c = s[i];
      if ( c == '-' )
      {
        sign = true;
        i += 1;
      }
      else
      {
        if ( c == '+' )
        {
          i += 1;
        }
        sign = false;
      }

      StrtodResult res = strtod( s, i );
      if ( res.errno != 0 )
      {
        if ( res.errno == TCL.DOUBLE_RANGE )
        {
          if ( interp != null )
          {
            interp.setErrorCode( TclString.newInstance( fpTooBigCode ) );
          }
          throw new TclException( interp, "floating-point value too large to represent" );
        }
        else
        {
          throw new TclException( interp, "expected floating-point number but got \"" + s + "\"" );
        }
      }
      else if ( res.index < len )
      {
        for ( i = res.index ; i < len ; i++ )
        {
          if ( !System.Char.IsWhiteSpace( s[i] ) )
          {
            throw new TclException( interp, "expected floating-point number but got \"" + s + "\"" );
          }
        }
      }

      if ( sign )
      {
        return (double)( -res.value );
      }
      else
      {
        return (double)( res.value );
      }
    }
コード例 #3
0
ファイル: Util.cs プロジェクト: Belxjander/Asuna
    internal static long getLong( Interp interp, string s )
    {
      int len = s.Length;
      bool sign;
      int i = 0;

      // Skip any leading blanks.

      while ( i < len && System.Char.IsWhiteSpace( s[i] ) )
      {
        i++;
      }
      if ( i >= len )
      {
        throw new TclException( interp, "expected integer but got \"" + s + "\"" );
      }

      char c = s[i];
      if ( c == '-' )
      {
        sign = true;
        i += 1;
      }
      else
      {
        if ( c == '+' )
        {
          i += 1;
        }
        sign = false;
      }

      StrtoulResult res = strtoul( s, i, 0 );
      if ( res.errno < 0 )
      {
        if ( res.errno == TCL.INTEGER_RANGE )
        {
          if ( interp != null )
          {
            interp.setErrorCode( TclString.newInstance( intTooBigCode ) );
          }
          throw new TclException( interp, "integer value too large to represent" );
        }
        else
        {
          throw new TclException( interp, "expected integer but got \"" + s + "\"" + checkBadOctal( interp, s ) );
        }
      }
      else if ( res.index < len )
      {
        for ( i = res.index ; i < len ; i++ )
        {
          if ( !System.Char.IsWhiteSpace( s[i] ) )
          {
            throw new TclException( interp, "expected integer but got \"" + s + "\"" + checkBadOctal( interp, s ) );
          }
        }
      }

      if ( sign )
      {
        return (long)( -res.value );
      }
      else
      {
        return (long)( res.value );
      }
    }
コード例 #4
0
ファイル: Parser.cs プロジェクト: Jaden-J/csharp-sqlite
    public static void evalObjv( Interp interp, TclObject[] objv, int length, int flags )
    {
      Command cmd;
      WrappedCommand wCmd = null;
      TclObject[] newObjv;
      int i;
      CallFrame savedVarFrame; //Saves old copy of interp.varFrame
      // in case TCL.EVAL_GLOBAL was set.

      interp.resetResult();
      if ( objv.Length == 0 )
      {
        return;
      }

      // If the interpreter was deleted, return an error.

      if ( interp.deleted )
      {
        interp.setResult( "attempt to call eval in deleted interpreter" );
        interp.setErrorCode( TclString.newInstance( "CORE IDELETE {attempt to call eval in deleted interpreter}" ) );
        throw new TclException( TCL.CompletionCode.ERROR );
      }

      // Check depth of nested calls to eval:  if this gets too large,
      // it's probably because of an infinite loop somewhere.

      if ( interp.nestLevel >= interp.maxNestingDepth )
      {
        throw new TclException( interp, "too many nested calls to eval (infinite loop?)" );
      }
      interp.nestLevel++;

      try
      {
        // Find the procedure to execute this command. If there isn't one,
        // then see if there is a command "unknown".  If so, create a new
        // word array with "unknown" as the first word and the original
        // command words as arguments.  Then call ourselves recursively
        // to execute it.


        cmd = interp.getCommand( objv[0].ToString() );
        if ( cmd == null )
          wCmd = interp.getObjCommand( objv[0].ToString() );
        // See if we are running as a slave interpretor, and this is a windows command        
        if ( cmd == null && wCmd == null && interp.slave != null )
        {
          wCmd = interp.slave.masterInterp.getObjCommand( objv[0].ToString() );
        }
        if ( cmd == null && wCmd == null )
        {
          newObjv = new TclObject[objv.Length + 1];
          for ( i = ( objv.Length - 1 ); i >= 0; i-- )
          {
            newObjv[i + 1] = objv[i];
          }
          newObjv[0] = TclString.newInstance( "unknown" );
          newObjv[0].preserve();
          cmd = interp.getCommand( "unknown" );
          if ( cmd == null )
          {

            Debug.Assert( false, "invalid command name \"" + objv[0].ToString() + "\"" );
            throw new TclException( interp, "invalid command name \"" + objv[0].ToString() + "\"" );
          }
          else
          {
            evalObjv( interp, newObjv, length, 0 );
          }
          newObjv[0].release();
          return;
        }

        // Finally, invoke the Command's cmdProc.

        interp.cmdCount++;
        savedVarFrame = interp.varFrame;
        if ( ( flags & TCL.EVAL_GLOBAL ) != 0 )
        {
          interp.varFrame = null;
        }

        int rc = 0;
        if ( cmd != null )
        {
          if ( cmd.cmdProc( interp, objv ) == TCL.CompletionCode.EXIT )
            throw new TclException( TCL.CompletionCode.EXIT );
        }
        else
        {
          rc = wCmd.objProc( wCmd.objClientData, interp, objv.Length, objv );
          if ( rc != 0 )
          {
            if ( rc == TCL.TCL_RETURN )
              throw new TclException( TCL.CompletionCode.RETURN );
            throw new TclException( TCL.CompletionCode.ERROR );
          }
        }
        interp.varFrame = savedVarFrame;
      }
      finally
      {
        interp.nestLevel--;
      }
    }
コード例 #5
0
ファイル: ExecCmd.cs プロジェクト: Belxjander/Asuna
    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      int firstWord; /* Index to the first non-switch arg */
      int argLen = argv.Length; /* No of args to copy to argStrs     */
      int exit; /* denotes exit status of process    */
      int errorBytes = 0; /* number of bytes of process stderr */
      //bool background; /* Indicates a bg process            */
      //bool keepNewline; /* Retains newline in pipline output */
      System.Diagnostics.Process p; /* The exec-ed process               */
      string argStr; /* Conversion of argv to a string    */
      System.Text.StringBuilder sbuf;

      /*
      * Check for a leading "-keepnewline" argument.
      */

      for ( firstWord = 1 ; firstWord < argLen ; firstWord++ )
      {
        argStr = argv[firstWord].ToString();
        if ( ( argStr.Length > 0 ) && ( argStr[0] == '-' ) )
        {
          //if (argStr.Equals("-keepnewline"))
          //{
          //  keepNewline = true;
          //}
          //else 
          if ( argStr.Equals( "--" ) )
          {
            firstWord++;
            break;
          }
          else
          {
            throw new TclException( interp, "bad switch \"" + argStr + "\": must be -keepnewline or --" );
          }
        }
      }

      if ( argLen <= firstWord )
      {
        throw new TclNumArgsException( interp, 1, argv, "?switches? arg ?arg ...?" );
      }


      /*
      * See if the command is to be run in background.
      * Currently this does nothing, it is just for compatibility
      */


      //if (argv[argLen - 1].ToString().Equals("&"))
      //{
      //  argLen--;
      //  background = true;
      //}

      try
      {
        /*
        * It is necessary to perform system specific 
        * operations before calling exec.  For now Solaris
        * and Windows execs are somewhat supported, in all other cases
        * we simply call exec and give it our "best shot"
        */

        if ( execMethod != null )
        {
          p = execReflection( interp, argv, firstWord, argLen );
        }
        else if ( Util.Unix )
        {
          p = execUnix( interp, argv, firstWord, argLen );
        }
        else if ( Util.Windows )
        {
          p = execWin( interp, argv, firstWord, argLen );
        }
        else
        {
          p = execDefault( interp, argv, firstWord, argLen );
        }


        //note to self : buffer reading should be done in
        //a separate thread and not by calling waitFor()
        //because a process that is waited for can block


        //Wait for the process to finish running,
        try
        {
          p.Start();
          p.WaitForExit();
          exit = p.ExitCode;
        }
        catch ( Exception e )
        {
          throw new TclException( interp, "exception in exec process: " + e.Message );
        }


        //Make buffer for the results of the subprocess execution
        sbuf = new System.Text.StringBuilder();

        //read data on stdout stream into  result buffer
        readStreamIntoBuffer( p.StandardOutput.BaseStream, sbuf );

        //if there is data on the stderr stream then append
        //this data onto the result StringBuffer
        //check for the special case where there is no error
        //data but the process returns an error result

        errorBytes = readStreamIntoBuffer( p.StandardError.BaseStream, sbuf );

        if ( ( errorBytes == 0 ) && ( exit != 0 ) )
        {
          sbuf.Append( "child process exited abnormally" );
        }

        //If the last character of the result buffer is a newline, then 
        //remove the newline character (the newline would just confuse 
        //things).  Finally, we set pass the result to the interpreter.



        // Tcl supports lots of child status conditions.
        // Unfortunately, we can only find the child's
        // exit status using the Java API

        if ( exit != 0 )
        {
          TclObject childstatus = TclList.newInstance();
          TclList.append( interp, childstatus, TclString.newInstance( "CHILDSTATUS" ) );

          // We don't know how to find the child's pid
          TclList.append( interp, childstatus, TclString.newInstance( "?PID?" ) );

          TclList.append( interp, childstatus, TclInteger.newInstance( exit ) );

          interp.setErrorCode( childstatus );
        }

        //when the subprocess writes to its stderr stream or returns
        //a non zero result we generate an error
        if ( ( exit != 0 ) || ( errorBytes != 0 ) )
        {
          throw new TclException( interp, sbuf.ToString() );
        }

        //otherwise things went well so set the result
        interp.setResult( sbuf.ToString() );
      }
      catch ( System.IO.IOException e )
      {
        //if exec fails we end up catching the exception here


        throw new TclException( interp, "couldn't execute \"" + argv[firstWord].ToString() + "\": no such file or directory" );
      }
      catch ( System.Threading.ThreadInterruptedException e )
      {
        /*
        * Do Nothing...
        */
      }
      return TCL.CompletionCode.RETURN;
    }
コード例 #6
0
ファイル: Expression.cs プロジェクト: Belxjander/Asuna
		internal static void  DomainError(Interp interp)
		{
			interp.setErrorCode(TclString.newInstance("ARITH DOMAIN {domain error: argument not in valid range}"));
			throw new TclException(interp, "domain error: argument not in valid range");
		}
コード例 #7
0
ファイル: Expression.cs プロジェクト: Belxjander/Asuna
		internal static void  DoubleTooSmall(Interp interp)
		{
			interp.setErrorCode(TclString.newInstance("ARITH UNDERFLOW {floating-point value too small to represent}"));
			throw new TclException(interp, "floating-point value too small to represent");
		}
コード例 #8
0
ファイル: Expression.cs プロジェクト: Belxjander/Asuna
 internal static void WideTooLarge( Interp interp )
 {
   interp.setErrorCode( TclString.newInstance( "ARITH IOVERFLOW {wide value too large to represent}" ) );
   throw new TclException( interp, "wide value too large to represent" );
 }
コード例 #9
0
ファイル: Expression.cs プロジェクト: Belxjander/Asuna
		internal static void  DivideByZero(Interp interp)
		{
			interp.setErrorCode(TclString.newInstance("ARITH DIVZERO {divide by zero}"));
			throw new TclException(interp, "divide by zero");
		}
コード例 #10
0
    public TclPosixException( Interp interp, int errno, bool appendPosixMsg, string errorMsg )
      : base( TCL.CompletionCode.ERROR )
    {

      string msg = getPosixMsg( errno );

      TclObject threeEltListObj = TclList.newInstance();
      TclList.append( interp, threeEltListObj, TclString.newInstance( "POSIX" ) );
      TclList.append( interp, threeEltListObj, TclString.newInstance( getPosixId( errno ) ) );
      TclList.append( interp, threeEltListObj, TclString.newInstance( msg ) );

      interp.setErrorCode( threeEltListObj );

      if ( interp != null )
      {
        if ( appendPosixMsg )
        {
          interp.setResult( errorMsg + ": " + msg );
        }
        else
        {
          interp.setResult( errorMsg );
        }
      }
    }