📄 tclmacresource.c
字号:
sprintf(idStr, "ID=%d", resourceNumber); Tcl_AppendResult(interp, "The resource \"", (resourceName != NULL ? resourceName : idStr), "\" could not be loaded from ", (fileName != NULL ? fileName : "application"), ".", NULL); rezEvalCleanUp: /* * TRICKY POINT: The code that you are sourcing here could load a * shared library. This will go AHEAD of the resource we stored away * in saveRef on the resource path. * If you restore the saveRef in this case, you will never be able * to get to the resources in the shared library, since you are now * pointing too far down on the resource list. * So, we only reset the current resource file if WE opened a resource * explicitly, and then only if the CurResFile is still the * one we opened... */ if (iOpenedResFile && (CurResFile() == fileRef)) { UseResFile(saveRef); } if (fileRef != -1) { CloseResFile(fileRef); } return result;}/* *----------------------------------------------------------------------------- * * Tcl_MacConvertTextResource -- * * Converts a TEXT resource into a Tcl suitable string. * * Side Effects: * Mallocs the returned memory, converts '\r' to '\n', and appends a NULL. * * Results: * A new malloced string. * *----------------------------------------------------------------------------- */char *Tcl_MacConvertTextResource( Handle resource) /* Handle to TEXT resource. */{ int i, size; char *resultStr; Tcl_DString dstr; size = GetResourceSizeOnDisk(resource); Tcl_ExternalToUtfDString(NULL, *resource, size, &dstr); size = Tcl_DStringLength(&dstr) + 1; resultStr = (char *) ckalloc((unsigned) size); memcpy((VOID *) resultStr, (VOID *) Tcl_DStringValue(&dstr), (size_t) size); Tcl_DStringFree(&dstr); for (i=0; i<size; i++) { if (resultStr[i] == '\r') { resultStr[i] = '\n'; } } return resultStr;}/* *----------------------------------------------------------------------------- * * Tcl_MacFindResource -- * * Higher level interface for loading resources. * * Side Effects: * Attempts to load a resource. * * Results: * A handle on success. * *----------------------------------------------------------------------------- */HandleTcl_MacFindResource( Tcl_Interp *interp, /* Interpreter in which to process file. */ long resourceType, /* Type of resource to load. */ CONST char *resourceName, /* Name of resource to find, * NULL if number should be used. */ int resourceNumber, /* Resource id of source. */ CONST char *resFileRef, /* Registered resource file reference, * NULL if searching all open resource files. */ int *releaseIt) /* Should we release this resource when done. */{ Tcl_HashEntry *nameHashPtr; OpenResourceFork *resourceRef; int limitSearch = false; short saveRef; Handle resource; if (resFileRef != NULL) { nameHashPtr = Tcl_FindHashEntry(&nameTable, resFileRef); if (nameHashPtr == NULL) { Tcl_AppendResult(interp, "invalid resource file reference \"", resFileRef, "\"", (char *) NULL); return NULL; } resourceRef = (OpenResourceFork *) Tcl_GetHashValue(nameHashPtr); saveRef = CurResFile(); UseResFile((short) resourceRef->fileRef); limitSearch = true; } /* * Some system resources (for example system resources) should not * be released. So we set autoload to false, and try to get the resource. * If the Master Pointer of the returned handle is null, then resource was * not in memory, and it is safe to release it. Otherwise, it is not. */ SetResLoad(false); if (resourceName == NULL) { if (limitSearch) { resource = Get1Resource(resourceType, resourceNumber); } else { resource = GetResource(resourceType, resourceNumber); } } else { Str255 rezName; Tcl_DString ds; Tcl_UtfToExternalDString(NULL, resourceName, -1, &ds); strcpy((char *) rezName + 1, Tcl_DStringValue(&ds)); rezName[0] = (unsigned) Tcl_DStringLength(&ds); if (limitSearch) { resource = Get1NamedResource(resourceType, rezName); } else { resource = GetNamedResource(resourceType, rezName); } Tcl_DStringFree(&ds); } if (*resource == NULL) { *releaseIt = 1; LoadResource(resource); } else { *releaseIt = 0; } SetResLoad(true); if (limitSearch) { UseResFile(saveRef); } return resource;}/* *---------------------------------------------------------------------- * * ResourceInit -- * * Initialize the structures used for resource management. * * Results: * None. * * Side effects: * Read the code. * *---------------------------------------------------------------------- */static voidResourceInit(){ initialized = 1; Tcl_InitHashTable(&nameTable, TCL_STRING_KEYS); Tcl_InitHashTable(&resourceTable, TCL_ONE_WORD_KEYS); resourceForkList = Tcl_NewObj(); Tcl_IncrRefCount(resourceForkList); BuildResourceForkList(); }/***//*Tcl_RegisterObjType(typePtr) *//* *---------------------------------------------------------------------- * * Tcl_NewOSTypeObj -- * * This procedure is used to create a new resource name type object. * * Results: * The newly created object is returned. This object will have a NULL * string representation. The returned object has ref count 0. * * Side effects: * None. * *---------------------------------------------------------------------- */Tcl_Obj *Tcl_NewOSTypeObj( OSType newOSType) /* Int used to initialize the new object. */{ register Tcl_Obj *objPtr; if (!osTypeInit) { osTypeInit = 1; Tcl_RegisterObjType(&osType); } objPtr = Tcl_NewObj(); objPtr->bytes = NULL; objPtr->internalRep.longValue = newOSType; objPtr->typePtr = &osType; return objPtr;}/* *---------------------------------------------------------------------- * * Tcl_SetOSTypeObj -- * * Modify an object to be a resource type and to have the * specified long value. * * Results: * None. * * Side effects: * The object's old string rep, if any, is freed. Also, any old * internal rep is freed. * *---------------------------------------------------------------------- */voidTcl_SetOSTypeObj( Tcl_Obj *objPtr, /* Object whose internal rep to init. */ OSType newOSType) /* Integer used to set object's value. */{ register Tcl_ObjType *oldTypePtr = objPtr->typePtr; if (!osTypeInit) { osTypeInit = 1; Tcl_RegisterObjType(&osType); } if ((oldTypePtr != NULL) && (oldTypePtr->freeIntRepProc != NULL)) { oldTypePtr->freeIntRepProc(objPtr); } objPtr->internalRep.longValue = newOSType; objPtr->typePtr = &osType; Tcl_InvalidateStringRep(objPtr);}/* *---------------------------------------------------------------------- * * Tcl_GetOSTypeFromObj -- * * Attempt to return an int from the Tcl object "objPtr". If the object * is not already an int, an attempt will be made to convert it to one. * * Results: * The return value is a standard Tcl object result. If an error occurs * during conversion, an error message is left in interp->objResult * unless "interp" is NULL. * * Side effects: * If the object is not already an int, the conversion will free * any old internal representation. * *---------------------------------------------------------------------- */intTcl_GetOSTypeFromObj( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tcl_Obj *objPtr, /* The object from which to get a int. */ OSType *osTypePtr) /* Place to store resulting int. */{ register int result; if (!osTypeInit) { osTypeInit = 1; Tcl_RegisterObjType(&osType); } if (objPtr->typePtr == &osType) { *osTypePtr = objPtr->internalRep.longValue; return TCL_OK; } result = SetOSTypeFromAny(interp, objPtr); if (result == TCL_OK) { *osTypePtr = objPtr->internalRep.longValue; } return result;}/* *---------------------------------------------------------------------- * * DupOSTypeInternalRep -- * * Initialize the internal representation of an int Tcl_Obj to a * copy of the internal representation of an existing int object. * * Results: * None. * * Side effects: * "copyPtr"s internal rep is set to the integer corresponding to * "srcPtr"s internal rep. * *---------------------------------------------------------------------- */static voidDupOSTypeInternalRep( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr) /* Object with internal rep to set. */{ copyPtr->internalRep.longValue = srcPtr->internalRep.longValue; copyPtr->typePtr = &osType;}/* *---------------------------------------------------------------------- * * SetOSTypeFromAny -- * * Attempt to generate an integer internal form for the Tcl object * "objPtr". * * Results: * The return value is a standard object Tcl result. If an error occurs * during conversion, an error message is left in interp->objResult * unless "interp" is NULL. * * Side effects: * If no error occurs, an int is stored as "objPtr"s internal * representation. * *---------------------------------------------------------------------- */static intSetOSTypeFromAny( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tcl_Obj *objPtr) /* The object to convert. */{ Tcl_ObjType *oldTypePtr = objPtr->typePtr; char *string; int length; long newOSType; /* * Get the string representation. Make it up-to-date if necessary. */ string = Tcl_GetStringFromObj(objPtr, &length); if (length != 4) { if (interp != NULL) { Tcl_ResetResult(interp); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "expected Macintosh OS type but got \"", string, "\"", (char *) NULL); } return TCL_ERROR; } newOSType = *((long *) string); /* * The conversion to resource type succeeded. Free the old internalRep * before setting the new one. */ if ((oldTypePtr != NULL) && (oldTypePtr->freeIntRepProc != NULL)) { oldTypePtr->freeIntRepProc(objPtr); } objPtr->internalRep.longValue = newOSType; objPtr->typePtr = &osType; return TCL_OK;}/* *---------------------------------------------------------------------- * * UpdateStringOfOSType -- * * Update the string representation for an resource type object. * Note: This procedure does not free an existing old string rep * so storage will be lost if this has not already been done. * * Results: * None. * * Side effects: * The object's string is set to a valid string that results from * the int-to-string conversion. * *---------------------------------------------------------------------- */static voidUpdateStringOfOSType( register Tcl_Obj *objPtr) /* Int object whose string rep to update. */{ objPtr->bytes = ckalloc(5); sprintf(objPtr->bytes, "%-4.4s", &(objPtr->internalRep.longValue)); objPtr->length = 4;}/* *---------------------------------------------------------------------- * * GetRsrcRefFromObj -- * * Given a String object containing a resource file token, return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -