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); }
private static void setDoubleFromAny(Interp interp, TclObject tobj) { IInternalRep rep = tobj.InternalRep; if (rep is TclDouble) { /* * Do nothing. */ } else if (rep is TclBoolean) { /* * Short-cut. */ bool b = TclBoolean.get(interp, tobj); if (b) { tobj.InternalRep = new TclDouble(1.0); } else { tobj.InternalRep = new TclDouble(0.0); } } else if (rep is TclInteger) { /* * Short-cut. */ int i = TclInteger.Get(interp, tobj); tobj.InternalRep = new TclDouble(i); } else { tobj.InternalRep = new TclDouble(interp, tobj.ToString()); } }
private string WrongNumProcArgs(TclObject name, Procedure proc) { StringBuilder sbuf = new StringBuilder(200); sbuf.Append("wrong # args: should be \""); sbuf.Append(name.ToString()); for (int i = 0; i < proc.ArgList.Length; i++) { TclObject arg = proc.ArgList[i][0]; TclObject def = proc.ArgList[i][1]; sbuf.Append(" "); if (def != null) sbuf.Append("?"); sbuf.Append(arg.ToString()); if (def != null) sbuf.Append("?"); } sbuf.Append("\""); throw new TclException(Interp, sbuf.ToString()); }
/// <summary> Appends a TclObject to a TclObject. This method is equivalent to /// Tcl_AppendToObj() in Tcl 8.0. /// /// The type of the TclObject will be a TclString that contains the /// string value: /// tobj.toString() + tobj2.toString(); /// </summary> internal static void append(TclObject tobj, TclObject tobj2) { append(tobj, tobj2.ToString()); }
/// <summary> Compares the order of two items in the array. /// /// </summary> /// <param name="obj1">first item. /// </param> /// <param name="obj2">second item. /// </param> /// <returns> 0 if they are equal, 1 if obj1 > obj2, -1 otherwise. /// /// </returns> /// <exception cref=""> TclException if an error occurs during sorting. /// </exception> private int compare(TclObject obj1, TclObject obj2) { int index; int code = 0; if (sortIndex != -1) { // The "-index" option was specified. Treat each object as a // list, extract the requested element from each list, and // compare the elements, not the lists. The special index "end" // is signaled here with a negative index (other than -1). TclObject obj; if (sortIndex < -1) { index = TclList.getLength(sortInterp, obj1) - 1; } else { index = sortIndex; } obj = TclList.index(sortInterp, obj1, index); if (obj == null) { throw new TclException(sortInterp, "element " + index + " missing from sublist \"" + obj1 + "\""); } obj1 = obj; if (sortIndex < -1) { index = TclList.getLength(sortInterp, obj2) - 1; } else { index = sortIndex; } obj = TclList.index(sortInterp, obj2, index); if (obj == null) { throw new TclException(sortInterp, "element " + index + " missing from sublist \"" + obj2 + "\""); } obj2 = obj; } switch (sortMode) { case ASCII: // ATK C# CompareTo use option // similar to -dictionary but a > A code = System.Globalization.CultureInfo.InvariantCulture.CompareInfo.Compare(obj1.ToString(), obj2.ToString(), System.Globalization.CompareOptions.Ordinal); // code = obj1.ToString().CompareTo(obj2.ToString()); break; case DICTIONARY: code = doDictionary(obj1.ToString(), obj2.ToString()); break; case INTEGER: try { int int1 = TclInteger.Get(sortInterp, obj1); int int2 = TclInteger.Get(sortInterp, obj2); if (int1 > int2) { code = 1; } else if (int2 > int1) { code = -1; } } catch (TclException e1) { sortInterp.AddErrorInfo("\n (converting list element from string to integer)"); throw e1; } break; case REAL: try { double f1 = TclDouble.Get(sortInterp, obj1); double f2 = TclDouble.Get(sortInterp, obj2); if (f1 > f2) { code = 1; } else if (f2 > f1) { code = -1; } } catch (TclException e2) { sortInterp.AddErrorInfo("\n (converting list element from string to real)"); throw e2; } break; case COMMAND: StringBuilder sbuf = new StringBuilder(sortCommand); Util.appendElement(sortInterp, sbuf, obj1.ToString()); Util.appendElement(sortInterp, sbuf, obj2.ToString()); try { sortInterp.Eval(sbuf.ToString(), 0); } catch (TclException e3) { sortInterp.AddErrorInfo("\n (user-defined comparison command)"); throw e3; } try { code = TclInteger.Get(sortInterp, sortInterp.GetResult()); } catch (TclException e) { sortInterp.ResetResult(); TclException e4 = new TclException(sortInterp, "comparison command returned non-numeric result"); throw e4; } break; default: throw new TclRuntimeError("Unknown sortMode " + sortMode); } if (sortIncreasing) { return code; } else { return -code; } }
/// <summary> Appends a string to a TclObject object. This method is equivalent to /// Tcl_AppendToObj() in Tcl 8.0. /// /// </summary> /// <param name="tobj">the TclObject to append a string to. /// </param> /// <param name="string">the string to append to the object. /// </param> public static void append(TclObject tobj, string toAppend) { StringFromAny = tobj; TclString tstr = (TclString)tobj.InternalRep; if (tstr.sbuf == null) { tstr.sbuf = new StringBuilder(tobj.ToString()); } tobj.invalidateStringRep(); tstr.sbuf.Append(toAppend); }
/// <summary> Appends an array of characters to a TclObject Object. /// Tcl_AppendUnicodeToObj() in Tcl 8.0. /// /// </summary> /// <param name="tobj">the TclObject to append a string to. /// </param> /// <param name="charArr">array of characters. /// </param> /// <param name="offset">index of first character to append. /// </param> /// <param name="length">number of characters to append. /// </param> public static void append(TclObject tobj, char[] charArr, int offset, int length) { StringFromAny = tobj; TclString tstr = (TclString)tobj.InternalRep; if (tstr.sbuf == null) { tstr.sbuf = new StringBuilder(tobj.ToString()); } tobj.invalidateStringRep(); tstr.sbuf.Append(charArr, offset, length); }
internal static Interp create( Interp interp, TclObject path, bool safe ) { Interp masterInterp; string pathString; TclObject[] objv = TclList.getElements( interp, path ); if ( objv.Length < 2 ) { masterInterp = interp; pathString = path.ToString(); } else { TclObject obj = TclList.NewInstance(); TclList.insert( interp, obj, 0, objv, 0, objv.Length - 2 ); masterInterp = InterpCmd.getInterp( interp, obj ); pathString = objv[objv.Length - 1].ToString(); } if ( !safe ) { safe = masterInterp._isSafe; } if ( masterInterp._slaveTable.ContainsKey( pathString ) ) { throw new TclException( interp, "interpreter named \"" + pathString + "\" already exists, cannot create" ); } Interp slaveInterp = new Interp(); InterpSlaveCmd slave = new InterpSlaveCmd(); slaveInterp._slave = slave; slaveInterp.SetAssocData( "InterpSlaveCmd", slave ); slave.masterInterp = masterInterp; slave.path = pathString; slave.slaveInterp = slaveInterp; masterInterp.CreateCommand( pathString, slaveInterp._slave ); slaveInterp._slave.interpCmd = NamespaceCmd.findCommand( masterInterp, pathString, null, 0 ); SupportClass.PutElement( masterInterp._slaveTable, pathString, slaveInterp._slave ); slaveInterp.SetVar( "tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY ); // Inherit the recursion limit. slaveInterp._maxNestingDepth = masterInterp._maxNestingDepth; if ( safe ) { try { makeSafe( slaveInterp ); } catch ( TclException e ) { SupportClass.WriteStackTrace( e, Console.Error ); } } else { //Tcl_Init(slaveInterp); } return slaveInterp; }
public void Eval(TclObject tobj, int flags) { Eval(tobj.ToString(), flags); }
/// <summary> Write to stdout or stderr. If the stdType is not set to /// STDOUT or STDERR this is an error; either the stdType wasnt /// correctly initialized, or this was called on a STDIN channel. /// /// </summary> /// <param name="interp">the current interpreter. /// </param> /// <param name="s">the string to write /// </param> public override void Write(Interp interp, TclObject outData) { checkWrite(interp); if (stdType == STDERR) { System.Console.Error.Write(outData.ToString()); } else { string s = outData.ToString(); System.Console.Out.Write(s); if (buffering == TclIO.BUFF_NONE || (buffering == TclIO.BUFF_LINE && s.EndsWith("\n"))) { System.Console.Out.Flush(); } } }
/// <summary> SetlongFromAny -> TclLong.setlongFromAny /// /// Called to convert the other object's longernal rep to this type. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="forIndex">true if this methid is called by getForIndex. /// </param> /// <param name="tobj">the TclObject to convert to use the /// representation provided by this class. /// </param> private static void setlongFromAny(Interp interp, TclObject tobj) { IInternalRep rep = tobj.InternalRep; if (rep is TclLong) { // Do nothing. } else if (rep is TclBoolean) { bool b = TclBoolean.get(interp, tobj); if (b) { tobj.InternalRep = new TclLong(1); } else { tobj.InternalRep = new TclLong(0); } } else { // (ToDo) other short-cuts tobj.InternalRep = new TclLong(interp, tobj.ToString()); } }
/// <summary> Called to convert the other object's internal rep to boolean. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the TclObject to convert to use the /// representation provided by this class. /// </param> private static void setBooleanFromAny(Interp interp, TclObject tobj) { IInternalRep rep = tobj.InternalRep; if (rep is TclBoolean) { /* * Do nothing. */ } else if (rep is TclInteger) { int i = TclInteger.Get(interp, tobj); tobj.InternalRep = new TclBoolean(i != 0); } else { /* * (ToDo) other short-cuts */ tobj.InternalRep = new TclBoolean(interp, tobj.ToString()); } }