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

📄 tclcmdil.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 5 页
字号:
/*  * tclCmdIL.c -- * *	This file contains the top-level command routines for most of *	the Tcl built-in commands whose names begin with the letters *	I through L.  It contains only commands in the generic core *	(i.e. those that don't depend much upon UNIX facilities). * * Copyright (c) 1987-1993 The Regents of the University of California. * Copyright (c) 1993-1997 Lucent Technologies. * Copyright (c) 1994-1997 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: @(#) tclCmdIL.c 1.6 98/08/07 11:41:56 */#include "tclInt.h"#include "tclPort.h"#include "tclCompile.h"/* * During execution of the "lsort" command, structures of the following * type are used to arrange the objects being sorted into a collection * of linked lists. */typedef struct SortElement {    Tcl_Obj *objPtr;			/* Object being sorted. */    struct SortElement *nextPtr;        /* Next element in the list, or					 * NULL for end of list. */} SortElement;/* * The "lsort" command needs to pass certain information down to the * function that compares two list elements, and the comparison function * needs to pass success or failure information back up to the top-level * "lsort" command.  The following structure is used to pass this * information. */typedef struct SortInfo {    int isIncreasing;		/* Nonzero means sort in increasing order. */    int sortMode;		/* The sort mode.  One of SORTMODE_*				 * values defined below */    Tcl_DString compareCmd;	/* The Tcl comparison command when sortMode				 * is SORTMODE_COMMAND.  Pre-initialized to				 * hold base of command.*/    int index;			/* If the -index option was specified, this				 * holds the index of the list element				 * to extract for comparison.  If -index				 * wasn't specified, this is -1. */    Tcl_Interp *interp;		/* The interpreter in which the sortis				 * being done. */    int resultCode;		/* Completion code for the lsort command.				 * If an error occurs during the sort this				 * is changed from TCL_OK to  TCL_ERROR. */} SortInfo;/* * The "sortMode" field of the SortInfo structure can take on any of the * following values. */#define SORTMODE_ASCII      0#define SORTMODE_INTEGER    1#define SORTMODE_REAL       2#define SORTMODE_COMMAND    3#define SORTMODE_DICTIONARY 4/* * Forward declarations for procedures defined in this file: */static void		AppendLocals _ANSI_ARGS_((Tcl_Interp *interp,			    Tcl_Obj *listPtr, char *pattern,			    int includeLinks));static int		DictionaryCompare _ANSI_ARGS_((char *left,			    char *right));static int		InfoArgsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoBodyCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoCmdCountCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoCommandsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoCompleteCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoDefaultCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoExistsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoGlobalsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoHostnameCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoLevelCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoLibraryCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoLoadedCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoLocalsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoNameOfExecutableCmd _ANSI_ARGS_((			    ClientData dummy, Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoPatchLevelCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoProcsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoScriptCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoSharedlibCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoTclVersionCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static int		InfoVarsCmd _ANSI_ARGS_((ClientData dummy,			    Tcl_Interp *interp, int objc,			    Tcl_Obj *CONST objv[]));static SortElement *    MergeSort _ANSI_ARGS_((SortElement *headPt,			    SortInfo *infoPtr));static SortElement *    MergeLists _ANSI_ARGS_((SortElement *leftPtr,			    SortElement *rightPtr, SortInfo *infoPtr));static int		SortCompare _ANSI_ARGS_((Tcl_Obj *firstPtr,			    Tcl_Obj *second, SortInfo *infoPtr));/* *---------------------------------------------------------------------- * * Tcl_IfCmd -- * *	This procedure is invoked to process the "if" Tcl command. *	See the user documentation for details on what it does. * *	With the bytecode compiler, this procedure is only called when *	a command name is computed at runtime, and is "if" or the name *	to which "if" was renamed: e.g., "set z if; $z 1 {puts foo}" * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation. * *---------------------------------------------------------------------- */	/* ARGSUSED */intTcl_IfCmd(dummy, interp, argc, argv)    ClientData dummy;			/* Not used. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    int i, result, value;    i = 1;    while (1) {	/*	 * 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 >= argc) {	    Tcl_AppendResult(interp, "wrong # args: no expression after \"",		    argv[i-1], "\" argument", (char *) NULL);	    return TCL_ERROR;	}	result = Tcl_ExprBoolean(interp, argv[i], &value);	if (result != TCL_OK) {	    return result;	}	i++;	if ((i < argc) && (strcmp(argv[i], "then") == 0)) {	    i++;	}	if (i >= argc) {	    Tcl_AppendResult(interp, "wrong # args: no script following \"",		    argv[i-1], "\" argument", (char *) NULL);	    return TCL_ERROR;	}	if (value) {	    return Tcl_Eval(interp, argv[i]);	}		/*	 * The expression evaluated to false.  Skip the command, then	 * see if there is an "else" or "elseif" clause.	 */	i++;	if (i >= argc) {	    return TCL_OK;	}	if ((argv[i][0] == 'e') && (strcmp(argv[i], "elseif") == 0)) {	    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 (strcmp(argv[i], "else") == 0) {	i++;	if (i >= argc) {	    Tcl_AppendResult(interp,		    "wrong # args: no script following \"else\" argument",		    (char *) NULL);	    return TCL_ERROR;	}    }    return Tcl_Eval(interp, argv[i]);}/* *---------------------------------------------------------------------- * * Tcl_IncrCmd -- * *	This procedure is invoked to process the "incr" Tcl command. *	See the user documentation for details on what it does. * *	With the bytecode compiler, this procedure is only called when *	a command name is computed at runtime, and is "incr" or the name *	to which "incr" was renamed: e.g., "set z incr; $z i -1" * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation. * *---------------------------------------------------------------------- */    /* ARGSUSED */intTcl_IncrCmd(dummy, interp, argc, argv)    ClientData dummy;			/* Not used. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    int value;    char *oldString, *result;    char newString[30];    if ((argc != 2) && (argc != 3)) {	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],		" varName ?increment?\"", (char *) NULL);	return TCL_ERROR;    }    oldString = Tcl_GetVar(interp, argv[1], TCL_LEAVE_ERR_MSG);    if (oldString == NULL) {	return TCL_ERROR;    }    if (Tcl_GetInt(interp, oldString, &value) != TCL_OK) {	Tcl_AddErrorInfo(interp,		"\n    (reading value of variable to increment)");	return TCL_ERROR;    }    if (argc == 2) {	value += 1;    } else {	int increment;	if (Tcl_GetInt(interp, argv[2], &increment) != TCL_OK) {	    Tcl_AddErrorInfo(interp,		    "\n    (reading increment)");	    return TCL_ERROR;	}	value += increment;    }    TclFormatInt(newString, value);    result = Tcl_SetVar(interp, argv[1], newString, TCL_LEAVE_ERR_MSG);    if (result == NULL) {	return TCL_ERROR;    }    /*     * Copy the result since the variable's value might change.     */        Tcl_SetResult(interp, result, TCL_VOLATILE);    return TCL_OK; }/* *---------------------------------------------------------------------- * * Tcl_InfoObjCmd -- * *	This procedure is invoked to process the "info" Tcl command. *	See the user documentation for details on what it does. * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation. * *---------------------------------------------------------------------- */	/* ARGSUSED */intTcl_InfoObjCmd(clientData, interp, objc, objv)    ClientData clientData;	/* Arbitrary value passed to the command. */    Tcl_Interp *interp;		/* Current interpreter. */    int objc;			/* Number of arguments. */    Tcl_Obj *CONST objv[];	/* Argument objects. */{    static char *subCmds[] = {            "args", "body", "cmdcount", "commands",	     "complete", "default", "exists", "globals",	     "hostname", "level", "library", "loaded",	     "locals", "nameofexecutable", "patchlevel", "procs",	     "script", "sharedlibextension", "tclversion", "vars",	     (char *) NULL};    enum ISubCmdIdx {	    IArgsIdx, IBodyIdx, ICmdCountIdx, ICommandsIdx,	    ICompleteIdx, IDefaultIdx, IExistsIdx, IGlobalsIdx,	    IHostnameIdx, ILevelIdx, ILibraryIdx, ILoadedIdx,	    ILocalsIdx, INameOfExecutableIdx, IPatchLevelIdx, IProcsIdx,	    IScriptIdx, ISharedLibExtensionIdx, ITclVersionIdx, IVarsIdx    } index;    int result;    if (objc < 2) {        Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");        return TCL_ERROR;    }        result = Tcl_GetIndexFromObj(interp, objv[1], subCmds, "option", 0,	    (int *) &index);    if (result != TCL_OK) {	return result;    }    switch (index) {        case IArgsIdx:	    result = InfoArgsCmd(clientData, interp, objc, objv);            break;	case IBodyIdx:	    result = InfoBodyCmd(clientData, interp, objc, objv);	    break;	case ICmdCountIdx:	    result = InfoCmdCountCmd(clientData, interp, objc, objv);	    break;        case ICommandsIdx:	    result = InfoCommandsCmd(clientData, interp, objc, objv);	    break;        case ICompleteIdx:	    result = InfoCompleteCmd(clientData, interp, objc, objv);	    break;	case IDefaultIdx:	    result = InfoDefaultCmd(clientData, interp, objc, objv);	    break;	case IExistsIdx:	    result = InfoExistsCmd(clientData, interp, objc, objv);	    break;        case IGlobalsIdx:	    result = InfoGlobalsCmd(clientData, interp, objc, objv);	    break;        case IHostnameIdx:	    result = InfoHostnameCmd(clientData, interp, objc, objv);	    break;	case ILevelIdx:	    result = InfoLevelCmd(clientData, interp, objc, objv);	    break;	case ILibraryIdx:	    result = InfoLibraryCmd(clientData, interp, objc, objv);	    break;        case ILoadedIdx:	    result = InfoLoadedCmd(clientData, interp, objc, objv);	    break;        case ILocalsIdx:	    result = InfoLocalsCmd(clientData, interp, objc, objv);	    break;	case INameOfExecutableIdx:	    result = InfoNameOfExecutableCmd(clientData, interp, objc, objv);	    break;	case IPatchLevelIdx:	    result = InfoPatchLevelCmd(clientData, interp, objc, objv);	    break;        case IProcsIdx:	    result = InfoProcsCmd(clientData, interp, objc, objv);	    break;        case IScriptIdx:	    result = InfoScriptCmd(clientData, interp, objc, objv);	    break;	case ISharedLibExtensionIdx:	    result = InfoSharedlibCmd(clientData, interp, objc, objv);	    break;	case ITclVersionIdx:	    result = InfoTclVersionCmd(clientData, interp, objc, objv);	    break;	case IVarsIdx:	    result = InfoVarsCmd(clientData, interp, objc, objv);	    break;    }    return result;}/* *---------------------------------------------------------------------- * * InfoArgsCmd -- * *      Called to implement the "info args" command that returns the *      argument list for a procedure. Handles the following syntax: * *          info args procName * * Results:

⌨️ 快捷键说明

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