/// <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 (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); }
/// <summary> This procedure is invoked to process the "eof" 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() + "\""); } if (chan.eof()) { interp.setResult(TclInteger.newInstance(1)); } else { interp.setResult(TclInteger.newInstance(0)); } return(TCL.CompletionCode.RETURN); }
/// <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 (System.IO.IOException e) { throw new TclException(interp, "Error in TellCmd"); } return(TCL.CompletionCode.RETURN); }
/// <summary> TCL.Tcl_GetIntFromObj -> TclInteger.get /// /// Returns the integer value of the object. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the object to operate on. /// </param> /// <returns> the integer value of the object. /// </returns> public static int get(Interp interp, TclObject tobj) { setIntegerFromAny(interp, tobj); TclInteger tint = (TclInteger)tobj.InternalRep; return(tint.value); }
internal static int FormatNumber(Interp interp, char type, TclObject src, byte[] resultBytes, int cursor) { if (type == 'd') { double dvalue = TclDouble.get(interp, src); System.IO.MemoryStream ms = new System.IO.MemoryStream(resultBytes, cursor, 8); System.IO.BinaryWriter writer = new System.IO.BinaryWriter(ms); writer.Write(dvalue); cursor += 8; writer.Close(); ms.Close(); } else if (type == 'f') { float fvalue = (float)TclDouble.get(interp, src); System.IO.MemoryStream ms = new System.IO.MemoryStream(resultBytes, cursor, 4); System.IO.BinaryWriter writer = new System.IO.BinaryWriter(ms); writer.Write(fvalue); cursor += 4; writer.Close(); ms.Close(); } else { int value = TclInteger.get(interp, src); if (type == 'c') { resultBytes[cursor++] = (byte)value; } else if (type == 's') { resultBytes[cursor++] = (byte)value; resultBytes[cursor++] = (byte)(value >> 8); } else if (type == 'S') { resultBytes[cursor++] = (byte)(value >> 8); resultBytes[cursor++] = (byte)value; } else if (type == 'i') { resultBytes[cursor++] = (byte)value; resultBytes[cursor++] = (byte)(value >> 8); resultBytes[cursor++] = (byte)(value >> 16); resultBytes[cursor++] = (byte)(value >> 24); } else if (type == 'I') { resultBytes[cursor++] = (byte)(value >> 24); resultBytes[cursor++] = (byte)(value >> 16); resultBytes[cursor++] = (byte)(value >> 8); resultBytes[cursor++] = (byte)value; } } return(cursor); }
/// <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); }
private static TclObject ScanNumber(byte[] src, int pos, int type) // Format character from "binary scan" { switch (type) { case 'c': { return(TclInteger.newInstance((sbyte)src[pos])); } case 's': { short value = (short)((src[pos] & 0xff) + ((src[pos + 1] & 0xff) << 8)); return(TclInteger.newInstance((int)value)); } case 'S': { short value = (short)((src[pos + 1] & 0xff) + ((src[pos] & 0xff) << 8)); return(TclInteger.newInstance((int)value)); } case 'i': { int value = (src[pos] & 0xff) + ((src[pos + 1] & 0xff) << 8) + ((src[pos + 2] & 0xff) << 16) + ((src[pos + 3] & 0xff) << 24); return(TclInteger.newInstance(value)); } case 'I': { int value = (src[pos + 3] & 0xff) + ((src[pos + 2] & 0xff) << 8) + ((src[pos + 1] & 0xff) << 16) + ((src[pos] & 0xff) << 24); return(TclInteger.newInstance(value)); } case 'f': { System.IO.MemoryStream ms = new System.IO.MemoryStream(src, pos, 4, false); System.IO.BinaryReader reader = new System.IO.BinaryReader(ms); double fvalue = reader.ReadSingle(); reader.Close(); ms.Close(); return(TclDouble.newInstance(fvalue)); } case 'd': { System.IO.MemoryStream ms = new System.IO.MemoryStream(src, pos, 8, false); System.IO.BinaryReader reader = new System.IO.BinaryReader(ms); double dvalue = reader.ReadDouble(); reader.Close(); ms.Close(); return(TclDouble.newInstance(dvalue)); } } return(null); }
/* *---------------------------------------------------------------------- * * InfoLevelCmd -- * * Called to implement the "info level" command that returns * information about the call stack. Handles the following syntax: * * info level ?number? * * Results: * Returns if successful, raises TclException otherwise. * * Side effects: * Returns a result in the interpreter's result object. * *---------------------------------------------------------------------- */ private static void InfoLevelCmd(Interp interp, TclObject[] objv) { int level; CallFrame frame; TclObject list; if (objv.Length == 2) { // just "info level" if (interp.varFrame == null) { interp.setResult(0); } else { interp.setResult(interp.varFrame.level); } return; } else if (objv.Length == 3) { level = TclInteger.get(interp, objv[2]); if (level <= 0) { if (interp.varFrame == null) { throw new TclException(interp, "bad level \"" + objv[2].ToString() + "\""); } level += interp.varFrame.level; } for (frame = interp.varFrame; frame != null; frame = frame.callerVar) { if (frame.level == level) { break; } } if ((frame == null) || frame.objv == null) { throw new TclException(interp, "bad level \"" + objv[2].ToString() + "\""); } list = TclList.newInstance(); for (int i = 0; i < frame.objv.Length; i++) { TclList.append(interp, list, TclString.newInstance(frame.objv[i])); } interp.setResult(list); return; } throw new TclNumArgsException(interp, 2, objv, "?number?"); }
public static void Tcl_SetIntObj(TclObject to, int result ) { while (to.Shared) { to.release(); } TclInteger.set(to, result); to.preserve(); }
public static int Tcl_GetIntFromObj(Interp interp, TclObject to, out int value) { try { value = TclInteger.get(interp, to); return(TCL.TCL_OK); } catch { value = 0; return(TCL.TCL_ERROR); } }
public static bool Tcl_GetInt(Interp interp, TclObject to, out u32 value) { try { value = (u32)TclInteger.get(interp, to); return(false); } catch { value = 0; return(true); } }
/// <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); }
internal static int getIntForIndex(Interp interp, TclObject tobj, int endValue) { int length, offset; if (tobj.InternalRep is TclInteger) { return(TclInteger.get(interp, tobj)); } string bytes = tobj.ToString(); length = bytes.Length; string intforindex_error = "bad index \"" + bytes + "\": must be integer or end?-integer?" + checkBadOctal(interp, bytes); // FIXME : should we replace this call to regionMatches with a generic strncmp? if (!(String.Compare("end", 0, bytes, 0, (length > 3) ? 3 : length) == 0)) { try { offset = TclInteger.get(null, tobj); } catch (TclException e) { throw new TclException(interp, "bad index \"" + bytes + "\": must be integer or end?-integer?" + checkBadOctal(interp, bytes)); } return(offset); } if (length <= 3) { return(endValue); } else if (bytes[3] == '-') { // This is our limited string expression evaluator offset = Util.getInt(interp, bytes.Substring(3)); return(endValue + offset); } else { throw new TclException(interp, "bad index \"" + bytes + "\": must be integer or end?-integer?" + checkBadOctal(interp, bytes.Substring(3))); } }
/// <summary> See Tcl user documentation for details.</summary> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int code; if (argv.Length > 2) { throw new TclNumArgsException(interp, 1, argv, "?returnCode?"); } if (argv.Length == 2) { code = TclInteger.get(interp, argv[1]); } else { code = 0; } return(TCL.CompletionCode.EXIT); }
/// <summary> See Tcl user documentation for details.</summary> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int code; if (argv.Length > 2) { throw new TclNumArgsException(interp, 1, argv, "?returnCode?"); } if (argv.Length == 2) { code = TclInteger.get(interp, argv[1]); } else { code = 0; } System.Environment.Exit(code); return(TCL.CompletionCode.RETURN); }
private static void setDoubleFromAny(Interp interp, TclObject tobj) { InternalRep 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()); } }
/// <summary> This procedure is invoked to process the "catch" 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 wrong number of arguments. /// </exception> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { if (argv.Length != 2 && argv.Length != 3) { throw new TclNumArgsException(interp, 1, argv, "command ?varName?"); } TclObject result; TCL.CompletionCode code = TCL.CompletionCode.OK; try { interp.eval(argv[1], 0); } catch (TclException e) { code = e.getCompletionCode(); } result = interp.getResult(); if (argv.Length == 3) { try { interp.setVar(argv[2], result, 0); } catch (TclException e) { throw new TclException(interp, "couldn't save command result in variable"); } } interp.resetResult(); interp.setResult(TclInteger.newInstance((int)code)); return(TCL.CompletionCode.RETURN); }
/// <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) { InternalRep 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()); } }
/// <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); }
public static bool Tcl_GetIntFromObj(Interp interp, TclObject to, ref int value) { try { value = TclInteger.get(interp, to); return(false); } catch { return(true); } }
/// <summary> This procedure is invoked to process the "scan" Tcl command. /// See the user documentation for details on what it does. /// /// Each iteration of the cmdProc compares the scanArr's current index to /// the frmtArr's index. If the chars are equal then the indicies are /// incremented. If a '%' is found in the frmtArr, the formatSpecifier /// is parced from the frmtArr, the corresponding value is extracted from /// the scanArr, and that value is set in the Tcl Interp. /// /// If the chars are not equal, or the conversion fails, the boolean /// scanArrDone is set to true, indicating the scanArr is not to be /// parced and no new values are to be set. However the frmtArr is still /// parced because of the priority of error messages. In the C version /// of Tcl, bad format specifiers throw errors before incorrect argument /// input or other scan errors. Thus we need to parce the entire frmtArr /// to verify correct formating. This is dumb and inefficient but it is /// consistent w/ the current C-version of Tcl. /// </summary> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { if (argv.Length < 3) { throw new TclNumArgsException(interp, 1, argv, "string format ?varName varName ...?"); } ; StrtoulResult strul; // Return value for parcing the scanArr when // extracting integers/longs StrtodResult strd;; // Return value for parcing the scanArr when // extracting doubles char[] scanArr; // Array containing parce info char[] frmtArr; // Array containing info on how to // parse the scanArr int scanIndex; // Index into the scan array int frmtIndex; // Index into the frmt array int tempIndex; // Temporary index holder int argIndex; // Index into the current arg int width; // Stores the user specified result width int base_; // Base of the integer being converted int numUnMatched; // Number of fields actually set. int numMatched; // Number of fields actually matched. int negateScan; // Mult by result, set to -1 if true int i; // Generic variable char ch; // Generic variable bool cont; // Used in loops to indicate when to stop bool scanOK; // Set to false if strtoul/strtod fails bool scanArrDone; // Set to false if strtoul/strtod fails bool widthFlag; // True is width is specified bool discardFlag; // If a "%*" is in the formatString dont // write output to arg scanArr = argv[1].ToString().ToCharArray(); frmtArr = argv[2].ToString().ToCharArray(); width = base_ = numMatched = numUnMatched = 0; scanIndex = frmtIndex = 0; scanOK = true; scanArrDone = false; argIndex = 3; // Skip all (if any) of the white space before getting to a char frmtIndex = skipWhiteSpace(frmtArr, frmtIndex); // Search through the frmtArr. If the next char is a '%' parse the // next chars and determine the type (if any) of the format specifier. // If the scanArr has been fully searched, do nothing but incerment // "numUnMatched". The reason to continue the frmtArr search is for // consistency in output. Previously scan format errors were reported // before arg input mismatch, so this maintains the same level of error // checking. while (frmtIndex < frmtArr.Length) { discardFlag = widthFlag = false; negateScan = 1; cont = true; // Parce the format array and read in the correct value from the // scan array. When the correct value is retrieved, set the // variable (from argv) in the interp. if (frmtArr[frmtIndex] == '%') { frmtIndex++; checkOverFlow(interp, frmtArr, frmtIndex); // Two '%'s in a row, do nothing... if (frmtArr[frmtIndex] == '%') { frmtIndex++; scanIndex++; continue; } // Check for a discard field flag if (frmtArr[frmtIndex] == '*') { discardFlag = true; frmtIndex++; checkOverFlow(interp, frmtArr, frmtIndex); } // Check for a width field and accept the 'h', 'l', 'L' // characters, but do nothing with them. // // Note: The order of the width specifier and the other // chars is unordered, so we need to iterate until all // of the specifiers are identified. while (cont) { cont = false; switch (frmtArr[frmtIndex]) { case 'h': case 'l': case 'L': { // Just ignore these values frmtIndex++; cont = true; break; } default: { if (System.Char.IsDigit(frmtArr[frmtIndex])) { strul = Util.strtoul(new string(frmtArr), frmtIndex, base_); frmtIndex = strul.index; width = (int)strul.value; widthFlag = true; cont = true; } } break; } checkOverFlow(interp, frmtArr, frmtIndex); } // On all conversion specifiers except 'c', move the // scanIndex to the next non-whitespace. ch = frmtArr[frmtIndex]; if ((ch != 'c') && (ch != '[') && !scanArrDone) { scanIndex = skipWhiteSpace(scanArr, scanIndex); } if (scanIndex >= scanArr.Length) { scanArrDone = true; } if ((scanIndex < scanArr.Length) && (ch != 'c') && (ch != '[')) { // Since strtoul dosent take signed numbers, make the // value positive and store the sign. if (scanArr[scanIndex] == '-') { negateScan = -1; scanIndex++; width--; } else if (scanArr[scanIndex] == '+') { scanIndex++; width--; } // The width+scanIndex might be greater than // the scanArr so we need to re-adjust when this // happens. if (widthFlag && (width + scanIndex > scanArr.Length)) { width = scanArr.Length - scanIndex; } } if (scanIndex >= scanArr.Length) { scanArrDone = true; } // Foreach iteration we want strul and strd to be // null since we error check on this case. strul = null; strd = null; switch (ch) { case 'd': case 'o': case 'x': { if (!scanArrDone) { if (ch == 'd') { base_ = 10; } else if (ch == 'o') { base_ = 8; } else { base_ = 16; } // If the widthFlag is set then convert only // "width" characters to an ascii representation, // else read in until the end of the integer. The // scanIndex is moved to the point where we stop // reading in. if (widthFlag) { strul = Util.strtoul(new string(scanArr, 0, width + scanIndex), scanIndex, base_); } else { strul = Util.strtoul(new string(scanArr), scanIndex, base_); } if (strul.errno != 0) { scanOK = false; break; } scanIndex = strul.index; if (!discardFlag) { i = (int)strul.value * negateScan; if (argIndex == argv.Length) { numMatched--; } else { testAndSetVar(interp, argv, argIndex++, TclInteger.newInstance(i)); } } } break; } case 'c': { if (widthFlag) { errorCharFieldWidth(interp); } if (!discardFlag && !scanArrDone) { testAndSetVar(interp, argv, argIndex++, TclInteger.newInstance(scanArr[scanIndex++])); } break; } case 's': { if (!scanArrDone) { // If the widthFlag is set then read only "width" // characters into the string, else read in until // the first whitespace or endArr is found. The // scanIndex is moved to the point where we stop // reading in. tempIndex = scanIndex; if (!widthFlag) { width = scanArr.Length; } for (i = 0; (scanIndex < scanArr.Length) && (i < width); i++) { ch = scanArr[scanIndex]; if ((ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t') || (ch == '\f')) { break; } scanIndex++; } if (!discardFlag) { string str = new string(scanArr, tempIndex, scanIndex - tempIndex); testAndSetVar(interp, argv, argIndex++, TclString.newInstance(str)); } } break; } case 'e': case 'f': case 'g': { if (!scanArrDone) { // If the wisthFlag is set then read only "width" // characters into the string, else read in until // the first whitespace or endArr is found. The // scanIndex is moved to the point where we stop // reading in. if (widthFlag) { strd = Util.strtod(new string(scanArr, 0, width + scanIndex), scanIndex); } else { strd = Util.strtod(new string(scanArr), scanIndex); } if (strd.errno != 0) { scanOK = false; break; } scanIndex = strd.index; if (!discardFlag) { double d = strd.value * negateScan; testAndSetVar(interp, argv, argIndex++, TclDouble.newInstance(d)); } } break; } case '[': { bool charMatchFound = false; bool charNotMatch = false; char[] tempArr; int startIndex; int endIndex; string unmatched = "unmatched [ in format string"; if ((++frmtIndex) >= frmtArr.Length) { throw new TclException(interp, unmatched); } if (frmtArr[frmtIndex] == '^') { charNotMatch = true; frmtIndex += 2; } else { frmtIndex++; } tempIndex = frmtIndex - 1; if (frmtIndex >= frmtArr.Length) { throw new TclException(interp, unmatched); } // Extract the list of chars for matching. while (frmtArr[frmtIndex] != ']') { if ((++frmtIndex) >= frmtArr.Length) { throw new TclException(interp, unmatched); } } tempArr = new string(frmtArr, tempIndex, frmtIndex - tempIndex).ToCharArray(); startIndex = scanIndex; if (charNotMatch) { // Format specifier contained a '^' so interate // until one of the chars in tempArr is found. while (scanOK && !charMatchFound) { if (scanIndex >= scanArr.Length) { scanOK = false; break; } for (i = 0; i < tempArr.Length; i++) { if (tempArr[i] == scanArr[scanIndex]) { charMatchFound = true; break; } } if (widthFlag && ((scanIndex - startIndex) >= width)) { break; } if (!charMatchFound) { scanIndex++; } } } else { // Iterate until the char in the scanArr is not // in the tempArr. charMatchFound = true; while (scanOK && charMatchFound) { if (scanIndex >= scanArr.Length) { scanOK = false; break; } charMatchFound = false; for (i = 0; i < tempArr.Length; i++) { if (tempArr[i] == scanArr[scanIndex]) { charMatchFound = true; break; } } if (widthFlag && (scanIndex - startIndex) >= width) { break; } if (charMatchFound) { scanIndex++; } } } // Indicates nothing was found. endIndex = scanIndex - startIndex; if (endIndex <= 0) { scanOK = false; break; } if (!discardFlag) { string str = new string(scanArr, startIndex, endIndex); testAndSetVar(interp, argv, argIndex++, TclString.newInstance(str)); } break; } default: { errorBadField(interp, ch); } break; } // As long as the scan was successful (scanOK), the format // specifier did not contain a '*' (discardFlag), and // we are not at the end of the scanArr (scanArrDone); // increment the num of vars set in the interp. Otherwise // increment the number of valid format specifiers. if (scanOK && !discardFlag && !scanArrDone) { numMatched++; } else if ((scanArrDone || !scanOK) && !discardFlag) { numUnMatched++; } frmtIndex++; } else if (scanIndex < scanArr.Length && scanArr[scanIndex] == frmtArr[frmtIndex]) { // No '%' was found, but the characters matched scanIndex++; frmtIndex++; } else { // No '%' found and the characters int frmtArr & scanArr // did not match. frmtIndex++; } } // The numMatched is the return value: a count of the num of vars set. // While the numUnMatched is the number of formatSpecifiers that // passed the parsing stage, but did not match anything in the scanArr. if ((numMatched + numUnMatched) != (argv.Length - 3)) { errorDiffVars(interp); } interp.setResult(TclInteger.newInstance(numMatched)); return(TCL.CompletionCode.RETURN); }
/// <summary> This procedure is invoked to process the "open" 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 pipeline = false; /* True if opening pipeline chan */ int prot = 438; /* Final rdwr permissions of file */ int modeFlags = TclIO.RDONLY; /* Rdwr mode for the file. See the * TclIO class for more info on the * valid modes */ if ((argv.Length < 2) || (argv.Length > 4)) { throw new TclNumArgsException(interp, 1, argv, "fileName ?access? ?permissions?"); } if (argv.Length > 2) { TclObject mode = argv[2]; string modeStr = mode.ToString(); int len = modeStr.Length; // This "r+1" hack is just to get a test case to pass if ((len == 0) || (modeStr.StartsWith("r+") && len >= 3)) { throw new TclException(interp, "illegal access mode \"" + modeStr + "\""); } if (len < 3) { switch (modeStr[0]) { case 'r': { if (len == 1) { modeFlags = TclIO.RDONLY; break; } else if (modeStr[1] == '+') { modeFlags = TclIO.RDWR; break; } } goto case 'w'; case 'w': { FileInfo f = FileUtil.getNewFileObj(interp, argv[1].ToString()); bool tmpBool; if (File.Exists(f.FullName)) { tmpBool = true; } else { tmpBool = Directory.Exists(f.FullName); } if (tmpBool) { bool tmpBool2; try { if (File.Exists(f.FullName)) { File.SetAttributes(f.FullName, FileAttributes.Normal); File.Delete(f.FullName); tmpBool2 = true; } else if (Directory.Exists(f.FullName)) { Directory.Delete(f.FullName); tmpBool2 = true; } else { tmpBool2 = false; } } // ATK added because .NET do not allow often to delete // files used by another process catch (System.IO.IOException e) { throw new TclException(interp, "cannot open file: " + argv[1].ToString()); } bool generatedAux = tmpBool2; } if (len == 1) { modeFlags = (TclIO.WRONLY | TclIO.CREAT); break; } else if (modeStr[1] == '+') { modeFlags = (TclIO.RDWR | TclIO.CREAT); break; } } goto case 'a'; case 'a': { if (len == 1) { modeFlags = (TclIO.WRONLY | TclIO.APPEND); break; } else if (modeStr[1] == '+') { modeFlags = (TclIO.RDWR | TclIO.CREAT | TclIO.APPEND); break; } } goto default; default: { throw new TclException(interp, "illegal access mode \"" + modeStr + "\""); } } } else { modeFlags = 0; bool gotRorWflag = false; int mlen = TclList.getLength(interp, mode); for (int i = 0; i < mlen; i++) { TclObject marg = TclList.index(interp, mode, i); if (marg.ToString().Equals("RDONLY")) { modeFlags |= TclIO.RDONLY; gotRorWflag = true; } else { if (marg.ToString().Equals("WRONLY")) { modeFlags |= TclIO.WRONLY; gotRorWflag = true; } else { if (marg.ToString().Equals("RDWR")) { modeFlags |= TclIO.RDWR; gotRorWflag = true; } else { if (marg.ToString().Equals("APPEND")) { modeFlags |= TclIO.APPEND; } else { if (marg.ToString().Equals("CREAT")) { modeFlags |= TclIO.CREAT; } else { if (marg.ToString().Equals("EXCL")) { modeFlags |= TclIO.EXCL; } else { if (marg.ToString().Equals("TRUNC")) { modeFlags |= TclIO.TRUNC; } else { throw new TclException(interp, "invalid access mode \"" + marg.ToString() + "\": must be RDONLY, WRONLY, RDWR, APPEND, " + "CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC"); } } } } } } } } if (!gotRorWflag) { throw new TclException(interp, "access mode must include either RDONLY, WRONLY, or RDWR"); } } } if (argv.Length == 4) { prot = TclInteger.get(interp, argv[3]); throw new TclException(interp, "setting permissions not implemented yet"); } if ((argv[1].ToString().Length > 0) && (argv[1].ToString()[0] == '|')) { pipeline = true; throw new TclException(interp, "pipes not implemented yet"); } /* * Open the file or create a process pipeline. */ if (!pipeline) { try { FileChannel file = new FileChannel(); file.open(interp, argv[1].ToString(), modeFlags); TclIO.registerChannel(interp, file); interp.setResult(file.ChanName); } catch (System.IO.IOException e) { throw new TclException(interp, "cannot open file: " + argv[1].ToString()); } } else { /* * Pipeline code here... */ } return(TCL.CompletionCode.RETURN); }
/// <summary> This procedure is invoked to process the "fconfigure" 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) || (((argv.Length % 2) == 1) && (argv.Length != 3))) { throw new TclNumArgsException(interp, 1, argv, "channelId ?optionName? ?value? ?optionName value?..."); } chan = TclIO.getChannel(interp, argv[1].ToString()); if (chan == null) { throw new TclException(interp, "can not find channel named \"" + argv[1].ToString() + "\""); } if (argv.Length == 2) { // return list of all name/value pairs for this channelId TclObject list = TclList.newInstance(); TclList.append(interp, list, TclString.newInstance("-blocking")); TclList.append(interp, list, TclBoolean.newInstance(chan.Blocking)); TclList.append(interp, list, TclString.newInstance("-buffering")); TclList.append(interp, list, TclString.newInstance(TclIO.getBufferingString(chan.Buffering))); TclList.append(interp, list, TclString.newInstance("-buffersize")); TclList.append(interp, list, TclInteger.newInstance(chan.BufferSize)); // -encoding TclList.append(interp, list, TclString.newInstance("-encoding")); System.Text.Encoding javaEncoding = chan.Encoding; string tclEncoding; if ((System.Object)javaEncoding == null) { tclEncoding = "binary"; } else { tclEncoding = EncodingCmd.getTclName(javaEncoding); } TclList.append(interp, list, TclString.newInstance(tclEncoding)); // -eofchar TclList.append(interp, list, TclString.newInstance("-eofchar")); if (chan.ReadOnly) { char eofChar = chan.InputEofChar; TclList.append(interp, list, (eofChar == 0) ? TclString.newInstance("") : TclString.newInstance(eofChar)); } else if (chan.WriteOnly) { char eofChar = chan.OutputEofChar; TclList.append(interp, list, (eofChar == 0) ? TclString.newInstance("") : TclString.newInstance(eofChar)); } else if (chan.ReadWrite) { char inEofChar = chan.InputEofChar; char outEofChar = chan.OutputEofChar; TclObject eofchar_pair = TclList.newInstance(); TclList.append(interp, eofchar_pair, (inEofChar == 0) ? TclString.newInstance("") : TclString.newInstance(inEofChar)); TclList.append(interp, eofchar_pair, (outEofChar == 0) ? TclString.newInstance("") : TclString.newInstance(outEofChar)); TclList.append(interp, list, eofchar_pair); } else { // Not readable or writeable, do nothing } // -translation TclList.append(interp, list, TclString.newInstance("-translation")); if (chan.ReadOnly) { TclList.append(interp, list, TclString.newInstance(TclIO.getTranslationString(chan.InputTranslation))); } else if (chan.WriteOnly) { TclList.append(interp, list, TclString.newInstance(TclIO.getTranslationString(chan.OutputTranslation))); } else if (chan.ReadWrite) { TclObject translation_pair = TclList.newInstance(); TclList.append(interp, translation_pair, TclString.newInstance(TclIO.getTranslationString(chan.InputTranslation))); TclList.append(interp, translation_pair, TclString.newInstance(TclIO.getTranslationString(chan.OutputTranslation))); TclList.append(interp, list, translation_pair); } else { // Not readable or writeable, do nothing } interp.setResult(list); } if (argv.Length == 3) { // return value for supplied name int index = TclIndex.get(interp, argv[2], validCmds, "option", 0); switch (index) { case OPT_BLOCKING: { // -blocking interp.setResult(chan.Blocking); break; } case OPT_BUFFERING: { // -buffering interp.setResult(TclIO.getBufferingString(chan.Buffering)); break; } case OPT_BUFFERSIZE: { // -buffersize interp.setResult(chan.BufferSize); break; } case OPT_ENCODING: { // -encoding System.Text.Encoding javaEncoding = chan.Encoding; if ((System.Object)javaEncoding == null) { interp.setResult("binary"); } else { interp.setResult(EncodingCmd.getTclName(javaEncoding)); } break; } case OPT_EOFCHAR: { // -eofchar if (chan.ReadOnly) { char eofChar = chan.InputEofChar; interp.setResult((eofChar == 0) ? TclString.newInstance("") : TclString.newInstance(eofChar)); } else if (chan.WriteOnly) { char eofChar = chan.OutputEofChar; interp.setResult((eofChar == 0) ? TclString.newInstance("") : TclString.newInstance(eofChar)); } else if (chan.ReadWrite) { char inEofChar = chan.InputEofChar; char outEofChar = chan.OutputEofChar; TclObject eofchar_pair = TclList.newInstance(); TclList.append(interp, eofchar_pair, (inEofChar == 0) ? TclString.newInstance("") : TclString.newInstance(inEofChar)); TclList.append(interp, eofchar_pair, (outEofChar == 0) ? TclString.newInstance("") : TclString.newInstance(outEofChar)); interp.setResult(eofchar_pair); } else { // Not readable or writeable, do nothing } break; } case OPT_TRANSLATION: { // -translation if (chan.ReadOnly) { interp.setResult(TclIO.getTranslationString(chan.InputTranslation)); } else if (chan.WriteOnly) { interp.setResult(TclIO.getTranslationString(chan.OutputTranslation)); } else if (chan.ReadWrite) { TclObject translation_pair = TclList.newInstance(); TclList.append(interp, translation_pair, TclString.newInstance(TclIO.getTranslationString(chan.InputTranslation))); TclList.append(interp, translation_pair, TclString.newInstance(TclIO.getTranslationString(chan.OutputTranslation))); interp.setResult(translation_pair); } else { // Not readable or writeable, do nothing } break; } default: { throw new TclRuntimeError("Fconfigure.cmdProc() error: " + "incorrect index returned from TclIndex.get()"); } } } for (int i = 3; i < argv.Length; i += 2) { // Iterate through the list setting the name with the // corresponding value. int index = TclIndex.get(interp, argv[i - 1], validCmds, "option", 0); switch (index) { case OPT_BLOCKING: { // -blocking chan.Blocking = TclBoolean.get(interp, argv[i]); break; } case OPT_BUFFERING: { // -buffering int id = TclIO.getBufferingID(argv[i].ToString()); if (id == -1) { throw new TclException(interp, "bad value for -buffering: must be " + "one of full, line, or none"); } chan.Buffering = id; break; } case OPT_BUFFERSIZE: { // -buffersize chan.BufferSize = TclInteger.get(interp, argv[i]); break; } case OPT_ENCODING: { // -encoding string tclEncoding = argv[i].ToString(); if (tclEncoding.Equals("") || tclEncoding.Equals("binary")) { chan.Encoding = null; } else { System.Text.Encoding javaEncoding = EncodingCmd.getJavaName(tclEncoding); if ((System.Object)javaEncoding == null) { throw new TclException(interp, "unknown encoding \"" + tclEncoding + "\""); } chan.Encoding = javaEncoding; } break; } case OPT_EOFCHAR: { // -eofchar TclList.setListFromAny(interp, argv[i]); int length = TclList.getLength(interp, argv[i]); if (length > 2) { throw new TclException(interp, "bad value for -eofchar: " + "should be a list of zero, one, or two elements"); } char inputEofChar, outputEofChar; string s; if (length == 0) { inputEofChar = outputEofChar = (char)(0); } else if (length == 1) { s = TclList.index(interp, argv[i], 0).ToString(); inputEofChar = outputEofChar = s[0]; } else { s = TclList.index(interp, argv[i], 0).ToString(); inputEofChar = s[0]; s = TclList.index(interp, argv[i], 1).ToString(); outputEofChar = s[0]; } chan.InputEofChar = inputEofChar; chan.OutputEofChar = outputEofChar; break; } case OPT_TRANSLATION: { // -translation TclList.setListFromAny(interp, argv[i]); int length = TclList.getLength(interp, argv[i]); if (length < 1 || length > 2) { throw new TclException(interp, "bad value for -translation: " + "must be a one or two element list"); } string inputTranslationArg, outputTranslationArg; int inputTranslation, outputTranslation; if (length == 2) { inputTranslationArg = TclList.index(interp, argv[i], 0).ToString(); inputTranslation = TclIO.getTranslationID(inputTranslationArg); outputTranslationArg = TclList.index(interp, argv[i], 1).ToString(); outputTranslation = TclIO.getTranslationID(outputTranslationArg); } else { outputTranslationArg = inputTranslationArg = argv[i].ToString(); outputTranslation = inputTranslation = TclIO.getTranslationID(outputTranslationArg); } if ((inputTranslation == -1) || (outputTranslation == -1)) { throw new TclException(interp, "bad value for -translation: " + "must be one of auto, binary, cr, lf, " + "crlf, or platform"); } if (outputTranslation == TclIO.TRANS_AUTO) { outputTranslation = TclIO.TRANS_PLATFORM; } if (chan.ReadOnly) { chan.InputTranslation = inputTranslation; if (inputTranslationArg.Equals("binary")) { chan.Encoding = null; } } else if (chan.WriteOnly) { chan.OutputTranslation = outputTranslation; if (outputTranslationArg.Equals("binary")) { chan.Encoding = null; } } else if (chan.ReadWrite) { chan.InputTranslation = inputTranslation; chan.OutputTranslation = outputTranslation; if (inputTranslationArg.Equals("binary") || outputTranslationArg.Equals("binary")) { chan.Encoding = null; } } else { // Not readable or writeable, do nothing } break; } default: { throw new TclRuntimeError("Fconfigure.cmdProc() error: " + "incorrect index returned from TclIndex.get()"); } } } return(TCL.CompletionCode.RETURN); }
public TclObject get() { TclObject obj; TclToken token; string typeString; int nextIndex; string cmd; int i; System.Diagnostics.Debug.WriteLine("Entered TclParse.get()"); System.Diagnostics.Debug.WriteLine("numTokens is " + numTokens); obj = TclList.newInstance(); try { if (commentSize > 0) { TclList.append(interp, obj, TclString.newInstance(new string( inString, commentStart, commentSize ))); } else { TclList.append(interp, obj, TclString.newInstance("-")); } if (commandStart >= (endIndex + 1)) { commandStart = endIndex; } cmd = new string( inString, commandStart, commandSize ); TclList.append(interp, obj, TclString.newInstance(cmd)); TclList.append(interp, obj, TclInteger.newInstance(numWords)); for (i = 0; i < numTokens; i++) { System.Diagnostics.Debug.WriteLine("processing token " + i); token = tokenList[i]; switch (token.type) { case Parser.TCL_TOKEN_WORD: typeString = "word"; break; case Parser.TCL_TOKEN_SIMPLE_WORD: typeString = "simple"; break; case Parser.TCL_TOKEN_EXPAND_WORD: typeString = "expand"; break; case Parser.TCL_TOKEN_TEXT: typeString = "text"; break; case Parser.TCL_TOKEN_BS: typeString = "backslash"; break; case Parser.TCL_TOKEN_COMMAND: typeString = "command"; break; case Parser.TCL_TOKEN_VARIABLE: typeString = "variable"; break; default: typeString = "??"; break; } System.Diagnostics.Debug.WriteLine("typeString is " + typeString); TclList.append(interp, obj, TclString.newInstance(typeString)); TclList.append(interp, obj, TclString.newInstance(token.TokenString)); TclList.append(interp, obj, TclInteger.newInstance(token.numComponents)); } nextIndex = commandStart + commandSize; TclList.append(interp, obj, TclString.newInstance(new string( inString, nextIndex, (endIndex - nextIndex)))); } catch (TclException e) { // Do Nothing. } return(obj); }
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); }
public static void Tcl_BackgroundError(Interp interp) { interp.setErrorCode(TclInteger.newInstance(TCL_ERROR)); interp.addErrorInfo("Background Error"); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int i; Notifier notifier = (Notifier)interp.getNotifier(); Object info; if (assocData == null) { /* * Create the "after" information associated for this * interpreter, if it doesn't already exist. */ assocData = (AfterAssocData)interp.getAssocData("tclAfter"); if (assocData == null) { assocData = new AfterAssocData(this); interp.setAssocData("tclAfter", assocData); } } if (argv.Length < 2) { throw new TclNumArgsException(interp, 1, argv, "option ?arg arg ...?"); } /* * First lets see if the command was passed a number as the first argument. */ bool isNumber = false; int ms = 0; if (argv[1].InternalRep is TclInteger) { ms = TclInteger.get(interp, argv[1]); isNumber = true; } else { string s = argv[1].ToString(); if ((s.Length > 0) && (System.Char.IsDigit(s[0]))) { ms = TclInteger.get(interp, argv[1]); isNumber = true; } } if (isNumber) { if (ms < 0) { ms = 0; } if (argv.Length == 2) { /* * Sleep for at least the given milliseconds and return. */ long endTime = System.DateTime.Now.Ticks / 10000 + ms; while (true) { try { System.Threading.Thread.Sleep(ms); return(TCL.CompletionCode.RETURN); } catch (System.Threading.ThreadInterruptedException e) { /* * We got interrupted. Sleep again if we havn't slept * long enough yet. */ long sysTime = System.DateTime.Now.Ticks / 10000; if (sysTime >= endTime) { return(TCL.CompletionCode.RETURN); } ms = (int)(endTime - sysTime); continue; } } } TclObject cmd = getCmdObject(argv); cmd.preserve(); assocData.lastAfterId++; TimerInfo timerInfo = new TimerInfo(this, notifier, ms); timerInfo.interp = interp; timerInfo.command = cmd; timerInfo.id = assocData.lastAfterId; assocData.handlers.Add(timerInfo); interp.setResult("after#" + timerInfo.id); return(TCL.CompletionCode.RETURN); } /* * If it's not a number it must be a subcommand. */ int index; try { index = TclIndex.get(interp, argv[1], validOpts, "option", 0); } catch (TclException e) { throw new TclException(interp, "bad argument \"" + argv[1] + "\": must be cancel, idle, info, or a number"); } switch (index) { case OPT_CANCEL: if (argv.Length < 3) { throw new TclNumArgsException(interp, 2, argv, "id|command"); } TclObject arg = getCmdObject(argv); arg.preserve(); /* * Search the timer/idle handler by id or by command. */ info = null; for (i = 0; i < assocData.handlers.Count; i++) { Object obj = assocData.handlers[i]; if (obj is TimerInfo) { TclObject cmd = ((TimerInfo)obj).command; if ((cmd == arg) || cmd.ToString().Equals(arg.ToString())) { info = obj; break; } } else { TclObject cmd = ((IdleInfo)obj).command; if ((cmd == arg) || cmd.ToString().Equals(arg.ToString())) { info = obj; break; } } } if (info == null) { info = getAfterEvent(arg.ToString()); } arg.release(); /* * Cancel the handler. */ if (info != null) { if (info is TimerInfo) { ((TimerInfo)info).cancel(); ((TimerInfo)info).command.release(); } else { ((IdleInfo)info).cancel(); ((IdleInfo)info).command.release(); } SupportClass.VectorRemoveElement(assocData.handlers, info); } break; case OPT_IDLE: if (argv.Length < 3) { throw new TclNumArgsException(interp, 2, argv, "script script ..."); } TclObject cmd2 = getCmdObject(argv); cmd2.preserve(); assocData.lastAfterId++; IdleInfo idleInfo = new IdleInfo(this, notifier); idleInfo.interp = interp; idleInfo.command = cmd2; idleInfo.id = assocData.lastAfterId; assocData.handlers.Add(idleInfo); interp.setResult("after#" + idleInfo.id); break; case OPT_INFO: if (argv.Length == 2) { /* * No id is given. Return a list of current after id's. */ TclObject list = TclList.newInstance(); for (i = 0; i < assocData.handlers.Count; i++) { int id; Object obj = assocData.handlers[i]; if (obj is TimerInfo) { id = ((TimerInfo)obj).id; } else { id = ((IdleInfo)obj).id; } TclList.append(interp, list, TclString.newInstance("after#" + id)); } interp.resetResult(); interp.setResult(list); return(TCL.CompletionCode.RETURN); } if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "?id?"); } /* * Return command and type of the given after id. */ info = getAfterEvent(argv[2].ToString()); if (info == null) { throw new TclException(interp, "event \"" + argv[2] + "\" doesn't exist"); } TclObject list2 = TclList.newInstance(); TclList.append(interp, list2, ((info is TimerInfo)?((TimerInfo)info).command:((IdleInfo)info).command)); TclList.append(interp, list2, TclString.newInstance((info is TimerInfo)?"timer":"idle")); interp.resetResult(); interp.setResult(list2); break; } return(TCL.CompletionCode.RETURN); }
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. } }
/// <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); }
public static TclObject Tcl_NewIntObj(int value) { return(TclInteger.newInstance(value)); }