public ColorLayer(LayerType type, DataUsed dataused, Interp interp, ProcessLayer calcdata, IGradientMap gr, double param1 = 0, double param2 = 0, double cycle = 1, double alpha = 1, double saturation = 1, double value = 1, LayerExtra alphaextr = LayerExtra.LAYER_EXTRA_NORMAL, LayerExtra saturationextr = LayerExtra.LAYER_EXTRA_NORMAL, LayerExtra valueextr = LayerExtra.LAYER_EXTRA_NORMAL) { c_type = type; c_dataused = dataused; c_interp = interp; c_valueextr = valueextr; c_saturationextr = saturationextr; c_alphaextr = alphaextr; c_param1 = param1; c_param2 = param2; c_value = value; c_saturation = saturation; c_alpha = alpha; c_cycle = cycle; c_calcdata = calcdata; c_gr = gr; }
/// <summary> A unique error msg is printed for read, therefore dont call this /// instead of the standard TclNumArgsException(). /// /// </summary> /// <param name="interp">the current interpreter. /// </param> /// <param name="cmd">the name of the command (extracted form argv[0] of cmdProc) /// </param> private void errorWrongNumArgs(Interp interp, string cmd) { throw new TclException(interp, "wrong # args: should be \"" + "read channelId ?numChars?\" " + "or \"read ?-nonewline? channelId\""); }
public TclException(Interp interp, string msg) : this(interp, msg, TCL.CompletionCode.ERROR, -1) { }
private static void deleteOneFile(Interp interp, string fileName, bool force) { if (fileName == ":memory:") { return; } bool isDeleted = true; System.IO.FileInfo fileObj = FileUtil.getNewFileObj(interp, fileName); // Trying to delete a file that does not exist is not // considered an error, just a no-op bool tmpBool; if (System.IO.File.Exists(fileObj.FullName)) { tmpBool = true; } else { tmpBool = System.IO.Directory.Exists(fileObj.FullName); } if ((!tmpBool) || (fileName.Length == 0)) { return; } // If the file is a non-empty directory, recursively delete its children if // the -force option was chosen. Otherwise, throw an error. if (System.IO.Directory.Exists(fileObj.FullName) && (System.IO.Directory.GetFileSystemEntries(fileObj.FullName).Length > 0)) { if (force) { string[] fileList = System.IO.Directory.GetFileSystemEntries(fileObj.FullName); for (int i = 0; i < fileList.Length; i++) { TclObject[] joinArrayObj = new TclObject[2]; joinArrayObj[0] = TclString.newInstance(fileName); joinArrayObj[1] = TclString.newInstance(fileList[i]); string child = FileUtil.joinPath(interp, joinArrayObj, 0, 2); deleteOneFile(interp, child, force); } } else { throw new TclPosixException(interp, TclPosixException.ENOTEMPTY, "error deleting \"" + fileName + "\": directory not empty"); } } try { bool tmpBool2; if (System.IO.File.Exists(fileObj.FullName)) { fileObj.Attributes = System.IO.FileAttributes.Normal; System.IO.File.Delete(fileObj.FullName); tmpBool2 = true; } else if (System.IO.Directory.Exists(fileObj.FullName)) { System.IO.Directory.Delete(fileObj.FullName); tmpBool2 = true; } else { tmpBool2 = false; } isDeleted = tmpBool2; } catch (System.IO.IOException e) { throw new TclException(interp, e.Message); } catch (System.Security.SecurityException e) { throw new TclException(interp, e.Message); } if (!isDeleted) { throw new TclPosixException(interp, TclPosixException.EACCES, true, "error deleting \"" + fileName + "\": best guess at reason"); } }
private static void getAndStoreStatData(Interp interp, string fileName, string varName) { System.IO.FileInfo fileObj = FileUtil.getNewFileObj(interp, fileName); bool tmpBool; if (System.IO.File.Exists(fileObj.FullName)) { tmpBool = true; } else { tmpBool = System.IO.Directory.Exists(fileObj.FullName); } if (!tmpBool) { throw new TclPosixException(interp, TclPosixException.ENOENT, true, "could not read \"" + fileName + "\""); } try { int mtime = getMtime(interp, fileName, fileObj); TclObject mtimeObj = TclInteger.newInstance(mtime); TclObject atimeObj = TclInteger.newInstance(mtime); TclObject ctimeObj = TclInteger.newInstance(mtime); interp.setVar(varName, "atime", atimeObj, 0); interp.setVar(varName, "ctime", ctimeObj, 0); interp.setVar(varName, "mtime", mtimeObj, 0); } catch (System.Security.SecurityException e) { throw new TclException(interp, e.Message); } catch (TclException e) { throw new TclException(interp, "can't set \"" + varName + "(dev)\": variable isn't array"); } try { TclObject sizeObj = TclInteger.newInstance((int)SupportClass.FileLength(fileObj)); interp.setVar(varName, "size", sizeObj, 0); } catch (System.Exception e) { // Do nothing. } try { TclObject typeObj = TclString.newInstance(getType(interp, fileName, fileObj)); interp.setVar(varName, "type", typeObj, 0); } catch (System.Exception e) { } try { TclObject uidObj = TclBoolean.newInstance(isOwner(interp, fileObj)); interp.setVar(varName, "uid", uidObj, 0); } catch (TclException e) { // Do nothing. } }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { string fileName = null; bool url = false; if (argv.Length == 2) { fileName = argv[1].ToString(); } else if (argv.Length == 3) { if (argv[1].ToString().Equals("-url")) { url = true; fileName = argv[2].ToString(); } } if ((System.Object)fileName == null) { throw new TclNumArgsException(interp, 1, argv, "?-url? fileName"); } try { if (url) { if (fileName.StartsWith("resource:/")) { interp.evalResource(fileName.Substring(9)); } else { interp.evalURL(null, fileName); } } else { interp.evalFile(fileName); } } catch (TclException e) { TCL.CompletionCode code = e.getCompletionCode(); if (code == TCL.CompletionCode.RETURN) { TCL.CompletionCode realCode = interp.updateReturnInfo(); if (realCode != TCL.CompletionCode.OK) { e.setCompletionCode(realCode); throw; } } else if (code == TCL.CompletionCode.ERROR) { /* * Record information telling where the error occurred. */ interp.addErrorInfo("\n (file line " + interp.errorLine + ")"); throw; } else { throw; } } return(TCL.CompletionCode.RETURN); }
public override int processEvent(int flags) { // See if the command is a complete Tcl command if (Interp.commandComplete(command)) { if (tcl.lang.ConsoleThread.debug) { WriteLine("line was a complete command"); } bool eval_exception = true; TclObject commandObj = TclString.newInstance(command); try { commandObj.preserve(); Enclosing_Instance.interp.recordAndEval(commandObj, 0); eval_exception = false; } catch (TclException e) { if (tcl.lang.ConsoleThread.debug) { WriteLine("eval returned exceptional condition"); } TCL.CompletionCode code = e.getCompletionCode(); switch (code) { case TCL.CompletionCode.ERROR: Enclosing_Instance.putLine(Enclosing_Instance.err, Enclosing_Instance.interp.getResult().ToString()); break; case TCL.CompletionCode.BREAK: Enclosing_Instance.putLine(Enclosing_Instance.err, "invoked \"break\" outside of a loop"); break; case TCL.CompletionCode.CONTINUE: Enclosing_Instance.putLine(Enclosing_Instance.err, "invoked \"continue\" outside of a loop"); break; default: Enclosing_Instance.putLine(Enclosing_Instance.err, "command returned bad code: " + code); break; } } finally { commandObj.release(); } if (!eval_exception) { if (tcl.lang.ConsoleThread.debug) { WriteLine("eval returned normally"); } string evalResult = Enclosing_Instance.interp.getResult().ToString(); if (tcl.lang.ConsoleThread.debug) { WriteLine("eval result was \"" + evalResult + "\""); } if (evalResult.Length > 0) { Enclosing_Instance.putLine(Enclosing_Instance.out_Renamed, evalResult); } } // Empty out the incoming command buffer Enclosing_Instance.sbuf.Length = 0; // See if the user set a custom shell prompt for the next command TclObject prompt; try { prompt = Enclosing_Instance.interp.getVar("tcl_prompt1", TCL.VarFlag.GLOBAL_ONLY); } catch (TclException e) { prompt = null; } if (prompt != null) { try { Enclosing_Instance.interp.eval(prompt.ToString(), TCL.EVAL_GLOBAL); } catch (TclException e) { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, "% "); } } else { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, "% "); } return(1); } else { // Interp.commandComplete() returned false if (tcl.lang.ConsoleThread.debug) { WriteLine("line was not a complete command"); } // We don't have a complete command yet. Print out a level 2 // prompt message and wait for further inputs. TclObject prompt; try { prompt = Enclosing_Instance.interp.getVar("tcl_prompt2", TCL.VarFlag.GLOBAL_ONLY); } catch (TclException) { prompt = null; } if (prompt != null) { try { Enclosing_Instance.interp.eval(prompt.ToString(), TCL.EVAL_GLOBAL); } catch (TclException e) { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, ""); } } else { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, ""); } return(1); } } // end processEvent method
/// <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 != 4) { throw new TclNumArgsException(interp, 1, argv, "list first last"); } int size = TclList.getLength(interp, argv[1]); int first; int last; first = Util.getIntForIndex(interp, argv[2], size - 1); last = Util.getIntForIndex(interp, argv[3], size - 1); if (last < 0) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } if (first >= size) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } if (first <= 0 && last >= size) { interp.setResult(argv[1]); return(TCL.CompletionCode.RETURN); } if (first < 0) { first = 0; } if (first >= size) { first = size - 1; } if (last < 0) { last = 0; } if (last >= size) { last = size - 1; } if (first > last) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } TclObject list = TclList.newInstance(); list.preserve(); try { for (int i = first; i <= last; i++) { TclList.append(interp, list, TclList.index(interp, argv[1], i)); } interp.setResult(list); } finally { list.release(); } return(TCL.CompletionCode.RETURN); }
/// <summary> /// Tcl_LappendObjCmd -> LappendCmd.cmdProc /// /// This procedure is invoked to process the "lappend" Tcl command. /// See the user documentation for details on what it does. /// </summary> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv) { TclObject varValue, newValue = null; int i;//int numElems, i, j; bool createdNewObj, createVar; if (objv.Length < 2) { throw new TclNumArgsException(interp, 1, objv, "varName ?value value ...?"); } if (objv.Length == 2) { try { newValue = interp.getVar(objv[1], 0); } catch (TclException e) { // The variable doesn't exist yet. Just create it with an empty // initial value. varValue = TclList.newInstance(); try { newValue = interp.setVar(objv[1], varValue, 0); } finally { if (newValue == null) { varValue.release(); // free unneeded object } } interp.resetResult(); return(TCL.CompletionCode.RETURN); } } else { // We have arguments to append. We used to call Tcl_SetVar2 to // append each argument one at a time to ensure that traces were run // for each append step. We now append the arguments all at once // because it's faster. Note that a read trace and a write trace for // the variable will now each only be called once. Also, if the // variable's old value is unshared we modify it directly, otherwise // we create a new copy to modify: this is "copy on write". createdNewObj = false; createVar = true; try { varValue = interp.getVar(objv[1], 0); } catch (TclException e) { // We couldn't read the old value: either the var doesn't yet // exist or it's an array element. If it's new, we will try to // create it with Tcl_ObjSetVar2 below. // FIXME : not sure we even need this parse for anything! // If we do not need to parse could we at least speed it up a bit string varName; int nameBytes; varName = objv[1].ToString(); nameBytes = varName.Length; // Number of Unicode chars in string for (i = 0; i < nameBytes; i++) { if (varName[i] == '(') { i = nameBytes - 1; if (varName[i] == ')') { // last char is ')' => array ref createVar = false; } break; } } varValue = TclList.newInstance(); createdNewObj = true; } // We only take this branch when the catch branch was not run if (createdNewObj == false && varValue.Shared) { varValue = varValue.duplicate(); createdNewObj = true; } // Insert the new elements at the end of the list. for (i = 2; i < objv.Length; i++) { TclList.append(interp, varValue, objv[i]); } // No need to call varValue.invalidateStringRep() since it // is called during the TclList.append operation. // Now store the list object back into the variable. If there is an // error setting the new value, decrement its ref count if it // was new and we didn't create the variable. try { newValue = interp.setVar(objv[1].ToString(), varValue, 0); } catch (TclException e) { if (createdNewObj && !createVar) { varValue.release(); // free unneeded obj } throw; } } // Set the interpreter's object result to refer to the variable's value // object. interp.setResult(newValue); return(TCL.CompletionCode.RETURN); }
/// <summary> See Tcl user documentation for details.</summary> public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv) { interp.SetResult(Util.concat(1, argv.Length, argv)); return(TCL.CompletionCode.RETURN); }
public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv) { interp._errorCode = null; interp._errorInfo = null; TCL.CompletionCode returnCode; int i; /* * Note: returnCode is the value given by the -code option. Don't * confuse this value with the compCode variable of the * TclException thrown by this method, which is always TCL.CompletionCode.RETURN. */ returnCode = TCL.CompletionCode.OK; for (i = 1; i < argv.Length - 1; i += 2) { if (argv[i].ToString().Equals("-code")) { if (argv[i + 1].ToString().Equals("ok")) { returnCode = TCL.CompletionCode.OK; } else { if (argv[i + 1].ToString().Equals("error")) { returnCode = TCL.CompletionCode.ERROR; } else { if (argv[i + 1].ToString().Equals("return")) { returnCode = TCL.CompletionCode.RETURN; } else { if (argv[i + 1].ToString().Equals("break")) { returnCode = TCL.CompletionCode.BREAK; } else { if (argv[i + 1].ToString().Equals("continue")) { returnCode = TCL.CompletionCode.CONTINUE; } else { try { returnCode = (TCL.CompletionCode)TclInteger.Get(interp, argv[i + 1]); } catch (TclException e) { throw new TclException(interp, "bad completion code \"" + argv[i + 1] + "\": must be ok, error, return, break, " + "continue, or an integer"); } } } } } } } else { if (argv[i].ToString().Equals("-errorcode")) { interp._errorCode = argv[i + 1].ToString(); } else { if (argv[i].ToString().Equals("-errorinfo")) { interp._errorInfo = argv[i + 1].ToString(); } else { throw new TclException(interp, "bad option \"" + argv[i] + "\": must be -code, -errorcode, or -errorinfo"); } } } } if (i != argv.Length) { interp.SetResult(argv[argv.Length - 1]); } interp._returnCode = returnCode; throw new TclException(TCL.CompletionCode.RETURN); }
/// <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 < 4) { throw new TclNumArgsException(interp, 1, argv, "list first last ?element element ...?"); } int size = TclList.getLength(interp, argv[1]); int first = Util.getIntForIndex(interp, argv[2], size - 1); int last = Util.getIntForIndex(interp, argv[3], size - 1); int numToDelete; if (first < 0) { first = 0; } // Complain if the user asked for a start element that is greater // than the list length. This won't ever trigger for the "end*" // case as that will be properly constrained by getIntForIndex // because we use size-1 (to allow for replacing the last elem). if ((first >= size) && (size > 0)) { throw new TclException(interp, "list doesn't contain element " + argv[2]); } if (last >= size) { last = size - 1; } if (first <= last) { numToDelete = (last - first + 1); } else { numToDelete = 0; } TclObject list = argv[1]; bool isDuplicate = false; // If the list object is unshared we can modify it directly. Otherwise // we create a copy to modify: this is "copy on write". if (list.Shared) { list = list.duplicate(); isDuplicate = true; } try { TclList.replace(interp, list, first, numToDelete, argv, 4, argv.Length - 1); interp.SetResult(list); } catch (TclException e) { if (isDuplicate) { list.Release(); } throw; } return(TCL.CompletionCode.RETURN); }
internal static ParseResult parseQuotes(Interp interp, string inString, int index, int length) { TclObject obj; TclParse parse = null; TclToken token; CharPointer script; try { script = new CharPointer(inString); script.index = index; parse = new TclParse(interp, script.array, length, null, 0); System.Diagnostics.Debug.WriteLine("string is \"" + inString + "\""); System.Diagnostics.Debug.WriteLine("script.array is \"" + new string( script.array ) + "\""); System.Diagnostics.Debug.WriteLine("index is " + index); System.Diagnostics.Debug.WriteLine("length is " + length); System.Diagnostics.Debug.WriteLine("parse.endIndex is " + parse.endIndex); parse.commandStart = script.index; token = parse.getToken(0); token.type = Parser.TCL_TOKEN_WORD; token.script_array = script.array; token.script_index = script.index; parse.numTokens++; parse.numWords++; parse = Parser.parseTokens(script.array, script.index, Parser.TYPE_QUOTE, parse); // Check for the error condition where the parse did not end on // a '"' char. Is this happened raise an error. if (script.array[parse.termIndex] != '"') { throw new TclException(interp, "missing \""); } // if there was no error then parsing will continue after the // last char that was parsed from the string script.index = parse.termIndex + 1; // Finish filling in the token for the word and check for the // special case of a word consisting of a single range of // literal text. token = parse.getToken(0); token.size = script.index - token.script_index; token.numComponents = parse.numTokens - 1; if ((token.numComponents == 1) && (parse.getToken(1).type == Parser.TCL_TOKEN_TEXT)) { token.type = Parser.TCL_TOKEN_SIMPLE_WORD; } parse.commandSize = script.index - parse.commandStart; if (parse.numTokens > 0) { obj = Parser.evalTokens(interp, parse.tokenList, 1, parse.numTokens - 1); } else { throw new TclRuntimeError("parseQuotes error: null obj result"); } } finally { parse.release(); } return(new ParseResult(obj, script.index)); }
public _aObjCmd( string zName, Interp.dxObjCmdProc xProc, object clientdata ) { this.zName = zName; this.xProc = xProc; this.clientData = clientdata.GetType().Name == "Int32" && (int)clientdata == 0 ? null : clientdata; }
/// <summary> Move the file pointer internal to the RandomAccessFile object. /// The file MUST be open or a TclRuntimeError is thrown. /// /// </summary> /// <param name="offset">The number of bytes to move the file pointer. /// </param> /// <param name="inmode">to begin incrementing the file pointer; beginning, /// current, or end of the file. /// </param> public override void seek(Interp interp, long offset, int inmode) { if (file == null) { throw new TclRuntimeError("FileChannel.seek(): null file object"); } //FIXME: Disallow seek on dead channels (raise TclPosixException ??) //if (CheckForDeadChannel(NULL, statePtr)) { // return Tcl_LongAsWide(-1); //} // Compute how much input and output is buffered. If both input and // output is buffered, cannot compute the current position. int inputBuffered = NumBufferedInputBytes; int outputBuffered = NumBufferedOutputBytes; if ((inputBuffered != 0) && (outputBuffered != 0)) { throw new TclPosixException(interp, TclPosixException.EFAULT, true, "error during seek on \"" + ChanName + "\""); } // If we are seeking relative to the current position, compute the // corrected offset taking into account the amount of unread input. if (inmode == TclIO.SEEK_CUR) { offset -= inputBuffered; } // The seekReset method will discard queued input and // reset flags like EOF and BLOCKED. if (input != null) { input.seekReset(); } // FIXME: Next block is disabled since non-blocking is not implemented. // If the channel is in asynchronous output mode, switch it back // to synchronous mode and cancel any async flush that may be // scheduled. After the flush, the channel will be put back into // asynchronous output mode. bool wasAsync = false; //if (false && !Blocking) //{ // wasAsync = true; // Blocking = true; // if (BgFlushScheduled) // { // //scheduleBgFlush(); // } //} // If there is data buffered in curOut then mark the // channel as ready to flush before invoking flushChannel. if (output != null) { output.seekCheckBuferReady(); } // If the flush fails we cannot recover the original position. In // that case the seek is not attempted because we do not know where // the access position is - instead we return the error. FlushChannel // has already called Tcl_SetErrno() to report the error upwards. // If the flush succeeds we do the seek also. if (output != null && output.flushChannel(null, false) != 0) { // FIXME: IS this the proper action to take on error? throw new IOException("flush error while seeking"); } else { // Now seek to the new position in the channel as requested by the // caller. long actual_offset; switch (inmode) { case TclIO.SEEK_SET: { actual_offset = offset; break; } case TclIO.SEEK_CUR: { actual_offset = file.Position + offset; break; } case TclIO.SEEK_END: { actual_offset = file.Length + offset; break; } default: { throw new TclRuntimeError("invalid seek mode"); } } // A negative offset to seek() would raise an IOException, but // we want to raise an invalid argument error instead if (actual_offset < 0) { throw new TclPosixException(interp, TclPosixException.EINVAL, true, "error during seek on \"" + ChanName + "\""); } file.Seek(actual_offset, SeekOrigin.Begin); } // Restore to nonblocking mode if that was the previous behavior. // // NOTE: Even if there was an async flush active we do not restore // it now because we already flushed all the queued output, above. if (wasAsync) { Blocking = false; } }
public _aObjCmd( string zName, Interp.dxObjCmdProc xProc ) { this.zName = zName; this.xProc = xProc; this.clientData = null; }
/* * This procedure is invoked to process the "for" Tcl command. * See the user documentation for details on what it does. * * @param interp the current interpreter. * @param argv command arguments. * @exception TclException if script causes error. */ public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { if (argv.Length != 5) { throw new TclNumArgsException(interp, 1, argv, "start test next command"); } TclObject start = argv[1]; string test = argv[2].ToString(); TclObject next = argv[3]; TclObject command = argv[4]; bool done = false; try { interp.eval(start, 0); } catch (TclException e) { interp.addErrorInfo("\n (\"for\" initial command)"); throw; } while (!done) { if (!interp.expr.evalBoolean(interp, test)) { break; } try { interp.eval(command, 0); } catch (TclException e) { switch (e.getCompletionCode()) { case TCL.CompletionCode.BREAK: done = true; break; case TCL.CompletionCode.CONTINUE: break; case TCL.CompletionCode.ERROR: interp.addErrorInfo("\n (\"for\" body line " + interp.errorLine + ")"); throw; default: throw; } } if (!done) { try { interp.eval(next, 0); } catch (TclException e) { switch (e.getCompletionCode()) { case TCL.CompletionCode.BREAK: done = true; break; case TCL.CompletionCode.CONTINUE: break; default: interp.addErrorInfo("\n (\"for\" loop-end command)"); throw; } } } } interp.resetResult(); return(TCL.CompletionCode.RETURN); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv) { string optLevel; int result; CallFrame savedVarFrame, frame; int objc = objv.Length; int objv_index; TclObject cmd; if (objv.Length < 2) { throw new TclNumArgsException(interp, 1, objv, "?level? command ?arg ...?"); } // Find the level to use for executing the command. optLevel = 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, optLevel, frameArr); frame = frameArr[0]; objc -= (result + 1); if (objc == 0) { throw new TclNumArgsException(interp, 1, objv, "?level? command ?arg ...?"); } objv_index = (result + 1); // Modify the interpreter state to execute in the given frame. savedVarFrame = interp.varFrame; interp.varFrame = frame; // Execute the residual arguments as a command. if (objc == 1) { cmd = objv[objv_index]; } else { cmd = TclString.newInstance(Util.concat(objv_index, objv.Length - 1, objv)); } cmd.preserve(); try { interp.eval(cmd, 0); } catch (TclException e) { if (e.getCompletionCode() == TCL.CompletionCode.ERROR) { interp.addErrorInfo("\n (\"uplevel\" body line " + interp.errorLine + ")"); } throw; } finally { interp.varFrame = savedVarFrame; cmd.release(); } return(TCL.CompletionCode.RETURN); }
/// <summary> Tcl_WriteChars -> write /// /// Write string data to the Channel. /// /// </summary> /// <param name="interp">is used for TclExceptions. /// </param> /// <param name="outStr">the String object to write. /// </param> public void Write(Interp interp, string outStr) { Write(interp, TclString.NewInstance(outStr)); }
/* ** 2009 July 17 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement the "sqlite" test harness ** which runs TCL commands for testing the C#-SQLite port. ** ** $Header$ */ public static void Main(string[] args) { // Array of command-line argument strings. { string fileName = null; // Create the interpreter. This will also create the built-in // Tcl commands. Interp interp = new Interp(); // Make command-line arguments available in the Tcl variables "argc" // and "argv". If the first argument doesn't start with a "-" then // strip it off and use it as the name of a script file to process. // We also set the argv0 and TCL.Tcl_interactive vars here. if ((args.Length > 0) && !(args[0].StartsWith("-"))) { fileName = args[0]; } TclObject argv = TclList.newInstance(); argv.preserve(); try { int i = 0; int argc = args.Length; if ((System.Object)fileName == null) { interp.setVar("argv0", "tcl.lang.Shell", TCL.VarFlag.GLOBAL_ONLY); interp.setVar("tcl_interactive", "1", TCL.VarFlag.GLOBAL_ONLY); } else { interp.setVar("argv0", fileName, TCL.VarFlag.GLOBAL_ONLY); interp.setVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY); i++; argc--; } for (; i < args.Length; i++) { TclList.append(interp, argv, TclString.newInstance(args[i])); } interp.setVar("argv", argv, TCL.VarFlag.GLOBAL_ONLY); interp.setVar("argc", System.Convert.ToString(argc), TCL.VarFlag.GLOBAL_ONLY); } catch (TclException e) { throw new TclRuntimeError("unexpected TclException: " + e.Message); } finally { argv.release(); } // Normally we would do application specific initialization here. // However, that feature is not currently supported. // If a script file was specified then just source that file // and quit. Console.WriteLine("C#-TCL version " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); Console.WriteLine("=============================================================="); Console.WriteLine(""); if ((System.Object)fileName != null) { try { interp.evalFile(fileName); } catch (TclException e) { TCL.CompletionCode code = e.getCompletionCode(); if (code == TCL.CompletionCode.RETURN) { code = interp.updateReturnInfo(); if (code != TCL.CompletionCode.OK) { System.Console.Error.WriteLine("command returned bad code: " + code); if (tcl.lang.ConsoleThread.debug) { System.Diagnostics.Debug.WriteLine("command returned bad code: " + code); } } } else if (code == TCL.CompletionCode.ERROR) { System.Console.Error.WriteLine(interp.getResult().ToString()); if (tcl.lang.ConsoleThread.debug) { System.Diagnostics.Debug.WriteLine(interp.getResult().ToString()); } System.Diagnostics.Debug.Assert(false, interp.getResult().ToString()); } else { System.Console.Error.WriteLine("command returned bad code: " + code); if (tcl.lang.ConsoleThread.debug) { System.Diagnostics.Debug.WriteLine("command returned bad code: " + code); } } } // Note that if the above interp.evalFile() returns the main // thread will exit. This may bring down the VM and stop // the execution of Tcl. // // If the script needs to handle events, it must call // vwait or do something similar. // // Note that the script can create AWT widgets. This will // start an AWT event handling thread and keep the VM up. However, // the interpreter thread (the same as the main thread) would // have exited and no Tcl scripts can be executed. interp.dispose(); System.Environment.Exit(0); } if ((System.Object)fileName == null) { // We are running in interactive mode. Start the ConsoleThread // that loops, grabbing stdin and passing it to the interp. ConsoleThread consoleThread = new ConsoleThread(interp); consoleThread.IsBackground = true; consoleThread.Start(); // Loop forever to handle user input events in the command line. Notifier notifier = interp.getNotifier(); while (true) { // process events until "exit" is called. notifier.doOneEvent(TCL.ALL_EVENTS); } } } }
/// <summary> Move the current file pointer. If seek is not supported on the /// given channel then -1 will be returned. A subclass should /// override this method if it supports the seek operation. /// /// </summary> /// <param name="interp">currrent interpreter. /// </param> /// <param name="offset">The number of bytes to move the file pointer. /// </param> /// <param name="mode">where to begin incrementing the file pointer; beginning, /// current, end. /// </param> public virtual void seek(Interp interp, long offset, int mode) { throw new TclPosixException(interp, TclPosixException.EINVAL, true, "error during seek on \"" + ChanName + "\""); }
private static void copyRenameOneFile(Interp interp, string sourceName, string targetName, bool copyFlag, bool force) { // Copying or renaming a file onto itself is a no-op if force is chosen, // otherwise, it will be caught later as an EEXISTS error. if (force && sourceName.Equals(targetName)) { return; } // Check that the source exists and that if -force was not specified, the // target doesn't exist. // // Prevent copying/renaming a file onto a directory and // vice-versa. This is a policy decision based on the fact that // existing implementations of copy and rename on all platforms // also prevent this. string action; if (copyFlag) { action = "copying"; } else { action = "renaming"; } System.IO.FileInfo sourceFileObj = FileUtil.getNewFileObj(interp, sourceName); bool tmpBool; if (System.IO.File.Exists(sourceFileObj.FullName)) { tmpBool = true; } else { tmpBool = System.IO.Directory.Exists(sourceFileObj.FullName); } if ((!tmpBool) || (sourceName.Length == 0)) { throw new TclPosixException(interp, TclPosixException.ENOENT, true, "error " + action + " \"" + sourceName + "\""); } if (targetName.Length == 0) { throw new TclPosixException(interp, TclPosixException.ENOENT, true, "error " + action + " \"" + sourceName + "\" to \"" + targetName + "\""); } System.IO.FileInfo targetFileObj = FileUtil.getNewFileObj(interp, targetName); bool tmpBool2; if (System.IO.File.Exists(targetFileObj.FullName)) { tmpBool2 = true; } else { tmpBool2 = System.IO.Directory.Exists(targetFileObj.FullName); } if (tmpBool2 && !force) { throw new TclPosixException(interp, TclPosixException.EEXIST, true, "error " + action + " \"" + sourceName + "\" to \"" + targetName + "\""); } if (System.IO.Directory.Exists(sourceFileObj.FullName) && !System.IO.Directory.Exists(targetFileObj.FullName)) { throw new TclPosixException(interp, TclPosixException.EISDIR, "can't overwrite file \"" + targetName + "\" with directory \"" + sourceName + "\""); } if (System.IO.Directory.Exists(targetFileObj.FullName) && !System.IO.Directory.Exists(sourceFileObj.FullName)) { throw new TclPosixException(interp, TclPosixException.EISDIR, "can't overwrite directory \"" + targetName + "\" with file \"" + sourceName + "\""); } if (!copyFlag) { // Perform the rename procedure. try { sourceFileObj.MoveTo(targetFileObj.FullName); } catch (Exception e) { throw new TclPosixException(interp, TclPosixException.EACCES, true, "error renaming \"" + sourceName + "\" to \"" + targetName + "\""); } // { // // if (System.IO.Directory.Exists(targetFileObj.FullName)) // { // throw new TclPosixException(interp, TclPosixException.EEXIST, true, "error renaming \"" + sourceName + "\" to \"" + targetName + "\""); // } // // throw new TclPosixException(interp, TclPosixException.EACCES, true, "error renaming \"" + sourceName + "\" to \"" + targetName + "\": best guess at reason"); // } } else { // Perform the copy procedure. try { sourceFileObj.CopyTo(targetFileObj.FullName, true); } catch (System.IO.IOException e) { throw new TclException(interp, "error copying: " + e.Message); } } }
/// <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) { int i; bool value; i = 1; while (true) { /* * At this point in the loop, argv and argc refer to an * expression to test, either for the main expression or * an expression following an "elseif". The arguments * after the expression must be "then" (optional) and a * script to execute if the expression is true. */ if (i >= argv.Length) { throw new TclException(interp, "wrong # args: no expression after \"" + argv[i - 1] + "\" argument"); } try { value = interp._expr.EvalBoolean(interp, argv[i].ToString()); } catch (TclException e) { switch (e.GetCompletionCode()) { case TCL.CompletionCode.ERROR: interp.AddErrorInfo("\n (\"if\" test expression)"); break; } throw; } i++; if ((i < argv.Length) && (argv[i].ToString().Equals("then"))) { i++; } if (i >= argv.Length) { throw new TclException(interp, "wrong # args: no script following \"" + argv[i - 1] + "\" argument"); } if (value) { try { interp.Eval(argv[i], 0); } catch (TclException e) { switch (e.GetCompletionCode()) { case TCL.CompletionCode.ERROR: interp.AddErrorInfo("\n (\"if\" then script line " + interp._errorLine + ")"); break; } throw; } return(TCL.CompletionCode.RETURN); } /* * The expression evaluated to false. Skip the command, then * see if there is an "else" or "elseif" clause. */ i++; if (i >= argv.Length) { interp.ResetResult(); return(TCL.CompletionCode.RETURN); } if (argv[i].ToString().Equals("elseif")) { i++; continue; } break; } /* * Couldn't find a "then" or "elseif" clause to execute. * Check now for an "else" clause. We know that there's at * least one more argument when we get here. */ if (argv[i].ToString().Equals("else")) { i++; if (i >= argv.Length) { throw new TclException(interp, "wrong # args: no script following \"else\" argument"); } else if (i != (argv.Length - 1)) { throw new TclException(interp, "wrong # args: extra words after \"else\" clause in " + "\"if\" command"); } } try { interp.Eval(argv[i], 0); } catch (TclException e) { switch (e.GetCompletionCode()) { case TCL.CompletionCode.ERROR: interp.AddErrorInfo("\n (\"if\" else script line " + interp._errorLine + ")"); break; } throw; } return(TCL.CompletionCode.RETURN); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { if (argv.Length < 2) { throw new TclNumArgsException(interp, 1, argv, "option ?arg ...?"); } int opt = TclIndex.get(interp, argv[1], validCmds, "option", 0); string path; System.IO.FileInfo fileObj = null; switch (opt) { case OPT_ATIME: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } // FIXME: Currently returns the same thing as MTIME. // Java does not support retrieval of access time. fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(getMtime(interp, argv[2].ToString(), fileObj)); return(TCL.CompletionCode.RETURN); case OPT_ATTRIBUTES: if (argv[3].ToString() == "-readonly") { fileSetReadOnly(interp, argv); } else { throw new TclException(interp, "sorry, \"file attributes\" is not implemented yet"); } return(TCL.CompletionCode.RETURN); case OPT_CHANNELS: throw new TclException(interp, "sorry, \"file channels\" is not implemented yet"); case OPT_COPY: fileCopyRename(interp, argv, true); return(TCL.CompletionCode.RETURN); case OPT_DELETE: fileDelete(interp, argv); return(TCL.CompletionCode.RETURN); case OPT_DIRNAME: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } path = argv[2].ToString(); // Return all but the last component. If there is only one // component, return it if the path was non-relative, otherwise // return the current directory. TclObject[] splitArrayObj = TclList.getElements(interp, FileUtil.splitAndTranslate(interp, path)); if (splitArrayObj.Length > 1) { interp.setResult(FileUtil.joinPath(interp, splitArrayObj, 0, splitArrayObj.Length - 1)); } else if ((splitArrayObj.Length == 0) || (FileUtil.getPathType(path) == FileUtil.PATH_RELATIVE)) { if (JACL.PLATFORM == JACL.PLATFORM_MAC) { interp.setResult(":"); } else { interp.setResult("."); } } else { interp.setResult(splitArrayObj[0].ToString()); } return(TCL.CompletionCode.RETURN); case OPT_EXECUTABLE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } bool isExe = false; fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); // A file must exist to be executable. Directories are always // executable. bool tmpBool; if (System.IO.File.Exists(fileObj.FullName)) { tmpBool = true; } else { tmpBool = System.IO.Directory.Exists(fileObj.FullName); } if (tmpBool) { isExe = System.IO.Directory.Exists(fileObj.FullName); if (isExe) { interp.setResult(isExe); return(TCL.CompletionCode.RETURN); } if (Util.Windows) { // File that ends with .exe, .com, or .bat is executable. string fileName = argv[2].ToString(); isExe = (fileName.EndsWith(".exe") || fileName.EndsWith(".com") || fileName.EndsWith(".bat")); } else if (Util.Mac) { // FIXME: Not yet implemented on Mac. For now, return true. // Java does not support executability checking. isExe = true; } else { // FIXME: Not yet implemented on Unix. For now, return true. // Java does not support executability checking. isExe = true; } } interp.setResult(isExe); return(TCL.CompletionCode.RETURN); case OPT_EXISTS: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); bool tmpBool2; if (System.IO.File.Exists(fileObj.FullName)) { tmpBool2 = true; } else { tmpBool2 = System.IO.Directory.Exists(fileObj.FullName); } interp.setResult(tmpBool2); return(TCL.CompletionCode.RETURN); case OPT_EXTENSION: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } interp.setResult(getExtension(argv[2].ToString())); return(TCL.CompletionCode.RETURN); case OPT_ISDIRECTORY: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(System.IO.Directory.Exists(fileObj.FullName)); return(TCL.CompletionCode.RETURN); case OPT_ISFILE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(System.IO.File.Exists(fileObj.FullName)); return(TCL.CompletionCode.RETURN); case OPT_JOIN: if (argv.Length < 3) { throw new TclNumArgsException(interp, 2, argv, "name ?name ...?"); } interp.setResult(FileUtil.joinPath(interp, argv, 2, argv.Length)); return(TCL.CompletionCode.RETURN); case OPT_LINK: throw new TclException(interp, "sorry, \"file link\" is not implemented yet"); case OPT_LSTAT: if (argv.Length != 4) { throw new TclNumArgsException(interp, 2, argv, "name varName"); } // FIXME: Not yet implemented. // Java does not support link access. throw new TclException(interp, "file command with opt " + argv[1].ToString() + " is not yet implemented"); case OPT_MTIME: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(getMtime(interp, argv[2].ToString(), fileObj)); return(TCL.CompletionCode.RETURN); case OPT_MKDIR: fileMakeDirs(interp, argv); return(TCL.CompletionCode.RETURN); case OPT_NATIVENAME: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } interp.setResult(FileUtil.translateFileName(interp, argv[2].ToString())); return(TCL.CompletionCode.RETURN); case OPT_NORMALIZE: throw new TclException(interp, "sorry, \"file normalize\" is not implemented yet"); case OPT_OWNED: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(isOwner(interp, fileObj)); return(TCL.CompletionCode.RETURN); case OPT_PATHTYPE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } switch (FileUtil.getPathType(argv[2].ToString())) { case FileUtil.PATH_RELATIVE: interp.setResult("relative"); return(TCL.CompletionCode.RETURN); case FileUtil.PATH_VOLUME_RELATIVE: interp.setResult("volumerelative"); return(TCL.CompletionCode.RETURN); case FileUtil.PATH_ABSOLUTE: interp.setResult("absolute"); break; } return(TCL.CompletionCode.RETURN); case OPT_READABLE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); // interp.setResult(fileObj.canRead()); // HACK interp.setResult(true); return(TCL.CompletionCode.RETURN); case OPT_READLINK: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } // FIXME: Not yet implemented. // Java does not support link access. throw new TclException(interp, "file command with opt " + argv[1].ToString() + " is not yet implemented"); case OPT_RENAME: fileCopyRename(interp, argv, false); return(TCL.CompletionCode.RETURN); case OPT_ROOTNAME: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } string fileName2 = argv[2].ToString(); string extension = getExtension(fileName2); int diffLength = fileName2.Length - extension.Length; interp.setResult(fileName2.Substring(0, (diffLength) - (0))); return(TCL.CompletionCode.RETURN); case OPT_SEPARATOR: throw new TclException(interp, "sorry, \"file separator\" is not implemented yet"); case OPT_SIZE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); bool tmpBool3; if (System.IO.File.Exists(fileObj.FullName)) { tmpBool3 = true; } else { tmpBool3 = System.IO.Directory.Exists(fileObj.FullName); } if (!tmpBool3) { throw new TclPosixException(interp, TclPosixException.ENOENT, true, "could not read \"" + argv[2].ToString() + "\""); } interp.setResult((int)SupportClass.FileLength(fileObj)); return(TCL.CompletionCode.RETURN); case OPT_SPLIT: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } interp.setResult(FileUtil.splitPath(interp, argv[2].ToString())); return(TCL.CompletionCode.RETURN); case OPT_STAT: if (argv.Length != 4) { throw new TclNumArgsException(interp, 2, argv, "name varName"); } getAndStoreStatData(interp, argv[2].ToString(), argv[3].ToString()); return(TCL.CompletionCode.RETURN); case OPT_SYSTEM: throw new TclException(interp, "sorry, \"file system\" is not implemented yet"); case OPT_TAIL: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } interp.setResult(getTail(interp, argv[2].ToString())); return(TCL.CompletionCode.RETURN); case OPT_TYPE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(getType(interp, argv[2].ToString(), fileObj)); return(TCL.CompletionCode.RETURN); case OPT_VOLUMES: if (argv.Length != 2) { throw new TclNumArgsException(interp, 2, argv, null); } // use Java 1.2's File.listRoots() method if available if (listRootsMethod == null) { throw new TclException(interp, "\"file volumes\" is not supported"); } try { System.IO.FileInfo[] roots = (System.IO.FileInfo[])listRootsMethod.Invoke(null, (System.Object[]) new System.Object[0]); if (roots != null) { TclObject list = TclList.newInstance(); for (int i = 0; i < roots.Length; i++) { string root = roots[i].FullName; TclList.append(interp, list, TclString.newInstance(root)); } interp.setResult(list); } } catch (System.UnauthorizedAccessException ex) { throw new TclRuntimeError("IllegalAccessException in volumes cmd"); } catch (System.ArgumentException ex) { throw new TclRuntimeError("IllegalArgumentException in volumes cmd"); } catch (System.Reflection.TargetInvocationException ex) { System.Exception t = ex.GetBaseException(); if (t is System.ApplicationException) { throw (System.ApplicationException)t; } else { throw new TclRuntimeError("unexected exception in volumes cmd"); } } return(TCL.CompletionCode.RETURN); case OPT_WRITABLE: if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "name"); } fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString()); interp.setResult(SupportClass.FileCanWrite(fileObj)); return(TCL.CompletionCode.RETURN); default: throw new TclRuntimeError("file command with opt " + argv[1].ToString() + " is not implemented"); } }
private TclDouble(Interp interp, string str) { value = Util.getDouble(interp, str); }
private static void fileCopyRename(Interp interp, TclObject[] argv, bool copyFlag) { int firstSource = 2; bool force = false; for (bool last = false; (firstSource < argv.Length) && (!last); firstSource++) { if (!argv[firstSource].ToString().StartsWith("-")) { break; } int opt = TclIndex.get(interp, argv[firstSource], validOptions, "option", 1); switch (opt) { case OPT_FORCE: force = true; break; case OPT_LAST: last = true; break; default: throw new TclRuntimeError("FileCmd.cmdProc: bad option " + opt + " index to validOptions"); } } if (firstSource >= (argv.Length - 1)) { throw new TclNumArgsException(interp, firstSource, argv, "?options? source ?source ...? target"); } // WARNING: ignoring links because Java does not support them. int target = argv.Length - 1; string targetName = argv[target].ToString(); System.IO.FileInfo targetObj = FileUtil.getNewFileObj(interp, targetName); if (System.IO.Directory.Exists(targetObj.FullName)) { // If the target is a directory, move each source file into target // directory. Extract the tailname from each source, and append it to // the end of the target path. for (int source = firstSource; source < target; source++) { string sourceName = argv[source].ToString(); if (targetName.Length == 0) { copyRenameOneFile(interp, sourceName, targetName, copyFlag, force); } else { string tailName = getTail(interp, sourceName); TclObject[] joinArrayObj = new TclObject[2]; joinArrayObj[0] = TclString.newInstance(targetName); joinArrayObj[1] = TclString.newInstance(tailName); string fullTargetName = FileUtil.joinPath(interp, joinArrayObj, 0, 2); copyRenameOneFile(interp, sourceName, fullTargetName, copyFlag, force); } } } else { // If there is more than 1 source file and the target is not a // directory, then throw an exception. if (firstSource + 1 != target) { string action; if (copyFlag) { action = "copying"; } else { action = "renaming"; } throw new TclPosixException(interp, TclPosixException.ENOTDIR, "error " + action + ": target \"" + argv[target].ToString() + "\" is not a directory"); } string sourceName = argv[firstSource].ToString(); copyRenameOneFile(interp, sourceName, targetName, copyFlag, force); } }
private Vector3 GetModifiedBendNormal() { float num = this.bendModifierWeight; if (num <= 0f) { return(this.bendNormal); } switch (this.bendModifier) { case IKSolverLimb.BendModifier.Animation: if (!this.maintainBendFor1Frame) { this.MaintainBend(); } this.maintainBendFor1Frame = false; return(Vector3.Lerp(this.bendNormal, this.animationNormal, num)); case IKSolverLimb.BendModifier.Target: { Quaternion b = this.IKRotation * Quaternion.Inverse(this.bone3DefaultRotation); return(Quaternion.Slerp(Quaternion.identity, b, num) * this.bendNormal); } case IKSolverLimb.BendModifier.Parent: { if (this.bone1.transform.parent == null) { return(this.bendNormal); } Quaternion lhs = this.bone1.transform.parent.rotation * Quaternion.Inverse(this.parentDefaultRotation); return(Quaternion.Slerp(Quaternion.identity, lhs * Quaternion.Inverse(this.defaultRootRotation), num) * this.bendNormal); } case IKSolverLimb.BendModifier.Arm: { if (this.bone1.transform.parent == null) { return(this.bendNormal); } if (this.goal == AvatarIKGoal.LeftFoot || this.goal == AvatarIKGoal.RightFoot) { if (!Warning.logged) { base.LogWarning("Trying to use the 'Arm' bend modifier on a leg."); } return(this.bendNormal); } Vector3 vector = (this.IKPosition - this.bone1.transform.position).normalized; vector = Quaternion.Inverse(this.bone1.transform.parent.rotation * Quaternion.Inverse(this.parentDefaultRotation)) * vector; if (this.goal == AvatarIKGoal.LeftHand) { vector.x = -vector.x; } for (int i = 1; i < this.axisDirections.Length; i++) { this.axisDirections[i].dot = Mathf.Clamp(Vector3.Dot(this.axisDirections[i].direction, vector), 0f, 1f); this.axisDirections[i].dot = Interp.Float(this.axisDirections[i].dot, InterpolationMode.InOutQuintic); } Vector3 vector2 = this.axisDirections[0].axis; for (int j = 1; j < this.axisDirections.Length; j++) { vector2 = Vector3.Slerp(vector2, this.axisDirections[j].axis, this.axisDirections[j].dot); } if (this.goal == AvatarIKGoal.LeftHand) { vector2.x = -vector2.x; vector2 = -vector2; } Vector3 vector3 = this.bone1.transform.parent.rotation * Quaternion.Inverse(this.parentDefaultRotation) * vector2; if (num >= 1f) { return(vector3); } return(Vector3.Lerp(this.bendNormal, vector3, num)); } case IKSolverLimb.BendModifier.Goal: { if (this.bendGoal == null) { if (!Warning.logged) { base.LogWarning("Trying to use the 'Goal' Bend Modifier, but the Bend Goal is unassigned."); } return(this.bendNormal); } Vector3 vector4 = Vector3.Cross(this.bendGoal.position - this.bone1.transform.position, this.IKPosition - this.bone1.transform.position); if (vector4 == Vector3.zero) { return(this.bendNormal); } if (num >= 1f) { return(vector4); } return(Vector3.Lerp(this.bendNormal, vector4, num)); } default: return(this.bendNormal); } }
public TclException(Interp interp, string msg, TCL.CompletionCode ccode) : this(interp, msg, ccode, -1) { }
/// <summary> Initialize the Extension to run in a normal (unsafe) /// interpreter. This usually means creating all the commands /// provided by this class. A particular implementation can arrange /// the commands to be loaded on-demand using the loadOnDemand() /// function. /// /// </summary> /// <param name="interp">current interpreter. /// </param> abstract public void init(Interp interp);
/// <summary> This procedure is invoked to process the "read" 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 int i = 1; // Index to the next arg in argv int toRead = 0; // Number of bytes or chars to read from channel int charactersRead; // Number of bytes or chars read from channel bool readAll = true; // If true read-all else toRead bool noNewline = false; // If true, strip the newline if there TclObject result; if ((argv.Length != 2) && (argv.Length != 3)) { errorWrongNumArgs(interp, argv[0].ToString()); } if (argv[i].ToString().Equals("-nonewline")) { noNewline = true; i++; } if (i == argv.Length) { errorWrongNumArgs(interp, argv[0].ToString()); } chan = TclIO.getChannel(interp, argv[i].ToString()); if (chan == null) { throw new TclException(interp, "can not find channel named \"" + argv[i].ToString() + "\""); } // Consumed channel name. i++; // Compute how many bytes or chars to read, and see whether the final // noNewline should be dropped. if (i < argv.Length) { string arg = argv[i].ToString(); if (System.Char.IsDigit(arg[0])) { toRead = TclInteger.get(interp, argv[i]); readAll = false; } else if (arg.Equals("nonewline")) { noNewline = true; } else { throw new TclException(interp, "bad argument \"" + arg + "\": should be \"nonewline\""); } } try { if ((System.Object)chan.Encoding == null) { result = TclByteArray.newInstance(); } else { result = TclString.newInstance(new System.Text.StringBuilder(64)); } if (readAll) { charactersRead = chan.read(interp, result, TclIO.READ_ALL, 0); // If -nonewline was specified, and we have not hit EOF // and the last char is a "\n", then remove it and return. if (noNewline) { string inStr = result.ToString(); if ((charactersRead > 0) && (inStr[charactersRead - 1] == '\n')) { interp.setResult(inStr.Substring(0, ((charactersRead - 1)) - (0))); return(TCL.CompletionCode.RETURN); } } } else { // FIXME: Bug here, the -nonewline flag must be respected // when reading a set number of bytes charactersRead = chan.read(interp, result, TclIO.READ_N_BYTES, toRead); } /* * // FIXME: Port this -nonewline logic from the C code. * if (charactersRead < 0) { * Tcl_ResetResult(interp); * Tcl_AppendResult(interp, "error reading \"", name, "\": ", * Tcl_PosixError(interp), (char *) NULL); * Tcl_DecrRefCount(resultPtr); * return TCL_ERROR; * } * * // If requested, remove the last newline in the channel if at EOF. * * if ((charactersRead > 0) && (newline != 0)) { * char *result; * int length; * * result = Tcl_GetStringFromObj(resultPtr, length); * if (result[length - 1] == '\n') { * Tcl_SetObjLength(resultPtr, length - 1); * } * } * */ interp.setResult(result); } catch (System.IO.IOException e) { throw new TclRuntimeError("ReadCmd.cmdProc() Error: IOException when reading " + chan.ChanName); } return(TCL.CompletionCode.RETURN); }
/// <summary> Initialize the Extension to run in a safe interpreter. This /// method should be written carefully, so that it initializes the /// safe interpreter only with partial functionality provided by /// the Extension that is safe for use by untrusted code. /// /// The default implementation always throws a TclException, so that /// a subclass of Extension cannot be loaded into a safe interpreter /// unless it has overridden the safeInit() method. /// /// </summary> /// <param name="safeInterp">the safe interpreter in which the Extension should /// be initialized. /// </param> public void safeInit(Interp safeInterp) { throw new TclException(safeInterp, "Extension \"" + GetType().ToString() + "\" cannot be loaded into a safe interpreter"); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int i, mode, body; bool matched; string inString; TclObject[] switchArgv = null; mode = EXACT; for (i = 1; i < argv.Length; i++) { if (!argv[i].ToString().StartsWith("-")) { break; } int opt = TclIndex.get(interp, argv[i], validCmds, "option", 1); if (opt == LAST) { i++; break; } else if (opt > LAST) { throw new TclException(interp, "SwitchCmd.cmdProc: bad option " + opt + " index to validCmds"); } else { mode = opt; } } if (argv.Length - i < 2) { throw new TclNumArgsException(interp, 1, argv, "?switches? string pattern body ... ?default body?"); } inString = argv[i].ToString(); i++; // If all of the pattern/command pairs are lumped into a single // argument, split them out again. if (argv.Length - i == 1) { switchArgv = TclList.getElements(interp, argv[i]); i = 0; } else { switchArgv = argv; } for ( ; i < switchArgv.Length; i += 2) { if (i == (switchArgv.Length - 1)) { throw new TclException(interp, "extra switch pattern with no body"); } // See if the pattern matches the string. matched = false; string pattern = switchArgv[i].ToString(); if ((i == switchArgv.Length - 2) && pattern.Equals("default")) { matched = true; } else { switch (mode) { case EXACT: matched = inString.Equals(pattern); break; case GLOB: matched = Util.stringMatch(inString, pattern); break; case REGEXP: matched = Util.regExpMatch(interp, inString, switchArgv[i]); break; } } if (!matched) { continue; } // We've got a match. Find a body to execute, skipping bodies // that are "-". for (body = i + 1; ; body += 2) { if (body >= switchArgv.Length) { throw new TclException(interp, "no body specified for pattern \"" + switchArgv[i] + "\""); } if (!switchArgv[body].ToString().Equals("-")) { break; } } try { interp.eval(switchArgv[body], 0); return(TCL.CompletionCode.RETURN); } catch (TclException e) { if (e.getCompletionCode() == TCL.CompletionCode.ERROR) { interp.addErrorInfo("\n (\"" + switchArgv[i] + "\" arm line " + interp.errorLine + ")"); } throw; } } // Nothing matched: return nothing. return(TCL.CompletionCode.RETURN); }
/// <summary> Create a stub command which autoloads the real command the first time /// the stub command is invoked. Register the stub command in the /// interpreter. /// /// </summary> /// <param name="interp">current interp. /// </param> /// <param name="cmdName">name of the command, e.g., "after". /// </param> /// <param name="clsName">name of the Java class that implements this command, /// e.g. "tcl.lang.AfterCmd" /// </param> public static void loadOnDemand(Interp interp, string cmdName, string clsName) { interp.createCommand(cmdName, new AutoloadStub(clsName)); }