コード例 #1
0
ファイル: macros.c プロジェクト: macssh/macssh
// 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;
}
コード例 #2
0
ファイル: lists.c プロジェクト: 8devices/Caraboot
/*
 * copy is only as large as necessary
 */
list_t ListCopy (list_t originalList)
{
	list_t tempList = NULL;
	int numItems;

	if (!originalList)
		return NULL;

	tempList = ListCreate ((*originalList)->itemSize);
	if (tempList) {
		numItems = ListNumItems (originalList);

		if (!SetHandleSize ((Handle) tempList,
				    sizeof (ListStruct) +
				    numItems * (*tempList)->itemSize)) {
			ListDispose (tempList);
			return NULL;
		}

		(*tempList)->numItems = (*originalList)->numItems;
		(*tempList)->listSize = (*originalList)->numItems;
		(*tempList)->itemSize = (*originalList)->itemSize;
		(*tempList)->percentIncrease = (*originalList)->percentIncrease;
		(*tempList)->minNumItemsIncrease =
				(*originalList)->minNumItemsIncrease;

		memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0),
				numItems * (*tempList)->itemSize);
	}

	return tempList;
}
コード例 #3
0
ファイル: lists.c プロジェクト: 8devices/Caraboot
/*
 * list1 = list1 + list2
 */
int ListAppend (list_t list1, list_t list2)
{
	int numItemsL1, numItemsL2;

	if (!list2)
		return 1;

	if (!list1)
		return 0;
	if ((*list1)->itemSize != (*list2)->itemSize)
		return 0;

	numItemsL1 = ListNumItems (list1);
	numItemsL2 = ListNumItems (list2);

	if (numItemsL2 == 0)
		return 1;

	if (!SetHandleSize ((Handle) list1,
			    sizeof (ListStruct) + (numItemsL1 + numItemsL2) *
					(*list1)->itemSize)) {
		return 0;
	}

	(*list1)->numItems = numItemsL1 + numItemsL2;
	(*list1)->listSize = numItemsL1 + numItemsL2;

	memmove (ITEMPTR (list1, numItemsL1),
		 ITEMPTR (list2, 0),
		 numItemsL2 * (*list2)->itemSize);

	return 1;
}
コード例 #4
0
ファイル: ALEditing.c プロジェクト: NikolaBorisov/racket
static long local_ALGetDataFromGroup(Handle dataHandle, OSType flavorType, Handle groupData, long *marker)
{	long		dataSize;
	OSErr	err;

	if ( dataHandle == nil || groupData == nil || marker == nil )
		return 0;

	// Check to see if we've got the right flavor of data.
	if ( *(long *)&((*groupData)[*marker]) != flavorType )
		return 0;

	// Set the dataHandle's size to match the data from the group.
	*marker += sizeof(long);
	dataSize = *(long *)&((*groupData)[*marker]);
	SetHandleSize(dataHandle, dataSize);
	err = MemError();

	if (err == noErr) {
		*marker += sizeof(long);
		BlockMoveData(&((*groupData)[ *marker ]), *dataHandle, dataSize);
		*marker += dataSize;

		return dataSize;
	} else
		return 0;
}
コード例 #5
0
ファイル: memory.track.c プロジェクト: pombredanne/frontier-1
boolean newgrowinghandle (long size, Handle *h) {

    /*
    allocate a handle of the specified size, but with room to grow.

    note that the first getnewhandle should never fail, since the memory
    manager just told us that an even large block could be produced. but
    it's easy enough to handle that case too, so we do.
    */

    register long ctgrab = getidealchunksize ();

    if (ctgrab > size) {

        *h = getnewhandle (ctgrab, false);

        if (*h != nil) {

            SetHandleSize (*h, size); /*can't fail, getting smaller*/

            return (true);
        }
    }

    return (newhandle (size, h));
} /*newhandlewithroomtogrow*/
コード例 #6
0
ファイル: runner.c プロジェクト: dylan-hackers/GD_2_4
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 );
			}
		}
	}
コード例 #7
0
ファイル: metafile.cpp プロジェクト: HackLinux/chandler-1
bool wxMetafileDataObject::SetData(size_t len, const void *buf)
{
    Handle handle = NewHandle( len ) ;
    SetHandleSize( handle , len ) ;
    memcpy( *handle , buf , len ) ;
    m_metafile.SetHMETAFILE( (WXHMETAFILE) handle ) ;
    return true ;
}
コード例 #8
0
ファイル: QTInfo.c プロジェクト: fruitsamples/qtinfo.win
void QTInfo_PStringToTextHandle (Str255 theString, Handle theHandle)
{
    SetHandleSize(theHandle, theString[0]);
    if (GetHandleSize(theHandle) != theString[0])
        return;

    BlockMoveData(&(theString[1]), *theHandle, theString[0]);
}
コード例 #9
0
ファイル: macros.c プロジェクト: macssh/macssh
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);
}
コード例 #10
0
ファイル: shapes_macintosh.c プロジェクト: DrItanium/moo
static void strip_collection_handle(
	struct collection_definition **collection)
{
	SetHandleSize((Handle)collection, (*collection)->low_level_shape_offset_table_offset);
	(*collection)->low_level_shape_count= 0;
	(*collection)->bitmap_count= 0;
	
	return;
}
コード例 #11
0
ファイル: lists.c プロジェクト: 8devices/Caraboot
/*
 * This function reallocate the list, minus any currently unused
 * portion of its allotted memory.
 */
void ListCompact (list_t list)
{

	if (!SetHandleSize ((Handle) list,
			    sizeof (ListStruct) +
			    (*list)->numItems * (*list)->itemSize)) {
		return;
	}

	(*list)->listSize = (*list)->numItems;
}
コード例 #12
0
ファイル: ALEditing.c プロジェクト: NikolaBorisov/racket
static OSErr local_ALAddDataToGroup(const ALDataDescriptor *flavorDesc, Handle *groupData)
{	OSErr	err = noErr;
	long		marker;

	// Sanity check on parameters.
	if (groupData == nil || flavorDesc == nil)
		return paramErr;

	if (*groupData == nil)
		err = _ALAllocate(0, 0, groupData);

	if (err == noErr) {
		marker = GetHandleSize(*groupData);

		// Make room for the type and size fields.
		SetHandleSize(*groupData, marker + 2 * sizeof(long));
		err = MemError();
	}

	if (err == noErr) {
		*(long *)&((*(*groupData))[marker]) = flavorDesc->descriptorType;
		marker += sizeof(long);

		// Make room for the data itself, if there is any.
		if (flavorDesc->dataHandle != nil) {
			*(long *)&((*(*groupData))[marker]) = GetHandleSize(flavorDesc->dataHandle);
			SetHandleSize(*groupData, GetHandleSize(*groupData) + GetHandleSize(flavorDesc->dataHandle));
			err = MemError();

			if (err == noErr) {
				// Copy the data.
				marker += sizeof(long);
				BlockMoveData(*flavorDesc->dataHandle, &(*(*groupData))[marker], GetHandleSize(flavorDesc->dataHandle));
			}
		} else
			*(long *)&((*(*groupData))[marker]) = 0;
	}

	return err;
}
コード例 #13
0
ファイル: macstore.c プロジェクト: sdottaka/cvsnt-sjis
void write_setting_filename(void *handle, const char *key, Filename fn)
{
    int fd = *(int *)handle;
    AliasHandle h;
    int id;
    OSErr error;
    Str255 pkey;

    UseResFile(fd);
    if (ResError() != noErr)
        fatalbox("Failed to open saved session (%d)", ResError());

    if (filename_is_null(fn)) {
	/* Generate a special "null" alias */
	h = (AliasHandle)NewHandle(sizeof(**h));
	if (h == NULL)
	    fatalbox("Failed to create fake alias");
	(*h)->userType = 'pTTY';
	(*h)->aliasSize = sizeof(**h);
    } else {
	error = NewAlias(NULL, &fn.fss, &h);
	if (error == fnfErr) {
	    /*
	     * NewAlias can't create an alias for a nonexistent file.
	     * Create an alias for the directory, and record the
	     * filename as well.
	     */
	    FSSpec tmpfss;

	    FSMakeFSSpec(fn.fss.vRefNum, fn.fss.parID, NULL, &tmpfss);
	    error = NewAlias(NULL, &tmpfss, &h);
	    if (error != noErr)
		fatalbox("Failed to create alias");
	    (*h)->userType = 'pTTY';
	    SetHandleSize((Handle)h, (*h)->aliasSize + fn.fss.name[0] + 1);
	    if (MemError() != noErr)
		fatalbox("Failed to create alias");
	    memcpy((char *)*h + (*h)->aliasSize, fn.fss.name,
		   fn.fss.name[0] + 1);
	}
	if (error != noErr)
	    fatalbox("Failed to create alias");
    }
    /* Put the data in a resource. */
    id = Unique1ID(rAliasType);
    if (ResError() != noErr)
	fatalbox("Failed to get ID for resource %s (%d)", key, ResError());
    c2pstrcpy(pkey, key);
    AddResource((Handle)h, rAliasType, id, pkey);
    if (ResError() != noErr)
	fatalbox("Failed to add resource %s (%d)", key, ResError());
}
コード例 #14
0
int
TkSelGetSelection(
    Tcl_Interp *interp,		/* Interpreter to use for reporting
				 * errors. */
    Tk_Window tkwin,		/* Window on whose behalf to retrieve
				 * the selection (determines display
				 * from which to retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection
				 * is to be returned. */
    Tk_GetSelProc *proc,	/* Procedure to call to process the
				 * selection, once it has been retrieved. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    int result;
    long length, offset = 0;
    Handle handle;

    if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
	    && (target == XA_STRING)) {
	/* 
	 * Get the scrap from the Macintosh global clipboard.
	 */
	handle = NewHandle(1);
	length = GetScrap(handle, 'TEXT', &offset);
	if (length > 0) {
	    Tcl_DString encodedText;

	    SetHandleSize(handle, (Size) length + 1);
	    HLock(handle);
	    (*handle)[length] = '\0';

	    Tcl_ExternalToUtfDString(NULL, *handle, length, &encodedText);
	    result = (*proc)(clientData, interp,
		    Tcl_DStringValue(&encodedText));
	    Tcl_DStringFree(&encodedText);

	    HUnlock(handle);
	    DisposeHandle(handle);
	    return result;
	}
	
	DisposeHandle(handle);
    }
    
    Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
	" selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
	"\" not defined", (char *) NULL);
    return TCL_ERROR;
}
コード例 #15
0
ファイル: lists.c プロジェクト: 8devices/Caraboot
/*
 * If numNewItems == 0 then expand the list by the number of items
 * indicated by its allocation policy.
 * If numNewItems > 0 then expand the list by exactly the number of
 * items indicated.
 * If numNewItems < 0 then expand the list by the absolute value of
 * numNewItems plus the number of items indicated by its allocation
 * policy.
 * Returns 1 for success, 0 if out of memory
*/
static int ExpandListSpace (list_t list, int numNewItems)
{
	if (numNewItems == 0) {
		numNewItems = NUMITEMSPERALLOC (list);
	} else if (numNewItems < 0) {
		numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list);
	}

	if (SetHandleSize ((Handle) list,
			   sizeof (ListStruct) +
			   ((*list)->listSize +
			   numNewItems) * (*list)->itemSize)) {
		(*list)->listSize += numNewItems;
		return 1;
	} else {
		return 0;
	}
}
コード例 #16
0
ファイル: scrap.c プロジェクト: LarBob/executor
P3(PUBLIC pascal trap, LONGINT, PutScrap, LONGINT, len, ResType, rest, Ptr, p)
{
    OSErr retval;
    LONGINT l, swappedlen;
    INTEGER f;

    LONGINT *lp;

    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    return(retval);
    }
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    PutScrapX(rest, len, (char *) p, CW (ScrapCount));
#endif /* defined(X) */
    if (Cx(ScrapState) == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     return(retval);
        SetFPos(f, fsFromStart, (LONGINT)Cx(ScrapSize));
        l = 4;
	rest = CL(rest);
        FSWriteAll(f, &l, (Ptr) &rest);
        l = 4;
	swappedlen = CL(len);
        FSWriteAll(f, &l, (Ptr) &swappedlen);
        l = len = (len + 1) & -2L;
        FSWriteAll(f, &len, p);
        FSClose(f);
    } else {
        SetHandleSize(MR(ScrapHandle), (Size)Cx(ScrapSize) + 8);
	if (MemErr != noErr)
/*-->*/	    return CW(MemErr);
	/* alignment stuff */
        lp = (LONGINT *)((char *)STARH(MR(ScrapHandle)) + Cx(ScrapSize));
        *lp++ = CL(rest);
        *lp++ = CL(len);
        len = (len + 1) & -2L;
        PtrAndHand(p, MR(ScrapHandle), (Size)len);
    }
    ScrapSize = CL(CL(ScrapSize) + 8 + len);
    return noErr;
}
コード例 #17
0
static OSErr SpriteUtils_GetImageDescription (QTAtomContainer theKeySample, QTAtom theImagesContainerAtom, short theImageIndex, ImageDescriptionHandle theImageDesc)
{
	QTAtom						myImageAtom, myImageDataAtom;
	UInt8						mySaveState;
	UInt32						mySize;
	OSErr						myErr = noErr;

	myImageAtom = QTFindChildByIndex(theKeySample, theImagesContainerAtom, kSpriteImageAtomType, theImageIndex, NULL);
	if (myImageAtom == 0)	{ 
		myErr = cannotFindAtomErr; 
		goto bail;
	}

	myImageDataAtom = QTFindChildByIndex(theKeySample, myImageAtom, kSpriteImageDataAtomType, 1, NULL);
	if (myImageDataAtom == 0)	{ 
		myErr = cannotFindAtomErr; 
		goto bail;
	}

	mySaveState = HGetState((Handle)theImageDesc);
	HUnlock((Handle)theImageDesc);

	// copy the data (ImageDescription followed by image data) to a handle
	myErr = QTCopyAtomDataToHandle(theKeySample, myImageDataAtom, (Handle)theImageDesc);
	if (myErr != noErr)
		goto bail;

	mySize = EndianU32_BtoN((**theImageDesc).idSize);

	// pull off anything following the image description (& its color table, if any, and any image description extensions)
	SetHandleSize((Handle)theImageDesc, mySize);

#if TARGET_RT_LITTLE_ENDIAN
	EndianUtils_ImageDescription_BtoN(theImageDesc);
#endif

	HSetState((Handle)theImageDesc, mySaveState);
	myErr = MemError();
	
bail:
	return(myErr);
}
コード例 #18
0
ファイル: Search.c プロジェクト: Bluehorn/wxPython
/*
**	CheckStack checks the size of the search stack (array) to see if there's
**	room to push another LevelRec. If not, CheckStack grows the stack by
**	another kAdditionalLevelRecs elements.
*/
static	OSErr	CheckStack(unsigned short stackDepth,
						   LevelRecHandle searchStack,
						   Size *searchStackSize)
{
	OSErr	result;
	
	if ( (*searchStackSize / sizeof(LevelRec)) == (stackDepth + 1) )
	{
		/* Time to grow stack */
		SetHandleSize((Handle)searchStack, *searchStackSize + (kAdditionalLevelRecs * sizeof(LevelRec)));
		result = MemError();	/* should be noErr */
		*searchStackSize = GetHandleSize((Handle)searchStack);
	}
	else
	{
		result = noErr;
	}
	
	return ( result );
}
コード例 #19
0
ファイル: memory.track.c プロジェクト: pombredanne/frontier-1
static boolean resizehandle (Handle hresize, long size) {

    register Handle h = hresize;

    if (size > gethandlesize (h)) {

        if (hsafetycushion == nil) { /*don't allocate new stuff w/out safety cushion*/

            if (!getsafetycushion ())
                return (false);
        }
    }

    flholdsafetycushion = true;

    SetHandleSize (h, size);

    flholdsafetycushion = false;

    return (MemError () == noErr);
} /*resizehandle*/
コード例 #20
0
ファイル: macros.c プロジェクト: macssh/macssh
// RAB BetterTelnet 2.0b5
// handle should be locked and detached
void ParseMacrosFromHandle(NewMacroInfo *macrost, Handle theHandle)
{
	Ptr macroPtr;
	long macroLength;

	macroPtr = *theHandle;
	macroLength = GetHandleSize(theHandle) - 2;
	// format and sanity checks follow
	if ((macroLength < 1) || (*macroPtr != '!') || (*(macroPtr + 1) != '\015')) {
		DisposeHandle(theHandle);
		setupNewMacros(macrost);
		return;
	} // bah
	BlockMoveData(macroPtr + 2, macroPtr, macroLength); // get rid of !CR
	HUnlock(theHandle);
	SetHandleSize(theHandle, macroLength);
	HLock(theHandle);

// now invoke the actual parser
	parseNewMacros2(macrost, theHandle);
}
コード例 #21
0
static PoolHandlePtr NewPoolListSlot()
{   // Find or make an empty slot in the list.
    // WARNING: returns a pointer to data in an unlocked handle.
    PoolHandlePtr p, q;
    long count;
    const int kInitialSlots = 4;
    const int kIncreaseBySlots = 4;

    // Initialize the pool list if necessary
    if ( poolList == 0 ) {
        poolList = (PoolListHandle)NewHandleClear(kInitialSlots*sizeof(Handle));
        assert( poolList != 0 );
    }

    // Find an empty slot in the poolList (if there is one)
    count = GetHandleSize( (Handle)poolList )/sizeof(PoolHandle);

    p = *poolList;
    q = p + count;

    while (p<q) {
        if ( *p == 0 )
            return p;
        p++;
    }

    // Couldn't find and empty slot. Make some.
    SetHandleSize( (Handle)poolList, sizeof(PoolHandle) * ( count + kIncreaseBySlots) );
    assert( MemError() == noErr );

    // Note: poolList might have moved, so we *must* rebuild p and q.
    p = *poolList + count;
    q = p + kIncreaseBySlots;

    while ( p<q ) {
        *(p++) = 0;
    }

    return *poolList + count;
}
コード例 #22
0
ComponentResult VP8_Encoder_GetSettings(VP8EncoderGlobals globals, Handle settings)
{
  ComponentResult err = noErr;

  dbg_printf("[VP8e -- %08lx] GetSettings()\n", (UInt32) globals);

  if (!settings) {
    err = paramErr;
    dbg_printf("[VP8e -- %08lx] ParamErr\n", (UInt32) globals);
  } else {
    SetHandleSize(settings, TOTAL_CUSTOM_VP8_SETTINGS * 4);
    ((UInt32 *) *settings)[0] = 'VP80';
    int i;
    for (i=1;i < TOTAL_CUSTOM_VP8_SETTINGS; i++)
    {
      ((UInt32 *) *settings)[i] = globals->settings[i];
      //dbg_printf("[vp8e] get setting %d as %lu\n",i,((UInt32 *) *settings)[i]);
    }
  }

  return err;
}
コード例 #23
0
/* Close the device. */
static int
mac_close(register gx_device *dev)
{
	gx_device_macos	* mdev = (gx_device_macos *)dev;
	
	long	len;
	
	HUnlock((Handle) mdev->pic);	// no more changes in the pict -> unlock handle
	if (strcmp(mdev->outputFileName, "")) {
		DisposeHandle((Handle) mdev->pic);
		gx_device_close_output_file(dev, mdev->outputFileName, mdev->outputFile);
		mdev->outputFile = 0;
	} else {
		len = (long)mdev->currPicPos - (long)*mdev->pic;
		SetHandleSize((Handle) mdev->pic, len + 10);  // +10 just for the case
	}
	
	// notify the caller that the device was closed
	// it has to dispose the PICT handle when it is ready!
	if (pgsdll_callback)
		(*pgsdll_callback) (GSDLL_DEVICE, (char *)mdev, 0);
	
	return 0;
}
コード例 #24
0
ファイル: _Resmodule.c プロジェクト: 0xcc/python-read
static int ResObj_set_data(ResourceObject *self, PyObject *v, void *closure)
{

                    char *data;
                    long size;

                    if ( v == NULL )
                            return -1;
                    if ( !PyString_Check(v) )
                            return -1;
                    size = PyString_Size(v);
                    data = PyString_AsString(v);
                    /* XXXX Do I need the GetState/SetState calls? */
            SetHandleSize(self->ob_itself, size);
            if ( MemError())
                return -1;
            HLock(self->ob_itself);
            memcpy((char *)*self->ob_itself, data, size);
            HUnlock(self->ob_itself);
            /* XXXX Should I do the Changed call immedeately? */
            return 0;

    return 0;
}
コード例 #25
0
ファイル: heapgrow.c プロジェクト: chunhualiu/OpenNT
int __cdecl _heap_grow (
	REG1 size_t size
	)
{
	REG2 int index;
	struct _heap_region_ *pHeapRegions;
	int free_entry = -1;
	size_t sizeTmp;
	Handle hTemp;

	/*
	 * Bump size to include header and round to nearest page boundary.
	 */

	size += _HDRSIZE;
	size = _ROUND2(size, _GRANULARITY);

	/*
	 * Loop through the region table looking for an existing region
	 * we can grow.  Remember the index of the first null region entry.
	 *
	 * size = size of grow request
	 */

	for ( index=index_start ; index < _heap_region_table_cur; index++ ) {

		pHeapRegions = (struct _heap_region_ *)(*hHeapRegions);
			/*
			 * Grow this region to satisfy the request.
			 */
		if ( (pHeapRegions+index)->_regbase != NULL)
			{
			if (_heap_grow_region(index, size) != -1)
				{
				index_start = index;
				return 0;
				}
			}

		pHeapRegions = (struct _heap_region_ *)(*hHeapRegions);
		if ( (free_entry == -1) &&
		    ((pHeapRegions+index)->_regbase == NULL) )

			/*
			 * Remember 1st free table entry for later
			 */
			{
			free_entry = index;
			break;
			}

	}

	/*
	 * Could not find any existing regions to grow.  Try to
	 * get a new region.
	 *
	 * size = size of grow request
	 * free_entry = index of first free entry in table
	 */

	if ( free_entry == -1)
		/*
		 * No free table entries: grow heap region table.
		 */
		{
		sizeTmp = sizeof(struct _heap_region_)*(_heap_region_table_cur+_HEAP_REGIONMAX);
		if (hHeapRegions)
			{
			SetHandleSize(hHeapRegions, sizeTmp);
			}
		if (hHeapRegions== NULL || *pMemErr != 0)
			{
			/*
			 * grow failed
			 */
			hTemp = NewHandle(sizeTmp);
			if (hTemp == NULL)
				{
				return (-1);
				}
			HLock(hTemp);
			if (hHeapRegions != NULL)
				{
				BlockMove(*hHeapRegions, *hTemp, sizeof(struct _heap_region_)*_heap_region_table_cur);
				DisposeHandle(hHeapRegions);
				}
			hHeapRegions = hTemp;
			}
		/*
		 * set rest of the table to zero
		 */
		memset(*hHeapRegions + sizeof(struct _heap_region_)*_heap_region_table_cur, 0, sizeof(struct _heap_region_)*_HEAP_REGIONMAX);
		free_entry = _heap_region_table_cur;
		_heap_region_table_cur += _HEAP_REGIONMAX;
		}
	/*
	 * Get a new region to satisfy the request.
	 */

	return( _heap_new_region(free_entry, size) );
}
コード例 #26
0
ファイル: BLAST Encode.c プロジェクト: MaddTheSane/tntbasic
Boolean EckerEncodeTheRect(EncodePtr theEncode)
{
	unsigned char 		*srcPtr;		// position in the pixmap
	unsigned char		*destPtr;		// position in the shape data
	unsigned char		*baseAddr;		// start of pixMap
	unsigned char		*rowStart;		// start of current scanline
	unsigned char		*lineStartPtr;	// address of the line start token for this line
	unsigned char		*runTokenPtr;	// where is the token for the current run
	
	short				runCounter;		// the number of pixels in the current run
	short				rowBytes;		// how many bytes in a scanline
	short				width,height;
	short				xCount,yCount;
	short				runMode;		// the mode that the encoder is in
	Boolean				runSwitch=false;	// a flag saying whether the encoder should switch modes
	Rect				shrunkRect=*theEncode->theRect;
	short				clearCol=theEncode->clearCol;		// the transparent colour
	short				shadowCol=theEncode->shadowCol;		// the shadow colour
	
	// get pointer to source
	baseAddr=theEncode->theRec->baseAddr;
	rowBytes=theEncode->theRec->rowBytes;
	
	if (theEncode->shrinkRect)
	{
		// shrink the rectangle to the smallest size possible
		// move top down
		short		counter,col;
		Boolean		exit=false;
		
		while (shrunkRect.top<shrunkRect.bottom && !exit)
		{
			for (counter=shrunkRect.left; counter<shrunkRect.right; counter++)
			{
				col=BL_PixCol(counter,shrunkRect.top);
				if (col!=clearCol) // hit the data, stop shrinking
				{
					exit=true;
					break;
				}
			}
			if (!exit) // shrink it
				shrunkRect.top++;
		}
		
		// move bottom up
		exit=false;
		while (shrunkRect.bottom>shrunkRect.top && !exit)
		{
			for (counter=shrunkRect.left; counter<shrunkRect.right; counter++)
			{
				col=BL_PixCol(counter,shrunkRect.bottom-1);
				if (col!=clearCol) // hit the data, stop shrinking
				{
					exit=true;
					break;
				}
			}
			if (!exit) // shrink it
				shrunkRect.bottom--;
		}
		
		// move left right
		exit=false;
		while (shrunkRect.left<shrunkRect.right && !exit)
		{
			for (counter=shrunkRect.top; counter<shrunkRect.bottom; counter++)
			{
				col=BL_PixCol(shrunkRect.left,counter);
				if (col!=clearCol) // hit the data, stop shrinking
				{
					exit=true;
					break;
				}
			}
			if (!exit) // shrink it
				shrunkRect.left++;
		}
		
		// more right left
		exit=false;
		while (shrunkRect.right>shrunkRect.left && !exit)
		{
			for (counter=shrunkRect.top; counter<shrunkRect.bottom; counter++)
			{
				col=BL_PixCol(shrunkRect.right-1,counter);
				if (col!=clearCol) // hit the data, stop shrinking
				{
					exit=true;
					break;
				}
			}
			if (!exit) // shrink it
				shrunkRect.right--;
		}
	}
	
	width=shrunkRect.right-shrunkRect.left;
	height=shrunkRect.bottom-shrunkRect.top;
	
	if (theEncode->theImage==0L)
	{
		theEncode->theImage=(ImageHandle)NewHandle(WorstCaseEncode(&shrunkRect));
		if (!theEncode->theImage)
			return false; // not enough RAM
	}
	
	// get pointer to dest
	destPtr=(unsigned char *)*theEncode->theImage; // pointer to destination buffer
	destPtr+=sizeof(ImageData); // skip past the header
	
	// Fill out the header
	// alter the x and y off sets so that the changes in shrinking the rect 
	// have no effect on any position strategies of the user
	(**theEncode->theImage).xoff=theEncode->theRect->left-shrunkRect.left;
	(**theEncode->theImage).yoff=theEncode->theRect->top-shrunkRect.top;
	(**theEncode->theImage).width=width;
	(**theEncode->theImage).height=height;
	
	// work out where we start from
	rowStart=baseAddr + rowBytes * shrunkRect.top + shrunkRect.left;
	
	// scan the shape
	for (yCount=0; yCount<height; yCount++)
	{
		// for each row do...
		lineStartPtr=destPtr;			// make a note of the place to place the line start token
		destPtr+=sizeof(unsigned long); // increase to point at next free slot (where the next token goes)
		
		// at the beginning of each row we are not in any run
		runMode=rmNoRun;
		runCounter=0;
		
		// move to the start of the row
		srcPtr=rowStart;
		
		// for each pixel of the row
		for (xCount=0; xCount<width; xCount++)
		{
			do		// this do while should only ever loop around once per pixel and only if a runswitch occurs
			{
				runSwitch=false;		// don't switch modes (therefore don't loop around)
				
				switch (runMode)
				{
					case rmSkipRun:		// we are currently skipping pixels, if this one is clear cont
						if (*srcPtr==clearCol)
							runCounter++;
						else
							runSwitch=true;	// if not it's time to switch run mode
						break;
					
					case rmDrawRun:		// we are currently drawing pixels, if this is not a shadow or clear then store it
						if ((*srcPtr!=clearCol) && (*srcPtr!=shadowCol))
						{
							*destPtr=*srcPtr;	// store the data
							destPtr++;
							runCounter++;
						}
						else
							runSwitch=true;
						break;
						
					case rmShadowRun:	// in a shadow run, if this is a shadow pixel continue
						if (*srcPtr==shadowCol)
							runCounter++;
						else
							runSwitch=true;
						break;
					
					case rmNoRun:		// if we're not in a run then switch into one
						runSwitch=true;
						break;
				}
				
				// at this stage, the pixel will have been processed unless the runMode was wrong for
				// the pixel. If it was wrong, the runSwitch flag will have been set. If it is set
				// then we switch modes here and loop back and do the above switch statement again.
				if (runSwitch)
				{
					// Time to switch runModes. First thing is to finish the current run if we were
					// actually in one.
					if (runMode!=rmNoRun)
					{
						*((unsigned long *)runTokenPtr)=(runMode<<24)+runCounter; // store the opCode
						if (runMode==rmDrawRun) // if we've been writing pixels then make sure it's all aligned
						{
							*((unsigned long *)destPtr)=0L; // clear the next 4 bytes
							destPtr += ((runCounter & 3L) == 0) ? 0 : (4-(runCounter & 3L)); // pad the data from the last run out so that it finishes on a 4 byte boundry
						}
					}
					
					// Reset for the next run
					runCounter=0; // reset for the next run
					runTokenPtr=destPtr;
					destPtr+=sizeof(unsigned long); // remember where the runtoken is to go
					
					if (*srcPtr==clearCol)		// switch the mode
						runMode=rmSkipRun;
					else if (*srcPtr==shadowCol)
						runMode=rmShadowRun;
					else
						runMode=rmDrawRun;
				}
				
			} while (runSwitch); // loop around again if there was a runMode switch
		
			srcPtr++; // next pixel across
		}

		// That is that row finished
		// We must finish any run that we are in as the run cannot continue across rows
		// it does not need to be finished if it is a skip pixel run as it is not necessary to
		// save them over rows (NB: Should never get to here no rmNoRun)
		if (runMode!=rmSkipRun)
		{
			*((unsigned long *)runTokenPtr)=(runMode<<24)+runCounter; // store the opCode
			if (runMode==rmDrawRun) // if data was being written then align it
			{
				*((unsigned long *)destPtr)=0L; // clear the next 4 bytes
				destPtr += ((runCounter & 3L) == 0) ? 0 : (4-(runCounter & 3L)); // pad the data from the last run out so that it finishes on a 4 byte boundry
			}
		}
		else
		{
			// as we don't need to write rmSkipRun tokens, we can move dest pointer back from
			// pointing at the slot after where the skip opcode was going to go to where the
			// skip op code was going to go (which is still empty).
			destPtr-=sizeof(unsigned long);
		}
			
		// Create line start token and increase row start
		*((unsigned long *)lineStartPtr)=(rmLineStart<<24)+(destPtr-(lineStartPtr+4)); // the data in the linestart op is how long this line is
		rowStart+=rowBytes; // start next row
	}
	
	// Finshed the shape
	// Create the end shape token
	*((unsigned long *)destPtr)= rmEndShape << 24;
	destPtr+=sizeof(unsigned long);

	if (theEncode->shrinkHandle)
	{
		// Resize the handle from the worst case size to the real size
		SetHandleSize((Handle)theEncode->theImage,destPtr-(unsigned char *)(*theEncode->theImage));
	}
	
	return true;
}
コード例 #27
0
ファイル: QTSound.c プロジェクト: fruitsamples/qtcreatemovie
static void QTSound_CreateSoundDescription (Handle sndHandle,
        SoundDescriptionHandle sndDesc,
        long *sndDataOffset,
        long *numSamples,
        long *sndDataSize )
{
    long sndHdrOffset = 0;
    long sampleDataOffset;
    SoundHeaderPtr sndHdrPtr = nil;
    long numFrames;
    long samplesPerFrame;
    long bytesPerFrame;
    SoundDescriptionPtr sndDescPtr;


    *sndDataOffset = 0;
    *numSamples = 0;
    *sndDataSize = 0;

    SetHandleSize( (Handle)sndDesc, sizeof(SoundDescription) );
    CheckError(MemError(),"SetHandleSize error");
    sndHdrOffset = QTSound_GetSndHdrOffset (sndHandle);
    if (sndHdrOffset == 0)
    {
        CheckError(-1, "QTSound_GetSndHdrOffset error");
    }

    /* we can use pointers since we don't move memory */
    sndHdrPtr = (SoundHeaderPtr) (*sndHandle + sndHdrOffset);
    sndDescPtr = *sndDesc;

    sndDescPtr->descSize = sizeof (SoundDescription);
    /* total size of sound description structure */
    sndDescPtr->resvd1 = 0;
    sndDescPtr->resvd2 = 0;
    sndDescPtr->dataRefIndex = 1;
    sndDescPtr->compressionID = 0;
    sndDescPtr->packetSize = 0;
    sndDescPtr->version = 0;
    sndDescPtr->revlevel = 0;
    sndDescPtr->vendor = 0;

    switch (sndHdrPtr->encode)
    {
    case stdSH:
        sndDescPtr->dataFormat = kRawCodecType;
        /* uncompressed offset-binary data */
        sndDescPtr->numChannels = 1;
        /* number of channels of sound */
        sndDescPtr->sampleSize = 8;
        /* number of bits per sample */
        sndDescPtr->sampleRate = sndHdrPtr->sampleRate;
        /* sample rate */
        *numSamples = sndHdrPtr->length;
        *sndDataSize = *numSamples;
        bytesPerFrame = 1;
        samplesPerFrame = 1;
        sampleDataOffset = (Ptr)&sndHdrPtr->sampleArea - (Ptr)sndHdrPtr;
        break;

    case extSH:
    {
        ExtSoundHeaderPtr extSndHdrP;

        extSndHdrP = (ExtSoundHeaderPtr)sndHdrPtr;
        sndDescPtr->dataFormat = kRawCodecType;
        /* uncompressed offset-binary data */

        /* we typecast a long to a short here, and it should really be fixed */
        sndDescPtr->numChannels = (short)extSndHdrP->numChannels;
        /* number of channels of sound */
        sndDescPtr->sampleSize = extSndHdrP->sampleSize;
        /* number of bits per sample */
        sndDescPtr->sampleRate = extSndHdrP->sampleRate;
        /* sample rate */
        numFrames = extSndHdrP->numFrames;
        *numSamples = numFrames;
        bytesPerFrame = extSndHdrP->numChannels * ( extSndHdrP->sampleSize / 8);
        samplesPerFrame = 1;
        *sndDataSize = numFrames * bytesPerFrame;
        sampleDataOffset = (Ptr)(&extSndHdrP->sampleArea) - (Ptr)extSndHdrP;
    }
    break;

    case cmpSH:
    {
        CmpSoundHeaderPtr cmpSndHdrP;

        cmpSndHdrP = (CmpSoundHeaderPtr)sndHdrPtr;
        /* we typecast a long to a short here, and it should really be fixed */

        sndDescPtr->numChannels = (short)cmpSndHdrP->numChannels;
        /* number of channels of sound */
        sndDescPtr->sampleSize = cmpSndHdrP->sampleSize;
        /* number of bits per sample before compression */
        sndDescPtr->sampleRate = cmpSndHdrP->sampleRate;
        /* sample rate */
        numFrames = cmpSndHdrP->numFrames;
        sampleDataOffset =(Ptr)(&cmpSndHdrP->sampleArea) - (Ptr)cmpSndHdrP;

        switch (cmpSndHdrP->compressionID)
        {
        case threeToOne:
            sndDescPtr->dataFormat = kMACE3Compression;
            /* compressed 3:1 data */
            samplesPerFrame = kMACEBeginningNumberOfBytes;
            *numSamples = numFrames * samplesPerFrame;

            switch (cmpSndHdrP->numChannels)
            {
            case 1:
                bytesPerFrame = cmpSndHdrP->numChannels
                                * kMACE31MonoPacketSize;
                break;

            case 2:
                bytesPerFrame = cmpSndHdrP->numChannels
                                * kMACE31StereoPacketSize;
                break;

            default:
                CheckError(-1, "Corrupt sound data" );
                break;
            }

            *sndDataSize = numFrames * bytesPerFrame;
            break;

        case sixToOne:
            sndDescPtr->dataFormat = kMACE6Compression;
            /* compressed 6:1 data */
            samplesPerFrame = kMACEBeginningNumberOfBytes;
            *numSamples = numFrames * samplesPerFrame;

            switch (cmpSndHdrP->numChannels)
            {
            case 1:
                bytesPerFrame = cmpSndHdrP->numChannels
                                * kMACE61MonoPacketSize;
                break;

            case 2:
                bytesPerFrame = cmpSndHdrP->numChannels
                                * kMACE61StereoPacketSize;
                break;

            default:
                CheckError(-1, "Corrupt sound data" );
                break;
            }

            *sndDataSize = (*numSamples) * bytesPerFrame;
            break;

        default:
            CheckError(-1, "Corrupt sound data" );
            break;
        }

        } /* switch cmpSndHdrP->compressionID:*/

        break;  /* of cmpSH: */

    default:
        CheckError(-1, "Corrupt sound data" );
        break;

    } /* switch sndHdrPtr->encode */

    *sndDataOffset = sndHdrOffset + sampleDataOffset;
}
コード例 #28
0
OSErr SpriteUtils_AddCompressedSpriteSampleToMedia (Media theMedia, QTAtomContainer theSample, TimeValue theDuration, Boolean isKeyFrame, OSType theDataCompressorType, TimeValue *theSampleTime)
{
	SpriteDescriptionHandle		mySampleDesc = NULL;
	Handle						myCompressedSample = NULL;
	ComponentInstance			myComponent = NULL;
	OSErr						myErr = noErr;
	
	myErr = OpenADefaultComponent(DataCompressorComponentType, theDataCompressorType, &myComponent);
	if (myErr != noErr)
		goto bail;

	mySampleDesc = (SpriteDescriptionHandle)NewHandleClear(sizeof(SpriteDescription));
	if (mySampleDesc == NULL) {
		myErr = MemError();
		goto bail;
	}
	
	if (myComponent != NULL) {
		UInt32					myCompressBufferSize, myActualCompressedSize, myDecompressSlop = 0;
		UInt32					myUncompressedSize;
		SignedByte 				mySaveState = HGetState(theSample);
		
		myErr = (OSErr)DataCodecGetCompressBufferSize(myComponent, GetHandleSize(theSample), &myCompressBufferSize);
		if (myErr != noErr)
			goto bail;
		
		myCompressedSample = NewHandle(sizeof(UInt32) + myCompressBufferSize);
		myErr = MemError();
		if (myErr != noErr)
			goto bail;
		
		HLockHi(theSample);
		HLockHi(myCompressedSample);
		myErr = (OSErr)DataCodecCompress(myComponent, 
										*theSample, 
										GetHandleSize(theSample), 
										*myCompressedSample + sizeof(UInt32), 		// room for size at beginning
										myCompressBufferSize, 
										&myActualCompressedSize,
										&myDecompressSlop);
		
		HSetState(theSample, mySaveState);
		HUnlock(myCompressedSample);
		
		if (myErr != noErr)
			goto bail;
		
		SetHandleSize(myCompressedSample, sizeof(UInt32) + myActualCompressedSize);
		myErr = MemError();
		if (myErr != noErr)
			goto bail;

		(**mySampleDesc).decompressorType = EndianU32_NtoB(theDataCompressorType);
	
		myUncompressedSize = GetHandleSize(theSample);
		(*(UInt32*) *myCompressedSample) = EndianU32_NtoB(myUncompressedSize);		// add uncompressed size at beginning
		
		myErr = AddMediaSample(theMedia,
								(Handle)myCompressedSample,
								0,
								GetHandleSize(myCompressedSample),
								theDuration,
								(SampleDescriptionHandle)mySampleDesc,
								1,
								(short)(isKeyFrame ? 0 : mediaSampleNotSync),
								theSampleTime);
	} else {
		myErr = AddMediaSample(theMedia,
								(Handle)theSample,
								0,
								GetHandleSize(theSample),
								theDuration,
								(SampleDescriptionHandle)mySampleDesc,
								1,
								(short)(isKeyFrame ? 0 : mediaSampleNotSync),
								theSampleTime);
	}
	
bail:
	if (myCompressedSample != NULL)
		DisposeHandle(myCompressedSample);
		
	if (mySampleDesc != NULL)
		DisposeHandle((Handle)mySampleDesc);
		
	if (myComponent != NULL)
		CloseComponent(myComponent);
	
	return(myErr);
}
コード例 #29
0
ファイル: scrap.c プロジェクト: pombredanne/Frontier
boolean getscrap (tyscraptype scraptype, Handle hscrap) {
	
	/*
	return true if something was loaded from the scrap, false 
	otherwise.
	
	12/26/91 dmb: return true if scraptype exists; generate error alert on real error.

	5.0a16 dmb: need to scan more than last 32 bytes for NUL char
	*/
	
	#ifdef MACVERSION
#if TARGET_API_MAC_CARBON == 1
		ScrapRef			theScrap;
	    ScrapFlavorType 	flavorType = (ScrapFlavorType)scraptype;
	    Size 				byteCount;
	    OSStatus			status;
	    ScrapFlavorFlags	flavorFlags;
		boolean				retVal = true;
		Size				prevCount;

	    status = GetCurrentScrap(&theScrap);
	    if(status != noErr)
			oserror (status);

		status = GetScrapFlavorFlags(theScrap, flavorType, &flavorFlags);
		if(status == noTypeErr)
		{
			retVal = false;
		}
		else if(status < 0)
		{
			retVal = false;
			oserror (status);
		}
		//if we get here and the handles nil, we really don't want the data
		//also if retVal is false, it means the type does not exist
		if(hscrap == nil || !retVal)
			return retVal;

		status = GetScrapFlavorSize(theScrap, flavorType, &byteCount);
		if(status != noErr)
			oserror (status);
		prevCount = byteCount;
		SetHandleSize(hscrap, byteCount);
		if (MemError () != noErr)
			return (false);
		//lock the handle before getting the data
		HLock(hscrap);
	    status = GetScrapFlavorData(theScrap, flavorType, &byteCount, *(hscrap));
	    HUnlock(hscrap);

	    if(status != noErr)
			oserror (status);
		//only return true if we got all the data.
		return (byteCount == prevCount);

		#else //precarbon mac		
		long result;
		long offset;
		
		result = GetScrap (hscrap, scraptype, &offset);
		
		if (result == noTypeErr)
			return (false);
		
		if (result < 0)
			oserror (result);

		return (true); /*there was something on the scrap of the given type*/
		#endif
		
	#endif
	
	#ifdef WIN95VERSION
		Handle hdata;
		long ctbytes;
		char *pdata;
		boolean fl;
		/*long i;*/
		UINT wintype;
		
		wintype = shell2winscraptype (scraptype);
		
		if (wintype == 0)
			return (false);
		
		releasethreadglobals (); //getting clipboard data can send us a WM_RENDERFORMAT msg
		
		hdata = GetClipboardData (wintype);
		
		grabthreadglobals ();
		
		if (hdata == NULL) {
			
			oserror (GetLastError ()); // may be no error
			
			return (false);
			}
		
		ctbytes = GlobalSize (hdata);
		
		pdata = GlobalLock (hdata);
		
		if (pdata == NULL)
			return (false);
		
		if (scraptype == textscraptype) {		//Handle reducing the scrap size to the NULL
			/* i = 0x40;
			 if (i > ctbytes)
				 i = ctbytes;

			 while (i > 0) {
				 if (*(pdata + ctbytes - i) == 0) {
					 ctbytes = ctbytes - i;
					 break;
					 }

				 --i;
				 } /%while%/
			*/

			ctbytes = strlen (pdata); /*7.1b23: call strlen to find the first terminator: removes junk from end*/
			} /*if*/

		fl = sethandlecontents (pdata, ctbytes, hscrap);
		
		GlobalUnlock (hdata);
		
		return (fl);
	#endif
	} /*getscrap*/
コード例 #30
-1
ファイル: scrap.c プロジェクト: LarBob/executor
A0(PUBLIC, LONGINT, ROMlib_ZeroScrap)
{
    OSErr retval;
    INTEGER f;
    THz saveZone;
    
    if (Cx(ScrapState) < 0) {
        ScrapCount = 0;
	saveZone = TheZone;
	TheZone = SysZone;
        ScrapHandle = RM(NewHandle((Size)0));
	TheZone = saveZone;
        ScrapState = CWC (1);
        ScrapName = RM((StringPtr) "\016Clipboard File");
    } else if (Cx(ScrapState) == 0) {
        retval = cropen(&f);
        if (retval != noErr)
            return retval;
        retval = SetEOF(f, (LONGINT)0);
        if (retval != noErr)
            return retval;
        FSClose(f);
    } else if (Cx(ScrapState) > 0)
        SetHandleSize(MR(ScrapHandle), (Size)0);
    ScrapSize = 0;
    ScrapCount = CW(CW(ScrapCount) + 1);
    return noErr;
}