Beispiel #1
0
void PAS_sortIDs(short sourceRefNum, OSType theType, short **IdPtr, long *count)
{
	short				oldRef;
	Handle				theHandle;
	short				resCount;
	short				resIndex;
	
	*count	=	-1;
	
	oldRef = CurResFile();
		
	UseResFile(sourceRefNum);

	resCount = Count1Resources(theType);
	
	*IdPtr	=	(short*) NewPtrClear( resCount * sizeof(short) );
	
	for (resIndex=1; resIndex <= resCount; resIndex++)
	{
		theHandle = Get1IndResource(theType, resIndex);
		
		if(theHandle == NULL) return;
	
		(*IdPtr)[resIndex-1] = PAS_getResourceID(theHandle);
		
		ReleaseResource(theHandle);
	}
	
	UseResFile(oldRef);
	
	PAS_bubbleSortIDS(*IdPtr, resCount);
	
	
	*count = resCount;
}
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 #3
0
INTEGER CountResourcesRN (INTEGER rn, ResType type)
{
  INTEGER savern, retval;

  savern = CurResFile();
  UseResFile(rn);
  retval = Count1Resources(type);
  UseResFile(savern);
  return retval;
}
int16_t	CResourceFile::Count( const std::string& type )
{
	if( mResRefNum > 0 )
	{
		return Count1Resources(MakeOSType(type));
	}
	else
	{
		return 0;
	}
}
Beispiel #5
0
static PyObject *Res_Count1Resources(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short _rv;
    ResType theType;
#ifndef Count1Resources
    PyMac_PRECHECK(Count1Resources);
#endif
    if (!PyArg_ParseTuple(_args, "O&",
                          PyMac_GetOSType, &theType))
        return NULL;
    _rv = Count1Resources(theType);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("h",
                         _rv);
    return _res;
}
Beispiel #6
0
/*
**	FindBundleGivenCreator
**
**	Search the current resource file for the 'BNDL' resource with the given
**	creator and return a handle to it.
*/
static	OSErr	FindBundleGivenCreator(OSType creator,
									   BNDLRecHandle *returnBndl)
{
	OSErr			error;
	short			numOfBundles;
	short			index;
	BNDLRecHandle	theBndl;
	
	error = afpItemNotFound;	/* default to not found */
	
	/* Search each BNDL resource until we find the one with a matching creator. */
	
	numOfBundles = Count1Resources(kBNDLResType);
	index = 1;
	*returnBndl = NULL;
	
	while ( (index <= numOfBundles) && (*returnBndl == NULL) )
	{
		theBndl = (BNDLRecHandle)Get1IndResource(kBNDLResType, index);
		
		if ( theBndl != NULL )
		{
			if ( (*theBndl)->signature == creator )
			{
				/* numTypes and typeArray->count will always be the actual count minus 1, */
				/* so 0 in both fields is valid. */
				if ( ((*theBndl)->numTypes >= 0) && ((*theBndl)->typeArray->count >= 0) )
				{
					/* got it */
					*returnBndl = theBndl;
					error = noErr;
				}
			}
		}	
		
		index ++;
	}
	
	return ( error );
}
// Parse all resources in a set
bool XML_ResourceFork::ParseResourceSet(ResType Type)
{
    short NumResources = Count1Resources(Type);

    if (NumResources <= 0) {
        return false;
    }

    // This sorting is necessary so that the resources will be read in ascending order of ID's
    short *IDList = new short[NumResources];

    // Get the resource ID's
    SetResLoad(false);

    for (int ir=0; ir<NumResources; ir++)
    {
        // Zero-based to one-based indexing
        ResourceHandle = Get1IndResource(Type,ir+1);
        ResType _Type;
        Str255 Name;
        GetResInfo(ResourceHandle,&IDList[ir],&_Type,Name);
        ReleaseResource(ResourceHandle);
    }

    SetResLoad(true);

    // Using a better sorter; STL will succeed where Rhys Hill had failed :-)
    sort(IDList,IDList+NumResources);

    // Now get the resources
    for (int ir=0; ir<NumResources; ir++)
    {
        ParseResource(Type,IDList[ir]);
    }

    delete [] IDList;
    return true;
}
Beispiel #8
0
// hdll, pluginmain and audiomaster are set here
// must be NULL beforehand!
bool VSTPlugin::NewPlugin(const char *plugname)
{
    FLEXT_ASSERT(!pluginmain && !audiomaster);

    dllname = plugname;

#if FLEXT_OS == FLEXT_OS_WIN
    hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/);
/*
    char buf[255],*c;
    strcpy(buf,dllname.c_str());
    for(c = buf; *c; ++c) 
        if(*c == '/') 
            *c = '\\';
    char *sl = strrchr(buf,'\\');
    if(sl) *sl = 0;
    SetCurrentDirectory(buf);
    hdll = LoadLibrary(dllname.c_str());
*/
    if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main");
    audiomaster = Master;  

#elif FLEXT_OS == FLEXT_OS_MAC

#if 1
	CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8);
	if(fileNameString == 0) goto bail;
	CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false);
	CFRelease(fileNameString);
	if(url == 0) goto bail;
	hdll = CFBundleCreate(NULL, url);
	CFRelease (url);
	if(hdll && !CFBundleLoadExecutable(hdll)) goto bail;

    PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain"));
	if(!mainaddr)
		mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho"));
#ifdef __CFM__
    pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr);
    audiomaster = NewCFMFromMachO(Master);
#else
    pluginmain = (PVSTMAIN)mainaddr;
    audiomaster = Master;
#endif

#else
    short   resFileID;
    FSSpec  spec;
    OSErr err;

    err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL);
    resFileID = FSpOpenResFile(&spec, fsRdPerm);
    short cResCB = Count1Resources('aEff');

    for(int i = 0; i < cResCB; i++) {
        Handle             codeH;
        CFragConnectionID  connID;
        Ptr                mainAddr;
        Str255             errName;
        Str255             fragName;
        char               fragNameCStr[256];
        short              resID;
        OSType             resType;

        codeH = Get1IndResource('aEff', short(i+1));
        if(!codeH) continue;

        GetResInfo(codeH, &resID, &resType, fragName);
        DetachResource(codeH);
        HLock(codeH);

        err = GetMemFragment(*codeH,
                             GetHandleSize(codeH),
                             fragName,
                             kPrivateCFragCopy,
                             &connID, (Ptr *) & mainAddr, errName);

        if(!err) {
           #ifdef __CFM__
           pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr);
           #else
           pluginmain = (PVSTMAIN)mainAddr;
           #endif
        }
    }
    CloseResFile(resFileID);

    audiomaster = 
#ifdef __CFM__
        NewCFMFromMachO(Master);
#else
        Master;
#endif

#endif

#else
#error Platform not supported
#endif    

bail:
    if(pluginmain && audiomaster)
        return true;
    else {
        FreePlugin();
        return false;
    }
}
Beispiel #9
0
   void LoadVSTPlugins()
   {
#ifdef __MACOSX__
      audioMasterCallback audioMasterFPtr =
         (audioMasterCallback)NewCFMFromMachO(audioMaster);
#else
      // What is the corrct way of creating an audioMasterCallback
      // in OS 9/Carbon???
      // audioMasterCallback audioMasterFPtr = NULL; 
      audioMasterCallback audioMasterFPtr = audioMaster;
#endif      

      wxArrayString audacityPathList = wxGetApp().audacityPathList;
      wxArrayString pathList;
      wxArrayString files;
      unsigned int i;
      
      for(i=0; i<audacityPathList.GetCount(); i++) {
         wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
         wxGetApp().AddUniquePathToPathList(prefix + "VST",
                                            pathList);
         wxGetApp().AddUniquePathToPathList(prefix + "Plugins",
                                            pathList);
         wxGetApp().AddUniquePathToPathList(prefix + "Plug-Ins",
                                            pathList);
      }

      #ifdef __MACOSX__
      wxGetApp().AddUniquePathToPathList("/Library/Audio/Plug-Ins/VST",
                              pathList);
      wxString vstPath;
      vstPath.Printf("/Users/%s/Library/Audio/Plug-Ins/VST",
                     wxGetenv("USER"));
      wxGetApp().AddUniquePathToPathList(vstPath,
                                         pathList);
      #endif

      wxGetApp().FindFilesInPathList("*", pathList, wxFILE, files);
      
      for(i=0; i<files.GetCount(); i++) {
         short   resFileID;
         FSSpec  spec;
         
         wxMacFilename2FSSpec(FILENAME(files[i]), &spec);
         resFileID = FSpOpenResFile(&spec, fsRdPerm);
         short cResCB = Count1Resources('aEff');

         for (int i = 0; i < cResCB; i++) {
            Handle             codeH;
            CFragConnectionID  connID;
            Ptr                mainAddr;
            Str255             errName;
            Str255             fragName;
            char               fragNameCStr[256];
            short              resID;
            OSType             resType;
            OSErr              err;

            codeH = Get1IndResource('aEff', short(i+1));
            if (!codeH)
               continue;

            GetResInfo(codeH, &resID, &resType, fragName);
            DetachResource(codeH);
            HLock(codeH);

            err = GetMemFragment(*codeH,
                                 GetHandleSize(codeH),
                                 fragName,
                                 kPrivateCFragCopy,
                                 &connID, (Ptr *) & mainAddr, errName);

            if (!err) {
               vstPluginMain   pluginMain;
               AEffect        *theEffect;

               #ifdef __MACOSX__
               pluginMain = (vstPluginMain)NewMachOFromCFM(mainAddr);
               #else
               pluginMain = (vstPluginMain)mainAddr;
               #endif

               theEffect = pluginMain(audioMasterFPtr);

               if (theEffect->magic == kEffectMagic) {
                  
                  memcpy(fragNameCStr, &fragName[1], fragName[0]);
                  fragNameCStr[fragName[0]] = 0;
                  
                  VSTEffect *vst =
                     new VSTEffect(wxString(fragNameCStr), theEffect);
                  Effect::RegisterEffect(vst);
               }

               #ifdef __MACOSX__
               DisposeMachOFromCFM(pluginMain);
               #endif
               
               audacityVSTID++;
            }
         }
         
         CloseResFile(resFileID);

      }
         
#ifdef __MACOSX__
      DisposeCFMFromMachO(audioMasterFPtr);
#endif  //   __MACOSX__
   }
Beispiel #10
0
void main(fptr *f) {
	OSStatus err;
	DateTimeRec date;
	
#ifdef MULTI_SEGMENT
	/* Multi-segment code resource stuff */
	{
		Str255 buf;
		short i, n, theID;
		char **ch;
		OSType theType;
		n = Count1Resources('Cccc');
	    post("This external has %ld resources", (long) n);
		for (i = 1; i <= n; i++) {
			ch = Get1IndResource('Cccc', i);
			GetResInfo(ch, &theID, &theType, buf);
			rescopy('Cccc', theID);
		}
	}
#endif

#ifdef EXTENDED_CODE_RESOURCE
	// Cause it's an extended code resource...
	// rescopy('Cccc',22222);
#endif

	setup((t_messlist **)&otudp_class, (method)otudp_new, (method) otudp_free, (short)sizeof(OTUDP), 0L, A_GIMME, 0);
	
	version(0);
#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	post("Expires %d/%d/%d", MONTH, DAY, YEAR);
#endif


#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	GetTime(&date);
	if((date.year > YEAR)  || 
       (date.year == YEAR && ((date.month > MONTH) ||
							  (date.month == MONTH && date.day > DAY)))) {
            ouchstring(EXPIRATION_NOTICE);
            return;
    }
#endif
        
    // post ("*** before  InitOpenTransport();");
	err = InitOpenTransportInContext(kInitOTForExtensionMask, &OTContext);
	if (err != kOTNoError) {
		error("¥ OTUDP: Couldn't InitOpenTransport (err %d).  Perhaps Open Transport is not installed.",
					err);
		return;
	}
	
	/* bind methods */
	addmess((method) otudp_write, "FullPacket", A_LONG, A_LONG, 0);
	addmess((method) version, "version", 0);
	addmess((method) otudp_toggleErrorReporting, "errorreporting", 0);
	addmess((method) otudp_tellmeeverything, "tellmeeverything", 0);
	addmess((method) otudp_old_write, "write", A_GIMME, 0);
	addmess((method) otudp_old_write, "gimme", A_GIMME, 0);
	addmess((method) otudp_assist, "assist", A_CANT, 0);
	addmess((method) otudp_changeHost, "host", A_SYM, A_LONG, 0);
	addmess((method) otudp_changeReceivePort, "receiveport", A_LONG, 0);

	/* These methods are just for debugging. */
	addmess((method) otudp_debugstats, "debugstats", 0);
	addmess((method) otudp_resetdebugstats, "resetdebugstats", 0);
	addmess((method) otudp_read, "readitagainsam", 0);

	finder_addclass("System","otudp");

	ps_read = gensym("read");
	ps_write = gensym("write");
	ps_FullPacket = gensym("FullPacket");
	ps_PartialPacket = gensym("PartialPacket");
	ps_nbufs = gensym("nbufs");
	ps_bufsize = gensym("bufsize");
}
Beispiel #11
0
   void LoadVSTPlugins() {
      wxString home = DirManager::GetHomeDir();
      wxString pathChar = DirManager::GetPathChar();
      wxString vstDirPath = home + pathChar + "vst";
      wxString fname;

      fname =
          wxFindFirstFile((const char *) (vstDirPath + pathChar + "*"));

      while (fname != "") {
         short resID;
         FSSpec spec;

         wxMacFilename2FSSpec(fname, &spec);
         resID = FSpOpenResFile(&spec, fsRdPerm);
         Handle codeH;

         int count = Count1Resources('aEff');
         for (int i = 0; i < count; i++) {
            CFragConnectionID connID;
            Ptr mainAddr;
            Str255 errName;
            Str255 fragName;
            char fragNameCStr[256];
            short resID;
            OSType resType;
            OSErr err;

            codeH = Get1IndResource('aEff', count);
            GetResInfo(codeH, &resID, &resType, fragName);
            DetachResource(codeH);
            HLock(codeH);

            err = GetMemFragment(*codeH,
                                 GetHandleSize(codeH),
                                 fragName,
                                 kPrivateCFragCopy,
                                 &connID, (Ptr *) & mainAddr, errName);

            if (err >= 0) {

               Ptr symbolAddress;
               CFragSymbolClass symbolClass;

               err =
                   FindSymbol(connID, "\pmain", &symbolAddress,
                              &symbolClass);
               if (!err) {
                  vstPluginMain pluginMain = (vstPluginMain) symbolAddress;

                  AEffect *theEffect;

                  theEffect = pluginMain(audioMaster);

                  if (theEffect->magic == kEffectMagic) {

                     memcpy(fragNameCStr, &fragName[1], fragName[0]);
                     fragNameCStr[fragName[0]] = 0;

                     VSTEffect *vst =
                         new VSTEffect(wxString(fragNameCStr), theEffect);
                     Effect::RegisterEffect(vst);
                  }
               }
            } else {
               HUnlock(codeH);
            }

            audacityVSTID++;

            // Don't HUnlock unless you don't want to keep it in memory
         }

         CloseResFile(resID);
         fname = wxFindNextFile();
      }
   }
Beispiel #12
0
void main(fptr *f) {
	long oldA4;
	OSStatus err;
	DateTimeRec date;
	
	oldA4 = SetCurrentA4();
	RememberA4();
	FNS = f;	

#ifdef MULTI_SEGMENT
	/* Multi-segment code resource stuff */
	{
		Str255 buf;
		short i, n, theID;
		char **ch;
		OSType theType;
		n = Count1Resources('Cccc');
	    post("This external has %ld resources", (long) n);
		for (i = 1; i <= n; i++) {
			ch = Get1IndResource('Cccc', i);
			GetResInfo(ch, &theID, &theType, buf);
			rescopy('Cccc', theID);
		}
	}
#endif

#ifdef EXTENDED_CODE_RESOURCE
	// Cause it's an extended code resource...
	// rescopy('Cccc',22222);
#endif

	ps_readbufsize = gensym("readbufsize");
	ps_writebufsize = gensym("writebufsize");
	ps_OTTCP_nbytes = gensym("OTTCP_nbytes");
	ps_OTTCP_delim = gensym("OTTCP_delim");
	ps_connected = gensym("connected");
	ps_disconnected = gensym("disconnected");

	setup(&ottcp_class, ottcp_new, (method) ottcp_free, (short)sizeof(OTTCP), 0L, A_GIMME, 0);
	
	version(0);
#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	post("Expires %d/%d/%d", MONTH, DAY, YEAR);
#endif

#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	GetTime(&date);
	if((date.year > YEAR)  || 
       (date.year == YEAR && ((date.month > MONTH) ||
							  (date.month == MONTH && date.day > DAY)))) {
            ouchstring(EXPIRATION_NOTICE);
            goto quit;
    }
#endif
    
    // post ("*** before  InitOpenTransport();");
	err = InitOpenTransport();
	if (err != kOTNoError) {
		ouchstring("Couldn't InitOpenTransport (err %d).  Perhaps Open Transport is not installed.",
					err);
		goto quit;
	}
	
	/* bind methods */
	addmess((method) ottcp_connect, "connect", A_SYM, A_LONG, 0);
	addmess((method) ottcp_disconnect, "disconnect", 0);
	addmess((method) ottcp_read_nbytes, "nbytes", A_LONG, 0);
	addmess((method) ottcp_read_until_delimiter_symbol, "delim", A_SYM, 0);
	addmess((method) ottcp_read_until_delimiter_bytes, "delim-bytes", A_GIMME, 0);
	addmess((method) ottcp_write, "write", A_LONG, A_LONG, 0);
	addmess((method) version, "version", 0);
	addmess((method) ottcp_ErrorReporting, "errorreporting", 0);
	addmess((method) ottcp_tellmeeverything, "tellmeeverything", 0);
	addmess((method) ottcp_assist, "assist", A_CANT, 0);

	finder_addclass("System","ottcp");

quit:
	RestoreA4(oldA4);
}
Beispiel #13
0
void
hashicons (ControlHandle c)
{
/* todo: worry about filenames in FREFs */
  /* get FREF, BNDL, ICN#, ics#, icl8, ics8, icl4, ics4 */
  /* BNDL is:
     4 bytes of signature
     2 bytes of 0 [signature resource id?]
     2 bytes of <number of main entries - 1> (almost always 1)
     numberofmainentries *
     4 bytes of 'ICN#' or 'FREF'
     2 bytes of <number of entries - 1>
     numberofentries *
     2 bytes of localid
     2 bytes of resid
   */
/* todo: see what happens with multiple BNDLs */

  char *p;
  short i, j, spacemade, nummain, numbndls;
  unsigned short hashval;
  iconentry **iconarray;
  icontableentry **node;
  Handle h;
  OSType signature;
  short refnum, sigid;
  unsigned char state;
  applist **ah;

  refnum = openappres (c);
  numbndls = Count1Resources ('BNDL');
  for (i = 1; i <= numbndls; i++)
    {
      h = (Handle) Get1IndResource ('BNDL', i);
      state = HGetState (h);
      HLock (h);
      p = *h;
      signature = *(OSType *) p;
      p += 4;
      sigid = *(short *) p;
      p += 2;

      hashval = (unsigned long) signature % SIGARRAYSIZE;
#define CONTROLPROBLEMS
#ifndef CONTROLPROBLEMS
      for (ah = sigowners[hashval]; ah != 0 && (*ah)->sig != signature; ah = (*ah)->next)
	;
      if (ah == 0)
	{
#endif /* CONTROLPROBLEMS */
	  ah = sigowners[hashval];
	  sigowners[hashval] = (applist **) NewHandle (sizeof (applist));
	  (*sigowners[hashval])->next = ah;
	  (*sigowners[hashval])->parid = (*(item **) (*c)->contrlData)->ioparid;
	  (*sigowners[hashval])->vrefnum = (*(item **) (*c)->contrlData)->vrefnum;
	  (*sigowners[hashval])->sig = signature;
	  mystr255copy ((*sigowners[hashval])->name, (*c)->contrlTitle);
#ifndef CONTROLPROBLEMS
	}
#endif /* CONTROLPROBLEMS */

/* todo: find out if nummain must == 2 */
      nummain = *(short *) p + 1;
      p += 2;

      spacemade = 0;
      for (j = 0; j < nummain; j++)
	{
	  dobundle (&spacemade, &iconarray, &p);
	}

      for (j = 0; j < spacemade; j++)
	{
	  hashval = ((unsigned long) signature + (unsigned long) (*iconarray)[j].type)
	    % ICONTABLESIZE;
	  for (node = icontable[hashval]; node != 0 &&
	       ((*node)->sig != signature || (*node)->type != (*iconarray)[j].type);
	       node = (*node)->next)
	    ;
	  if (node == 0)
	    {
	      node = (icontableentry **) NewHandle (sizeof (icontableentry));
	      (*node)->sig = signature;
	      (*node)->type = (*iconarray)[j].type;
	      (*node)->next = icontable[hashval];
	      geticons (node, (*iconarray)[j].resid);
	      icontable[hashval] = node;
	    }
	}
      DisposHandle ((Handle) iconarray);
      HSetState (h, state);
      ReleaseResource (h);
    }
  CloseResFile (refnum);
}
Beispiel #14
0
// mode is either
// rnStartsWith
// rnContains
// rnIs
// rnEndsWith
// Please note this code is as yet untested
Handle BetterGetResourceByName(short resFile,ResType type,StringPtr name,unsigned char mode,Boolean caseSens)
{
	UResFileSaver		safe(resFile);
	UResLoadSaver		safe2(false);
	short				numRes=Count1Resources(type);
	Str255				resName;
	Handle				handle;
	Boolean				ok=false;
	
	gGetResErr=noErr;
	
	for (short counter=1; counter<numRes; counter++)
	{
		handle=BetterGetIndResource(-1,type,counter);
		if (!handle)
			return 0L;
		
		// got the handle, get the name.
		GetResName(handle,resName);
		
		// got the name, do the check
		switch (mode)
		{
			case rnStartsWith:
				if (name[0]<=resName[0])
					resName[0]=name[0];	// fall through and do a comparison
				else
				{
					ok=false;
					break;
				}
				
			case rnIs:		// exact match
				if (caseSens)
					ok=CmpPStr(name,resName);
				else
					ok=CmpPStrNoCase(name,resName);
				break;
								
			case rnContains:
				ok=(SearchForChars((Ptr)&resName[1],(Ptr)&name[1],resName[0],name[0],caseSens)!=-1);
				break;
				
			case rnEndsWith:
				if (name[0]<=resName[0])
					ok=CmpBuffer((Ptr)&name[1],(Ptr)&resName[name[0]],name[0],caseSens);
				else
					ok=false;
				break;
			
			default:
				ok=false;
				break;
		}
		
		if (ok)
			return handle;
		else
			ReleaseResource(handle);
	}
	
	gGetResErr=resNotFound;
	
	return 0L;
}
Beispiel #15
0
OSErr                osErr;
unsigned long        secs;
PaletteHandle        hPalette, hOldPalette;
CTabHandle           hColor;  
long                 total, contig;
Debug( DEBUGPARMS	 DebugParms; )

/**  validations  **/
	if (!fValidateConfiguration())
		ExitToShell(); 
	SetCursor(*GetCursor(watchCursor));

/**  a little memory cleanup  **/
#ifdef powerc
	SetResLoad(false);
	total = Count1Resources('CODE');
	for (int i = 1; i < total; i++)
	{
		Handle	hdl;
		if ((hdl = Get1IndResource('CODE', i)) != nil) 
		{
			HUnlock(hdl);
			ReleaseResource(hdl);
		}
	}
	SetResLoad(true);
	(void)CompactMem(kMinFreeSIZE);
#endif  // powerc

/**  get monitor device  **/
	if ((gMainScreen = GetMainDevice()) == nil)
Beispiel #16
0
/* parse and summarize FOND resource information */
static fond_table * parse_fond(FSSpec *spec)
{
    OSErr result = noErr;
    FSRef specref;
    SInt16 ref;
    Handle fond = NULL;
    unsigned char *res;
    fond_table *table = NULL;
    int i,j, count, n, start;

        /* FSpOpenResFile will fail for data fork resource (.dfont) files.
           FSOpenResourceFile can open either, but cannot handle broken resource
           maps, as often occurs in font files (the suitcase version of Arial,
           for example) Thus, we try one, and then the other. */

    result = FSpMakeFSRef(spec,&specref);
#ifdef __CARBON__
        if (result == noErr)
                result = FSOpenResourceFile(&specref, 0, NULL, fsRdPerm, &ref);
#else
        result = bdNamErr; /* simulate failure of the carbon routine above */
#endif
    if (result != noErr) {
            ref = FSpOpenResFile(spec, fsRdPerm);
            result = ResError();
        }
    if (result != noErr || ref <= 0) {
        char path[256];
        convertSpecToPath(spec, path, 256);
        dlprintf2("unable to open resource file '%s' for font enumeration (error %d)\n",
                path, result);
        goto fin;
    }

    /* we've opened the font file, now loop over the FOND resource(s)
       and construct a table of the font references */

    start = 0; /* number of entries so far */
    UseResFile(ref);
    count = Count1Resources('FOND');
    for (i = 0; i < count; i++) {
        fond = Get1IndResource('FOND', i+1);
        if (fond == NULL) {
            result = ResError();
            goto fin;
        }

        /* The FOND resource structure corresponds to the FamRec and AsscEntry
           data structures documented in the FontManager reference. However,
           access to these types is deprecated in Carbon. We therefore access the
           data by direct offset in the hope that the resource format will not change
           even if api access to the in-memory versions goes away. */
        HLock(fond);
        res = *fond + 52; /* offset to association table */
        n = get_int16(res) + 1;	res += 2;
                table = fond_table_grow(table, n);
        for (j = start; j < start + n; j++ ) {
            table->refs[j].size = get_int16(res); res += 2;
            table->refs[j].style = get_int16(res); res += 2;
            table->refs[j].id = get_int16(res); res += 2;
        }
        start += n;
        HUnlock(fond);
    }
fin:
    CloseResFile(ref);
    return table;
}