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

📄 tkconsole.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
static voidConsoleWatch(instanceData, mask)    ClientData instanceData;		/* Device ID for the channel. */    int mask;				/* OR-ed combination of                                         * TCL_READABLE, TCL_WRITABLE and                                         * TCL_EXCEPTION, for the events                                         * we are interested in. */{}/* *---------------------------------------------------------------------- * * ConsoleHandle -- * *	Invoked by the generic IO layer to get a handle from a channel. *	Because console channels are not devices, this function always *	fails. * * Results: *	Always returns TCL_ERROR. * * Side effects: *	None. * *---------------------------------------------------------------------- */	/* ARGSUSED */static intConsoleHandle(instanceData, direction, handlePtr)    ClientData instanceData;	/* Device ID for the channel. */    int direction;		/* TCL_READABLE or TCL_WRITABLE to indicate				 * which direction of the channel is being				 * requested. */    ClientData *handlePtr;	/* Where to store handle */{    return TCL_ERROR;}/* *---------------------------------------------------------------------- * * ConsoleCmd -- * *	The console command implements a Tcl interface to the various console *	options. * * Results: *	None. * * Side effects: *	None. * *---------------------------------------------------------------------- */static intConsoleCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Not used. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    ConsoleInfo *info = (ConsoleInfo *) clientData;    char c;    int length;    int result;    Tcl_Interp *consoleInterp;    if (argc < 2) {	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],		" option ?arg arg ...?\"", (char *) NULL);	return TCL_ERROR;    }        c = argv[1][0];    length = strlen(argv[1]);    result = TCL_OK;    consoleInterp = info->consoleInterp;    Tcl_Preserve((ClientData) consoleInterp);    if ((c == 't') && (strncmp(argv[1], "title", length)) == 0) {	Tcl_DString dString;		Tcl_DStringInit(&dString);	Tcl_DStringAppend(&dString, "wm title . ", -1);	if (argc == 3) {	    Tcl_DStringAppendElement(&dString, argv[2]);	}	Tcl_Eval(consoleInterp, Tcl_DStringValue(&dString));	Tcl_DStringFree(&dString);    } else if ((c == 'h') && (strncmp(argv[1], "hide", length)) == 0) {	Tcl_Eval(info->consoleInterp, "wm withdraw .");    } else if ((c == 's') && (strncmp(argv[1], "show", length)) == 0) {	Tcl_Eval(info->consoleInterp, "wm deiconify .");    } else if ((c == 'e') && (strncmp(argv[1], "eval", length)) == 0) {	if (argc == 3) {	    Tcl_Eval(info->consoleInterp, argv[2]);	} else {	    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],		    " eval command\"", (char *) NULL);	    return TCL_ERROR;	}    } else {	Tcl_AppendResult(interp, "bad option \"", argv[1],		"\": should be hide, show, or title",		(char *) NULL);        result = TCL_ERROR;    }    Tcl_Release((ClientData) consoleInterp);    return result;}/* *---------------------------------------------------------------------- * * InterpreterCmd -- * *	This command allows the console interp to communicate with the *	main interpreter. * * Results: *	None. * * Side effects: *	None. * *---------------------------------------------------------------------- */static intInterpreterCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Not used. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    ConsoleInfo *info = (ConsoleInfo *) clientData;    char c;    int length;    int result;    Tcl_Interp *otherInterp;    if (argc < 2) {	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],		" option ?arg arg ...?\"", (char *) NULL);	return TCL_ERROR;    }        c = argv[1][0];    length = strlen(argv[1]);    otherInterp = info->interp;    Tcl_Preserve((ClientData) otherInterp);    if ((c == 'e') && (strncmp(argv[1], "eval", length)) == 0) {   	result = Tcl_GlobalEval(otherInterp, argv[2]);    	Tcl_AppendResult(interp, otherInterp->result, (char *) NULL);    } else if ((c == 'r') && (strncmp(argv[1], "record", length)) == 0) {   	Tcl_RecordAndEval(otherInterp, argv[2], TCL_EVAL_GLOBAL);	result = TCL_OK;    	Tcl_AppendResult(interp, otherInterp->result, (char *) NULL);    } else {	Tcl_AppendResult(interp, "bad option \"", argv[1],		"\": should be eval or record",		(char *) NULL);	result = TCL_ERROR;    }    Tcl_Release((ClientData) otherInterp);    return result;}/* *---------------------------------------------------------------------- * * ConsoleDeleteProc -- * *	If the console command is deleted we destroy the console window *	and all associated data structures. * * Results: *	None. * * Side effects: *	A new console it created. * *---------------------------------------------------------------------- */void ConsoleDeleteProc(clientData)     ClientData clientData;{    ConsoleInfo *info = (ConsoleInfo *) clientData;    Tcl_DeleteInterp(info->consoleInterp);    info->consoleInterp = NULL;}/* *---------------------------------------------------------------------- * * ConsoleEventProc -- * *	This event procedure is registered on the main window of the *	slave interpreter.  If the user or a running script causes the *	main window to be destroyed, then we need to inform the console *	interpreter by invoking "tkConsoleExit". * * Results: *	None. * * Side effects: *	Invokes the "tkConsoleExit" procedure in the console interp. * *---------------------------------------------------------------------- */static voidConsoleEventProc(clientData, eventPtr)    ClientData clientData;    XEvent *eventPtr;{    ConsoleInfo *info = (ConsoleInfo *) clientData;    Tcl_Interp *consoleInterp;        if (eventPtr->type == DestroyNotify) {        consoleInterp = info->consoleInterp;        /*         * It is possible that the console interpreter itself has         * already been deleted. In that case the consoleInterp         * field will be set to NULL. If the interpreter is already         * gone, we do not have to do any work here.         */                if (consoleInterp == (Tcl_Interp *) NULL) {            return;        }        Tcl_Preserve((ClientData) consoleInterp);	Tcl_Eval(consoleInterp, "tkConsoleExit");        Tcl_Release((ClientData) consoleInterp);    }}/* *---------------------------------------------------------------------- * * TkConsolePrint -- * *	Prints to the give text to the console.  Given the main interp *	this functions find the appropiate console interp and forwards *	the text to be added to that console. * * Results: *	None. * * Side effects: *	None. * *---------------------------------------------------------------------- */voidTkConsolePrint(interp, devId, buffer, size)    Tcl_Interp *interp;		/* Main interpreter. */    int devId;			/* TCL_STDOUT for stdout, TCL_STDERR for                                 * stderr. */    char *buffer;		/* Text buffer. */    long size;			/* Size of text buffer. */{    Tcl_DString command, output;    Tcl_CmdInfo cmdInfo;    char *cmd;    ConsoleInfo *info;    Tcl_Interp *consoleInterp;    int result;    if (interp == NULL) {	return;    }        if (devId == TCL_STDERR) {	cmd = "tkConsoleOutput stderr ";    } else {	cmd = "tkConsoleOutput stdout ";    }        result = Tcl_GetCommandInfo(interp, "console", &cmdInfo);    if (result == 0) {	return;    }    info = (ConsoleInfo *) cmdInfo.clientData;        Tcl_DStringInit(&output);    Tcl_DStringAppend(&output, buffer, size);    Tcl_DStringInit(&command);    Tcl_DStringAppend(&command, cmd, strlen(cmd));    Tcl_DStringAppendElement(&command, output.string);    consoleInterp = info->consoleInterp;    Tcl_Preserve((ClientData) consoleInterp);    Tcl_Eval(consoleInterp, command.string);    Tcl_Release((ClientData) consoleInterp);        Tcl_DStringFree(&command);    Tcl_DStringFree(&output);}

⌨️ 快捷键说明

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