static PyObject *ResObj_SetResAttrs(ResourceObject *_self, PyObject *_args) { PyObject *_res = NULL; short attrs; #ifndef SetResAttrs PyMac_PRECHECK(SetResAttrs); #endif if (!PyArg_ParseTuple(_args, "h", &attrs)) return NULL; SetResAttrs(_self->ob_itself, attrs); { OSErr _err = ResError(); if (_err != noErr) return PyMac_Error(_err); } Py_INCREF(Py_None); _res = Py_None; return _res; }
OSErr PAS_decodeResource(PASEntry *entry, FSSpec *outFile, short inRefNum) { OSErr err = noErr; short outRefNum; PASResFork info; SInt32 infoSize; short oldResFile; PASResource pasRes; SInt32 pasResSize; long bufSize; Handle buffer; long counter=0; infoSize = sizeof(PASResFork); err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset ); if (err != noErr) return err; err = FSRead( inRefNum, &infoSize, &info); if (err != noErr) return err; if(infoSize != sizeof(PASResFork)) { err = -1; goto error; } oldResFile=CurResFile(); outRefNum = FSpOpenResFile(outFile, fsRdWrPerm); if (outRefNum < noErr) return outRefNum; UseResFile(outRefNum); while (1) { pasResSize = sizeof(PASResource); err = FSRead( inRefNum, &pasResSize, &pasRes); if (err != noErr) { if(err == eofErr) err = noErr; break; } bufSize = pasRes.length; buffer = NewHandle(bufSize); HLock(buffer); if(buffer == NULL) { /* if we did not get our memory, try updateresfile */ HUnlock(buffer); UpdateResFile(outRefNum); counter=0; buffer = NewHandle(bufSize); HLock(buffer); if(buffer == NULL) { err = memFullErr; break; } } err = FSRead( inRefNum, &bufSize, &(**buffer)); if (err != noErr && err != eofErr) break; AddResource(buffer, pasRes.attrType, pasRes.attrID, pasRes.attrName); WriteResource(buffer); SetResAttrs(buffer, pasRes.attr); ChangedResource(buffer); WriteResource(buffer); ReleaseResource(buffer); if (counter++ > 100) { UpdateResFile(outRefNum); counter=0; } } error: UseResFile(oldResFile); CloseResFile(outRefNum); return err; }
static int WriteTextResource( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ char **argv) /* Argument strings. */ { char *errNum = "wrong # args: "; char *errBad = "bad argument: "; char *errStr; char *fileName = NULL, *rsrcName = NULL; char *data = NULL; int rsrcID = -1, i, protectIt = 0; short fileRef = -1; OSErr err; Handle dataHandle; Str255 resourceName; FSSpec fileSpec; /* * Process the arguments. */ for (i = 1 ; i < argc ; i++) { if (!strcmp(argv[i], "-rsrc")) { rsrcName = argv[i + 1]; i++; } else if (!strcmp(argv[i], "-rsrcid")) { rsrcID = atoi(argv[i + 1]); i++; } else if (!strcmp(argv[i], "-file")) { fileName = argv[i + 1]; i++; } else if (!strcmp(argv[i], "-protected")) { protectIt = 1; } else { data = argv[i]; } } if ((rsrcName == NULL && rsrcID < 0) || (fileName == NULL) || (data == NULL)) { errStr = errBad; goto sourceFmtErr; } /* * Open the resource file. */ err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec); if (!(err == noErr || err == fnfErr)) { Tcl_AppendResult(interp, "couldn't validate file name", (char *) NULL); return TCL_ERROR; } if (err == fnfErr) { FSpCreateResFile(&fileSpec, 'WIsH', 'rsrc', smSystemScript); } fileRef = FSpOpenResFile(&fileSpec, fsRdWrPerm); if (fileRef == -1) { Tcl_AppendResult(interp, "couldn't open resource file", (char *) NULL); return TCL_ERROR; } UseResFile(fileRef); /* * Prepare data needed to create resource. */ if (rsrcID < 0) { rsrcID = UniqueID('TEXT'); } strcpy((char *) resourceName, rsrcName); c2pstr((char *) resourceName); dataHandle = NewHandle(strlen(data)); HLock(dataHandle); strcpy(*dataHandle, data); HUnlock(dataHandle); /* * Add the resource to the file and close it. */ AddResource(dataHandle, 'TEXT', rsrcID, resourceName); UpdateResFile(fileRef); if (protectIt) { SetResAttrs(Get1Resource('TEXT', rsrcID), resProtected); } CloseResFile(fileRef); return TCL_OK; sourceFmtErr: Tcl_AppendResult(interp, errStr, "error in \"", argv[0], "\"", (char *) NULL); return TCL_ERROR; }