コード例 #1
0
ファイル: EofCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #2
0
ファイル: TimeCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #3
0
ファイル: BgErrorMgr.cs プロジェクト: BclEx/GpuStructs
        private ArrayList Errors = new ArrayList(10); // A list of the pending background error handlers.

        internal BgErrorMgr(Interp i)
        {
            Interp = i;
            BgerrorCmdObj = TclString.NewInstance("bgerror");
            BgerrorCmdObj.Preserve();
            Errors = new ArrayList(10);
        }
コード例 #4
0
ファイル: BreakCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> This procedure is invoked to process the "break" Tcl command.
        /// See the user documentation for details on what it does.
        /// </summary>
        /// <exception cref=""> TclException is always thrown.
        /// </exception>

        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            if (argv.Length != 1)
            {
                throw new TclNumArgsException(interp, 1, argv, null);
            }
            throw new TclException(interp, null, TCL.CompletionCode.BREAK);
        }
コード例 #5
0
ファイル: QSort.cs プロジェクト: BclEx/GpuStructs
        /// <summary> This is a generic version of C.A.R Hoare's Quick Sort 
        /// algorithm.  This will handle arrays that are already
        /// sorted, and arrays with duplicate keys.<BR>
        /// 
        /// If you think of a one dimensional array as going from
        /// the lowest index on the left to the highest index on the right
        /// then the parameters to this function are lowest index or
        /// left and highest index or right.  The first time you call
        /// this function it will be with the parameters 0, a.length - 1.
        /// 
        /// </summary>
        /// <param name="a">      an integer array
        /// </param>
        /// <param name="lo0">    left boundary of array partition
        /// </param>
        /// <param name="hi0">    right boundary of array partition
        /// </param>
        private void quickSort(TclObject[] a, int lo0, int hi0)
        {
            int lo = lo0;
            int hi = hi0;
            TclObject mid;

            if (hi0 > lo0)
            {
                // Arbitrarily establishing partition element as the midpoint of
                // the array.
                mid = a[(lo0 + hi0) / 2];

                // loop through the array until indices cross
                while (lo <= hi)
                {
                    // find the first element that is greater than or equal to 
                    // the partition element starting from the left Index.

                    while ((lo < hi0) && (compare(a[lo], mid) < 0))
                    {
                        ++lo;
                    }

                    // find an element that is smaller than or equal to 
                    // the partition element starting from the right Index.

                    while ((hi > lo0) && (compare(a[hi], mid) > 0))
                    {
                        --hi;
                    }

                    // if the indexes have not crossed, swap
                    if (lo <= hi)
                    {
                        swap(a, lo, hi);
                        ++lo;
                        --hi;
                    }
                }

                // If the right index has not reached the left side of array
                // must now sort the left partition.

                if (lo0 < hi)
                {
                    quickSort(a, lo0, hi);
                }

                // If the left index has not reached the right side of array
                // must now sort the right partition.

                if (lo < hi0)
                {
                    quickSort(a, lo, hi0);
                }
            }
        }
コード例 #6
0
ファイル: LlengthCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: BgErrorMgr.cs プロジェクト: BclEx/GpuStructs
 // The interpreter in which this AssocData instance is registered in.
 public void Dispose(Interp interp)
 {
     for (int i = Errors.Count - 1; i >= 0; i--)
     {
         BgError bgError = (BgError)Errors[i];
         Errors.RemoveAt(i);
         bgError.Cancel();
         bgError.ErrorMsg.Release(); bgError.ErrorMsg = null;
         bgError.ErrorInfo.Release(); bgError.ErrorInfo = null;
         bgError.ErrorCode.Release(); bgError.ErrorCode = null;
     }
     BgerrorCmdObj.Release(); BgerrorCmdObj = null;
 }
コード例 #9
0
ファイル: test_mutex_c.cs プロジェクト: mdickson/opensim-libs
 static bool Tcl_GetIndexFromObjStruct(Interp interp, TclObject to, ConfigOption[] table, int s, string msg, int flags, ref int index)
 {
     try
     {
         for (index = 0; index < table.Length; index++)
         {
             if (table[index].zName == msg)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch { return(true); }
 }
コード例 #10
0
ファイル: ListCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> See Tcl user documentation for details.</summary>
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            TclObject list = TclList.NewInstance();

            list.Preserve();
            try
            {
                for (int i = 1; i < argv.Length; i++)
                    TclList.Append(interp, list, argv[i]);
                interp.SetResult(list);
            }
            finally
            {
                list.Release();
            }
            return TCL.CompletionCode.RETURN;
        }
コード例 #11
0
ファイル: IncrCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #12
0
ファイル: JoinCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> See Tcl user documentation for details.</summary>
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            string sep = null;

            if (argv.Length == 2)
            {
                sep = null;
            }
            else if (argv.Length == 3)
            {

                sep = argv[2].ToString();
            }
            else
            {
                throw new TclNumArgsException(interp, 1, argv, "list ?joinString?");
            }
            TclObject list = argv[1];
            int size = TclList.getLength(interp, list);

            if (size == 0)
            {
                interp.ResetResult();
                return TCL.CompletionCode.RETURN;
            }


            StringBuilder sbuf = new StringBuilder(TclList.index(interp, list, 0).ToString());

            for (int i = 1; i < size; i++)
            {
                if ((System.Object)sep == null)
                {
                    sbuf.Append(' ');
                }
                else
                {
                    sbuf.Append(sep);
                }

                sbuf.Append(TclList.index(interp, list, i).ToString());
            }
            interp.SetResult(sbuf.ToString());
            return TCL.CompletionCode.RETURN;
        }
コード例 #13
0
ファイル: ExitCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #14
0
ファイル: TraceCmd.cs プロジェクト: BclEx/GpuStructs
        /*
        *----------------------------------------------------------------------
        *
        * initOptStr --
        *
        *	This static method is called when the TraceCmd class is loaded
        *	into the VM. It initializes the opStr array.
        *
        * Results:
        *	Initial value for opStr.
        *
        * Side effects:
        *	The TclObjects stored in opStr are preserve()'ed.
        *
        *----------------------------------------------------------------------
        */

        private static TclObject[] initOptStr()
        {
            TclObject[] strings = new TclObject[8];
            strings[0] = TclString.NewInstance("error");
            strings[1] = TclString.NewInstance("r");
            strings[2] = TclString.NewInstance("w");
            strings[3] = TclString.NewInstance("rw");
            strings[4] = TclString.NewInstance("u");
            strings[5] = TclString.NewInstance("ru");
            strings[6] = TclString.NewInstance("wu");
            strings[7] = TclString.NewInstance("rwu");

            for (int i = 0; i < 8; i++)
            {
                strings[i].Preserve();
            }

            return strings;
        }
コード例 #15
0
ファイル: SetCmd.cs プロジェクト: BclEx/GpuStructs
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            bool debug;

            if (argv.Length == 2)
            {
                System.Diagnostics.Debug.WriteLine("getting value of \"" + argv[1].ToString() + "\"");

                interp.SetResult(interp.GetVar(argv[1], 0));
            }
            else if (argv.Length == 3)
            {
                System.Diagnostics.Debug.WriteLine("setting value of \"" + argv[1].ToString() + "\" to \"" + argv[2].ToString() + "\"");
                interp.SetResult(interp.SetVar(argv[1], argv[2], 0));
            }
            else
            {
                throw new TclNumArgsException(interp, 1, argv, "varName ?newValue?");
            }
            return TCL.CompletionCode.RETURN;
        }
コード例 #16
0
ファイル: TclDouble.cs プロジェクト: BclEx/GpuStructs
        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());
            }
        }
コード例 #17
0
ファイル: PwdCmd.cs プロジェクト: BclEx/GpuStructs
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            if (argv.Length != 1)
            {
                throw new TclNumArgsException(interp, 1, argv, null);
            }

            // Get the name of the working dir.

            string dirName = interp.getWorkingDir().ToString();

            // Java File Object methods use backslashes on Windows.
            // Convert them to forward slashes before returning the dirName to Tcl.

            if (JACL.PLATFORM == JACL.PLATFORM_WINDOWS)
            {
                dirName = dirName.Replace('\\', '/');
            }

            interp.SetResult(dirName);
            return TCL.CompletionCode.RETURN;
        }
コード例 #18
0
ファイル: UnsetCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> Tcl_UnsetObjCmd -> UnsetCmd.cmdProc
        /// 
        /// Unsets Tcl variable (s). See Tcl user documentation * for
        /// details.
        /// </summary>
        /// <exception cref=""> TclException If tries to unset a variable that does
        /// not exist.
        /// </exception>

        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            switch (objv.Length)
            {
                case 2:
                    interp.UnsetVar(objv[1], 0);
                    break;
                case 3:
                    for (int i = (objv[1].ToString() != "-nocomplain") ? 1 : 2; i < objv.Length; i++)
                    {
                        Var.UnsetVar(interp, objv[i].ToString(), 0);
                    }
                    break;
                default:
                    if (objv.Length < 2)
                    {
                        throw new TclNumArgsException(interp, 1, objv, "varName ?varName ...?");
                    }
                    break;
            }

            return TCL.CompletionCode.RETURN;
        }
コード例 #19
0
ファイル: UpdateCmd.cs プロジェクト: BclEx/GpuStructs
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            int flags;

            if (argv.Length == 1)
            {
                flags = TCL.ALL_EVENTS | TCL.DONT_WAIT;
            }
            else if (argv.Length == 2)
            {
                TclIndex.Get(interp, argv[1], validOpts, "option", 0);

                /*
                * Since we just have one valid option, if the above call returns
                * without an exception, we've got "idletasks" (or abreviations).
                */

                flags = TCL.IDLE_EVENTS | TCL.DONT_WAIT;
            }
            else
            {
                throw new TclNumArgsException(interp, 1, argv, "?idletasks?");
            }

            while (interp.GetNotifier().doOneEvent(flags) != 0)
            {
                /* Empty loop body */
            }

            /*
            * Must clear the interpreter's result because event handlers could
            * have executed commands.
            */

            interp.ResetResult();
            return TCL.CompletionCode.RETURN;
        }
コード例 #20
0
ファイル: EncodingCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> This procedure is invoked to process the "encoding" 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)
        {
            if (argv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, argv, "option ?arg ...?");
            }

            int index = TclIndex.Get(interp, argv[1], validCmds, "option", 0);

            switch (index)
            {

                case OPT_CONVERTTO:
                case OPT_CONVERTFROM:
                    {
                        string tclEncoding;
                        Encoding javaEncoding;
                        TclObject data;

                        if (argv.Length == 3)
                        {
                            tclEncoding = systemTclEncoding;
                            data = argv[2];
                        }
                        else if (argv.Length == 4)
                        {

                            tclEncoding = argv[2].ToString();
                            data = argv[3];
                        }
                        else
                        {
                            throw new TclNumArgsException(interp, 2, argv, "?encoding? data");
                        }

                        javaEncoding = getJavaName(tclEncoding);

                        if ((System.Object)javaEncoding == null)
                        {
                            throw new TclException(interp, "unknown encoding \"" + tclEncoding + "\"");
                        }

                        try
                        {
                            if (index == OPT_CONVERTFROM)
                            {
                                // Treat the string as binary data
                                byte[] bytes = TclByteArray.getBytes(interp, data);

                                // ATK
                                interp.SetResult(System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length));
                            }
                            else
                            {
                                // Store the result as binary data


                                // ATK byte[] bytes = data.ToString().getBytes(javaEncoding);
                                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data.ToString());
                                interp.SetResult(TclByteArray.NewInstance(bytes));
                            }
                        }
                        catch (IOException ex)
                        {
                            throw new TclRuntimeError("Encoding.cmdProc() error: " + "unsupported java encoding \"" + javaEncoding + "\"");
                        }

                        break;
                    }

                case OPT_NAMES:
                    {
                        if (argv.Length > 2)
                        {
                            throw new TclNumArgsException(interp, 2, argv, null);
                        }

                        TclObject list = TclList.NewInstance();
                        for (int i = 0; i < tclNames.Length; i++)
                        {
                            TclList.Append(interp, list, TclString.NewInstance(tclNames[i]));
                        }
                        interp.SetResult(list);
                        break;
                    }

                case OPT_SYSTEM:
                    {
                        if (argv.Length > 3)
                            throw new TclNumArgsException(interp, 2, argv, "?encoding?");

                        if (argv.Length == 2)
                        {
                            interp.SetResult(systemTclEncoding);
                        }
                        else
                        {

                            string tclEncoding = argv[2].ToString();
                            Encoding javaEncoding = getJavaName(tclEncoding);

                            if (javaEncoding == null)
                            {
                                throw new TclException(interp, "unknown encoding \"" + tclEncoding + "\"");
                            }

                            systemTclEncoding = tclEncoding;
                            systemJavaEncoding = javaEncoding;
                        }

                        break;
                    }

                default:
                    {
                        throw new TclRuntimeError("Encoding.cmdProc() error: " + "incorrect index returned from TclIndex.get()");
                    }

            }
            return TCL.CompletionCode.RETURN;
        }
コード例 #21
0
ファイル: TclDouble.cs プロジェクト: BclEx/GpuStructs
        public static void set(TclObject tobj, double d)
        // The new value for the object. 
        {
            tobj.invalidateStringRep();
            IInternalRep rep = tobj.InternalRep;

            if (rep is TclDouble)
            {
                TclDouble tdouble = (TclDouble)rep;
                tdouble.value = d;
            }
            else
            {
                tobj.InternalRep = new TclDouble(d);
            }
        }
コード例 #22
0
ファイル: ProcCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> 
        /// Tcl_ProcObjCmd -> ProcCmd.cmdProc
        /// 
        /// Creates a new Tcl procedure.
        /// 
        /// </summary>
        /// <param name="interp">the current interpreter.
        /// </param>
        /// <param name="objv">command arguments.
        /// </param>
        /// <exception cref=""> TclException If incorrect number of arguments.
        /// </exception>

        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            Procedure proc;
            string fullName, procName;
            NamespaceCmd.Namespace ns, altNs, cxtNs;
            ICommand cmd;
            StringBuilder ds;

            if (objv.Length != 4)
            {
                throw new TclNumArgsException(interp, 1, objv, "name args body");
            }

            // Determine the namespace where the procedure should reside. Unless
            // the command name includes namespace qualifiers, this will be the
            // current namespace.


            fullName = objv[1].ToString();

            // Java does not support passing an address so we pass
            // an array of size 1 and then assign arr[0] to the value
            NamespaceCmd.Namespace[] nsArr = new NamespaceCmd.Namespace[1];
            NamespaceCmd.Namespace[] altNsArr = new NamespaceCmd.Namespace[1];
            NamespaceCmd.Namespace[] cxtNsArr = new NamespaceCmd.Namespace[1];
            string[] procNameArr = new string[1];

            NamespaceCmd.getNamespaceForQualName(interp, fullName, null, 0, nsArr, altNsArr, cxtNsArr, procNameArr);

            // Get the values out of the arrays
            ns = nsArr[0];
            altNs = altNsArr[0];
            cxtNs = cxtNsArr[0];
            procName = procNameArr[0];

            if (ns == null)
            {
                throw new TclException(interp, "can't create procedure \"" + fullName + "\": unknown namespace");
            }
            if ((System.Object)procName == null)
            {
                throw new TclException(interp, "can't create procedure \"" + fullName + "\": bad procedure name");
            }
            // FIXME : could there be a problem with a command named ":command" ?
            if ((ns != NamespaceCmd.getGlobalNamespace(interp)) && ((System.Object)procName != null) && ((procName.Length > 0) && (procName[0] == ':')))
            {
                throw new TclException(interp, "can't create procedure \"" + procName + "\" in non-global namespace with name starting with \":\"");
            }

            //  Create the data structure to represent the procedure.

            proc = new Procedure(interp, ns, procName, objv[2], objv[3], interp.ScriptFile, interp.getArgLineNumber(3));

            // Now create a command for the procedure. This will initially be in
            // the current namespace unless the procedure's name included namespace
            // qualifiers. To create the new command in the right namespace, we
            // generate a fully qualified name for it.

            ds = new StringBuilder();
            if (ns != NamespaceCmd.getGlobalNamespace(interp))
            {
                ds.Append(ns.fullName);
                ds.Append("::");
            }
            ds.Append(procName);

            interp.CreateCommand(ds.ToString(), proc);

            // Now initialize the new procedure's cmdPtr field. This will be used
            // later when the procedure is called to determine what namespace the
            // procedure will run in. This will be different than the current
            // namespace if the proc was renamed into a different namespace.

            // FIXME : we do not handle renaming into another namespace correctly yet!
            //procPtr->cmdPtr = (Command *) cmd;

            return TCL.CompletionCode.RETURN;
        }
コード例 #23
0
ファイル: SwitchCmd.cs プロジェクト: BclEx/GpuStructs
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            int i, mode, body;
            bool matched;
            string inString;
            TclObject[] switchArgv = null;

            mode = EXACT;
            for (i = 1; i < argv.Length; i++)
            {

                if (!argv[i].ToString().StartsWith("-"))
                {
                    break;
                }
                int opt = TclIndex.Get(interp, argv[i], validCmds, "option", 1);
                if (opt == LAST)
                {
                    i++;
                    break;
                }
                else if (opt > LAST)
                {
                    throw new TclException(interp, "SwitchCmd.cmdProc: bad option " + opt + " index to validCmds");
                }
                else
                {
                    mode = opt;
                }
            }

            if (argv.Length - i < 2)
            {
                throw new TclNumArgsException(interp, 1, argv, "?switches? string pattern body ... ?default body?");
            }

            inString = argv[i].ToString();
            i++;

            // If all of the pattern/command pairs are lumped into a single
            // argument, split them out again.

            if (argv.Length - i == 1)
            {
                switchArgv = TclList.getElements(interp, argv[i]);
                i = 0;
            }
            else
            {
                switchArgv = argv;
            }

            for (; i < switchArgv.Length; i += 2)
            {
                if (i == (switchArgv.Length - 1))
                {
                    throw new TclException(interp, "extra switch pattern with no body");
                }

                // See if the pattern matches the string.

                matched = false;

                string pattern = switchArgv[i].ToString();

                if ((i == switchArgv.Length - 2) && pattern.Equals("default"))
                {
                    matched = true;
                }
                else
                {
                    switch (mode)
                    {

                        case EXACT:
                            matched = inString.Equals(pattern);
                            break;

                        case GLOB:
                            matched = Util.StringMatch(inString, pattern);
                            break;

                        case REGEXP:
                            matched = Util.regExpMatch(interp, inString, switchArgv[i]);
                            break;
                    }
                }
                if (!matched)
                {
                    continue;
                }

                // We've got a match.  Find a body to execute, skipping bodies
                // that are "-".

                for (body = i + 1; ; body += 2)
                {
                    if (body >= switchArgv.Length)
                    {

                        throw new TclException(interp, "no body specified for pattern \"" + switchArgv[i] + "\"");
                    }

                    if (!switchArgv[body].ToString().Equals("-"))
                    {
                        break;
                    }
                }

                try
                {
                    interp.Eval(switchArgv[body], 0);
                    return TCL.CompletionCode.RETURN;
                }
                catch (TclException e)
                {
                    if (e.GetCompletionCode() == TCL.CompletionCode.ERROR)
                    {

                        interp.AddErrorInfo("\n    (\"" + switchArgv[i] + "\" arm line " + interp._errorLine + ")");
                    }
                    throw;
                }
            }

            // Nothing matched:  return nothing.
            return TCL.CompletionCode.RETURN;
        }
コード例 #24
0
ファイル: TclDouble.cs プロジェクト: BclEx/GpuStructs
        public static double Get(Interp interp, TclObject tobj)
        {
            IInternalRep rep = tobj.InternalRep;
            TclDouble tdouble;

            if (!(rep is TclDouble))
            {
                setDoubleFromAny(interp, tobj);
                tdouble = (TclDouble)(tobj.InternalRep);
            }
            else
            {
                tdouble = (TclDouble)rep;
            }

            return tdouble.value;
        }
コード例 #25
0
ファイル: ScanCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> Called whenever the cmdProc wants to set an interp value.  
        /// This method <ol>
        /// <li> verifies that there exisits a varName from the argv array, 
        /// <li> that the variable either dosent exisit or is of type scalar
        /// <li> set the variable in interp if (1) and (2) are OK
        /// </ol>
        /// 
        /// </summary>
        /// <param name="interp">  - the Tcl interpreter
        /// </param>
        /// <param name="argv">    - the argument array
        /// </param>
        /// <param name="argIndex">- the current index into the argv array
        /// </param>
        /// <param name="tobj">    - the TclObject that the varName equals
        /// 
        /// </param>

        private static void testAndSetVar(Interp interp, TclObject[] argv, int argIndex, TclObject tobj)
        {
            if (argIndex < argv.Length)
            {
                try
                {

                    interp.SetVar(argv[argIndex].ToString(), tobj, 0);
                }
                catch (TclException e)
                {

                    throw new TclException(interp, "couldn't set variable \"" + argv[argIndex].ToString() + "\"");
                }
            }
            else
            {
                errorDiffVars(interp);
            }
        }
コード例 #26
0
ファイル: ScanCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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;
        }
コード例 #27
0
ファイル: IfCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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)
        {
            int i;
            bool value;

            i = 1;
            while (true)
            {
                /*
                * At this point in the loop, argv and argc refer to an
                * expression to test, either for the main expression or
                * an expression following an "elseif".  The arguments
                * after the expression must be "then" (optional) and a
                * script to execute if the expression is true.
                */

                if (i >= argv.Length)
                {

                    throw new TclException(interp, "wrong # args: no expression after \"" + argv[i - 1] + "\" argument");
                }
                try
                {

                    value = interp._expr.EvalBoolean(interp, argv[i].ToString());
                }
                catch (TclException e)
                {
                    switch (e.GetCompletionCode())
                    {

                        case TCL.CompletionCode.ERROR:
                            interp.AddErrorInfo("\n    (\"if\" test expression)");
                            break;
                    }
                    throw;
                }

                i++;

                if ((i < argv.Length) && (argv[i].ToString().Equals("then")))
                {
                    i++;
                }
                if (i >= argv.Length)
                {

                    throw new TclException(interp, "wrong # args: no script following \"" + argv[i - 1] + "\" argument");
                }
                if (value)
                {
                    try
                    {
                        interp.Eval(argv[i], 0);
                    }
                    catch (TclException e)
                    {
                        switch (e.GetCompletionCode())
                        {

                            case TCL.CompletionCode.ERROR:
                                interp.AddErrorInfo("\n    (\"if\" then script line " + interp._errorLine + ")");
                                break;
                        }
                        throw;
                    }
                    return TCL.CompletionCode.RETURN;
                }

                /*
                * The expression evaluated to false.  Skip the command, then
                * see if there is an "else" or "elseif" clause.
                */

                i++;
                if (i >= argv.Length)
                {
                    interp.ResetResult();
                    return TCL.CompletionCode.RETURN;
                }

                if (argv[i].ToString().Equals("elseif"))
                {
                    i++;
                    continue;
                }
                break;
            }

            /*
            * Couldn't find a "then" or "elseif" clause to execute.
            * Check now for an "else" clause.  We know that there's at
            * least one more argument when we get here.
            */


            if (argv[i].ToString().Equals("else"))
            {
                i++;
                if (i >= argv.Length)
                {
                    throw new TclException(interp, "wrong # args: no script following \"else\" argument");
                }
                else if (i != (argv.Length - 1))
                {
                    throw new TclException(interp, "wrong # args: extra words after \"else\" clause in " + "\"if\" command");
                }
            }
            try
            {
                interp.Eval(argv[i], 0);
            }
            catch (TclException e)
            {
                switch (e.GetCompletionCode())
                {

                    case TCL.CompletionCode.ERROR:
                        interp.AddErrorInfo("\n    (\"if\" else script line " + interp._errorLine + ")");
                        break;
                }
                throw;
            }
            return TCL.CompletionCode.RETURN;
        }
コード例 #28
0
ファイル: SubstCmd.cs プロジェクト: BclEx/GpuStructs
        /// <summary> This procedure is invoked to process the "subst" 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 # of args or invalid argument(s).
        /// </exception>

        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            int currentObjIndex, len, i;
            int objc = argv.Length - 1;
            bool doBackslashes = true;
            bool doCmds = true;
            bool doVars = true;
            StringBuilder result = new StringBuilder();
            string s;
            char c;

            for (currentObjIndex = 1; currentObjIndex < objc; currentObjIndex++)
            {

                if (!argv[currentObjIndex].ToString().StartsWith("-"))
                {
                    break;
                }
                int opt = TclIndex.Get(interp, argv[currentObjIndex], validCmds, "switch", 0);
                switch (opt)
                {

                    case OPT_NOBACKSLASHES:
                        doBackslashes = false;
                        break;

                    case OPT_NOCOMMANDS:
                        doCmds = false;
                        break;

                    case OPT_NOVARS:
                        doVars = false;
                        break;

                    default:
                        throw new TclException(interp, "SubstCmd.cmdProc: bad option " + opt + " index to cmds");

                }
            }
            if (currentObjIndex != objc)
            {
                throw new TclNumArgsException(interp, currentObjIndex, argv, "?-nobackslashes? ?-nocommands? ?-novariables? string");
            }

            /*
            * Scan through the string one character at a time, performing
            * command, variable, and backslash substitutions.
            */


            s = argv[currentObjIndex].ToString();
            len = s.Length;
            i = 0;
            while (i < len)
            {
                c = s[i];

                if ((c == '[') && doCmds)
                {
                    ParseResult res;
                    try
                    {
                        interp._evalFlags = Parser.TCL_BRACKET_TERM;
                        interp.Eval(s.Substring(i + 1, (len) - (i + 1)));
                        TclObject interp_result = interp.GetResult();
                        interp_result.Preserve();
                        res = new ParseResult(interp_result, i + interp._termOffset);
                    }
                    catch (TclException e)
                    {
                        i = e.errIndex + 1;
                        throw;
                    }
                    i = res.nextIndex + 2;

                    result.Append(res.Value.ToString());
                    res.Release();
                }
                else if (c == '\r')
                {
                    /*
                    * (ToDo) may not be portable on Mac
                    */

                    i++;
                }
                else if ((c == '$') && doVars)
                {
                    ParseResult vres = Parser.parseVar(interp, s.Substring(i, (len) - (i)));
                    i += vres.nextIndex;

                    result.Append(vres.Value.ToString());
                    vres.Release();
                }
                else if ((c == '\\') && doBackslashes)
                {
                    BackSlashResult bs = Tcl.Lang.Interp.backslash(s, i, len);
                    i = bs.NextIndex;
                    if (bs.IsWordSep)
                    {
                        break;
                    }
                    else
                    {
                        result.Append(bs.C);
                    }
                }
                else
                {
                    result.Append(c);
                    i++;
                }
            }

            interp.SetResult(result.ToString());
            return TCL.CompletionCode.RETURN;
        }
コード例 #29
0
ファイル: CallFrame.cs プロジェクト: BclEx/GpuStructs
 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());
 }
コード例 #30
0
ファイル: ClockCmd.cs プロジェクト: BclEx/GpuStructs
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            int clockVal; // Time value as seconds of epoch.
            string dateString; // Time value as string.
            int argIx; // Counter over arguments.
            string format = null; // User specified format string.
            bool useGmt = false; // User specified flag to use gmt.
            TclObject baseObj = null; // User specified raw value of baseClock.
            System.DateTime baseClock; // User specified time value.
            System.DateTime date; // Parsed date value.

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

            switch (cmd)
            {

                case CMD_CLICKS:
                    {
                        if (objv.Length > 3)
                        {
                            throw new TclNumArgsException(interp, 2, objv, "?-milliseconds?");
                        }
                        if (objv.Length == 3)
                        {
                            // We can safely ignore the -milliseconds options, since
                            // we measure the clicks in milliseconds anyway...
                            int clicksOpt = TclIndex.Get(interp, objv[2], clicksOpts, "switch", 0);
                        }
                        long millis = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                        int clicks = (int)(millis % System.Int32.MaxValue);
                        interp.SetResult(clicks);
                        break;
                    }


                case CMD_FORMAT:
                    {
                        if ((objv.Length < 3) || (objv.Length > 7))
                        {
                            throw new TclNumArgsException(interp, 2, objv, "clockval ?-format string? ?-gmt boolean?");
                        }
                        clockVal = TclInteger.Get(interp, objv[2]);

                        for (argIx = 3; argIx + 1 < objv.Length; argIx += 2)
                        {
                            int formatOpt = TclIndex.Get(interp, objv[argIx], formatOpts, "switch", 0);
                            switch (formatOpt)
                            {

                                case OPT_FORMAT_FORMAT:
                                    {

                                        format = objv[argIx + 1].ToString();
                                        break;
                                    }

                                case OPT_FORMAT_GMT:
                                    {
                                        useGmt = TclBoolean.get(interp, objv[argIx + 1]);
                                        break;
                                    }
                            }
                        }
                        if (argIx < objv.Length)
                        {
                            throw new TclNumArgsException(interp, 2, objv, "clockval ?-format string? ?-gmt boolean?");
                        }
                        FormatClock(interp, clockVal, useGmt, format);
                        break;
                    }


                case CMD_SCAN:
                    {
                        if ((objv.Length < 3) || (objv.Length > 7))
                        {
                            throw new TclNumArgsException(interp, 2, objv, "dateString ?-base clockValue? ?-gmt boolean?");
                        }

                        dateString = objv[2].ToString();

                        for (argIx = 3; argIx + 1 < objv.Length; argIx += 2)
                        {
                            int scanOpt = TclIndex.Get(interp, objv[argIx], scanOpts, "switch", 0);
                            switch (scanOpt)
                            {

                                case OPT_SCAN_BASE:
                                    {
                                        baseObj = objv[argIx + 1];
                                        break;
                                    }

                                case OPT_SCAN_GMT:
                                    {
                                        useGmt = TclBoolean.get(interp, objv[argIx + 1]);
                                        break;
                                    }
                            }
                        }
                        if (argIx < objv.Length)
                        {
                            throw new TclNumArgsException(interp, 2, objv, "clockval ?-format string? ?-gmt boolean?");
                        }
                        if (baseObj != null)
                        {
                            long seconds = TclInteger.Get(interp, baseObj);
                            baseClock = new System.DateTime((long)seconds * 10000 * 1000 + 621355968000000000);
                        }
                        else
                        {
                            baseClock = System.DateTime.Now;
                        }
                        try
                        {
                            date = GetDate(dateString, baseClock, useGmt);
                        }
                        catch (FormatException)
                        {
                            throw new TclException(interp, "unable to convert date-time string \"" + dateString + "\"");
                        }
                        long millis = (date.Ticks - 621355968000000000) / 10000;
                        int seconds2 = (int)(millis / 1000);
                        interp.SetResult(seconds2);
                        break;
                    }


                case CMD_SECONDS:
                    {
                        if (objv.Length != 2)
                        {
                            throw new TclNumArgsException(interp, 2, objv, null);
                        }
                        long millis = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                        int seconds = (int)(millis / 1000);
                        interp.SetResult(seconds);
                        break;
                    }
            }
            return TCL.CompletionCode.RETURN;
        }
コード例 #31
0
 internal void MakeReference(TclObject tobj)
 {
     throw new TclRuntimeError("This shouldn't be called");
 }
コード例 #32
0
ファイル: CallFrame.cs プロジェクト: BclEx/GpuStructs
 /// <summary>
 /// Creates a CallFrame. It changes the following variables:
 /// <ul>
 /// <li>this.caller</li>
 /// <li>this.callerVar</li>
 /// <li>interp.frame</li>
 /// <li>interp.varFrame</li>
 /// </ul>
 /// </summary>
 /// <param name="i">
 /// current interpreter.
 /// </param>
 /// <param name="proc">
 /// the procedure to invoke in this call frame.
 /// </param>
 /// <param name="objv">
 /// the arguments to the procedure.
 /// </param>
 /// <exception cref="">
 /// TclException if error occurs in parameter bindings.
 /// </exception>
 internal CallFrame(Interp i, Procedure proc, TclObject[] objv)
     : this(i)
 {
     try { Chain(proc, objv); }
     catch (TclException)
     {
         Dispose();
         throw;
     }
 }
コード例 #33
0
    /*
    ** 2009 July 17
    **
    ** The author disclaims copyright to this source code.  In place of
    ** a legal notice, here is a blessing:
    **
    **    May you do good and not evil.
    **    May you find forgiveness for yourself and forgive others.
    **    May you share freely, never taking more than you give.
    **
    *************************************************************************
    ** This file contains code to implement the "sqlite" test harness
    ** which runs TCL commands for testing the C#-SQLite port.
    **
    **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
    **  C#-SQLite is an independent reimplementation of the SQLite software library
    **
    *************************************************************************
    */
    public static void Main(string[] args)
    {
        // Array of command-line argument strings.
        {
            string fileName = null;

            // Create the interpreter. This will also create the built-in
            // Tcl commands.

            Interp interp = new Interp();

            // Make command-line arguments available in the Tcl variables "argc"
            // and "argv".  If the first argument doesn't start with a "-" then
            // strip it off and use it as the name of a script file to process.
            // We also set the argv0 and TCL.Tcl_interactive vars here.

            if ((args.Length > 0) && !(args[0].StartsWith("-")))
            {
                fileName = args[0];
            }

            TclObject argv = TclList.newInstance();
            argv.preserve();
            try
            {
                int i    = 0;
                int argc = args.Length;
                if ((System.Object)fileName == null)
                {
                    interp.setVar("argv0", "tcl.lang.Shell", TCL.VarFlag.GLOBAL_ONLY);
                    interp.setVar("tcl_interactive", "1", TCL.VarFlag.GLOBAL_ONLY);
                }
                else
                {
                    interp.setVar("argv0", fileName, TCL.VarFlag.GLOBAL_ONLY);
                    interp.setVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY);
                    i++;
                    argc--;
                }
                for ( ; i < args.Length; i++)
                {
                    TclList.append(interp, argv, TclString.newInstance(args[i]));
                }
                interp.setVar("argv", argv, TCL.VarFlag.GLOBAL_ONLY);
                interp.setVar("argc", System.Convert.ToString(argc), TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
                throw new TclRuntimeError("unexpected TclException: " + e.Message);
            }
            finally
            {
                argv.release();
            }

            init_all(interp);
            TCL.Tcl_CreateObjCommand(interp, "load_testfixture_extensions", init_all_cmd, 0, null);


            // Normally we would do application specific initialization here.
            // However, that feature is not currently supported.
            // If a script file was specified then just source that file
            // and quit.

            Console.WriteLine("               C#-SQLite version " + Sqlite3.sqlite3_version);
            Console.WriteLine("An independent reimplementation of the SQLite software library");
            Console.WriteLine("==============================================================");
            Console.WriteLine("");

            if ((System.Object)fileName != null)
            {
                try
                {
                    interp.evalFile(fileName);
                }
                catch (TclException e)
                {
                    TCL.CompletionCode code = e.getCompletionCode();
                    if (code == TCL.CompletionCode.RETURN)
                    {
                        code = interp.updateReturnInfo();
                        if (code != TCL.CompletionCode.OK)
                        {
                            System.Console.Error.WriteLine("command returned bad code: " + code);
                            if (tcl.lang.ConsoleThread.debug)
                            {
                                System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
                            }
                        }
                    }
                    else if (code == TCL.CompletionCode.ERROR)
                    {
                        System.Console.Error.WriteLine(interp.getResult().ToString());
                        if (tcl.lang.ConsoleThread.debug)
                        {
                            System.Diagnostics.Debug.WriteLine(interp.getResult().ToString());
                        }
                        System.Diagnostics.Debug.Assert(false, interp.getResult().ToString());
                    }
                    else if (code != TCL.CompletionCode.EXIT)
                    {
                        System.Console.Error.WriteLine("command returned bad code: " + code);
                        if (tcl.lang.ConsoleThread.debug)
                        {
                            System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
                        }
                    }
                }

                // Note that if the above interp.evalFile() returns the main
                // thread will exit.  This may bring down the VM and stop
                // the execution of Tcl.
                //
                // If the script needs to handle events, it must call
                // vwait or do something similar.
                //
                // Note that the script can create AWT widgets. This will
                // start an AWT event handling thread and keep the VM up. However,
                // the interpreter thread (the same as the main thread) would
                // have exited and no Tcl scripts can be executed.

                interp.dispose();
                Sqlite3.sqlite3_shutdown();

                System.Environment.Exit(0);
            }

            if ((System.Object)fileName == null)
            {
                // We are running in interactive mode. Start the ConsoleThread
                // that loops, grabbing stdin and passing it to the interp.

                ConsoleThread consoleThread = new ConsoleThread(interp);
                consoleThread.IsBackground = true;
                consoleThread.Start();

                // Loop forever to handle user input events in the command line.

                Notifier notifier = interp.getNotifier();
                while (true)
                {
                    // process events until "exit" is called.

                    notifier.doOneEvent(TCL.ALL_EVENTS);
                }
            }
        }
    }
コード例 #34
0
ファイル: CallFrame.cs プロジェクト: BclEx/GpuStructs
 /// <summary>
 /// Chain this frame into the call frame stack and binds the parameters values to the formal parameters of the procedure.
 /// </summary>
 /// <param name="proc">
 /// the procedure.
 /// </param>
 /// <param name="proc">
 /// argv the parameter values.
 /// </param>
 /// <exception cref="">
 /// TclException if wrong number of arguments.
 /// </exception>
 internal void Chain(Procedure proc, TclObject[] objv)
 {
     // FIXME: double check this ns thing in case where proc is renamed to different ns.
     NS = proc.NS;
     Objv = objv;
     // FIXME : quick level hack : fix later
     Level = (Interp.VarFrame == null ? 1 : Interp.VarFrame.Level + 1);
     Caller = Interp.Frame;
     CallerVar = Interp.VarFrame;
     Interp.Frame = this;
     Interp.VarFrame = this;
     // parameter bindings
     int numArgs = proc.ArgList.Length;
     if (!proc.isVarArgs && objv.Length - 1 > numArgs)
         WrongNumProcArgs(objv[0], proc);
     for (int i = 0, j = 1; i < numArgs; i++, j++)
     {
         // Handle the special case of the last formal being "args".  When it occurs, assign it a list consisting of
         // all the remaining actual arguments.
         TclObject varName = proc.ArgList[i][0];
         TclObject value = null;
         if (i == (numArgs - 1) && proc.isVarArgs)
         {
             value = TclList.NewInstance();
             value.Preserve();
             for (int k = j; k < objv.Length; k++)
                 TclList.Append(Interp, value, objv[k]);
             Interp.SetVar(varName, value, 0);
             value.Release();
         }
         else
         {
             if (j < objv.Length)
                 value = objv[j];
             else if (proc.ArgList[i][1] != null)
                 value = proc.ArgList[i][1];
             else
                 WrongNumProcArgs(objv[0], proc);
             Interp.SetVar(varName, value, 0);
         }
     }
 }