Ejemplo n.º 1
0
        public void traceProc(Interp interp, string part1, string part2, TCL.VarFlag flags)
        {
            if (((this.flags & flags) != 0) && ((flags & TCL.VarFlag.INTERP_DESTROYED) == 0))
            {
                StringBuilder sbuf = new StringBuilder(command);

                try
                {
                    Util.appendElement(interp, sbuf, part1);
                    if ((System.Object)part2 != null)
                    {
                        Util.appendElement(interp, sbuf, part2);
                    }
                    else
                    {
                        Util.appendElement(interp, sbuf, "");
                    }

                    if ((flags & TCL.VarFlag.TRACE_READS) != 0)
                    {
                        Util.appendElement(interp, sbuf, "r");
                    }
                    else if ((flags & TCL.VarFlag.TRACE_WRITES) != 0)
                    {
                        Util.appendElement(interp, sbuf, "w");
                    }
                    else if ((flags & TCL.VarFlag.TRACE_UNSETS) != 0)
                    {
                        Util.appendElement(interp, sbuf, "u");
                    }
                }
                catch (TclException e)
                {
                    throw new TclRuntimeError("unexpected TclException: " + e.Message, e);
                }

                // Execute the command.

                interp.Eval(sbuf.ToString(), 0);
            }
        }
Ejemplo n.º 2
0
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            int len;

            if (objv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, objv, "option [arg arg ...]");
            }
            int opt = TclIndex.Get(interp, objv[1], validCmds, "option", 0);

            switch (opt)
            {
            case OPT_VARIABLE:
            case OPT_VDELETE:
                if (objv.Length != 5)
                {
                    if (opt == OPT_VARIABLE)
                    {
                        throw new TclNumArgsException(interp, 1, objv, "variable name ops command");
                    }
                    else
                    {
                        throw new TclNumArgsException(interp, 1, objv, "vdelete name ops command");
                    }
                }

                TCL.VarFlag flags = 0;

                string ops = objv[3].ToString();
                len = ops.Length;
                {
                    for (int i = 0; i < len; i++)
                    {
                        switch (ops[i])
                        {
                        case 'r':
                            flags |= TCL.VarFlag.TRACE_READS;
                            break;

                        case 'w':
                            flags |= TCL.VarFlag.TRACE_WRITES;
                            break;

                        case 'u':
                            flags |= TCL.VarFlag.TRACE_UNSETS;
                            break;

                        default:
                            flags = 0;
                            goto check_ops_brk;
                        }
                    }
                }

check_ops_brk:
                ;


                if (flags == 0)
                {
                    throw new TclException(interp, "bad operations \"" + objv[3] + "\": should be one or more of rwu");
                }

                if (opt == OPT_VARIABLE)
                {
                    CmdTraceProc trace = new CmdTraceProc(objv[4].ToString(), flags);
                    Var.TraceVar(interp, objv[2], flags, trace);
                }
                else
                {
                    // Search through all of our traces on this variable to
                    // see if there's one with the given command.  If so, then
                    // delete the first one that matches.


                    ArrayList traces = Var.getTraces(interp, objv[2].ToString(), 0);
                    if (traces != null)
                    {
                        len = traces.Count;
                        for (int i = 0; i < len; i++)
                        {
                            TraceRecord rec = (TraceRecord)traces[i];

                            if (rec.trace is CmdTraceProc)
                            {
                                CmdTraceProc proc = (CmdTraceProc)rec.trace;

                                if (proc.flags == flags && proc.command.ToString().Equals(objv[4].ToString()))
                                {
                                    Var.UntraceVar(interp, objv[2], flags, proc);
                                    break;
                                }
                            }
                        }
                    }
                }
                break;


            case OPT_VINFO:
                if (objv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, objv, "name");
                }

                ArrayList traces2 = Var.getTraces(interp, objv[2].ToString(), 0);
                if (traces2 != null)
                {
                    len = traces2.Count;
                    TclObject list = TclList.NewInstance();
                    TclObject cmd  = null;
                    list.Preserve();

                    try
                    {
                        for (int i = 0; i < len; i++)
                        {
                            TraceRecord rec = (TraceRecord)traces2[i];

                            if (rec.trace is CmdTraceProc)
                            {
                                CmdTraceProc proc = (CmdTraceProc)rec.trace;
                                TCL.VarFlag  mode = proc.flags;
                                mode &= (TCL.VarFlag.TRACE_READS | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_UNSETS);
                                int modeInt = (int)mode;
                                modeInt /= ((int)TCL.VarFlag.TRACE_READS);

                                cmd = TclList.NewInstance();
                                TclList.Append(interp, cmd, opStr[modeInt]);
                                TclList.Append(interp, cmd, TclString.NewInstance(proc.command));
                                TclList.Append(interp, list, cmd);
                            }
                        }
                        interp.SetResult(list);
                    }
                    finally
                    {
                        list.Release();
                    }
                }
                break;
            }
            return(TCL.CompletionCode.RETURN);
        }
Ejemplo n.º 3
0
 internal CmdTraceProc(string cmd, TCL.VarFlag newFlags)
 {
     flags   = newFlags;
     command = cmd;
 }
Ejemplo n.º 4
0
		internal CmdTraceProc(string cmd, TCL.VarFlag newFlags)
		{
			flags = newFlags;
			command = cmd;
		}
Ejemplo n.º 5
0
 public void traceProc(Interp interp, string part1, string part2, TCL.VarFlag flags)
 // Mode flags: Should only be TCL.VarFlag.TRACE_WRITES.
 {
     done = true;
 }
Ejemplo n.º 6
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 var 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;
        }