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

📄 tclwininit.c

📁 这是leon3处理器的交叉编译链
💻 C
📖 第 1 页 / 共 2 页
字号:
AppendDllPath(    Tcl_Obj *pathPtr,     HMODULE hModule,    CONST char *lib){    WCHAR wName[MAX_PATH + LIBRARY_SIZE];    char name[(MAX_PATH + LIBRARY_SIZE) * TCL_UTF_MAX];    if (GetModuleFileNameW(hModule, wName, MAX_PATH) == 0) {	GetModuleFileNameA(hModule, name, MAX_PATH);    } else {	ToUtf(wName, name);    }    if (lib != NULL) {	char *end, *p;	end = strrchr(name, '\\');	*end = '\0';	p = strrchr(name, '\\');	if (p != NULL) {	    end = p;	}	*end = '\\';	strcpy(end + 1, lib);    }    TclWinNoBackslash(name);    Tcl_ListObjAppendElement(NULL, pathPtr, Tcl_NewStringObj(name, -1));}/* *--------------------------------------------------------------------------- * * ToUtf -- * *	Convert a char string to a UTF string.   * * Results: *	None. * * Side effects: *	None. * *--------------------------------------------------------------------------- */static intToUtf(    CONST WCHAR *wSrc,    char *dst){    char *start;    start = dst;    while (*wSrc != '\0') {	dst += Tcl_UniCharToUtf(*wSrc, dst);	wSrc++;    }    *dst = '\0';    return (int) (dst - start);}/* *--------------------------------------------------------------------------- * * TclpSetInitialEncodings -- * *	Based on the locale, determine the encoding of the operating *	system and the default encoding for newly opened files. * *	Called at process initialization time, and part way through *	startup, we verify that the initial encodings were correctly *	setup.  Depending on Tcl's environment, there may not have been *	enough information first time through (above). * * Results: *	None. * * Side effects: *	The Tcl library path is converted from native encoding to UTF-8, *	on the first call, and the encodings may be changed on first or *	second call. * *--------------------------------------------------------------------------- */voidTclpSetInitialEncodings(){    CONST char *encoding;    char buf[4 + TCL_INTEGER_SPACE];    if (libraryPathEncodingFixed == 0) {	int platformId;	platformId = TclWinGetPlatformId();	TclWinSetInterfaces(platformId == VER_PLATFORM_WIN32_NT);		wsprintfA(buf, "cp%d", GetACP());	Tcl_SetSystemEncoding(NULL, buf);	if (platformId != VER_PLATFORM_WIN32_NT) {	    Tcl_Obj *pathPtr = TclGetLibraryPath();	    if (pathPtr != NULL) {		int i, objc;		Tcl_Obj **objv;				objc = 0;		Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv);		for (i = 0; i < objc; i++) {		    int length;		    char *string;		    Tcl_DString ds;		    string = Tcl_GetStringFromObj(objv[i], &length);		    Tcl_ExternalToUtfDString(NULL, string, length, &ds);		    Tcl_SetStringObj(objv[i], Tcl_DStringValue(&ds), 			    Tcl_DStringLength(&ds));		    Tcl_DStringFree(&ds);		}	    }	}		libraryPathEncodingFixed = 1;    } else {	wsprintfA(buf, "cp%d", GetACP());	Tcl_SetSystemEncoding(NULL, buf);    }    /* This is only ever called from the startup thread */    if (binaryEncoding == NULL) {	/*	 * Keep this encoding preloaded.  The IO package uses it for	 * gets on a binary channel.	 */	encoding = "iso8859-1";	binaryEncoding = Tcl_GetEncoding(NULL, encoding);    }}/* *--------------------------------------------------------------------------- * * TclpSetVariables -- * *	Performs platform-specific interpreter initialization related to *	the tcl_platform and env variables, and other platform-specific *	things. * * Results: *	None. * * Side effects: *	Sets "tcl_platform", and "env(HOME)" Tcl variables. * *---------------------------------------------------------------------- */voidTclpSetVariables(interp)    Tcl_Interp *interp;		/* Interp to initialize. */	{	        CONST char *ptr;    char buffer[TCL_INTEGER_SPACE * 2];    SYSTEM_INFO sysInfo;    OemId *oemId;    OSVERSIONINFOA osInfo;    Tcl_DString ds;    osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);    GetVersionExA(&osInfo);    oemId = (OemId *) &sysInfo;    GetSystemInfo(&sysInfo);    /*     * Define the tcl_platform array.     */    Tcl_SetVar2(interp, "tcl_platform", "platform", "windows",	    TCL_GLOBAL_ONLY);    if (osInfo.dwPlatformId < NUMPLATFORMS) {	Tcl_SetVar2(interp, "tcl_platform", "os",		platforms[osInfo.dwPlatformId], TCL_GLOBAL_ONLY);    }    wsprintfA(buffer, "%d.%d", osInfo.dwMajorVersion, osInfo.dwMinorVersion);    Tcl_SetVar2(interp, "tcl_platform", "osVersion", buffer, TCL_GLOBAL_ONLY);    if (oemId->wProcessorArchitecture < NUMPROCESSORS) {	Tcl_SetVar2(interp, "tcl_platform", "machine",		processors[oemId->wProcessorArchitecture],		TCL_GLOBAL_ONLY);    }#ifdef _DEBUG    /*     * The existence of the "debug" element of the tcl_platform array indicates     * that this particular Tcl shell has been compiled with debug information.     * Using "info exists tcl_platform(debug)" a Tcl script can direct the      * interpreter to load debug versions of DLLs with the load command.     */    Tcl_SetVar2(interp, "tcl_platform", "debug", "1",	    TCL_GLOBAL_ONLY);#endif    /*     * Set up the HOME environment variable from the HOMEDRIVE & HOMEPATH     * environment variables, if necessary.     */    Tcl_DStringInit(&ds);    ptr = Tcl_GetVar2(interp, "env", "HOME", TCL_GLOBAL_ONLY);    if (ptr == NULL) {	ptr = Tcl_GetVar2(interp, "env", "HOMEDRIVE", TCL_GLOBAL_ONLY);	if (ptr != NULL) {	    Tcl_DStringAppend(&ds, ptr, -1);	}	ptr = Tcl_GetVar2(interp, "env", "HOMEPATH", TCL_GLOBAL_ONLY);	if (ptr != NULL) {	    Tcl_DStringAppend(&ds, ptr, -1);	}	if (Tcl_DStringLength(&ds) > 0) {	    Tcl_SetVar2(interp, "env", "HOME", Tcl_DStringValue(&ds),		    TCL_GLOBAL_ONLY);	} else {	    Tcl_SetVar2(interp, "env", "HOME", "c:\\", TCL_GLOBAL_ONLY);	}    }    /*     * Initialize the user name from the environment first, since this is much     * faster than asking the system.     */    Tcl_DStringSetLength(&ds, 100);    if (TclGetEnv("USERNAME", &ds) == NULL) {	if (GetUserName(Tcl_DStringValue(&ds), (LPDWORD) &Tcl_DStringLength(&ds)) == 0) {	    Tcl_DStringSetLength(&ds, 0);	}    }    Tcl_SetVar2(interp, "tcl_platform", "user", Tcl_DStringValue(&ds),	    TCL_GLOBAL_ONLY);    Tcl_DStringFree(&ds);}/* *---------------------------------------------------------------------- * * TclpFindVariable -- * *	Locate the entry in environ for a given name.  On Unix this  *	routine is case sensetive, on Windows this matches mioxed case. * * Results: *	The return value is the index in environ of an entry with the *	name "name", or -1 if there is no such entry.   The integer at *	*lengthPtr is filled in with the length of name (if a matching *	entry is found) or the length of the environ array (if no matching *	entry is found). * * Side effects: *	None. * *---------------------------------------------------------------------- */intTclpFindVariable(name, lengthPtr)    CONST char *name;		/* Name of desired environment variable				 * (UTF-8). */    int *lengthPtr;		/* Used to return length of name (for				 * successful searches) or number of non-NULL				 * entries in environ (for unsuccessful				 * searches). */{    int i, length, result = -1;    register CONST char *env, *p1, *p2;    char *envUpper, *nameUpper;    Tcl_DString envString;    /*     * Convert the name to all upper case for the case insensitive     * comparison.     */    length = strlen(name);    nameUpper = (char *) ckalloc((unsigned) length+1);    memcpy((VOID *) nameUpper, (VOID *) name, (size_t) length+1);    Tcl_UtfToUpper(nameUpper);        Tcl_DStringInit(&envString);    for (i = 0, env = environ[i]; env != NULL; i++, env = environ[i]) {	/*	 * Chop the env string off after the equal sign, then Convert	 * the name to all upper case, so we do not have to convert	 * all the characters after the equal sign.	 */		envUpper = Tcl_ExternalToUtfDString(NULL, env, -1, &envString);	p1 = strchr(envUpper, '=');	if (p1 == NULL) {	    continue;	}	length = (int) (p1 - envUpper);	Tcl_DStringSetLength(&envString, length+1);	Tcl_UtfToUpper(envUpper);	p1 = envUpper;	p2 = nameUpper;	for (; *p2 == *p1; p1++, p2++) {	    /* NULL loop body. */	}	if ((*p1 == '=') && (*p2 == '\0')) {	    *lengthPtr = length;	    result = i;	    goto done;	}		Tcl_DStringFree(&envString);    }        *lengthPtr = i;    done:    Tcl_DStringFree(&envString);    ckfree(nameUpper);    return result;}/* *---------------------------------------------------------------------- * * Tcl_Init -- * *	This procedure is typically invoked by Tcl_AppInit procedures *	to perform additional initialization for a Tcl interpreter, *	such as sourcing the "init.tcl" script. * * Results: *	Returns a standard Tcl completion code and sets the interp's *	result if there is an error. * * Side effects: *	Depends on what's in the init.tcl script. * *---------------------------------------------------------------------- */intTcl_Init(interp)    Tcl_Interp *interp;		/* Interpreter to initialize. */{    Tcl_Obj *pathPtr;    if (tclPreInitScript != NULL) {	if (Tcl_Eval(interp, tclPreInitScript) == TCL_ERROR) {	    return (TCL_ERROR);	};    }    pathPtr = TclGetLibraryPath();    if (pathPtr == NULL) {	pathPtr = Tcl_NewObj();    }    Tcl_SetVar2Ex(interp, "tcl_libPath", NULL, pathPtr, TCL_GLOBAL_ONLY);    return Tcl_Eval(interp, initScript);}/* *---------------------------------------------------------------------- * * Tcl_SourceRCFile -- * *	This procedure is typically invoked by Tcl_Main of Tk_Main *	procedure to source an application specific rc file into the *	interpreter at startup time. * * Results: *	None. * * Side effects: *	Depends on what's in the rc script. * *---------------------------------------------------------------------- */voidTcl_SourceRCFile(interp)    Tcl_Interp *interp;		/* Interpreter to source rc file into. */{    Tcl_DString temp;    CONST char *fileName;    Tcl_Channel errChannel;    fileName = Tcl_GetVar(interp, "tcl_rcFileName", TCL_GLOBAL_ONLY);    if (fileName != NULL) {        Tcl_Channel c;	CONST char *fullName;        Tcl_DStringInit(&temp);	fullName = Tcl_TranslateFileName(interp, fileName, &temp);	if (fullName == NULL) {	    /*	     * Couldn't translate the file name (e.g. it referred to a	     * bogus user or there was no HOME environment variable).	     * Just do nothing.	     */	} else {	    /*	     * Test for the existence of the rc file before trying to read it.	     */            c = Tcl_OpenFileChannel(NULL, fullName, "r", 0);            if (c != (Tcl_Channel) NULL) {                Tcl_Close(NULL, c);		if (Tcl_EvalFile(interp, fullName) != TCL_OK) {		    errChannel = Tcl_GetStdChannel(TCL_STDERR);		    if (errChannel) {			Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp));			Tcl_WriteChars(errChannel, "\n", 1);		    }		}	    }	}        Tcl_DStringFree(&temp);    }}

⌨️ 快捷键说明

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