Example #1
0
        private Object GetAfterEvent(string inString) // Textual identifier for after event, such as "after#6".
        {
            if (!inString.StartsWith("after#"))
            {
                return(null);
            }
            StrtoulResult res = Util.Strtoul(inString, 6, 10);

            if (res.errno != 0)
            {
                return(null);
            }
            for (int i = 0; i < _assocData.Handlers.Count; i++)
            {
                Object obj = _assocData.Handlers[i];
                if (obj is TimerInfo)
                {
                    if (((TimerInfo)obj).Id == res.value)
                    {
                        return(obj);
                    }
                }
                else
                {
                    if (((IdleInfo)obj).Id == res.value)
                    {
                        return(obj);
                    }
                }
            }
            return(null);
        }
Example #2
0
        internal static long getLong(Interp interp, string s)
        {
            int  len = s.Length;
            bool sign;
            int  i = 0;

            // Skip any leading blanks.

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

            char c = s[i];

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

            StrtoulResult res = Strtoul(s, i, 0);

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

            if (sign)
            {
                return((long)(-res.value));
            }
            else
            {
                return((long)(res.value));
            }
        }
Example #3
0
        public void traceProc(Interp interp, string name1, string name2, TCL.VarFlag flags)
        {
            // If the variable is unset, then recreate the trace and restore
            // the default value of the format string.

            if ((flags & TCL.VarFlag.TRACE_UNSETS) != 0)
            {
                if (((flags & TCL.VarFlag.TRACE_DESTROYED) != 0) && ((flags & TCL.VarFlag.INTERP_DESTROYED) == 0))
                {
                    interp.TraceVar(name1, name2, new PrecTraceProc(), TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_READS | TCL.VarFlag.TRACE_UNSETS);
                    Util.precision = Util.DEFAULT_PRECISION;
                }
                return;
            }

            // When the variable is read, reset its value from our shared
            // value. This is needed in case the variable was modified in
            // some other interpreter so that this interpreter's value is
            // out of date.

            if ((flags & TCL.VarFlag.TRACE_READS) != 0)
            {
                interp.SetVar(name1, name2, TclInteger.NewInstance(Util.precision), flags & TCL.VarFlag.GLOBAL_ONLY);
                return;
            }

            // The variable is being written. Check the new value and disallow
            // it if it isn't reasonable.
            //
            // (ToDo) Disallow it if this is a safe interpreter (we don't want
            // safe interpreters messing up the precision of other
            // interpreters).

            TclObject tobj = null;

            try
            {
                tobj = interp.GetVar(name1, name2, (flags & TCL.VarFlag.GLOBAL_ONLY));
            }
            catch (TclException e)
            {
                // Do nothing when fixme does not exist.
            }

            string value;

            if (tobj != null)
            {
                value = tobj.ToString();
            }
            else
            {
                value = "";
            }

            StrtoulResult r = Util.Strtoul(value, 0, 10);

            if ((r == null) || (r.value <= 0) || (r.value > TCL_MAX_PREC) || (r.value > 100) || (r.Index == 0) || (r.Index != value.Length))
            {
                interp.SetVar(name1, name2, TclInteger.NewInstance(Util.precision), TCL.VarFlag.GLOBAL_ONLY);
                throw new TclException(interp, "improper value for precision");
            }

            Util.precision = (int)r.value;
        }