Beispiel #1
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);
        }
Beispiel #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;
        }