⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcltestobj.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  * tclTestObj.c -- * *	This file contains C command procedures for the additional Tcl *	commands that are used for testing implementations of the Tcl object *	types. These commands are not normally included in Tcl *	applications; they're only used for testing. * * Copyright (c) 1995, 1996 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tclTestObj.c 1.27 97/05/19 17:37:31 */#include "tclInt.h"/* * An array of Tcl_Obj pointers used in the commands that operate on or get * the values of Tcl object-valued variables. varPtr[i] is the i-th * variable's Tcl_Obj *. */#define NUMBER_OF_OBJECT_VARS 20static Tcl_Obj *varPtr[NUMBER_OF_OBJECT_VARS];/* * Forward declarations for procedures defined later in this file: */static int		CheckIfVarUnset _ANSI_ARGS_((Tcl_Interp *interp,			    int varIndex));static int		GetVariableIndex _ANSI_ARGS_((Tcl_Interp *interp,			    char *string, int *indexPtr));static void		SetVarToObj _ANSI_ARGS_((int varIndex,			    Tcl_Obj *objPtr));int			TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));static int		TestbooleanobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TestconvertobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TestdoubleobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TestindexobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TestintobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TestobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		TeststringobjCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));/* *---------------------------------------------------------------------- * * TclObjTest_Init -- * *	This procedure creates additional commands that are used to test the *	Tcl object support. * * Results: *	Returns a standard Tcl completion code, and leaves an error *	message in interp->result if an error occurs. * * Side effects: *	Creates and registers several new testing commands. * *---------------------------------------------------------------------- */intTclObjTest_Init(interp)    Tcl_Interp *interp;{    register int i;        for (i = 0;  i < NUMBER_OF_OBJECT_VARS;  i++) {        varPtr[i] = NULL;    }	    Tcl_CreateObjCommand(interp, "testbooleanobj", TestbooleanobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "testconvertobj", TestconvertobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "testdoubleobj", TestdoubleobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "testintobj", TestintobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "testindexobj", TestindexobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "testobj", TestobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    Tcl_CreateObjCommand(interp, "teststringobj", TeststringobjCmd,	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);    return TCL_OK;}/* *---------------------------------------------------------------------- * * TestbooleanobjCmd -- * *	This procedure implements the "testbooleanobj" command.  It is used *	to test the boolean Tcl object type implementation. * * Results: *	A standard Tcl object result. * * Side effects: *	Creates and frees boolean objects, and also converts objects to *	have boolean type. * *---------------------------------------------------------------------- */static intTestbooleanobjCmd(clientData, interp, objc, objv)    ClientData clientData;	/* Not used. */    Tcl_Interp *interp;		/* Current interpreter. */    int objc;			/* Number of arguments. */    Tcl_Obj *CONST objv[];	/* Argument objects. */{    int varIndex, boolValue, length;    char *index, *subCmd;    if (objc < 3) {	wrongNumArgs:	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");	return TCL_ERROR;    }    /*     * THIS FAILS IF AN OBJECT'S STRING REP HAS A NULL BYTE.     */    index = Tcl_GetStringFromObj(objv[2], &length);    if (GetVariableIndex(interp, index, &varIndex) != TCL_OK) {	return TCL_ERROR;    }    subCmd = Tcl_GetStringFromObj(objv[1], &length);    if (strcmp(subCmd, "set") == 0) {	if (objc != 4) {	    goto wrongNumArgs;	}	if (Tcl_GetBooleanFromObj(interp, objv[3], &boolValue) != TCL_OK) {	    return TCL_ERROR;	}	/*	 * If the object currently bound to the variable with index varIndex	 * has ref count 1 (i.e. the object is unshared) we can modify that	 * object directly. Otherwise, if RC>1 (i.e. the object is shared),	 * we must create a new object to modify/set and decrement the old	 * formerly-shared object's ref count. This is "copy on write".	 */	if ((varPtr[varIndex] != NULL) && !Tcl_IsShared(varPtr[varIndex])) {	    Tcl_SetBooleanObj(varPtr[varIndex], boolValue);	} else {	    SetVarToObj(varIndex, Tcl_NewBooleanObj(boolValue));	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else if (strcmp(subCmd, "get") == 0) {	if (objc != 3) {	    goto wrongNumArgs;	}	if (CheckIfVarUnset(interp, varIndex)) {	    return TCL_ERROR;	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else if (strcmp(subCmd, "not") == 0) {	if (objc != 3) {	    goto wrongNumArgs;	}	if (CheckIfVarUnset(interp, varIndex)) {	    return TCL_ERROR;	}	if (Tcl_GetBooleanFromObj(interp, varPtr[varIndex],				  &boolValue) != TCL_OK) {	    return TCL_ERROR;	}	if (!Tcl_IsShared(varPtr[varIndex])) {	    Tcl_SetBooleanObj(varPtr[varIndex], !boolValue);	} else {	    SetVarToObj(varIndex, Tcl_NewBooleanObj(!boolValue));	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"bad option \"", Tcl_GetStringFromObj(objv[1], (int *) NULL),		"\": must be set, get, or not", (char *) NULL);	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * TestconvertobjCmd -- * *	This procedure implements the "testconvertobj" command. It is used *	to test converting objects to new types. * * Results: *	A standard Tcl object result. * * Side effects: *	Converts objects to new types. * *---------------------------------------------------------------------- */static intTestconvertobjCmd(clientData, interp, objc, objv)    ClientData clientData;	/* Not used. */    Tcl_Interp *interp;		/* Current interpreter. */    int objc;			/* Number of arguments. */    Tcl_Obj *CONST objv[];	/* Argument objects. */{    int length;    char *subCmd;    char buf[20];    if (objc < 3) {	wrongNumArgs:	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");	return TCL_ERROR;    }    /*     * THIS FAILS IF AN OBJECT'S STRING REP HAS A NULL BYTE.     */    subCmd = Tcl_GetStringFromObj(objv[1], &length);    if (strcmp(subCmd, "double") == 0) {	double d;	if (objc != 3) {	    goto wrongNumArgs;	}	if (Tcl_GetDoubleFromObj(interp, objv[2], &d) != TCL_OK) {	    return TCL_ERROR;	}	sprintf(buf, "%f", d);        Tcl_AppendToObj(Tcl_GetObjResult(interp), buf, -1);    } else {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"bad option \"", Tcl_GetStringFromObj(objv[1], (int *) NULL),		"\": must be double", (char *) NULL);	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * TestdoubleobjCmd -- * *	This procedure implements the "testdoubleobj" command.  It is used *	to test the double-precision floating point Tcl object type *	implementation. * * Results: *	A standard Tcl object result. * * Side effects: *	Creates and frees double objects, and also converts objects to *	have double type. * *---------------------------------------------------------------------- */static intTestdoubleobjCmd(clientData, interp, objc, objv)    ClientData clientData;	/* Not used. */    Tcl_Interp *interp;		/* Current interpreter. */    int objc;			/* Number of arguments. */    Tcl_Obj *CONST objv[];	/* Argument objects. */{    int varIndex, length;    double doubleValue;    char *index, *subCmd, *string;	    if (objc < 3) {	wrongNumArgs:	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");	return TCL_ERROR;    }    /*     * THIS FAILS IF AN OBJECT'S STRING REP HAS A NULL BYTE.     */    index = Tcl_GetStringFromObj(objv[2], &length);    if (GetVariableIndex(interp, index, &varIndex) != TCL_OK) {	return TCL_ERROR;    }    subCmd = Tcl_GetStringFromObj(objv[1], &length);    if (strcmp(subCmd, "set") == 0) {	if (objc != 4) {	    goto wrongNumArgs;	}	string = Tcl_GetStringFromObj(objv[3], &length);	if (Tcl_GetDouble(interp, string, &doubleValue) != TCL_OK) {	    return TCL_ERROR;	}	/*	 * If the object currently bound to the variable with index varIndex	 * has ref count 1 (i.e. the object is unshared) we can modify that	 * object directly. Otherwise, if RC>1 (i.e. the object is shared),	 * we must create a new object to modify/set and decrement the old	 * formerly-shared object's ref count. This is "copy on write".	 */	if ((varPtr[varIndex] != NULL) && !Tcl_IsShared(varPtr[varIndex])) {	    Tcl_SetDoubleObj(varPtr[varIndex], doubleValue);	} else {	    SetVarToObj(varIndex, Tcl_NewDoubleObj(doubleValue));	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else if (strcmp(subCmd, "get") == 0) {	if (objc != 3) {	    goto wrongNumArgs;	}	if (CheckIfVarUnset(interp, varIndex)) {	    return TCL_ERROR;	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else if (strcmp(subCmd, "mult10") == 0) {	if (objc != 3) {	    goto wrongNumArgs;	}	if (CheckIfVarUnset(interp, varIndex)) {	    return TCL_ERROR;	}	if (Tcl_GetDoubleFromObj(interp, varPtr[varIndex],				 &doubleValue) != TCL_OK) {	    return TCL_ERROR;	}	if (!Tcl_IsShared(varPtr[varIndex])) {	    Tcl_SetDoubleObj(varPtr[varIndex], (doubleValue * 10.0));	} else {	    SetVarToObj(varIndex, Tcl_NewDoubleObj( (doubleValue * 10.0) ));	}	Tcl_SetObjResult(interp, varPtr[varIndex]);    } else if (strcmp(subCmd, "div10") == 0) {	if (objc != 3) {	    goto wrongNumArgs;	}	if (CheckIfVarUnset(interp, varIndex)) {	    return TCL_ERROR;	}	if (Tcl_GetDoubleFromObj(interp, varPtr[varIndex],

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -