Exemplo n.º 1
0
// Parse a single resource
bool XML_ResourceFork::ParseResource(ResType Type, short ID)
{
    ResourceHandle = Get1Resource(Type,ID);
    if (ResourceHandle == NULL) {
        return false;
    }

    HLock(ResourceHandle);
    if (!DoParse()) {
        const char *Name = SourceName ? SourceName : "[]";
#ifdef TARGET_API_MAC_CARBON
        csprintf(
            temporary,
            "There were configuration-file parsing errors in resource %hd of object %s",
            ID,Name);
        SimpleAlert(kAlertStopAlert,temporary);
#else
        psprintf(
            ptemporary,
            "There were configuration-file parsing errors in resource %hd of object %s",
            ID,Name);
        ParamText(ptemporary,0,0,0);
        Alert(FatalErrorAlert,NULL);
#endif
        ExitToShell();
    }
    HUnlock(ResourceHandle);
    ReleaseResource(ResourceHandle);
    return true;
}
Exemplo n.º 2
0
/*
**	GetLocalIDFromFREF
**
**	Given a pointer to a 'FREF' BundleType record, load each 'FREF' resource
**	looking for a matching fileType. If a matching fileType is found, return
**	its icon local ID. If no match is found, return afpItemNotFound as the
**	function result.
*/
static	OSErr	GetLocalIDFromFREF(BundleTypePtr theBundleType,
								   OSType fileType,
								   short *iconLocalID)
{
	OSErr			error;
	short			index;
	IDRecPtr		idIterator;
	FREFRecHandle	theFref;
	
	error = afpItemNotFound;	/* default to not found */
	
	/* For each localID in this type, get the FREF resource looking for fileType */
	index = 0;
	idIterator = &theBundleType->idArray[0];
	*iconLocalID = 0;
	
	while ( (index <= theBundleType->count) && (*iconLocalID == 0) )
	{
		theFref = (FREFRecHandle)Get1Resource(kFREFResType, idIterator->rsrcID);
		if ( theFref != NULL )
		{
			if ( (*theFref)->fileType == fileType )
			{
				*iconLocalID = (*theFref)->iconID;
				error = noErr;
			}
		}
		
		++idIterator;
		++index;
	}
	
	return ( error );
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
Handle BetterGetResource(short resFile,ResType theType,short resID)
{
	short		saveFile=::CurResFile();
	Handle		theHandle;
	
	if (resFile!=-1)
		UseResFile(resFile);
		
	theHandle=Get1Resource(theType,resID);
	if (!theHandle)
	{
		gGetResErr=ResError();
		if (!gGetResErr)
		{
			if (ResourceExists(resFile,theType,resID))
				gGetResErr=memFullErr;
			else
				gGetResErr=resNotFound;
		}
	}
	else
		gGetResErr=noErr;
		
	UseResFile(saveFile);
	
	return theHandle;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
static Vector<String> stringListFromResourceId(SInt16 id)
{
    Vector<String> list;

    Handle handle = Get1Resource('STR#', id);
    if (!handle)
        return list;

    CFStringEncoding encoding = stringEncodingForResource(handle);

    unsigned char* p = (unsigned char*)*handle;
    if (!p)
        return list;

    SInt16 count = *(SInt16*)p;
    p += sizeof(SInt16);

    for (SInt16 i = 0; i < count; ++i) {
        unsigned char length = *p;
        WTF::RetainPtr<CFStringRef> str = CFStringCreateWithPascalString(0, p, encoding);
        list.append(str.get());
        p += 1 + length;
    }

    return list;
}
Exemplo n.º 7
0
static void mac_updatelicence(WindowPtr window)
{
    Handle h;
    int len;
    long fondsize;
    Rect textrect;

    SetPort((GrafPtr)GetWindowPort(window));
    BeginUpdate(window);
    fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize);
    TextFont(HiWord(fondsize));
    TextSize(LoWord(fondsize));
    h = Get1Resource('TEXT', wLicence);
    len = GetResourceSizeOnDisk(h);
#if TARGET_API_MAC_CARBON
    GetPortBounds(GetWindowPort(window), &textrect);
#else
    textrect = window->portRect;
#endif
    if (h != NULL) {
	HLock(h);
	TETextBox(*h, len, &textrect, teFlushDefault);
	HUnlock(h);
    }
    EndUpdate(window);
}
Exemplo n.º 8
0
pascal Handle SafeGet1Resource(ResType type, short resNum)
{
	Handle result = NULL;
	
	if (gLocaleResFile)
	{
		StAcroResourceContext resContext(gLocaleResFile);
		result = Get1Resource(type, resNum);
	}
	if (result == NULL && GetAcroPluginResourceMap())
	{
		StAcroResourceContext resContext(GetAcroPluginResourceMap());
		result = Get1Resource(type, resNum);
	}
	return result;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
void mac_openabout(void)
{
    DialogItemType itemtype;
    Handle item;
    VersRecHndl vers;
    Rect box;
    StringPtr longvers;
    WinInfo *wi;

    if (windows.about)
	SelectWindow(windows.about);
    else {
	windows.about =
	    GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1));
	wi = snew(WinInfo);
	memset(wi, 0, sizeof(*wi));
	wi->wtype = wAbout;
	wi->update = &mac_updateabout;
	wi->click = &mac_clickabout;
	wi->activate = &mac_activateabout;
	wi->close = &mac_closeabout;
	SetWRefCon(windows.about, (long)wi);
	vers = (VersRecHndl)Get1Resource('vers', 1);
	if (vers != NULL && *vers != NULL) {
	    longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1;
	    GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion,
			  &itemtype, &item, &box);
	    assert(itemtype & kStaticTextDialogItem);
	    SetDialogItemText(item, longvers);
	}
	ShowWindow(windows.about);
    }
}
Exemplo n.º 11
0
// Pass resFile as -1 to use the current resource file
// true = exists
Boolean ResourceExists(short resFile,ResType resType,short resID)
{
	short 	oldRes=::CurResFile();
	Handle	theRes=0L;
	
	if (resFile!=-1)
	{
		UseResFile(resFile);
		if (ResError())
			return false;
	}
	
	SetResLoad(false);
	theRes=Get1Resource(resType,resID);
	SetResLoad(true);
	UseResFile(oldRes);
	
	if (theRes)
	{
		ReleaseResource(theRes);
		return true;
	}
	else
		return false;
}
Exemplo n.º 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;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
CResource	CResourceFile::GetByID( const std::string& type, int16_t id )
{
	if( mResRefNum > 0 )
	{
		return CResource( Get1Resource( type, id ) );
	}
	else
	{
		return CResource( NULL );
	}
}
Exemplo n.º 15
0
Handle MADGet1Resource( OSType type, short id, MADLibrary* init)
{
	if( init->sysMemory)
	{
		Handle	tH, dH;
		
		tH = Get1Resource( type, id);
		if( tH == NULL) return NULL;
		
		DetachResource( tH);
		HNoPurge( tH);
		
		dH = NewHandle( GetHandleSize( tH));
		if( dH == NULL) MyDebugStr( __LINE__, __FILE__, "");
		if( MemError() != noErr) MyDebugStr( __LINE__, __FILE__, "");
		
		HLock( dH);
		HLock( tH);
		
		BlockMoveData( *tH, *dH, GetHandleSize( tH));
		
		HUnlock( dH);
		HUnlock( tH);
		
		DisposeHandle( tH);
		tH = NULL;
		
		return dH;
	}
	else
	{
		Handle dH = Get1Resource( type, id);
		if( dH == NULL) return NULL;
		
		DetachResource( dH);
		HNoPurge( dH);
		
		return dH;
	}
}
Exemplo n.º 16
0
pascal Handle SafeGet1Resource(ResType type, short resNum)
{
#if TARGET_API_MAC_CARBON
	Handle result = NULL;
	
	if (gLocaleResFile)
	{
		StAcroResourceContext resContext(gLocaleResFile);
		result = Get1Resource(type, resNum);
	}
	if (result == NULL && gResFile)
	{
		StAcroResourceContext resContext(gResFile);
		result = Get1Resource(type, resNum);
	}
	return result;
#else

	Handle result;
	short oldResFile = CurResFile();

	if( gLocaleResFile ) {					// Look in the Locale file first

		UseResFile( gLocaleResFile );
		result = Get1Resource(type, resNum);
		if( result ) {						// If the resource was there, then
			UseResFile( oldResFile );		// restore the chain and exit
			return result;
		}
	}

	UseResFile( gResFile );					// Default to base resource file
	result = Get1Resource(type, resNum);	// and get resource.

	UseResFile(oldResFile);					// restore and return
	return result;
#endif
}
Exemplo n.º 17
0
/* convert IPIcon to IconFamily */
OSErr	IPIconToIconFamily(const IPIconRec *ipIcon,IconFamilyHandle *iconFamily)
{
	OSErr	err=noErr;
	short	curRefNum = CurResFile();
	
	if (ipIcon->iconSuite == NULL)
	{
		UseResFile(gApplRefNum);
		*iconFamily=(IconFamilyHandle)Get1Resource(kXIconClipType,2002);
		DetachResource((Handle)*iconFamily);
		HUnlock((Handle)*iconFamily);
		UseResFile(curRefNum);
	}
	else
	{
		err=IconSuiteToIconFamily(ipIcon->iconSuite,kSelectorMy32Data,iconFamily);
		if (err==memFullErr)
		{
			UseResFile(gApplRefNum);
			*iconFamily=(IconFamilyHandle)Get1Resource(kXIconClipType,2002);
			DetachResource((Handle)*iconFamily);
			HUnlock((Handle)*iconFamily);
			err=noErr;
			UseResFile(curRefNum);
		}
	}
	if (err==noErr && isThumbnailIconsAvailable)
	{
		/* thumbnail */
		if (ipIcon->it32Data != NULL)
			err=SetIconFamilyData(*iconFamily,kThumbnail32BitData,ipIcon->it32Data);
		if (ipIcon->t8mkData != NULL)
			err=SetIconFamilyData(*iconFamily,kThumbnail8BitMask,ipIcon->t8mkData);
	}
	
	return err;
}
Exemplo n.º 18
0
// RAB BetterTelnet 2.0b5 - added GetDefaultMacros
// note that we ASSUME the resource fork has new-style macros - don't even think
// about putting the old format there. it would be useless anyway given that the
// purpose of having defaults in the resource fork is to make sure the arrows et al. work
// right from the get-go.
void GetDefaultMacros(void)
{
	Handle resHandle;

	UseResFile(TelInfo->ApplicationFile);
	resHandle = Get1Resource('Mcro', 128);
	UseResFile(TelInfo->SettingsFile);
	if (!resHandle) {		// RAB 2.0b5 - get the blank macros, then
		setupNewMacros(&TelInfo->newMacros); // ignore the error, and let the lusers learn on their own
		return;								// not to use ResEdit unless they know what they're doing :-)
	}
	DetachResource(resHandle);
	HLock(resHandle);
	disposemacros(&TelInfo->newMacros); // we are replacing, not merging
	ParseMacrosFromHandle(&TelInfo->newMacros, resHandle);
}
Exemplo n.º 19
0
static Boolean
LibInPefContainer(const FSSpec* inSpec, StringPtr inName, UInt32* outCodeOffset, UInt32* outCodeLength)
{
	short					refNum;
	CFragResourceHandle		hCfrg;
	CFragResourceMember*	pCurItem;
	UInt32					curLibIndex;
	Boolean					found;
	
	// asume we didn't find it
	found = false;
	
	// open the resource fork, if we can't bail
	refNum = FSpOpenResFile(inSpec, fsRdPerm);
	require(-1 != refNum, Exit);
	
	// grab out the alias record, if it's not there bail
	hCfrg = (CFragResourceHandle) Get1Resource(kCFragResourceType, kCFragResourceID);
	require(NULL != hCfrg, CloseResourceAndExit);
	
	HLock((Handle)hCfrg);
	
	// get ptr to first item
	pCurItem = &(*hCfrg)->firstMember;
	for (curLibIndex = 0; curLibIndex < (*hCfrg)->memberCount; curLibIndex++)
	{
		// is this our library?
		if ((pCurItem->name[0] == inName[0]) &&
			(strncmp((char*) inName + 1, (char*) pCurItem->name + 1, PR_MIN(pCurItem->name[0], inName[0])) == 0))
		{
			*outCodeOffset = pCurItem->offset;
			*outCodeLength = pCurItem->length;
			found = true;
		}
		
		// skip to next one
		pCurItem = (CFragResourceMember*) ((char*) pCurItem + pCurItem->memberSize);						
	}
	
	HUnlock((Handle)hCfrg);
	
CloseResourceAndExit:
	CloseResFile(refNum);
Exit:
	return (found);

}
Exemplo n.º 20
0
void LCD_makepalette(void)
{
	Handle myClut;
	
	if (hasColorQD) {
		myClut = Get1Resource('clut', myRes);
		
		if (!myClut) {
		    post("Color Problem");
		    myPalette = GetNewPalette(0);
		}
		/* DDZ changed palette from "courteous" to "tolerant" 12/14/92 */
		else    
			myPalette = NewPalette(numPaletteColors,(CTabHandle)myClut,pmTolerant,0x5000);
	} else
		myPalette = 0;
}
Exemplo n.º 21
0
OSErr GetShortVersionString(short rID, StringPtr version)
{
	VersRecHndl		versionH;
	OSErr			error = resNotFound;
	
	versionH = (VersRecHndl)Get1Resource('vers', rID);		
	
	if (versionH)
	{
		CopyPascalString(version, (**versionH).shortVersion);
		ReleaseResource((Handle) versionH);
		error = noErr;
	}
	else
 		CopyPascalString(version, (StringPtr)"\p<unknown>");

	return error;
}
Exemplo n.º 22
0
/* time to actually transfer the data.                              */
int
gp_read_macresource(byte *buf, const char *fname, const uint type, const ushort id)
{
    Handle resource = NULL;
    SInt32 size = 0;
    FSSpec spec;
    SInt16 fileref;
    OSErr result;

    /* open file */
    result = convertPathToSpec(fname, strlen(fname), &spec);
    if (result != noErr) goto fin;
    fileref = FSpOpenResFile(&spec, fsRdPerm);
    if (fileref == -1) goto fin;

    if_debug1('s', "[s] loading resource from fileref %d\n", fileref);

    /* load resource */
    resource = Get1Resource((ResType)type, (SInt16)id);
    if (resource == NULL) goto fin;

    /* allocate res */
    /* GetResourceSize() is probably good enough */
    //size = GetResourceSizeOnDisk(resource);
    size = GetMaxResourceSize(resource);

    if_debug1('s', "[s] resource size on disk is %d bytes\n", size);

    /* if we don't have a buffer to fill, just return */
    if (buf == NULL) goto fin;

    /* otherwise, copy resource into res from handle */
    HLock(resource);
    memcpy(buf, *resource, size);
    HUnlock(resource);

fin:
    /* free resource, if necessary */
    ReleaseResource(resource);
    CloseResFile(fileref);

    return (size);
}
Exemplo n.º 23
0
/* ファイルのアイコンをチェック */
OSErr FileIconCheck(const FSSpec *theIconFile,short *alertMode)
{
	OSErr	err;
	short	refNum;
	IconFamilyHandle	iconFamily;
	
	refNum=FSpOpenResFile(theIconFile,fsRdWrPerm);
	if (refNum <=0) /* 開けない場合は追加確認 */
	{
		if ((err=ResError())==eofErr)
		{
			*alertMode = kAddResourceForkMode;
			return noErr;
		}
		return err;
	}
	
	/* 'icns'リソースを探す */
	UseResFile(refNum);
	iconFamily=(IconFamilyHandle)Get1Resource(kXIconFileType,kCustomIconResource);
	if (iconFamily==nil) /* 'icns'リソースがない場合は問題なし */
	{
		CloseResFile(refNum);
		UseResFile(gApplRefNum);
		return noErr;
	}
	
	if (!isIconServicesAvailable)
	{
		ReleaseResource((Handle)iconFamily);
		
		*alertMode = kDeleteIconFamilyMode;
	}
	else
		if (!IsEditableIconFamily(iconFamily))
			*alertMode = kDeleteIconMode;
	
	CloseResFile(refNum);
	UseResFile(gApplRefNum);
	
	return noErr;
}
Exemplo n.º 24
0
// MT : this is a compatibility routine to do stuff that used to be done in the cfm initialiser of rezlib
static Handle LoadDITL()
{
	//Load the dialog item list for our AskIfNewResolutionWorks() function dialog box
	static Handle		s_ditl=NULL;
	if (!s_ditl)
	{
		//Load our DITL
		s_ditl = Get1Resource( 'DITL', 27398 );
		if( s_ditl )
		{
			DEBUGMESSAGE( "\"AskIfNewResolutionWorks\" DITL loaded." );
			DetachResource( s_ditl );
		}
		else
			DEBUGMESSAGE( "Error: Failed to load DITL." );
		
		OSStatus err = ResError();
		CHECKERR( err );
		if( err )
			DEBUGMESSAGE( "Found Resource Manager error # " << err << " after attempting to load the \"AskIfNewResolutionWorks\" DITL. " );	
	}
	return s_ditl;
}
Exemplo n.º 25
0
static PyObject *Res_Get1Resource(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    Handle _rv;
    ResType theType;
    short theID;
#ifndef Get1Resource
    PyMac_PRECHECK(Get1Resource);
#endif
    if (!PyArg_ParseTuple(_args, "O&h",
                          PyMac_GetOSType, &theType,
                          &theID))
        return NULL;
    _rv = Get1Resource(theType,
                       theID);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("O&",
                         ResObj_New, _rv);
    return _res;
}
Exemplo n.º 26
0
/* カレントリソースから指定されたアイコンをIPIconとして得る */
OSErr Get1IPIcon(IPIconRec *ipIcon,short resID,const IPIconSelector *selector)
{
	OSErr	err;
	IconFamilyHandle	iconFamily;
	
	if (isIconServicesAvailable)
	{
		iconFamily = (IconFamilyHandle)Get1Resource(kIconFamilyType,resID);
		if (iconFamily != NULL)
		{
			/* IconSuiteにおさめる部分 */
			err = IconFamilyToIPIconWithSelector(iconFamily,selector,ipIcon);
			ReleaseResource((Handle)iconFamily);
			
			return err;
		}
	}
	
	err = Get1IconSuite(&ipIcon->iconSuite,resID,selector->selector);
	ipIcon->it32Data = ipIcon->t8mkData = NULL;
	
	return err;
}
Exemplo n.º 27
0
OSErr CreateToolNameRes(StringPtr toolName) {
	short			ref;
	FSSpec		prefs;
	OSErr			error;
	Handle		theStrings;

	//	build the 'STR ' resource

	error = FindPrefs(&prefs);
	if (error == noErr) {
		ref = FSpOpenResFile(&prefs, fsRdWrPerm);
		if (ref != -1) {
			theStrings = Get1Resource('STR ',kToolNameRes);
			if (theStrings != nil) {
				RemoveResource(theStrings);
				error = ResError();
			}

			error = PtrToHand(toolName, &theStrings, toolName[0] + 1);

			AddResource(theStrings, 'STR ', kToolNameRes, "\ptoolName");
			error = ResError();

			ChangedResource(theStrings);
			error = ResError();

			WriteResource(theStrings);
			error = ResError();

			//ReleaseResource(theStrings);		// Release the resource from memory.
			//error = ResError();
			UpdateResFile(ref);						// No screwing around; write that resource!
			error = ResError();
			FlushVol(nil, prefs.vRefNum);

			CloseResFile(ref);
		} else {
Exemplo n.º 28
0
OSErr PAS_flattenResource(ResType type, short *ids, long count, short source, short dest)
{
	long 			idIndex;
	
	
	Handle			resToCopy;
	long			handleLength;
	
	PASResource		pasResource;
	long			pasResLen;
	
	OSErr			err;
	
	for (idIndex=0; idIndex < count; idIndex++)
	{
		if( (type == 'SIZE') && ( ids[idIndex] == 1 || ids[idIndex] == 0  ) )
		{
			/* 	
				We do not want to encode/flatten SIZE 0 or 1 because this
				is the resource that the user can modify.  Most applications
				will not be affected if we remove these resources
			*/
		}
		else
		{	
			resToCopy=Get1Resource(type,ids[idIndex]);
					
			if(!resToCopy)	
			{
				return resNotFound;
			}	
				
			memset(&pasResource, 0, sizeof(PASResource));	
				
			GetResInfo(	resToCopy, 	
						&pasResource.attrID, 
						&pasResource.attrType, 
						pasResource.attrName);	
			
			pasResource.attr = GetResAttrs(resToCopy);
			
			DetachResource(resToCopy);	
			HLock(resToCopy);
			
			pasResource.length 	= GetHandleSize(resToCopy);
			handleLength 		= pasResource.length;
			
			pasResLen			=	sizeof(PASResource);
			
			err = FSWrite(dest, &pasResLen, &pasResource);
			
			if(err != noErr) 
			{
				return err;
			}
			
			err = FSWrite(dest, &handleLength, &(**resToCopy));

			if(err != noErr) 
			{
				return err;
			}
			
			HUnlock(resToCopy);
			DisposeHandle(resToCopy);		
		}
	}
	
	
	return noErr;
}
Exemplo n.º 29
0
Arquivo: ftmac.c Projeto: 32767/libgdx
  /* Read Type 1 data from the POST resources inside the LWFN file,
     return a PFB buffer.  This is somewhat convoluted because the FT2
     PFB parser wants the ASCII header as one chunk, and the LWFN
     chunks are often not organized that way, so we glue chunks
     of the same type together. */
  static FT_Error
  read_lwfn( FT_Memory      memory,
             ResFileRefNum  res,
             FT_Byte**      pfb_data,
             FT_ULong*      size )
  {
    FT_Error       error = FT_Err_Ok;
    ResID          res_id;
    unsigned char  *buffer, *p, *size_p = NULL;
    FT_ULong       total_size = 0;
    FT_ULong       old_total_size = 0;
    FT_ULong       post_size, pfb_chunk_size;
    Handle         post_data;
    char           code, last_code;


    UseResFile( res );

    /* First pass: load all POST resources, and determine the size of */
    /* the output buffer.                                             */
    res_id    = 501;
    last_code = -1;

    for (;;)
    {
      post_data = Get1Resource( TTAG_POST, res_id++ );
      if ( post_data == NULL )
        break;  /* we are done */

      code = (*post_data)[0];

      if ( code != last_code )
      {
        if ( code == 5 )
          total_size += 2; /* just the end code */
        else
          total_size += 6; /* code + 4 bytes chunk length */
      }

      total_size += GetHandleSize( post_data ) - 2;
      last_code = code;

      /* detect integer overflows */
      if ( total_size < old_total_size )
      {
        error = FT_Err_Array_Too_Large;
        goto Error;
      }

      old_total_size = total_size;
    }

    if ( FT_ALLOC( buffer, (FT_Long)total_size ) )
      goto Error;

    /* Second pass: append all POST data to the buffer, add PFB fields. */
    /* Glue all consecutive chunks of the same type together.           */
    p              = buffer;
    res_id         = 501;
    last_code      = -1;
    pfb_chunk_size = 0;

    for (;;)
    {
      post_data = Get1Resource( TTAG_POST, res_id++ );
      if ( post_data == NULL )
        break;  /* we are done */

      post_size = (FT_ULong)GetHandleSize( post_data ) - 2;
      code = (*post_data)[0];

      if ( code != last_code )
      {
        if ( last_code != -1 )
        {
          /* we are done adding a chunk, fill in the size field */
          if ( size_p != NULL )
          {
            *size_p++ = (FT_Byte)(   pfb_chunk_size         & 0xFF );
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8  ) & 0xFF );
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
          }
          pfb_chunk_size = 0;
        }

        *p++ = 0x80;
        if ( code == 5 )
          *p++ = 0x03;  /* the end */
        else if ( code == 2 )
          *p++ = 0x02;  /* binary segment */
        else
          *p++ = 0x01;  /* ASCII segment */

        if ( code != 5 )
        {
          size_p = p;   /* save for later */
          p += 4;       /* make space for size field */
        }
      }

      ft_memcpy( p, *post_data + 2, post_size );
      pfb_chunk_size += post_size;
      p += post_size;
      last_code = code;
    }
Exemplo n.º 30
0
boolean initmacintosh (void) {
	
	/*
	the magic stuff that every Macintosh application needs to do 
	before doing anything else.
	
	4/24/91 dmb: added memory config resource stuff
	
	3.0.4 dmb: use LMGetCurStackBase, not CurStackBase global
	
	3.0.4 dmb: pass 0L to InitDialogs
	*/
	
	register short i;
	register hdlmemoryconfig h;
	register long ctbytes;
	//Code change by Timothy Paustian Thursday, June 8, 2000 3:45:13 PM
	//
	#if TARGET_API_MAC_CARBON == 0
	long ctstack;
	#endif
	long ctheap, ctcode;
	short ctmasters;
	
	h = (hdlmemoryconfig) Get1Resource ('MCFG', 1);
	
	if (h == nil)
		clearbytes (&macmemoryconfig, sizeof (macmemoryconfig));
	else
		macmemoryconfig = **h;
	
	//Code change by Timothy Paustian Saturday, June 3, 2000 10:13:20 PM
	//Changed to Opaque call for Carbon
	//we don't need this in carbon.
	#if TARGET_API_MAC_CARBON == 0
	if (h != nil) { /*first check stack size*/
		
		ctbytes = (**h).minstacksize;
		
		ctstack = LMGetCurStackBase () - GetApplLimit (); /*current stack size*/
		
		if (ctbytes > ctstack)
			SetApplLimit (LMGetCurStackBase () - ctbytes);
		}
	MaxApplZone ();
	
	#endif

	
	
	if (h != nil) { /*check heap size and master pointers*/
		
		ctbytes = (**h).minheapsize;
		
		//Code change by Timothy Paustian Thursday, June 8, 2000 3:04:31 PM
		//Changed to Opaque call for Carbon
		//This is meaningless for OS X since it has unlimited memory.
		
		#if TARGET_API_MAC_CARBON == 1
		//we need to do somethings else. FreeMem is going to return some large value
		//of all the available system memory
		//This whole thing is pointless. We can get as much memory as we need.

			#pragma unused (ctmasters)
			#pragma unused (ctcode)
			#pragma unused (ctheap)
		
		#else

		ctheap = FreeMem ();
		
		if (ctbytes > ctheap) {
			
			return (false);
			}
		
		ctbytes = (**h).avghandlesize;
		
		ctcode = (**h).reserveforcode;
		
		if ((ctbytes > 0) && (ctheap > ctcode)) {
			
			ctmasters = ((ctheap - ctcode) / ctbytes) / kNumberOfMasters;
			
			ctmasters = min (ctmasters, 1024);  /*7.1b37 PBS: You'd think 1024 calls would be enough. With large memory alottments on Mac
			  						  			Classic, we're calling MoreMasters in excess of 20,000 times. That makes the app take
			  						  			a minute or so to start up! So instead I've chosen an arbitrary limit.*/
			  						  
			for (i = 1; i < ctmasters; i++) 
				MoreMasters ();
			}
		#endif

		ReleaseResource ((Handle) h); /*we're done with it*/
		}
	
	//Code change by Timothy Paustian Thursday, June 8, 2000 3:21:06 PM
	//Changed to Opaque call for Carbon
	//we don't need this initialization in carbon
	#if TARGET_API_MAC_CARBON == 0
	InitGraf (&qd.thePort);
	
	InitFonts ();
	
	FlushEvents (everyEvent, 0);
	
	InitWindows ();
	
	InitMenus ();
	
	TEInit ();
	
	InitDialogs (0L);
	#endif

	
	InitCursor ();
	//Code change by Timothy Paustian Thursday, June 8, 2000 3:22:57 PM
	//Changed to Opaque call for Carbon
	//this is obsolete, we should be using gestalt for this.
	
	{	
		long quickDrawFeatures;
		OSErr theErr = Gestalt(gestaltSystemVersion, &gSystemVersion);
		if(oserror(theErr))
			ExitToShell();

		theErr = Gestalt(gestaltQuickdrawFeatures, &quickDrawFeatures);
		
		if(oserror(theErr))
			ExitToShell();
		gHasColorQD = (quickDrawFeatures & (1 << gestaltHasColor));
		//Nav services has to be present and we want the 1.1 or greater version.
		gCanUseNavServ = (NavServicesAvailable() && (NavLibraryVersion() >= 0x01108000));
	}
	
	
	//SysEnvirons (1, &macworld);
	
	//gee I bet this isn't required anymore either.
	for (i = 1; i <= 5; i++) { /*register with Multifinder*/
		
		EventRecord ev;
		
		EventAvail (everyEvent, &ev); /*see TN180 -- splash screen*/
		} /*for*/
	
	#if TARGET_API_MAC_CARBON == 1
	
		RegisterAppearanceClient ();
		
	#endif
	
	return (true);
	} /*initmacintosh*/