Exemplo n.º 1
0
char *__PHYSFS_platformGetUserName(void)
{
    char *retval = NULL;
    StringHandle strHandle;
    short origResourceFile = CurResFile();

    /* use the System resource file. */
    UseResFile(0);
    /* apparently, -16096 specifies the username. */
    strHandle = GetString(-16096);
    UseResFile(origResourceFile);
    BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);

    HLock((Handle) strHandle);
    retval = (char *) malloc((*strHandle)[0] + 1);
    if (retval == NULL)
    {
        HUnlock((Handle) strHandle);
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
    } /* if */
    memcpy(retval, &(*strHandle)[1], (*strHandle)[0]);
    retval[(*strHandle)[0]] = '\0';  /* null-terminate it. */
    HUnlock((Handle) strHandle);

    return(retval);
} /* __PHYSFS_platformGetUserName */
Exemplo n.º 2
0
void
UpdateAdditionsWin(void)
{
	Rect		r;
	Cell		c;
	int			i;
	GrafPtr		oldPort;
	GetPort(&oldPort);
	
	SetPort(gWPtr);
	
	MoveTo( gControls->aw->compListBox.left, gControls->aw->compListBox.top - kInterWidgetPad + 1);
	HLock(gControls->cfg->selAddMsg);
	DrawString( CToPascal(*gControls->cfg->selAddMsg));
	HUnlock(gControls->cfg->selAddMsg);
	
#if 0
	RGBColor backColorOld;
    Rect adjustedRect, *clRect = &gControls->aw->compListBox;
    SetRect(&adjustedRect, clRect->left, clRect->top+1, clRect->right, clRect->bottom-1);
    GetBackColor(&backColorOld);
    BackColor(whiteColor);
    EraseRect(&adjustedRect);
    RGBBackColor(&backColorOld);
#endif
   
	LUpdate( (*gControls->aw->compList)->port->visRgn, gControls->aw->compList);
	SetRect(&r, gControls->aw->compListBox.left, gControls->aw->compListBox.top,
	            gControls->aw->compListBox.right + 1, gControls->aw->compListBox.bottom);
	FrameRect(&r);	
	
	SetPt(&c, 0, 0);
	if (LGetSelect(true, &c, gControls->aw->compList))
	{
		HLock((Handle)gControls->aw->compDescTxt);
		SetRect(&r, (*gControls->aw->compDescTxt)->viewRect.left,
					(*gControls->aw->compDescTxt)->viewRect.top,
					(*gControls->aw->compDescTxt)->viewRect.right,
					(*gControls->aw->compDescTxt)->viewRect.bottom);
		HUnlock((Handle)gControls->aw->compDescTxt);
		TEUpdate(&r, gControls->aw->compDescTxt);	
	}
	
	DrawDiskSpaceMsgs( gControls->opt->vRefNum );
	
	for (i = 0; i < numRows; i++)
	{
		if (gControls->cfg->comp[rowToComp[i]].highlighted)
		{
			AddInitRowHighlight(i);
			break;
		}
	}
	
	SetPort(oldPort);
}
Exemplo n.º 3
0
static void unlock_collection(
	struct collection_header *header)
{
	assert(header->collection);
	
	HUnlock((Handle)header->collection);
	HUnlock((Handle)header->shading_tables);
	
	return;
}
Exemplo n.º 4
0
// This routine makes sure there is at least a null byte (and accompanying index)
// for every defined macro numbered n such that n < NUM_MACROS
// It lengthens the handle if necessary (backwards compatibility),
// but does NOT truncate additional data (forwards compatibility).
void fixMacros(NewMacroInfo *macrost)
{
	Handle macroHandle;
	Ptr macroPtr, pos;
	long len, len2;
	short i, num;

	macroHandle = macrost->handle;
	HLock(macroHandle);
	macroPtr = *macroHandle;
	len = macrost->index[0];
	pos = macroPtr;
	pos += (len - 1);

	if (*pos != 0) {
		len++;
		HUnlock(macroHandle);
		SetHandleSize(macroHandle, len);
		HLock(macroHandle);
		macroPtr = *macroHandle;
		pos = macroPtr + (len - 1);
		*pos = 0;
	}

	num = 0;
	for (i = 1; i < NUM_MACROS; i++) {
		if (macrost->index[i] == 0) {
			num = i;
			break;
		}
	}

	if (num) {
		len2 = len;
		len += (NUM_MACROS - num);
		HUnlock(macroHandle);
		SetHandleSize(macroHandle, len);
		HLock(macroHandle);
		macroPtr = *macroHandle;
		pos = macroPtr + len2;
		for (i = num; i < NUM_MACROS; i++, pos++) {
			*pos = 0;
			macrost->index[i] = pos - macroPtr;
		}
	}

	HUnlock(macroHandle);
	macrost->index[0] = len;
}
Exemplo n.º 5
0
void LoadAudioUnits()
{
   ComponentDescription desc;
   Component component;
   
   desc.componentType = kAudioUnitType_Effect; //'aufx'
   desc.componentSubType = 0;
   desc.componentManufacturer = 0;
   desc.componentFlags = 0;
   desc.componentFlagsMask = 0;
   
   component = FindNextComponent(NULL, &desc);
   while (component != NULL) {
      ComponentDescription found;
      Handle nameHandle = NewHandle(0);
      GetComponentInfo(component, &found, nameHandle, 0, 0);
      HLock(nameHandle);
      int len = ((const char *)(*nameHandle))[0];
      wxString name((const char *)(*nameHandle)+1, len);
      HUnlock(nameHandle);
      DisposeHandle(nameHandle);

      Effect::RegisterEffect(new AudioUnitEffect(name, component));

      component = FindNextComponent (component, &desc);
   }
}
Exemplo n.º 6
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.º 7
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.º 8
0
PRIVATE PicHandle
pict_from_gworld (GWorldPtr gp, int *lenp)
{
  PicHandle retval;

  if (!gp)
    retval = NULL;
  else
    {
      Rect pict_frame;
      PixMapHandle pm;

      pm = GetGWorldPixMap (gp);
      pict_frame = PIXMAP_BOUNDS (pm);
      retval = OpenPicture (&pict_frame);
      if (retval)
	{
	  ClipRect (&pict_frame);
	  HLock ((Handle) pm);
	  CopyBits ((BitMap *) STARH (pm), PORT_BITS_FOR_COPY (thePort),
		    &pict_frame, &pict_frame, srcCopy, NULL);
	  HUnlock ((Handle) pm);
	  ClosePicture ();
	}
    }
  return retval;
}
void	free_all_alloc_pools()
{
    PoolHandlePtr p, q;
    long count;

    if ( poolList == 0 ) return;
    assert( *poolList != 0 );

    // loop through the allocated blocks and free them
    p = *poolList;
    count = GetHandleSize( (Handle)poolList )/sizeof(PoolHandle);

    q = p + count;

    HLock( (Handle)poolList );
    while (p<q) {
        if ( *p != 0 )
            DisposeHandle( (Handle)*p );
        *p = 0;
        p++;
    }
    HUnlock( (Handle)poolList );

    DisposeHandle( (Handle)poolList );
    poolList = 0;

    // reset the alloc mechanism
    uninitialize_memory_pool();
}
Exemplo n.º 10
0
void PushCalcEntry(CtlRecHndl entryBox)
{
    abCalcOp *op;

    GetLETextByID(gCalcWinPtr, abCalcEntryBox, &gStrBuf);

    if (gStrBuf.textLength > 0) {
        gStrBuf.text[gStrBuf.textLength] = '\0';

        op = abCalcOpLookup(gStrBuf.text);

        if (op != NULL) {
            op->execute();
        } else if (abCalcParseExpr(&gNDAExpr, gStrBuf.text) != NULL) {
            abCalcStackExprPush(&gNDAExpr);
        } else {
            LERecHndl leHandle;

            HLock((Handle)entryBox);
            leHandle = (LERecHndl)(*entryBox)->ctlData;
            HUnlock((Handle)entryBox);

            LESetSelect(0, gStrBuf.textLength, leHandle);
            abCalcRaiseError(abCalcSyntaxError, NULL);
            return;
        }

        gStrBuf.textLength = 0;
        SetLETextByID(gCalcWinPtr, abCalcEntryBox, &gStrBuf);
    }
}
Exemplo n.º 11
0
/* convert icns(icons for MacOS X) to IPIcon */
OSErr	XIconToIPIcon(const FSSpec *theFile,IPIconRec *ipIcon)
{
	OSErr	err;
	IconFamilyHandle	theIconFamily;
	short		refNum;
	long		count;
	
	if (isIconServicesAvailable)
	{
		/* open icns file */
		err=FSpOpenDF(theFile,fsRdPerm,&refNum);
		if (err!=noErr) return err;
		
		err=GetEOF(refNum,&count);
		if (err!=noErr)
		{
			FSClose(refNum);
			return err;
		}
		theIconFamily=(IconFamilyHandle)NewHandle(count);
		HLock((Handle)theIconFamily);
		err=FSRead(refNum,&count,*theIconFamily);
		HUnlock((Handle)theIconFamily);
		
		err=FSClose(refNum);
		
		/* convert IconFamily to IPIcon */
		err=IconFamilyToIPIcon(theIconFamily,ipIcon);
		
		DisposeHandle((Handle)theIconFamily);
		return err;
	}
	else
		return -1;
}
Exemplo n.º 12
0
static int ResObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
{
    char *srcdata = NULL;
    int srclen = 0;
    Handle itself;
    char *kw[] = {"itself", 0};

    if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, ResObj_Convert, &itself))
    {
        ((ResourceObject *)_self)->ob_itself = itself;
        return 0;
    }
    PyErr_Clear();
    if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|s#", kw, &srcdata, &srclen)) return -1;
    if ((itself = NewHandle(srclen)) == NULL)
    {
        PyErr_NoMemory();
        return 0;
    }
    ((ResourceObject *)_self)->ob_itself = itself;
    if (srclen && srcdata)
    {
        HLock(itself);
        memcpy(*itself, srcdata, srclen);
        HUnlock(itself);
    }
    return 0;
}
Exemplo n.º 13
0
static PyObject *Res_Handle(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;

    char *buf;
    int len;
    Handle h;
    ResourceObject *rv;

    if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
        return NULL;
    h = NewHandle(len);
    if ( h == NULL ) {
        PyErr_NoMemory();
        return NULL;
    }
    HLock(h);
    memcpy(*h, buf, len);
    HUnlock(h);
    rv = (ResourceObject *)ResObj_New(h);
    rv->ob_freeit = PyMac_AutoDisposeHandle;
    _res = (PyObject *)rv;
    return _res;

}
Exemplo n.º 14
0
void FindFolderPath( Handle appendPathTo, int folderType, Str255  pathInFolder )
{
	OSErr err;
	short vRefNum;
	long dirID;
	long appendPathToLength;
	short pathLength;
	Handle path;
		
	// Try to get the application support folder
	err = FindFolder( kOnSystemDisk, folderType, FALSE, &vRefNum, &dirID );
	if( ! err )
	{		
		// Find the mindy:libraries dir and get its full path
		// Resize the destination handle to fit,
		// then copy in the path and the sub-path
		err = GetFullPath( vRefNum, dirID, "\p", &pathLength, &path );
		if( ! err )
		{
			appendPathToLength = GetHandleSize( appendPathTo );
			SetHandleSize( appendPathTo,  appendPathToLength+ pathLength + pathInFolder[ 0 ] );
			err = MemError();
			if( ! err )
			{
				HLock( appendPathTo );
				HLock( path );
					BlockMove( *path, &((*appendPathTo)[ appendPathToLength ]),  pathLength );
					BlockMove( &(pathInFolder[ 1 ]), &((*appendPathTo)[ appendPathToLength + pathLength ])  ,  pathInFolder[ 0 ] );
				HUnlock( path );
				HLock( appendPathTo );
			}
		}
	}
Exemplo n.º 15
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;
	}
}
Exemplo n.º 16
0
void * __sys_alloc(mem_size size, struct mem_pool_obj * )
{
    PoolHandlePtr slot;
    OSErr err;

    slot = NewPoolListSlot();
    assert ( slot != 0 );

    // (slot is dereferenced from poolList, and we dont want it to move)
    HLock( (Handle)poolList );

    // Allocate a new handle.
    // Use temporary memory if asked to.
    // Use application heap if temporary memory fails.
    if (use_temporary_memory)
        *slot = (PoolHandle)TempNewHandle( size, &err );
    if ( !use_temporary_memory || *slot == nil || err!=noErr )
        *slot = (PoolHandle)NewHandle( size );

    assert( *slot != 0 );
    HUnlock( (Handle)poolList );

    HLock( *slot );

    return(**slot);
}
Exemplo n.º 17
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.º 18
0
void runlock(
	handle h)
{
	HUnlock((Handle)h);
	
	return;
}
Exemplo n.º 19
0
Boolean
AddPopulateCompInfo()
{
	int 	i;
	char	*currDesc;
	Point	currCell;
	Boolean bCellSelected = false;
	int		nextRow = 0;
	
	for (i=0; i<gControls->cfg->numComps; i++)
	{
		if (!gControls->cfg->comp[i].invisible && gControls->cfg->comp[i].additional)
		{
			HLock(gControls->cfg->comp[i].shortDesc);
			currDesc = *gControls->cfg->comp[i].shortDesc;
			SetPt(&currCell, 0, nextRow);
			rowToComp[nextRow++] = i;
			LSetCell( currDesc, strlen(currDesc), currCell, gControls->aw->compList);
			HUnlock(gControls->cfg->comp[i].shortDesc);
			if (gControls->cfg->comp[i].selected == true)
			{
				LSetSelect(true, currCell, gControls->aw->compList);
				bCellSelected = true;
			}
		}
	}

	numRows = nextRow;	
	return bCellSelected;
}
Exemplo n.º 20
0
char *getpstr(
	char *buffer,
	short resource_number,
	short string_number)
{
	Handle strings= GetResource('STR#', resource_number);

	assert(strings);
	if (strings)
	{
		short count;
		byte *string_address;
		
		vassert(string_number>=0&&string_number<**((short**)strings),
			csprintf(temporary, "asked for #%d/#%d in 'STR#' ID#%d", string_number, **((short**)strings), resource_number));
		
		HLock(strings);
		count= 0;
		string_address= ((byte *)*strings)+2;
		while (count++<string_number)
		{
			string_address+= *string_address+1;
		}
		pstrcpy(buffer, (const char *)string_address);
		HUnlock(strings);
	}
	else
	{
		*buffer= '\0';
	}
	
	return buffer;
}
Exemplo n.º 21
0
void debug_newhand(long size,void *ptr)
{
long i;
Handle h;

if (current_level < 0) return;

if (!ptr) McoErrorAlert(MCO_INVALID_PTR);
if (!dbg_hand_ptrs) return;
if (!dbg_hand_sizes) return;
if (!dbg_hand_counts) return;
if (!dbg_hand_levels) return;
for (i=0; i<max_ptrs; i++) if (!dbg_hand_ptrs[i]) 
	{
	dbg_hand_ptrs[i] = ptr;
	dbg_hand_sizes[i] = size;
	dbg_hand_counts[i] = num_hand;
	dbg_hand_levels[i] = current_level;
	if ((num_hand == 24) || (num_hand == 25))
		{
		i = 0;
		}
	num_hand++;
	break;
	}
if (i == max_hand) McoErrorAlert(MCO_MAX_MEMORY);
h = (Handle)ptr;
HLock((Handle)h);
fill_mem(size,*h,HAND_FILL_I);
HUnlock((Handle)h);
}
Exemplo n.º 22
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.º 23
0
CFDataRef copyIconDataForURL(CFURLRef URL) {
	CFDataRef data = NULL;

	if (URL) {
		FSRef ref;
		if (CFURLGetFSRef(URL, &ref)) {
			IconRef icon = NULL;
			SInt16 label_noOneCares;
			OSStatus err = GetIconRefFromFileInfo(&ref,
												  /*inFileNameLength*/ 0U, /*inFileName*/ NULL,
												  kFSCatInfoNone, /*inCatalogInfo*/ NULL,
												  kIconServicesNoBadgeFlag | kIconServicesUpdateIfNeededFlag,
												  &icon,
												  &label_noOneCares);
			if (err != noErr) {
				NSLog(CFSTR("in copyIconDataForURL in CFGrowlAdditions: could not get icon for %@: GetIconRefFromFileInfo returned %li\n"), URL, (long)err);
			} else {
				IconFamilyHandle fam = NULL;
				err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &fam);
				if (err != noErr) {
					NSLog(CFSTR("in copyIconDataForURL in CFGrowlAdditions: could not get icon for %@: IconRefToIconFamily returned %li\n"), URL, (long)err);
				} else {
					HLock((Handle)fam);
					data = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)*(Handle)fam, GetHandleSize((Handle)fam));
					HUnlock((Handle)fam);
					DisposeHandle((Handle)fam);
				}
				ReleaseIconRef(icon);
			}
		}
	}

	return data;
}
Exemplo n.º 24
0
short getmacro(NewMacroInfo *macrost, short n, char *dest,
				short room) // no more quoteflag! no more kludge!
{ // RAB BetterTelnet 2.0b5
	Handle macroHandle;
	Ptr pos;
	long offset, length;

	if (n < 0 || n >= NUM_MACROS) {
		return -1;
		}

	// find the macro in the new structure
	if (n == 0)  // no offset for this
		offset = 0;
	else
		offset = macrost->index[n];

	macroHandle = macrost->handle;
	HLock(macroHandle);
	pos = *macroHandle;
	pos += offset;

	length = strlen(pos);
	if (length >= room) { // >= compensates for null termination
		length = room - 1; // truncate if too long
		strncpy(dest, pos, length);
		pos += length;
		*pos = 0;
	} else
		strcpy(dest, pos); // or just move it in
	HUnlock(macroHandle);
	return 0;
}
Exemplo n.º 25
0
pascal void snd_channel_callback(SndChannelPtr theChannel,SndCommand* theCommand) {
	long theA5;
	short channel = -1,i,which_sound;
	
#ifndef EXILE_BIG_GUNS
	theA5 = SetA5(theCommand->param2);
#endif
	
	for (i = 0; i < 4; i++)
		if (chan[i] == theChannel)
			channel = i;
	which_sound = snd_played[channel];
	snd_played[channel] = -1;
	//if (in_startup_mode == false)
	//	print_num(0,snd_played[channel],channel);
  	if ((sound_going(which_sound) == false) && (load_when_play[which_sound] == true)) {
	  	HUnlock(sound_handles[which_sound]);
		//if (in_startup_mode == false)
		//	print_num(99,snd_played[channel],channel);
	}
	
#ifndef EXILE_BIG_GUNS
	theA5 = SetA5(theA5);
#endif
}
Exemplo n.º 26
0
// postcondition: returns _LOCKED_ macro handle in desthp
short getmacrointohandle(NewMacroInfo *macrost, short n, Handle *desthp)
{ // RAB BetterTelnet 2.0b5 - for new sendmacro
	Handle macroHandle, desth;
	Ptr pos, dest;
	long offset, length;

	if (n < 0 || n >= NUM_MACROS) {
		return -1;
		}

	// find the macro in the new structure
	if (n == 0)  // no offset for this
		offset = 0;
	else
		offset = macrost->index[n];

	macroHandle = macrost->handle;
	HLock(macroHandle);
	pos = *macroHandle;
	pos += offset;

	length = strlen(pos);
	if (!length) return -1; // don't bother if it's null
	desth = myNewHandle(length + 1);
	if (!desth) return -1; // ouch
	HLock(desth);
	*desthp = desth;
	dest = *desth;
	strcpy(dest, pos); // here we go

	HUnlock(macroHandle); // that's right, we DON'T unlock the handle into which the macro
						  // has been copied (desth), only the global macros handle!
	return 0;
}
Exemplo n.º 27
0
  static short
  count_faces( Handle        fond,
               const UInt8*  pathname )
  {
    ResID     sfnt_id;
    short     have_sfnt, have_lwfn;
    Str255    lwfn_file_name;
    UInt8     buff[PATH_MAX];
    FT_Error  err;
    short     num_faces;


    have_sfnt = have_lwfn = 0;

    HLock( fond );
    parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );

    if ( lwfn_file_name[0] )
    {
      err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
                                 buff, sizeof ( buff )  );
      if ( !err )
        have_lwfn = 1;
    }

    if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
      num_faces = 1;
    else
      num_faces = count_faces_scalable( *fond );

    HUnlock( fond );
    return num_faces;
  }
Exemplo n.º 28
0
void setmacro(NewMacroInfo *macrost, short n, char *s) // RAB BetterTelnet 2.0b5
{
	// note that we don't check MACRO_MAX_LEN anymore - the new structure can handle most any
	// size of macro, doesn't use 8-bit length descriptors anywhere (all 16 or 32 bit) -
	// however, the final implementation still uses Str255-sized memory spaces. It is the
	// responsibility of whoever calls getmacro() to pass a reasonable value for "room"
	// to ensure correct truncation of oversized values.
	short i;
	Handle macroHandle;
	Ptr pos;
	long offset, offset2, offset3, ohlen, nhlen;
	short oslen, nslen; // ..len: o = old, n = new, h = handle, s = string

	macroHandle = macrost->handle;
	HLock(macroHandle);
	pos = *macroHandle;
	ohlen = GetHandleSize(macroHandle); // get all the lengths and offsets calculated
	if (n)
		offset = macrost->index[n];
	else offset = 0;
	oslen = strlen(pos + offset);
	nslen = strlen(s);
	nhlen = ohlen - oslen + nslen;
	offset2 = offset + oslen + 1; // the end of the old string
	offset3 = offset + nslen + 1; // the end of the new strings
	if (nhlen > ohlen) {
		HUnlock(macroHandle);
		SetHandleSize(macroHandle, nhlen); // make sure we have enough room
		HLock(macroHandle);
		pos = *macroHandle;
	}

	if (ohlen > offset2) { // move data after the insertion position up or down
		BlockMoveData(pos + offset2, pos + offset3, ohlen - offset2);
		for (i = n + 1; i < NUM_MACROS; i++) // fix the offsets
			macrost->index[i] += offset3 - offset2;
	}

	HUnlock(macroHandle);
	SetHandleSize(macroHandle, nhlen);
	HLock(macroHandle);
	pos = *macroHandle; // dereference _yet_ _again_ (rrgh)

	strcpy(pos+offset, s);
	HUnlock(macroHandle);
}
Exemplo n.º 29
0
PicHandle OpenPICTFile(
	short 	vRefNum, 
	Str255 	fName)
{
	short		fRefNum;
	OSErr		err;
	long		curEOF;
	PicHandle	myPic;
	long 		count;
	Ptr 		buffer;
	
	/* open PICT file */
	err = FSOpen(fName, vRefNum, &fRefNum);
	if (err != 0) {
		/*printf("Error - cannot open file\n"); */
		exit(-1);
	}
	
	/* get size of file */
	err = GetEOF(fRefNum, &curEOF);
	if (err != 0) {
		/*printf("Error - cannot get EOF\n"); */
		exit(-2);
	}
	
	/* move the file mark to 512 */
	err = SetFPos(fRefNum, SEEK_SET, 512L);
	if (err != 0) {
		/*printf("Error - cannot seek 512\n"); */
		exit(-3);
	}

	/* size of data to read */
	count = curEOF - 512;
	
	/* create the PicHandle */
	myPic = (PicHandle)NewHandle(count);
	HLock((Handle)myPic);
	
	/* read the PICT info */
	buffer = (Ptr)(*myPic);
	err = FSRead(fRefNum, &count, buffer);
	if (err != 0) {
		/*printf("Error - cannot read\n");*/
		exit(-4);
	}
	HUnlock((Handle)myPic);
	
	/* release the file */
	err = FSClose(fRefNum);
	if (err != 0) {
		/*printf("Error - cannot close file \n"); */
		exit(-5);
	}
	
	return (myPic);
}
Exemplo n.º 30
-1
P0(PUBLIC pascal trap, LONGINT, LoadScrap)
{
    OSErr retval;
    INTEGER f;
    LONGINT l = Cx(ScrapSize);
    
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
            return(retval);

        HUnlock(MR(ScrapHandle));
        ReallocHandle(MR(ScrapHandle), (Size)Cx(ScrapSize));
	if (MemErr != noErr)
/*-->*/	    return Cx(MemErr);
        HLock(MR(ScrapHandle));
        retval = FSReadAll(f, &l, STARH(MR(ScrapHandle)));
        HUnlock(MR(ScrapHandle));
        if (retval != noErr)
            return(retval);
        SetEOF(f, (LONGINT) 0);
        FSClose(f);
        ScrapState = CWC (1);
    }
    return(Cx(ScrapState) > 0 ? noErr : noScrapErr);
}