OSStatus
WindowRegisterTXNScrollProcs( WindowRef window, TXNObject txnObj )
{
    OSStatus status = memFullErr;
    ControlRef aScrollControl;
    ControlRef* pScrollControl;
    ControlID controlID = { kMyVerticalScrollBar, 0 };
    
    // allocate memory to hold scroll controls
    Ptr scrollControlArray = NewPtr( sizeof(ControlRef) * 2 ); // don't forget to dispose when finished
    require( scrollControlArray != NULL, MemoryError );
    
    // pointer to first ControlRef in array
    pScrollControl = (ControlRef*)scrollControlArray;
    
    // set up and store vertical scroll control
    status = GetControlByID( window, &controlID, &aScrollControl );
    require_noerr( status, CantSetupControl );
    status = ControlRegisterActionProc( window, aScrollControl, kTXNVertical );
    require_noerr( status, CantSetupControl );
                            
    *pScrollControl = aScrollControl;
    
    // advance to next ControlRef in array
    pScrollControl++;
    
    // set up and store horizontal scroll control
    controlID.signature = kMyHorizontalScrollBar;
    status = GetControlByID( window, &controlID, &aScrollControl);
    require_noerr( status, CantSetupControl );
    status = ControlRegisterActionProc( window, aScrollControl, kTXNHorizontal );
    require_noerr( status, CantSetupControl );
    *pScrollControl = aScrollControl;
    
    // The scroll info proc is MLTE's way to tell you that the content of
    // the TXNObject has changed and that the scrollbars should be updated
    // We need a way to find the controlRefs to our scroll controls while inside the callback.
    // One way to do that is just put a pointer to an array of controlRefs inside the userData
    // item for the callback.  (You could also put a pointer to your own struct/class instance)
    if( scrollControlArray != NULL )
    {
        gScrollInfoUPP = NewTXNScrollInfoUPP( MyMLTEScrollInfoCallback );
        require( gScrollInfoUPP != NULL, CantMakeScrollUPP );
        TXNRegisterScrollInfoProc( txnObj, gScrollInfoUPP, (SInt32)scrollControlArray/*userData*/);
    }
    
    MemoryError:
    return status;
    
    // clean up allocated memory if jumped to here
    CantSetupControl:
    CantMakeScrollUPP:
    DisposePtr( scrollControlArray );
    return status;
    
}
static int __cdecl _heap_grow_emptylist (
        void
        )
{
        REG1 _PBLKDESC first;
        REG2 _PBLKDESC next;
        _PBLKDESC last;


        /*
         * Get memory for the new empty heap descriptors
         *
         * Note that last is used to hold the returned pointer because
         * first (and next) are register class.
         */

        if ((last = (_PBLKDESC)NewPtr(_HEAP_EMPTYLIST_SIZE)) == NULL)
                {
                return 0;
                }

        /*
         * Init the empty heap descriptor list.
         */

        _heap_desc.emptylist = first = last;


        /*
         * Carve the memory into an empty list
         */

        last = (_PBLKDESC) ((char *) first + _HEAP_EMPTYLIST_SIZE - sizeof(_BLKDESC));
        next = (_PBLKDESC) ((char *) first + sizeof(_BLKDESC));

        while ( first < last ) {

                /* Init this descriptor */
                first->pnextdesc = next;

                /* onto the next block */

                first = next++;

        }

        /*
         * Take care of the last descriptor (end of the empty list)
         */

        last->pnextdesc = NULL;


        return 1;

}
char *
CFStringToCString(CFStringRef input)
{
	if (input == NULL)
		return NULL;
	int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
	char *output = NewPtr(strlen+1);
	CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
	return output;
}
Example #4
0
void *pgp_realloc(void *orig, long newLen)
{
#ifdef	PGP_MACINTOSH
	Ptr newSpace;
	long oldLen;
	
	if(orig)
		SetPtrSize((Ptr)orig, newLen);
	else
		orig=NewPtr(newLen);
	if(MemError())
	{
		if((newSpace = NewPtr(newLen)) != NULL)
		{
			oldLen=GetPtrSize((Ptr)orig);
			BlockMove(orig, newSpace, oldLen);
			DisposePtr((Ptr)orig);
			orig=newSpace;
		}
		else
			orig = NIL;
	}
	return orig;
#elif	PGP_WIN32
	void	*ptr = NULL;
#ifdef _DEBUG
	if (!HeapValidate(heapID, 0, NULL))
		DebugLog("validation failed before reallocating %d bytes at %p",
			newLen, ptr);
#endif	// _DEBUG

	ptr = HeapReAlloc(heapID, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
		ptr, newLen);

#ifdef _DEBUG
	if (!HeapValidate(heapID, 0, NULL))
		DebugLog("validation failed after reallocating %d bytes at %p",
			newLen, ptr);
#endif	// _DEBUG

	return ptr;
#endif	// PGP_WIN32
}
Example #5
0
void *
_TIFFrealloc(void* p, size_t s)
{
	Ptr n = p;

	SetPtrSize(p, s);
	if (MemError() && (n = NewPtr(s)) != NULL) {
		BlockMove(p, n, GetPtrSize(p));
		DisposePtr(p);
	}
	return (n);
}
Example #6
0
tdata_t
_TIFFrealloc(tdata_t p, tsize_t s)
{
	Ptr n = p;

	SetPtrSize(p, (size_t) s);
	if (MemError() && (n = NewPtr((size_t) s)) != NULL) {
		BlockMove(p, n, GetPtrSize(p));
		DisposePtr(p);
	}
	return ((tdata_t) n);
}
Example #7
0
void *pgp_malloc(long len)
{
	void	*ptr;

	//DebugLog("malloc:%ld\r",len);
#ifdef	PGP_MACINTOSH
	ptr = NewPtr(len);
#elif	PGP_WIN32
	ptr = HeapAlloc(heapID, HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, len);
#endif
	pgpAssert(IsntNull(ptr));
	return ptr;
}
Example #8
0
void *_realloc_r(struct _reent *reent_ptr, void *ptr, size_t sz)
{
	if(ptr == NULL)
	{
		Ptr p = NewPtr(sz);

		if(!p)
			errno = ENOMEM;

		return p;
	}
	else
	{
		MemError();
		SetPtrSize(ptr, sz);
		if(MemError())
		{
			size_t oldSz = GetPtrSize(ptr);
			if(sz > oldSz)
			{
				void *newPtr = NewPtr(sz);
				if(!newPtr)
				{
					errno = ENOMEM;
					return NULL;
				}
				memcpy(newPtr, ptr, oldSz);
				return newPtr;
			}
			else
			{
				errno = ENOMEM;
				return NULL;
			}
		}
		else
			return ptr;
	}
}
Example #9
0
void 
TclMacInitExitToShell(
    int usePatch)	/* True if on 68k. */
{
    if (gExitToShellData == (ExitToShellDataPtr) NULL){
#if GENERATINGCFM
	gExitToShellData = (ExitToShellDataPtr)
	  NewPtr(sizeof(ExitToShellDataRec));
	gExitToShellData->a5 = SetCurrentA5();
	gExitToShellData->userProcs = (ExitToShellUPPList*) NULL;
#else
	ExitToShellUPP oldExitToShell, newExitToShellPatch;
	short exitToShellTrap;
	
	/*
	 * Initialize patch mechanism.
	 */
	 
	gExitToShellData = (ExitToShellDataPtr) NewPtr(sizeof(ExitToShellDataRec));
	gExitToShellData->a5 = SetCurrentA5();
	gExitToShellData->userProcs = (ExitToShellUPPList*) NULL;

	/*
	 * Save state needed to call origional ExitToShell routine.  Install
	 * the new ExitToShell code in it's place.
	 */
	if (usePatch) {
	    exitToShellTrap = _ExitToShell & 0x3ff;
	    newExitToShellPatch = NewExitToShellProc(ExitToShellPatchRoutine);
	    oldExitToShell = (ExitToShellUPP)
	      NGetTrapAddress(exitToShellTrap, ToolTrap);
	    NSetTrapAddress((UniversalProcPtr) newExitToShellPatch,
		    exitToShellTrap, ToolTrap);
	    gExitToShellData->oldProc = oldExitToShell;
	}
#endif
    }
}
Example #10
0
// moo is the element to insert the data after
Boolean BetterAddElement(Ptr dataPtr,Size dataSize,ElementHandle moo)
{
	// Moo now points to a Ptr to store the next element in. The Ptr is the address of the 'next'
	// field of the last element in the list.
	// Add a new ListElement to the list
	*moo=(ElementPtr)NewPtr(sizeof(ListElement));
	if (!*moo) // failed?
		return false;

	(*moo)->next=0L;
	(*moo)->data=0L;
	
	// Add the data to that element
	(*moo)->data=NewPtr(dataSize);
	if (!(*moo)->data) // failed?
	{
		DisposePtr((Ptr)*moo);
		*moo=0L;
		return false;
	}
	BlockMove(dataPtr,(*moo)->data,dataSize);
	return true;
}
Example #11
0
OSErr PAS_decodeData(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
	OSErr 		err;	
	short		outRefNum;
	Ptr 		buffer;
	SInt32 		currentWrite = 	PAS_BUFFER_SIZE;
	SInt32		totalSize;
	
	
	buffer = NewPtr(currentWrite);
	
	
	err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum);
	if (err != noErr)	return err;
	
	
	err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
	if (err != noErr)	return err;
	
	err = SetFPos(outRefNum, fsFromStart, 0 );
	if (err != noErr)	return err;
	
	totalSize = (*entry).entryLength;
	
	while(totalSize > 0)
	{	
		currentWrite = PAS_BUFFER_SIZE;

		if (totalSize < currentWrite)
		{
			currentWrite = totalSize;
		}

		err	= FSRead( inRefNum, &currentWrite, buffer);
		if (err != noErr && err != eofErr)	return err;
	
		err = FSWrite(outRefNum, &currentWrite, buffer);
		if (err != noErr)	return err;
		
		totalSize = totalSize - currentWrite;

	}
	
	FSClose(outRefNum);
	
	DisposePtr(buffer);
	
	return noErr;

}
Example #12
0
// This is the most overloaded routine I've seen in a long time.
void *realloc(
	void *pointer,
	size_t size)
{
	if ((pointer==NULL) && (size!=0))
	{
		return NewPtr(size);
	}
	
	if (size==0)
	{
		if (pointer) DisposePtr((Ptr)pointer);
		return NULL;
	}
	
	if (size==GetPtrSize((Ptr)pointer)) return pointer;
	
	SetPtrSize((Ptr)pointer, size);
	
	// SetPtrSize can fail if the pointer couldn't be expanded in place
	if (MemError())
	{
		Size old_size= GetPtrSize((Ptr)pointer);
		Ptr	realloced_pointer= NewPtr(size);

		// so we make a whole new one if possible
		if (MemError()) return NULL;
		
		// and copy the data into it.
		BlockMoveData(pointer, realloced_pointer, old_size > size ? size : old_size);
		// and then destroy the old pointer		
		DisposePtr((Ptr)pointer);
		
		return realloced_pointer;
	}
	return pointer;
}
Example #13
0
int sqCopyDirectorysizetosize(char *srcNameIndex, int srcNameSize, char *dstNameIndex, int dstNameSize) {

	OSErr error;
	FSSpec	srcSpec,dstSpec,dstFolderSpec;
	char *pointer;
	const int desiredBufferSize = 64*1024;
    char name[256];

	memmove(name,srcNameIndex,srcNameSize);
	memmove(name+srcNameSize,":",1);
	FSpLocationFromFullPath(srcNameSize+1,name,&srcSpec);
	memmove(name,dstNameIndex,dstNameSize);
	memmove(name+dstNameSize,":",1);
	FSpLocationFromFullPath(dstNameSize+1,name,&dstFolderSpec);
	FSMakeFSSpecCompat(dstFolderSpec.vRefNum, dstFolderSpec.parID, "\p:", &dstSpec);

#if TARGET_API_MAC_CARBON
		pointer = NewPtr(desiredBufferSize);
#else
	    pointer = NewPtr(desiredBufferSize);
	    if (pointer == NULL) 
		    pointer = NewPtrSys(desiredBufferSize);
	    if (pointer == NULL) 
  			return false;
 #endif
    memmove(name,dstFolderSpec.name,sizeof(dstFolderSpec.name));
	error = FSpDirectoryCopy(&srcSpec,
						&dstSpec,
						(ConstStr255Param) &name,
						pointer,
						desiredBufferSize,
						false,
						&handleDupError);

	DisposePtr((void *)pointer);
	return error;
} 
Example #14
0
//  SGSettingsDialog with the "Compression" panel removed
static OSErr MinimalSGSettingsDialog(SeqGrabComponent seqGrab,
                                     SGChannel sgchanVideo, WindowPtr gMonitor)
{
        OSErr err;
        Component *panelListPtr = NULL;
        UInt8 numberOfPanels = 0;

        ComponentDescription cd = { SeqGrabPanelType, VideoMediaType, 0, 0, 0 };
        Component c = 0;
        Component *cPtr = NULL;

        numberOfPanels = CountComponents(&cd);
        panelListPtr =
            (Component *) NewPtr(sizeof(Component) * (numberOfPanels + 1));

        cPtr = panelListPtr;
        numberOfPanels = 0;
        CFStringRef compressionCFSTR = CFSTR("Compression");
        do {
                ComponentDescription compInfo;
                c = FindNextComponent(c, &cd);
                if (c) {
                        Handle hName = NewHandle(0);
                        GetComponentInfo(c, &compInfo, hName, NULL, NULL);
                        CFStringRef nameCFSTR =
                            CFStringCreateWithPascalString(kCFAllocatorDefault,
                                                           (unsigned char
                                                            *)(*hName),
                                                           kCFStringEncodingASCII);
                        if (CFStringCompare
                            (nameCFSTR, compressionCFSTR,
                             kCFCompareCaseInsensitive) != kCFCompareEqualTo) {
                                *cPtr++ = c;
                                numberOfPanels++;
                        }
                        DisposeHandle(hName);
                }
        } while (c);

        if ((err =
             SGSettingsDialog(seqGrab, sgchanVideo, numberOfPanels,
                              panelListPtr, seqGrabSettingsPreviewOnly,
                              (SGModalFilterUPP)
                              NewSGModalFilterUPP(SeqGrabberModalFilterProc),
                              (long)gMonitor))) {
                return err;
        }
        return 0;
}
Example #15
0
/* pass a buffer to tcp connection for writing
 *  dispose of -1 = copy data
 */
short NATCPwrite(na_tcp i, Ptr data, long len, short dispose)
{
	tcpinfo *tcp = (*tcpstate)->tcpbufs[i];
	rdsEntry *rds = NULL;
	tcpwb *wb;
	long totallen = 0;
	int j;
	
	if (tcp == NULL || tcp->lclose > 0 || tcp->rclose == 3) {
		return (NATCP_nocon);
	}
	wb = tcp->wb + tcp->wbnum;
	if (wb->rused == RDS) wb = tcp->wb + (1 - tcp->wbnum);
	if (wb->rused == -1 || wb->rused == RDS) return (NATCP_notcpbuf);
	for (j = 0; j < wb->rused; ++j) {
		totallen += wb->rds[j].length;
	}
	if (totallen + len >= 65535) return (NATCP_notcpbuf);
	rds = wb->rds + wb->rused;
	rds->length = len;
	rds->ptr = data;
	rds[1].length = 0;
	if (dispose < 0) {
		if (len < tcp->wbsize - wb->wused) {
			/* if data short enough, use small internal buffer */
			rds->ptr = wb->buf + wb->wused;
			wb->wused += len;
			dispose = 0;
			/* If adjacent to last rds, attach to it */
			if (wb->rused && rds[-1].ptr + rds[-1].length == rds->ptr) {
				--wb->rused;
				rds[-1].length += len;
				rds->length = 0;
			}
		} else {
			rds->ptr = NewPtr(len);
			if (!rds->ptr) return (NATCP_nomem);
			dispose = 1;
		}
		memcpy(rds->ptr, data, len);
	}
	wb->fflag[wb->rused++] = dispose;
	if (tcp->push && tcp->state == TCP_READY) {
		(void) beginwrite(tcp);
	}
	
	return (NATCP_data);
}
Example #16
0
PRIVATE OSErr
begin_track_buffering_for_write (void)
{
  OSErr retval;

  track_bufp = NewPtr (N_TRACK_BYTES);
  if (track_bufp)
    {
      retval = noErr;
      offset = 0;
      length = 0;
    }
  else
    retval = MemErr;
  return retval;
}
Example #17
0
static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
{
	GammaTblPtr		pTableGammaOut = NULL;
	short			tableSize, dataWidth;

	if (pTableGammaIn)												
	{
		dataWidth = (pTableGammaIn->gDataWidth + 7) / 8;			
		tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
					(pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
		pTableGammaOut = (GammaTblPtr) NewPtr (tableSize);			
		if (pTableGammaOut)											
			BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize);	
	}
	return (Ptr)pTableGammaOut;										
}
Example #18
0
static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
{
	GammaTblPtr		pTableGammaOut = NULL;
	short			tableSize, dataWidth;

	if (pTableGammaIn)												/* if there is a table to copy  */
	{
		dataWidth = (pTableGammaIn->gDataWidth + 7) / 8;			/* number of bytes per entry */
		tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
					(pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
		pTableGammaOut = (GammaTblPtr) NewPtr (tableSize);			/* allocate new table */
		if (pTableGammaOut)											
			BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize);	/* move everything */
	}
	return (Ptr)pTableGammaOut;										/* return whatever we allocated, could be NULL */
}
Example #19
0
OSErr FetchParamAnySize(AEKeyword plop,AppleEvent *appIn,Ptr *dest,DescType theType)
{
	OSErr	err;
	Size	size;
	DescType	actualType;

	err=AESizeOfParam(appIn,plop, &actualType, &size);
	if (err)
		return err;
	
	*dest=NewPtr(size);
	
	err=AEGetParamPtr(appIn, plop, theType, &actualType, *dest, size, &size);

	return err;
}
Example #20
0
//
//	This function allocates a block of CFM glue code which contains the instructions to call CFM routines
//
static void* NewMachOFunctionPointer(void* cfmfp)
{
#if TARGET_RT_MAC_CFM
    static UInt32 CFM_glue[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420};
    UInt32	*mfp = (UInt32*) NewPtr(sizeof(CFM_glue));		//	Must later dispose of allocated memory
    if (mfp) {
	    BlockMoveData(CFM_glue, mfp, sizeof(CFM_glue));
	    mfp[0] |= ((UInt32)cfmfp >> 16);
	    mfp[1] |= ((UInt32)cfmfp & 0xFFFF);
	    MakeDataExecutable(mfp, sizeof(CFM_glue));
	}
	return mfp;
#elif TARGET_RT_MAC_MACHO
    return cfmfp;
#endif
}
Example #21
0
void *my_malloc (int n)
{
	int i = MaxBlock ();
	void *x;

	if (n >= i) {
		printf ("Error: malloc = %d, maxblock = %d\n", n, i);
		exit (-1);
	}

	if ((x = (void *)NewPtr(n)) == NULL) {
		printf ("Error: %d\n", MemError());
		exit (-1);
	}

	return x;
}
Example #22
0
void MADInitImportPlug( MADLibrary *inMADDriver, FSRefPtr PluginFolder)
{
	FSSpecPtr spec2;
	if(PluginFolder != NULL)
	{
		spec2 = (FSSpecPtr)NewPtr(sizeof(FSSpec));
		FSGetCatalogInfo(PluginFolder, kFSCatInfoNone, NULL, NULL, spec2, NULL);
	}
	else {
		spec2 = NULL;
	}

	MInitImportPlug(inMADDriver, spec2);
	
	if (spec2 != NULL) {
		DisposePtr((Ptr)spec2);
	}
}
Example #23
0
boolean openabout (boolean flzoom, long ctreservebytes) {
#pragma unused(flzoom)

	/*
	2.1b5 dmb: added ctreservebytes parameter. of non-zero, caller wants us to 
	reserve space in the heap below the dialog record (during initialization)
	*/
	
	hdlwindowinfo hinfo;
	
#ifdef MACVERSION
	Ptr ptemp = nil;
	
	if (ctreservebytes > 0)
		ptemp = NewPtr (ctreservebytes); /*force about window to load high*/
#endif

	aboutstart ();
	
	shellpatchnilroutines ();
	
//	aboutwindow = newmodaldialog (128, -1);
	newaboutwindow (true);
	
	if (findaboutwindow (&hinfo))
	{
		shellupdatenow ((**hinfo).macwindow);
		//Code change by Timothy Paustian 10/5/00
		//We need to flush the about window to the screen
		//safe because this routine only gets call during init. 
		#if TARGET_API_MAC_CARBON == 1
		QDFlushPortBuffer(GetWindowPort((**hinfo).macwindow), nil);
		#endif
	}
#ifdef MACVERSION
	if (ptemp != nil)
		DisposePtr (ptemp); /*restore heap space for remaining code segments*/
#endif
	
	aboutopenticks = gettickcount ();
	
	return (true);
	} /*openabout*/
Example #24
0
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef, AEDesc *pObjSpecifier){
	OSErr anErr = paramErr;

	if (nil != pCFURLRef) {
		Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef);
		CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef, kCFURLHFSPathStyle);
		AEDesc containerDesc = {
			typeNull, NULL
		};
		AEDesc nameDesc = {
			typeNull, NULL
		};
		UniCharPtr buf = nil;

		if (nil != tCFStringRef) {
			Size bufSize = ( CFStringGetLength(tCFStringRef) + ( isDirectory ? 1 : 0 ) ) * sizeof( UniChar );

			buf = (UniCharPtr) NewPtr(bufSize);

			if ( ( anErr = MemError() ) == noErr) {
				CFStringGetCharacters(tCFStringRef, CFRangeMake(0, bufSize / 2), buf);
				if (isDirectory) ( buf )[ ( bufSize - 1 ) / 2 ] = (UniChar) 0x003A;
			}
		} else
			anErr = coreFoundationUnknownErr;

		if (anErr == noErr)
			anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize( (Ptr) buf), &nameDesc);
		if (anErr == noErr)
			if (isDirectory) {
				anErr = CreateObjSpecifier(cFolder, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
			} else {
				anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
			}

		MoreAEDisposeDesc(&nameDesc);

		if (buf)
			DisposePtr( (Ptr) buf);
	}
	return anErr;
}
Example #25
0
SYMBOL * StoreSymbol(SYMBOL *NewSym,char *string)
{
    SYMBOL *Sym = FreeSymbol();
    char *ThisName;					// Location of PTR to name
    int StringLen;
    int entry;

    StringLen = strlen(string) + 1;	// Get length of string

    // if there was not Symbol space quit

    if (Sym == NULL)
        return NULL;

    // if there was no name space quit

    ThisName = (char *) NewPtr((int) StringLen);

    // Copy the name to the NamesList

    memcpy(ThisName,string,StringLen);
    memcpy(Sym,NewSym,sizeof(SYMBOL));

    // Set the Symbol data ptr

    Sym->Name = ThisName;
    Sym->Len = StringLen-1;

    Sym->Flags = 0;

    // Add symbol to hash table

#ifdef USE_HASHING

    entry = HashSymbol(Sym->Name, Sym->LocalScope, Sym->Section);
    BucketArrayAdd(&SymbolHash, entry, (int) Sym);

#endif
    // Carry forward the names pointer

    return Sym;
}
Example #26
0
int InitSymbolTable(void)
{
    register SYMBOL *Sym;
    register int n;

    SymTab = (SYMBOL *) NewPtr(sizeof(SYMBOL) * (SYMMAX + 10));

    if (!SymTab)
        return 0;

    Sym = SymTab;
    n = SYMMAX;

    do
    {
        Sym->Section	= 0;
        Sym->Name		= NULL;
        Sym->LocalScope	= 0;
        Sym->LabelType	= 0;
        Sym->VirtualIndex = 0;
        Sym->EndIP		= 0;
        Sym->Flags		= 0;
        Sym->Params		= 0;
        Sym->RetType	= 0;
        Sym->LabelEnum	= 0;
        Sym->Interface	= 0;
        Sym++;
    }
    while(--n);

#ifdef USE_HASHING
    BucketArrayInit(&SymbolHash, SYMBOL_HASH_SIZE);
#endif

    NextFreeSym = SymTab;
    NextSymbolCount = 0;

    SymbolCount = 0;
    return 1;
}
Example #27
0
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef,AEDesc *pObjSpecifier)
{
	OSErr 		anErr = paramErr;

	if (NULL != pCFURLRef)
	{
		CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef,kCFURLHFSPathStyle);

		anErr = coreFoundationUnknownErr;
		if (NULL != tCFStringRef)
		{
			Boolean 		isDirectory = CFURLHasDirectoryPath(pCFURLRef);
			AEDesc 			containerDesc = {typeNull, NULL};
			AEDesc 			nameDesc = {typeNull, NULL};
				Size			bufSize = (CFStringGetLength(tCFStringRef) + (isDirectory ? 1 : 0)) * sizeof(UniChar);
				UniCharPtr		buf = (UniCharPtr) NewPtr(bufSize);

				if ((anErr = MemError()) == noErr)
				{
					CFStringGetCharacters(tCFStringRef, CFRangeMake(0,bufSize/2), buf);
					if (isDirectory) (buf)[(bufSize-1)/2] = (UniChar) 0x003A;				
				}
			
			if (anErr == noErr)
				anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize((Ptr) buf), &nameDesc);
			if (anErr == noErr)
				{
					if (isDirectory)	// we use cObject here since this might be a package (and we have no way to tell)
						anErr = CreateObjSpecifier(cObject, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
					else
						anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
				}
			MoreAEDisposeDesc(&nameDesc);

			if (buf)
				DisposePtr((Ptr)buf);
		}
	}
	return anErr;
}//end MoreAEOCreateObjSpecifierFromCFURLRef
int createStash()
{
	int i;
	int returnValue = -1;
	for (i = 0; i < kStashSize; i++)
	{
		stash[i].state = kFree;
		stash[i].data = (Packet*)NewPtr(kMaxPacketLength);
		if (!stash[i].data) 
		{ 
			ofLogNotice() << "out of memory" << endl; 
			returnValue =  -1; 
		}else 
		{
			counter++;
			//ofLogNotice() << "STASH CREATED: " << counter << endl; 
			returnValue = 1;
		}
		
	}
	return returnValue;
}
Example #29
0
void initialize_shape_handler(
	void)
{
	FSSpec shapes_file;
	OSErr error;

	/* open the resource fork of our shape file for reading */
	error= get_file_spec(&shapes_file, strFILENAMES, filenameSHAPES8, strPATHS);
	if (error==noErr)
	{
		open_shapes_file(&shapes_file);
	}
	
	if (error!=noErr || shapes_file_refnum==-1)
	{
		alert_user(fatalError, strERRORS, badExtraFileLocations, error);
	}
	else
	{
		atexit(shutdown_shape_handler);
	}

	hollow_pixmap= NewPixMap();
	assert(hollow_pixmap);
	if (HOLLOW_PIXMAP_BUFFER_SIZE)
	{
		hollow_data= (pixel8 *)NewPtr(HOLLOW_PIXMAP_BUFFER_SIZE);
		assert(hollow_data);
	}

	/* bounds and rowBytes are deliberately unset! */
	(*hollow_pixmap)->pixelType= 0;
	(*hollow_pixmap)->pixelSize= 8;
	(*hollow_pixmap)->cmpCount= 1;
	(*hollow_pixmap)->cmpSize= (*hollow_pixmap)->pixelSize;
	(*hollow_pixmap)->pmReserved= 0;

	return;
}
Example #30
0
/* get a TCP buffer block
 */
static tcpinfo *getTCPbuf(na_tcpreadp *callback, void *context, int *id)
{
	int i;
	tcpinfo *tcp;
	
	/* make sure driver is open */
	if (!(*tcpstate)->tcp_driver
		&& (!tcp_wait(NULL, NULL) || !(*tcpstate)->tcp_driver)) {
		(*callback)(context, -1, NATCP_nodriver, 0, NULL);
		return (NULL);
	}
	
	/* find pointer slot and create buffer */
	for (i = 0; i < MAX_TCPCON && (*tcpstate)->tcpbufs[i]; ++i);
	if (i == MAX_TCPCON) {
		(*callback)(context, -1, NATCP_notcpbuf, 0, NULL);
		return (NULL);
	}
	tcp = (tcpinfo *) NewPtr(sizeof (tcpinfo) - 1
		+ (*tcpstate)->streamsize + (unsigned long) (*tcpstate)->wbsize * 2);
	if (!tcp) {
		(*callback)(context, -1, NATCP_nomem, 0, NULL);
		return (NULL);
	};
	*id = i;
	(*tcpstate)->tcpbufs[i] = tcp;
	memset((char *) tcp, 0, sizeof (tcpinfo));
	
	/* initialize fields from global state */
	tcp->wbsize = (*tcpstate)->wbsize;
	tcp->wb[0].buf = tcp->buf + (*tcpstate)->streamsize;
	tcp->wb[1].buf = tcp->wb[0].buf + tcp->wbsize;
	tcp->pb.ioCRefNum = (*tcpstate)->tcp_driver;
	tcp->context = context;
	tcp->callback = callback;
	
	return (tcp);
}