Beispiel #1
0
void test_hcreateresfile(void)
{
    OSErr err;

    // will 0, 0 work on real macos?

    HDelete(0, 0, fname);
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile failed (File does not exist): %d\n", err);
        exit(1);
    }

    // Verify it doesn't fail if the file/fork already exist.
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile (File/Fork exist) failed: %d\n", err);
        exit(2);
    }

    // Verify it doesn't fail if the file exists w/o a resource fork.
    HDelete(0, 0, fname);
    HCreate(0, 0, fname, 'TEST', 'BINA');
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile (File exists) failed: %d\n", err);
        exit(2);
    }

    HDelete(0, 0, fname);
}
Beispiel #2
0
char *read_setting_s(void *handle, char const *key, char *buffer, int buflen) {
    int fd;
    Handle h;
    size_t len;
    Str255 pkey;

    if (handle == NULL) goto out;
    fd = *(int *)handle;
    UseResFile(fd);
    if (ResError() != noErr) goto out;
    c2pstrcpy(pkey, key);
    h = Get1NamedResource(FOUR_CHAR_CODE('TEXT'), pkey);
    if (h == NULL) goto out;

    len = GetHandleSize(h);
    if (len + 1 > buflen) goto out;
    memcpy(buffer, *h, len);
    buffer[len] = '\0';

    ReleaseResource(h);
    if (ResError() != noErr) goto out;
    return buffer;

  out:
    return NULL;
}
Beispiel #3
0
void test_createresfile(void)
{
    OSErr err;

    FSDelete(fname, 0);
    CreateResFile(fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "CreateResFile failed (File does not exist): %d\n", err);
        exit(1);
    }

    // Verify it does fail if the file/fork already exist.
    CreateResFile(fname);
    if ( (err = ResError()) != dupFNErr) {
        fprintf(stderr, "CreateResFile (File/Fork exist) failed: %d\n", err);
        exit(2);
    }

    // Verify it doesn't fail if the file exists w/o a resource fork.
    FSDelete(fname, 0);
    Create(fname, 0, 'TEST', 'BINA');
    CreateResFile(fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "CreateResFile (File exists) failed: %d\n", err);
        exit(2);
    }

    FSDelete(fname, 0);


}
Beispiel #4
0
void close_settings_r(void *handle) {
    int fd;

    if (handle == NULL) return;
    fd = *(int *)handle;
    CloseResFile(fd);
    if (ResError() != noErr)
	fatalbox("Close of saved session failed (%d)", ResError());
    sfree(handle);
}
Beispiel #5
0
void
ShowLogo(Boolean bEraseRect)
{
	short 		reserr;
	Rect 		derefd, logoRect;
	PicHandle 	logoPicH;
	Handle		logoRectH; 

	/* draw the image well */
    ControlHandle imgWellH = GetNewControl(rLogoImgWell, gWPtr);
    if (!imgWellH)
    {
        ErrorHandler(eMem, nil);
        return;
	}

	/* initialize Netscape logo */
	logoPicH = GetPicture(rNSLogo);  
	reserr = ResError();
	
	if (reserr == noErr)
	{
		/* draw Netscape logo */
		if (logoPicH != nil)
		{		
			logoRectH = GetResource('RECT', rNSLogoBox);
			reserr = ResError();
			if (reserr == noErr && logoRectH)
			{
				HLock(logoRectH);
				derefd = (Rect) **((Rect**)logoRectH);
				SetRect(&logoRect, derefd.left, derefd.top, derefd.right, derefd.bottom);
				HUnlock(logoRectH);
				reserr = ResError();
				if (reserr == noErr)
				{
					if (bEraseRect)
					{
						EraseRect(&logoRect);
						InvalRect(&logoRect);
					}
					DrawPicture(logoPicH, &logoRect);
					ReleaseResource((Handle)logoPicH);
				}
				
				ReleaseResource((Handle)logoRectH);
			}
		}
	}
	
	if (reserr != noErr)
		ErrorHandler(reserr, nil);
}
Beispiel #6
0
void dump_colors(
	struct rgb_color_value *colors, 
	short color_count)
{
	CTabHandle new_table;
	Handle old_bad_clut;
	struct rgb_color_value *color;
	short loop;
	FSSpec file;
	short refnum;
	
	file.vRefNum= -1;
	file.parID= 2;
	strcpy((char *)file.name, (const char *)"\pMarathon2 Clut\0");

	FSpCreateResFile(&file, 'RSED', 'rsrc', smSystemScript);
	refnum= FSpOpenResFile(&file, fsWrPerm);
	if(refnum>=0)
	{
		new_table= (CTabHandle) NewHandleClear(sizeof(ColorTable)+color_count*sizeof(ColorSpec));
		HLock((Handle) new_table);
		(*new_table)->ctSeed= GetCTSeed();
		(*new_table)->ctFlags= 0;
		(*new_table)->ctSize= color_count-1;
		
		/* Slam the colors.. */
		color= colors;
		for(loop=0; loop<=color_count; ++loop)
		{
			(*new_table)->ctTable[loop].rgb.red= color->red;
			(*new_table)->ctTable[loop].rgb.green= color->green;
			(*new_table)->ctTable[loop].rgb.blue= color->blue;
			(*new_table)->ctTable[loop].value= loop;
			color++;
		}
		HUnlock((Handle) new_table);
	
		old_bad_clut= GetResource('clut', 5454);
		if (old_bad_clut)
		{
			RmveResource((Handle) old_bad_clut);
			DisposeHandle((Handle) old_bad_clut);
			UpdateResFile(CurResFile());
		}
		
		AddResource((Handle) new_table, 'clut', 5454, "\pMarathon2 Color Table");
		if(ResError()) dprintf("Err adding it: %d", ResError());
		WriteResource((Handle) new_table);
		ReleaseResource((Handle) new_table);
		
		CloseResFile(refnum);
	}
Beispiel #7
0
/* Copy a resource into the current resource file */
static OSErr copy_resource(ResType restype, short resid)
{
    Handle h;
    Str255 resname;

    h = GetResource(restype, resid);
    if (h != NULL) {
	GetResInfo(h, &resid, &restype, resname);
	DetachResource(h);
	AddResource(h, restype, resid, resname);
	if (ResError() == noErr)
	    WriteResource(h);
    }
    return ResError();
}
Beispiel #8
0
OSErr	FindPrefs(FSSpec* where)
{
	OSErr		error = noErr;
	Str255	theString;
	Str255	name;
	FSSpec	spec;
	short		foundVRefNum;
	long		foundDirID;
	// Look for the prefs in the folder
	GetIndString(theString, kTransportPath, 1);
	p2cstr(theString);
	strncpy(name, theString, 63);
	strncat(name, "Modem prefs", 63);
	c2pstr(name);
	error = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &foundVRefNum, &foundDirID);
	if (error == noErr) {
		error = FSMakeFSSpec(foundVRefNum, foundDirID, name, where);
		if (error == fnfErr) {		// May need to create the file
			FSpCreateResFile(where, 'mwNT', 'pref', smSystemScript);
			error = ResError();
		}
	}

	return error;
}
Beispiel #9
0
OSErr GetToolname(char* toolName)
{
	OSErr			error = noErr;
	FSSpec		where;
	short			ref;
	Handle		theString;
	toolName[0] = '\0';													// Start without a name
	error = FindPrefs(&where);
	ref = FSpOpenResFile(&where, fsRdWrPerm);
	if (ref != -1) {
		theString = Get1Resource('STR ',kToolNameRes);			// Should look in most recent file first
		if (theString != nil) {
			HLock(theString);
			memcpy(toolName, *theString, (*theString)[0] + 1);
			HUnlock(theString);
			ReleaseResource(theString);
		} else {
			error = -5;
		}
		CloseResFile(ref);
		if (error == noErr) {											// CTB is touchy; make sure this tool exists
			error = VerifyToolExists(toolName);
		}
	} else {
		error = ResError();
	}

	return error;
}
Beispiel #10
0
texture::texture()
{

    if (TTF_Init() == -1)
        throw MenuError(TTF_GetError());
    if (!(_font = TTF_OpenFont("src_graphic/res/DejaVuSans.ttf", 50)))
        throw ResError(TTF_GetError());

    addImage(IMG_Load("src_graphic/res/hud.png"), "HUD");
    int i = 0;
    std::string s;
    while (i < 300)
    {
        s = std::to_string(i);
        TextTotexture(s);
        i += 1;
    }
    TextTotexture("lvl:");
    TextTotexture("time:");

    addImage(IMG_Load("src_graphic/res/ground/Grass.png"), "GROUND");
    addImage(IMG_Load("src_graphic/res/ground/Gcorner.png"), "GCORNER");
    addImage(IMG_Load("src_graphic/res/ground/GEdge.png"), "GEDGE");
    addImage(IMG_Load("src_graphic/res/bg2.jpg"), "BG");
    addImage(IMG_Load("src_graphic/res/broadcast.png"), "BROADCAST");
    addImage(IMG_Load("src_graphic/res/lvlup.png"), "LVLUP");

    addImage(IMG_Load("src_graphic/res/gemme/food.png"), "food");
    addImage(IMG_Load("src_graphic/res/gemme/cyan.png"), "linemate");
    addImage(IMG_Load("src_graphic/res/gemme/green.png"), "deraumere");
    addImage(IMG_Load("src_graphic/res/gemme/lopez.png"), "sibur");
    addImage(IMG_Load("src_graphic/res/gemme/purple.png"), "Mendiane");
    addImage(IMG_Load("src_graphic/res/gemme/red.png"), "Phiras");
    addImage(IMG_Load("src_graphic/res/gemme/yellow.png"), "Thystame");
}
Beispiel #11
0
Handle BetterGetIndResource(short resFile,ResType theType,short resID)
{
	short		saveFile=::CurResFile();
	Handle		theHandle;
	
	if (resFile!=-1)
		UseResFile(resFile);
	theHandle=Get1IndResource(theType,resID);
	if (!theHandle)
	{
		gGetResErr=ResError();
		if (!gGetResErr)
		{
			if (IndResourceExists(resFile,theType,resID))
				gGetResErr=memFullErr;
			else
				gGetResErr=resNotFound;
		}
	}
	else
		gGetResErr=noErr;
	
	if (resFile!=-1)
		UseResFile(saveFile);
	
	return theHandle;
}
Beispiel #12
0
short
GetRectFromRes(Rect *outRect, short inResID)
{
    Handle rectH;
    short reserr;
    
    if (!outRect)
        return eParam;
        
	// get rect for save bits message
	rectH = Get1Resource('RECT', inResID);
	reserr = ResError();
	if (reserr == noErr && rectH != NULL)
	{
		 *outRect  = (Rect) **((Rect **)rectH);
		 DisposeHandle(rectH);
    }
	else
	{
		ErrorHandler(reserr, nil);
		return reserr;
	}
	
	return 0;
}
Beispiel #13
0
static PyObject *Res_HCreateResFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short vRefNum;
    long dirID;
    Str255 fileName;
#ifndef HCreateResFile
    PyMac_PRECHECK(HCreateResFile);
#endif
    if (!PyArg_ParseTuple(_args, "hlO&",
                          &vRefNum,
                          &dirID,
                          PyMac_GetStr255, fileName))
        return NULL;
    HCreateResFile(vRefNum,
                   dirID,
                   fileName);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    Py_INCREF(Py_None);
    _res = Py_None;
    return _res;
}
Beispiel #14
0
static PyObject *Res_OpenRFPerm(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short _rv;
    Str255 fileName;
    short vRefNum;
    SignedByte permission;
#ifndef OpenRFPerm
    PyMac_PRECHECK(OpenRFPerm);
#endif
    if (!PyArg_ParseTuple(_args, "O&hb",
                          PyMac_GetStr255, fileName,
                          &vRefNum,
                          &permission))
        return NULL;
    _rv = OpenRFPerm(fileName,
                     vRefNum,
                     permission);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("h",
                         _rv);
    return _res;
}
Beispiel #15
0
static PyObject *ResObj_GetResInfo(ResourceObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short theID;
    ResType theType;
    Str255 name;
#ifndef GetResInfo
    PyMac_PRECHECK(GetResInfo);
#endif
    if (!PyArg_ParseTuple(_args, ""))
        return NULL;
    GetResInfo(_self->ob_itself,
               &theID,
               &theType,
               name);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("hO&O&",
                         theID,
                         PyMac_BuildOSType, theType,
                         PyMac_BuildStr255, name);
    return _res;
}
Beispiel #16
0
static PyObject *Res_FSResourceFileAlreadyOpen(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    Boolean _rv;
    FSRef resourceFileRef;
    Boolean inChain;
    SInt16 refNum;
#ifndef FSResourceFileAlreadyOpen
    PyMac_PRECHECK(FSResourceFileAlreadyOpen);
#endif
    if (!PyArg_ParseTuple(_args, "O&",
                          PyMac_GetFSRef, &resourceFileRef))
        return NULL;
    _rv = FSResourceFileAlreadyOpen(&resourceFileRef,
                                    &inChain,
                                    &refNum);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("bbh",
                         _rv,
                         inChain,
                         refNum);
    return _res;
}
Beispiel #17
0
static PyObject *Res_FSCreateResFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    FSRef parentRef;
    UniChar *nameLength__in__;
    UniCharCount nameLength__len__;
    int nameLength__in_len__;
    FSRef newRef;
    FSSpec newSpec;
#ifndef FSCreateResFile
    PyMac_PRECHECK(FSCreateResFile);
#endif
    if (!PyArg_ParseTuple(_args, "O&u#",
                          PyMac_GetFSRef, &parentRef,
                          &nameLength__in__, &nameLength__in_len__))
        return NULL;
    nameLength__len__ = nameLength__in_len__;
    FSCreateResFile(&parentRef,
                    nameLength__len__, nameLength__in__,
                    0,
                    (FSCatalogInfo *)0,
                    &newRef,
                    &newSpec);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("O&O&",
                         PyMac_BuildFSRef, &newRef,
                         PyMac_BuildFSSpec, &newSpec);
    return _res;
}
Beispiel #18
0
static PyObject *Res_FSpCreateResFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    FSSpec spec;
    OSType creator;
    OSType fileType;
    ScriptCode scriptTag;
#ifndef FSpCreateResFile
    PyMac_PRECHECK(FSpCreateResFile);
#endif
    if (!PyArg_ParseTuple(_args, "O&O&O&h",
                          PyMac_GetFSSpec, &spec,
                          PyMac_GetOSType, &creator,
                          PyMac_GetOSType, &fileType,
                          &scriptTag))
        return NULL;
    FSpCreateResFile(&spec,
                     creator,
                     fileType,
                     scriptTag);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    Py_INCREF(Py_None);
    _res = Py_None;
    return _res;
}
Beispiel #19
0
OSErr GetConfig(Ptr config)
{
	OSErr			error = noErr;
	FSSpec		where;
	short			ref;
	Handle		theString;
	Ptr			temp = nil;
	long			len;
	config[0] = '\0';											// Start without a name
	error = FindPrefs(&where);
	ref = FSpOpenResFile(&where, fsRdWrPerm);
	if (ref != -1) {
		theString = Get1Resource('STR ',kConfigRes);	// Should look in most recent file first
		if (theString != nil) {
			len = SizeResource(theString);
			SetPtrSize(config, len);						// Set the size
			error = MemError();								// And make sure it worked
			if (error == noErr) {
				HLock(theString);
				temp = (Ptr)*theString;
				memcpy(config, temp, len);
				HUnlock(theString);
				ReleaseResource(theString);
			}
		} else {
			error = -4;
		}
		CloseResFile(ref);
	} else {
		error = ResError();
	}
	return error;
}
Beispiel #20
0
static PyObject *ResObj_AddResource(ResourceObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    ResType theType;
    short theID;
    Str255 name;
#ifndef AddResource
    PyMac_PRECHECK(AddResource);
#endif
    if (!PyArg_ParseTuple(_args, "O&hO&",
                          PyMac_GetOSType, &theType,
                          &theID,
                          PyMac_GetStr255, name))
        return NULL;
    AddResource(_self->ob_itself,
                theType,
                theID,
                name);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    Py_INCREF(Py_None);
    _res = Py_None;
    return _res;
}
Beispiel #21
0
static PyObject *Res_HOpenResFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short _rv;
    short vRefNum;
    long dirID;
    Str255 fileName;
    SignedByte permission;
#ifndef HOpenResFile
    PyMac_PRECHECK(HOpenResFile);
#endif
    if (!PyArg_ParseTuple(_args, "hlO&b",
                          &vRefNum,
                          &dirID,
                          PyMac_GetStr255, fileName,
                          &permission))
        return NULL;
    _rv = HOpenResFile(vRefNum,
                       dirID,
                       fileName,
                       permission);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("h",
                         _rv);
    return _res;
}
Beispiel #22
0
/****************************************************************
 DefineMenu() reads the menu's 'MDAT' resource into memory and
 fills in the fields.  It creates the resource if it doesn't
 exist.
 ****************************************************************/
void DefineMenu(int menuID,
          		short cellHeight,
				short menuWidth,
				Boolean bFixedWidth,
				short numColumns,
//JLM				ProcPtr drawProc,
//JLM				ProcPtr invertProc,
//JLM				ProcPtr disableProc)
				SAMenuActionProcPtr drawProc,
				SAMenuActionProcPtr invertProc,
				SAMenuActionProcPtr disableProc)
{
   MenuDataRec **menuDataHandle;
   char message[100];

   menuDataHandle = (MenuDataRec **)GetResource('MDAT', menuID);
   if (menuDataHandle == nil) {
      // try to create the resource
      menuDataHandle = (MenuDataRec **)_NewHandle(sizeof (MenuDataRec));
      if (menuDataHandle == nil) {
         sprintf(message, "Could not create info structure for menu ID %d.", menuID);
         // debugstr(message);
		 SysBeep(1);
         return;
      }
      AddResource((Handle)menuDataHandle, 'MDAT', menuID, "\p");
      if (ResError() != 0) {
         sprintf(message, "Could not add 'MDAT' resource for menu ID %d.", menuID);
         // debugstr(message);
		 SysBeep(1);
         return;
      }
Beispiel #23
0
// Pass resFile as -1 to use the current resource file
// true = exists
Boolean IndResourceExists(short resFile,ResType resType,short inIndex)
{
	short 	oldRes=::CurResFile();
	Handle	theRes=0L;
	
	if (resFile!=-1)
	{
		UseResFile(resFile);
		if (ResError())
			return false;
	}
	
	SetResLoad(false);
	theRes=Get1IndResource(resType,inIndex);
	SetResLoad(true);
	UseResFile(oldRes);
	
	if (theRes)
	{
		ReleaseResource(theRes);
		return true;
	}
	else
		return false;
}
Beispiel #24
0
void BuildLibPath( void )
{
	Handle searchPath;
	
	// make the search path handle 
	// and fill it with the initial search path
	// use strlen neat so as to chop off trailing null!
	searchPath = NewHandle( strlen( INITIAL_SEARCH_PATH ) );
	if( (searchPath != NULL) && ( ResError() == noErr ) )
	{
		HLock( searchPath );
			BlockMove( INITIAL_SEARCH_PATH, *searchPath, strlen( INITIAL_SEARCH_PATH  ) );
		HUnlock( searchPath );
			
		// Try to get the application support folder
		FindFolderPath( searchPath, kApplicationSupportFolderType, FOLDER_SEARCH_PATH );
		
		// Try to get the extensions folder
		FindFolderPath( searchPath, kExtensionFolderType, FOLDER_SEARCH_PATH  );
		
		// lock it out of the way, 
		// null terminate it, overwriting the last \t, making a c string
		// and set LIBDIR to it
		HLockHi( searchPath );
		(*searchPath)[ GetHandleSize( searchPath ) -1 ] = '\0';
		LIBDIR = *searchPath;
	}
}
Handle CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, TypeListPtr theTypeList)
{
	Handle			myHandle = NULL;

	// see if we have an 'open' resource...
	myHandle = Get1Resource('open', 128);
	if ( myHandle != NULL && ResError() == noErr ) {
		DetachResource( myHandle );
		return myHandle;
	} else {
		myHandle = NULL;
	}

	// nope, use the passed in types and dynamically create the NavTypeList
	if (theTypeList == NULL)
		return myHandle;

	if (theNumTypes > 0) {
		myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
		if (myHandle != NULL) {
			NavTypeListHandle 	myOpenResHandle	= (NavTypeListHandle)myHandle;

			(*myOpenResHandle)->componentSignature = theApplicationSignature;
			(*myOpenResHandle)->osTypeCount = theNumTypes;
			BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
		}
	}

	return myHandle;
}
Beispiel #26
0
/*
 * We don't bother with the usual FSpExchangeFiles dance here because
 * it doesn't really matter if the old random seed gets lost.
 */
void write_random_seed(void *data, int len)
{
    short puttyVRefNum;
    long puttyDirID;
    OSErr error;
    FSSpec dstfile;
    short refnum;
    long count = len;

    if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr)
	return;

    error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed",
			 &dstfile);
    if (error == fnfErr) {
	/* Set up standard resources */
	FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman);
	refnum = FSpOpenResFile(&dstfile, fsWrPerm);
	if (ResError() == noErr) {
	    copy_resource('STR ', -16397);
	    CloseResFile(refnum);
	}
    } else if (error != noErr) return;

    if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return;
    FSWrite(refnum, &count, data);
    FSClose(refnum);

    return;
}
Beispiel #27
0
/*-----------------------------------------------------------------

	GetNamedFragmentOffsets

	Get the offsets into the data fork of the named fragment,
	by reading the 'cfrg' resoruce.

-----------------------------------------------------------------*/
OSErr GetNamedFragmentOffsets(const FSSpec *fileSpec, const char* fragmentName,
							UInt32 *outOffset, UInt32 *outLength)
{
	CFragResourceHandle		cFragHandle;
	short									fileRefNum;
	OSErr									err = noErr;
	
	fileRefNum = FSpOpenResFile(fileSpec, fsRdPerm);
	err = ResError();
	if (err != noErr) return err;

	cFragHandle = (CFragResourceHandle)Get1Resource(kCFragResourceType, kCFragResourceID);	
	if (!cFragHandle)
	{
		err = resNotFound;
		goto done;
	}
	
	/* nothing here moves memory, so no need to lock the handle */
	
	err = cfragNoLibraryErr;			/* in case of failure */
	*outOffset = 0;
	*outLength = 0;
	
	/* Now look for the named fragment */
	if ((**cFragHandle).memberCount > 0)
	{
		CFragResourceMemberPtr	memberPtr;
		UInt16									i;
		
		for (	i = 0, memberPtr = &(**cFragHandle).firstMember;
					i < (**cFragHandle).memberCount;
					i ++, memberPtr = (CFragResourceMemberPtr)((char *)memberPtr + memberPtr->memberSize))
		{
			char		memberName[256];
			UInt16	nameLen = PR_MIN(memberPtr->name[0], 255);
		
			// avoid malloc here for speed
			strncpy(memberName, (char *)&memberPtr->name[1], nameLen);
			memberName[nameLen] = '\0';
		
			// fragment names are case insensitive, so act like the system
			if (PL_strcasecmp(memberName, fragmentName) == 0)
			{
				*outOffset = memberPtr->offset;
				*outLength = memberPtr->length;
				err = noErr;
				break;
			}
		}
	}
	
	/* Resource handle will go away when the res fork is closed */
	
done:
	CloseResFile(fileRefNum);
	return err;
}
Beispiel #28
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_Suitcase( FT_Library    library,
                             const UInt8*  pathname,
                             FT_Long       face_index,
                             FT_Face*      aface )
  {
    FT_Error       error = FT_ERR( Cannot_Open_Resource );
    ResFileRefNum  res_ref;
    ResourceIndex  res_index;
    Handle         fond;
    short          num_faces_in_res;


    if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
      return FT_THROW( Cannot_Open_Resource );

    UseResFile( res_ref );
    if ( ResError() )
      return FT_THROW( Cannot_Open_Resource );

    num_faces_in_res = 0;
    for ( res_index = 1; ; ++res_index )
    {
      short  num_faces_in_fond;


      fond = Get1IndResource( TTAG_FOND, res_index );
      if ( ResError() )
        break;

      num_faces_in_fond  = count_faces( fond, pathname );
      num_faces_in_res  += num_faces_in_fond;

      if ( 0 <= face_index && face_index < num_faces_in_fond && error )
        error = FT_New_Face_From_FOND( library, fond, face_index, aface );

      face_index -= num_faces_in_fond;
    }

    CloseResFile( res_ref );
    if ( !error && aface )
      (*aface)->num_faces = num_faces_in_res;
    return error;
  }
OSStatus		CAComponent::GetResourceVersion (UInt32 &outVersion) const
{
	bool versionFound = false;
	ResFileRefNum componentResFileID = kResFileNotOpened;
	OSStatus result;
	short thngResourceCount;
	
	short curRes = CurResFile();
	require_noerr (result = OpenAComponentResFile( mComp, &componentResFileID), home);
	require_noerr (result = componentResFileID <= 0, home);
	
	UseResFile(componentResFileID);

	thngResourceCount = Count1Resources(kComponentResourceType);
	
	require_noerr (result = ResError(), home);
			// only go on if we successfully found at least 1 thng resource
	require_noerr (thngResourceCount <= 0 ? -1 : 0, home);

	// loop through all of the Component thng resources trying to 
	// find one that matches this Component description
	for (short i = 0; i < thngResourceCount && (!versionFound); i++)
	{
		// try to get a handle to this code resource
		Handle thngResourceHandle = Get1IndResource(kComponentResourceType, i+1);
		if (thngResourceHandle != NULL && ((*thngResourceHandle) != NULL))
		{
			if (UInt32(GetHandleSize(thngResourceHandle)) >= sizeof(ExtComponentResource))
			{
				ExtComponentResource * componentThng = (ExtComponentResource*) (*thngResourceHandle);

				// check to see if this is the thng resource for the particular Component that we are looking at
				// (there often is more than one Component described in the resource)
				if ((componentThng->cd.componentType == mDesc.Type()) 
						&& (componentThng->cd.componentSubType == mDesc.SubType()) 
						&& (componentThng->cd.componentManufacturer == mDesc.Manu()))
				{
					outVersion = componentThng->componentVersion;
					versionFound = true;
				}
			}
			ReleaseResource(thngResourceHandle);
		}
	}

	if (!versionFound)
		result = resNotFound;
		
	UseResFile(curRes);	// revert
	
	if ( componentResFileID != kResFileNotOpened )
		CloseComponentResFile(componentResFileID);
		
home:
	return result;
}
Beispiel #30
0
ConstStr255Param fname = (ConstStr255Param)"\pxxx-test-resource-xxx";


void test_fspcreateresfile(void)
{
    OSErr err;
    FSSpec spec;

    err = FSMakeFSSpec(0, 0, fname, &spec);
    if (err) {

        fprintf(stderr, "FSMakeFSSpec failed: %d\n", err);
        exit(3);
    }

    FSpDelete(&spec);
    FSpCreateResFile(&spec, 'TEST', 'BINA', 0);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "FSpCreateResFile failed (File does not exist): %d\n", err);
        exit(1);
    }

    // Verify it doesn't fail if the file/fork already exist.
    FSpCreateResFile(&spec, 'TEST', 'BINA', 0);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "FSpCreateResFile (File/Fork exist) failed: %d\n", err);
        exit(2);
    }

    // Verify it doesn't fail if the file exists w/o a resource fork.
    FSpDelete(&spec);
    FSpCreate(&spec, 'TEST', 'BINA', 0);
    FSpCreateResFile(&spec, 'TEST', 'BINA', 0);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "FSpCreateResFile (File exists) failed: %d\n", err);
        exit(2);
    }

    FSpDelete(&spec);


}