⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdmac.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//##############################################################################//###############################################################################pragma mark -#pragma mark STRING OPERATIONS#if !defined(MAC_NSPR_STANDALONE)//	PStrFromCStr converts the source C string to a destination//	pascal string as it copies. The dest string will//	be truncated to fit into an Str255 if necessary.//  If the C String pointer is NULL, the pascal string's length is set to zero//void PStrFromCStr(const char* src, Str255 dst){	short 	length  = 0;		// handle case of overlapping strings	if ( (void*)src == (void*)dst )	{		unsigned char*		curdst = &dst[1];		unsigned char		thisChar;						thisChar = *(const unsigned char*)src++;		while ( thisChar != '\0' ) 		{			unsigned char	nextChar;						// use nextChar so we don't overwrite what we are about to read			nextChar = *(const unsigned char*)src++;			*curdst++ = thisChar;			thisChar = nextChar;						if ( ++length >= 255 )				break;		}	}	else if ( src != NULL )	{		unsigned char*		curdst = &dst[1];		short 				overflow = 255;		// count down so test it loop is faster		register char		temp;			// Can't do the K&R C thing of "while (*s++ = *t++)" because it will copy trailing zero		// which might overrun pascal buffer.  Instead we use a temp variable.		while ( (temp = *src++) != 0 ) 		{			*(char*)curdst++ = temp;							if ( --overflow <= 0 )				break;		}		length = 255 - overflow;	}	dst[0] = length;}void CStrFromPStr(ConstStr255Param pString, char **cString){	// Allocates a cString and copies a Pascal string into it.	unsigned int	len;		len = pString[0];	*cString = malloc(len+1);		if (*cString != NULL) {		strncpy(*cString, (char *)&pString[1], len);		(*cString)[len] = NULL;	}}void dprintf(const char *format, ...){#if DEBUG    va_list ap;	Str255 buffer;		va_start(ap, format);	buffer[0] = PR_vsnprintf((char *)buffer + 1, sizeof(buffer) - 1, format, ap);	va_end(ap);		DebugStr(buffer);#endif /* DEBUG */}#elsevoid debugstr(const char *debuggerMsg){	Str255		pStr;		PStrFromCStr(debuggerMsg, pStr);	DebugStr(pStr);}char *strdup(const char *source){	char 	*newAllocation;	size_t	stringLength;	PR_ASSERT(source);		stringLength = strlen(source) + 1;		newAllocation = (char *)PR_MALLOC(stringLength);	if (newAllocation == NULL)		return NULL;	BlockMoveData(source, newAllocation, stringLength);	return newAllocation;}//	PStrFromCStr converts the source C string to a destination//	pascal string as it copies. The dest string will//	be truncated to fit into an Str255 if necessary.//  If the C String pointer is NULL, the pascal string's length is set to zero//void PStrFromCStr(const char* src, Str255 dst){	short 	length  = 0;		// handle case of overlapping strings	if ( (void*)src == (void*)dst )	{		unsigned char*		curdst = &dst[1];		unsigned char		thisChar;						thisChar = *(const unsigned char*)src++;		while ( thisChar != '\0' ) 		{			unsigned char	nextChar;						// use nextChar so we don't overwrite what we are about to read			nextChar = *(const unsigned char*)src++;			*curdst++ = thisChar;			thisChar = nextChar;						if ( ++length >= 255 )				break;		}	}	else if ( src != NULL )	{		unsigned char*		curdst = &dst[1];		short 				overflow = 255;		// count down so test it loop is faster		register char		temp;			// Can't do the K&R C thing of "while (*s++ = *t++)" because it will copy trailing zero		// which might overrun pascal buffer.  Instead we use a temp variable.		while ( (temp = *src++) != 0 ) 		{			*(char*)curdst++ = temp;							if ( --overflow <= 0 )				break;		}		length = 255 - overflow;	}	dst[0] = length;}void CStrFromPStr(ConstStr255Param pString, char **cString){	// Allocates a cString and copies a Pascal string into it.	unsigned int	len;		len = pString[0];	*cString = PR_MALLOC(len+1);		if (*cString != NULL) {		strncpy(*cString, (char *)&pString[1], len);		(*cString)[len] = NULL;	}}size_t strlen(const char *source){	size_t currentLength = 0;		if (source == NULL)		return currentLength;				while (*source++ != '\0')		currentLength++;			return currentLength;}int strcmpcore(const char *str1, const char *str2, int caseSensitive){	char 	currentChar1, currentChar2;	while (1) {			currentChar1 = *str1;		currentChar2 = *str2;				if (!caseSensitive) {						if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))				currentChar1 += ('A' - 'a');					if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))				currentChar2 += ('A' - 'a');				}			if (currentChar1 == '\0')			break;			if (currentChar1 != currentChar2)			return currentChar1 - currentChar2;					str1++;		str2++;		}		return currentChar1 - currentChar2;}int strcmp(const char *str1, const char *str2){	return strcmpcore(str1, str2, true);}int strcasecmp(const char *str1, const char *str2){	return strcmpcore(str1, str2, false);}void *memcpy(void *to, const void *from, size_t size){	if (size != 0) {#if DEBUG		if ((UInt32)to < 0x1000)			DebugStr("\pmemcpy has illegal to argument");		if ((UInt32)from < 0x1000)			DebugStr("\pmemcpy has illegal from argument");#endif		BlockMoveData(from, to, size);	}	return to;}void dprintf(const char *format, ...){    va_list ap;	char	*buffer;		va_start(ap, format);	buffer = (char *)PR_vsmprintf(format, ap);	va_end(ap);		debugstr(buffer);	PR_DELETE(buffer);}voidexit(int result){#pragma unused (result)		ExitToShell();}void abort(void){	exit(-1);}#endif//##############################################################################//###############################################################################pragma mark -#pragma mark FLUSHING THE GARBAGE COLLECTOR#if !defined(MAC_NSPR_STANDALONE)unsigned char GarbageCollectorCacheFlusher(PRUint32){    PRIntn is;	UInt32		oldPriority;	//	If java wasn't completely initialized, then bail 	//	harmlessly.		if (PR_GetGCInfo()->lock == NULL)		return false;#if DEBUG	if (_MD_GET_INTSOFF() == 1)		DebugStr("\pGarbageCollectorCacheFlusher at interrupt time!");#endif	//	The synchronization here is very tricky.  We really	//	don't want any other threads to run while we are 	//	cleaning up the gc heap... they could call malloc,	//	and then we would be in trouble in a big way.  So,	//	we jack up our priority and that of the finalizer	//	so that we won't yield to other threads.	//	dkc 5/17/96	oldPriority = PR_GetThreadPriority(PR_GetCurrentThread());	_PR_INTSOFF(is);	_PR_SetThreadPriority(PR_GetCurrentThread(), (PRThreadPriority)30);	_PR_INTSON(is);	//	Garbage collect twice.  This will finalize any	//	dangling AWT resources (images, components), and	//	then free up their GC space, too.	//	dkc 2/15/96	//  interrupts must be on during PR_GC		PR_GC();		//	By setting the finalizer priority to 31, then we 	//	ensure it will run before us.  When it finishes	//	its list of finalizations, it returns to us	//	for the second garbage collection.		PR_Yield();	PR_GC();		//	Restore our old priorities.		_PR_INTSOFF(is);	_PR_SetThreadPriority(PR_GetCurrentThread(), (PRThreadPriority)oldPriority);	_PR_INTSON(is);	return false;}#endif//##############################################################################//###############################################################################pragma mark -#pragma mark MISCELLANEOUS-HACKS////		***** HACK  FIX THESE ****//extern long _MD_GetOSName(char *buf, long count){	long	len;		len = PR_snprintf(buf, count, "Mac OS");		return 0;}extern long _MD_GetOSVersion(char *buf, long count){	long	len;		len = PR_snprintf(buf, count, "7.5");	return 0;}extern long _MD_GetArchitecture(char *buf, long count){	long	len;	#if defined(TARGET_CPU_PPC) && TARGET_CPU_PPC		len = PR_snprintf(buf, count, "PowerPC");#else	len = PR_snprintf(buf, count, "Motorola68k");#endif	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -