[Scummvm-cvs-logs] SF.net SVN: scummvm: [22862] scummvm/trunk/backends/PalmOS/Src/missing

chrilith at users.sourceforge.net chrilith at users.sourceforge.net
Sat Jun 3 13:00:26 CEST 2006


Revision: 22862
Author:   chrilith
Date:     2006-06-03 04:00:15 -0700 (Sat, 03 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22862&view=rev

Log Message:
-----------
Don't reinvent the wheel, use MSL functions when available for better compatibility and smaller code size

Modified Paths:
--------------
    scummvm/trunk/backends/PalmOS/Src/missing/ext_stdio.c
    scummvm/trunk/backends/PalmOS/Src/missing/ext_stdlib.c
    scummvm/trunk/backends/PalmOS/Src/missing/ext_string.c
    scummvm/trunk/backends/PalmOS/Src/missing/stdio.h
    scummvm/trunk/backends/PalmOS/Src/missing/stdlib.h
    scummvm/trunk/backends/PalmOS/Src/missing/string.h
Modified: scummvm/trunk/backends/PalmOS/Src/missing/ext_stdio.c
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/ext_stdio.c	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/ext_stdio.c	2006-06-03 11:00:15 UTC (rev 22862)
@@ -381,6 +381,9 @@
 	return numBytesWritten;
 }
 
+/* needed with 68k mode only, already defined in ARM MSL */
+#ifdef PALMOS_68K
+
 Int32 sprintf(Char* s, const Char* formatStr, ...) {
 	Int16 count;
 	va_list va;
@@ -571,12 +574,12 @@
 				mod++;
 
 			// prepare new format
-#if !defined(PALMOS_ARM)
+//#if !defined(PALMOS_ARM)
 			if (*mod == 'c') {
 				StrCopy(tmp, "`c`%c%c");
 
 			} else
-#endif
+//#endif
 			if (*mod == 'p') {
 				StrCopy(tmp, "%08lX");			// %x = %08X in palmos
 
@@ -635,11 +638,13 @@
 	
 	// Copy result in a temp buffer to process last formats
 	StrVPrintF(result, format, argParam);
-#if !defined(PALMOS_ARM)
+//#if !defined(PALMOS_ARM)
 	StrProcC_(result, 256);
-#endif
+//#endif
 	StrProcXO(result, 256, tmp);
 	StrCopy(s, result);
 	
 	return StrLen(s);
 }
+
+#endif

Modified: scummvm/trunk/backends/PalmOS/Src/missing/ext_stdlib.c
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/ext_stdlib.c	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/ext_stdlib.c	2006-06-03 11:00:15 UTC (rev 22862)
@@ -27,21 +27,7 @@
 #define memNewChunkFlagAllowLarge	0x1000 
 SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP) SYS_TRAP(sysTrapSysGetAppInfo);
 
-void *bsearch(const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *)) {
-#ifdef PALMOS_68K
-	Int32 position;
-	if (SysBinarySearch(base, nmemb, size, (SearchFuncPtr)compar, key, 0, &position, true))
-		return (void *)((UInt32)base + size * position);
-#else
-	int i;
-	for (i = 0; i < nmemb; i++) 
-		if (compar(key, (void*)((UInt32)base + size * i)) == 0)
-			return (void*)((UInt32)base + size * i);
-#endif
-
-	return NULL;
-}
-
+#ifdef PALMOS68K
 long strtol(const char *s, char **endptr, int base) {
 	// WARNING : only base = 10 supported
 	long val = StrAToI(s);
@@ -56,6 +42,7 @@
 
 	return val;
 }
+#endif
 
 MemPtr __malloc(UInt32 size) {
 	MemPtr newP = NULL;

Modified: scummvm/trunk/backends/PalmOS/Src/missing/ext_string.c
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/ext_string.c	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/ext_string.c	2006-06-03 11:00:15 UTC (rev 22862)
@@ -24,6 +24,7 @@
 
 #include <string.h>
 
+#ifdef PALMOS_68K
 void *memchr(const void *s, int c, UInt32 n) {
 	UInt32 chr;
 	for(chr = 0; chr < n;chr++,((UInt8 *)s)++)
@@ -33,84 +34,6 @@
 	return NULL;
 }
 
-UInt32 strspn(const char *s1, const char *s2) {
-	UInt32 chr = 0;
-
-	while (	chr < strlen(s1) &&
-			strchr(s2, s1[chr]) )
-		chr++;
-
-	return chr;
-}
-
-static Char *StrTokNext = NULL;
-
-Char *strtok(Char *str, const Char *sep) {
-	Char	*position = NULL,
-			*found,
-			*end;
-
-	UInt16	loop = 0,
-			chars= StrLen(sep);
-
-	str			= (str)?(str):(StrTokNext);
-	StrTokNext	= NULL;
-
-	if (!str)
-		return NULL;
-
-	end = str+StrLen(str);
-
-	while (loop<chars)
-	{
-		found = StrChr(str,sep[loop]);
-		loop++;
-
-		if (found == str)
-		{
-			str++;
-			loop = 0;
-		}
-		else if (position == NULL || position > found)
-			position = found;
-	}
-
-	if (position == NULL)
-		if (str==end)
-			return NULL;
-		else
-			return str;
-
-	position[0] = 0;
-	StrTokNext	= position+1;
-
-	return str;
-}
-
-Char *strpbrk(const Char *s1, const Char *s2) {
-	Char *found;
-	UInt32 n;
-
-	for (n=0; n <= StrLen(s2); n++) {
-		found = StrChr(s1, s2[n]);
-		if (found)
-			return found;
-	}
-
-	return NULL;
-}
-
-Char *strrchr(const Char *s, int c) {
-	UInt32 chr;
-	UInt32 n = StrLen(s);
-
-	for(chr = n; chr >= 0; chr--)
-		if ( *((UInt8 *)s+chr) == c)
-			return (Char *)(s+chr);
-
-	return NULL;
-}
-
 Char *strdup(const Char *s1) {
 	Char* buf = (Char *)MemPtrNew(StrLen(s1)+1);
 
@@ -118,4 +41,5 @@
 		StrCopy(buf, s1);
 
 	return buf;
-}
\ No newline at end of file
+}
+#endif

Modified: scummvm/trunk/backends/PalmOS/Src/missing/stdio.h
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/stdio.h	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/stdio.h	2006-06-03 11:00:15 UTC (rev 22862)
@@ -32,7 +32,8 @@
 extern "C" {
 #endif
 
-typedef void (*LedProc)(Boolean show);
+typedef void	(*LedProc)(Boolean show);
+typedef UInt32	size_t;
 
 typedef struct {
 	FileRef fileRef;
@@ -41,57 +42,60 @@
 	UInt16 mode, err;
 } FILE;
 
-extern FILE	gStdioOutput;
-typedef UInt32 size_t;
-
-#ifdef stdin
 #undef stdin
 #undef stdout
 #undef stderr
-#endif
 
-#ifdef SEEK_SET
-#undef SEEK_SET
-#undef SEEK_CUR
-#undef SEEK_END
-#endif
-
 #define stdin		0
 #define stdout		(&gStdioOutput)
 #define stderr		(&gStdioOutput)
 
-#define clearerr(a)
-#define fflush(a)
-#define vsnprintf(a,b,c,d)	vsprintf(a,c,d)
-#define getc(a)				fgetc(a)
+#undef SEEK_SET
+#undef SEEK_CUR
+#undef SEEK_END
 
 #define	SEEK_SET			vfsOriginBeginning 
 #define	SEEK_CUR			vfsOriginCurrent  
 #define	SEEK_END			vfsOriginEnd
 
+extern FILE	gStdioOutput;
 
-UInt16		fclose	(FILE *stream);
-UInt16		feof	(FILE *stream);
-UInt16		ferror	(FILE *stream);
-Char *		fgets	(Char *s, UInt32 n, FILE *stream);
-Int16		fgetc	(FILE *stream);
-FILE *		fopen	(const Char *filename, const Char *type);
-UInt32		fread	(void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
-UInt32		fwrite	(const void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
-Int16		fseek	(FILE *stream, Int32 offset, Int32 whence);
-Int32		ftell	(FILE *stream);
-
-Int32	fprintf	(FILE *stream, const Char *formatStr, ...);
-Int32	printf	(const Char* formatStr, ...);
-Int32	sprintf	(Char* s, const Char* formatStr, ...);
-Int32	snprintf(Char* s, UInt32 len, const Char* formatStr, ...);
-Int32	vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam);
-
 void	StdioInit			(UInt16 volRefNum, const Char *output);
 void	StdioSetLedProc		(LedProc ledProc);
 void	StdioSetCacheSize	(UInt32 s);
 void	StdioRelease		();
 
+/* missing functions in 68k MSL (some are defined in ARM) */
+#define		clearerr(a)
+#define		fflush(a)
+#define		getc(a)				fgetc(a)
+#define		vsnprintf(a,b,c,d)	vsprintf(a,c,d)
+
+UInt16		 fclose	(FILE *stream);
+UInt16		 feof	(FILE *stream);
+UInt16		 ferror	(FILE *stream);
+Char		*fgets	(Char *s, UInt32 n, FILE *stream);
+Int16		 fgetc	(FILE *stream);
+FILE		*fopen	(const Char *filename, const Char *type);
+UInt32		 fread	(void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+UInt32		 fwrite	(const void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+Int16		 fseek	(FILE *stream, Int32 offset, Int32 whence);
+Int32		 ftell	(FILE *stream);
+
+Int32		 fprintf	(FILE *stream, const Char *formatStr, ...);
+Int32		 printf		(const Char* formatStr, ...);
+Int32		 sprintf	(Char* s, const Char* formatStr, ...);
+Int32		 snprintf	(Char* s, UInt32 len, const Char* formatStr, ...);
+Int32		 vsprintf	(Char* s, const Char* formatStr, _Palm_va_list argParam);
+
+/* ARM MSL only */
+#ifdef PALMOS_ARM
+#undef vsnprintf
+
+int			 vsnprintf	(char *str, size_t size, const char *format, va_list ap); 
+int			 sscanf		( char * buffer, const char * format, ...); 
+#endif
+
 #ifdef __cplusplus
 }
 #endif

Modified: scummvm/trunk/backends/PalmOS/Src/missing/stdlib.h
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/stdlib.h	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/stdlib.h	2006-06-03 11:00:15 UTC (rev 22862)
@@ -35,6 +35,7 @@
 extern "C" {
 #endif
 
+/* malloc stuff */
 #if defined(COMPILE_ZODIAC)
 #	define malloc	MemPtrNew
 #elif defined(COMPILE_OS5) && defined(PALMOS_ARM)
@@ -43,27 +44,20 @@
 #	define malloc	MemGluePtrNew
 #endif
 
+/* custom exit (true exit !) */
 extern ErrJumpBuf stdlib_errJumpBuf;
-
 #define DO_EXIT( code ) \
 	if (ErrSetJump(stdlib_errJumpBuf) == 0) { code }
-	
+
+/* mapped to system functions */	
 #define atoi				StrAToI
 #define atol				StrAToI
 #define abs(a)				((a) < 0 ? -(a) : (a))
-
-#ifdef PALMOS_68K
-#	define qsort(a,b,c,d)		SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0);
-#else
-	typedef int (*_compare_function)(const void*, const void*);
-	void qsort(void * table_base, UInt32 num_members, UInt32 member_size, _compare_function compare_members);
-#endif
-
+#define qsort(a,b,c,d)		SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0);
 #define rand()				SysRandom(0)
 #define abort()
 #define strtoul(a,b,c)		((unsigned long)strtol(a,b,c))
 
-void	*bsearch	(const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *));
 MemPtr	__malloc	(UInt32);
 MemPtr	 calloc		(UInt32 nelem, UInt32 elsize);
 void	 exit		(Int16 status);
@@ -71,6 +65,22 @@
 MemPtr	 realloc	(MemPtr oldP, UInt32 size);
 long	 strtol		(const char *s, char **endptr, int base);
 
+/* already defined in MSL */
+void	*bsearch	(const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *));
+
+/* ARM MSL only */
+#ifdef PALMOS_ARM
+#undef qsort
+#undef strtol
+#undef strtoul
+
+typedef int (*_compare_function)(const void*, const void*);
+
+void				qsort	(void * table_base, UInt32 num_members, UInt32 member_size, _compare_function compare_members);
+long int			strtol	(const char *nptr, char **endptr, int base);
+unsigned longint	strtoul	(const char *nptr, char **endptr,int base);
+#endif
+
 #ifdef __cplusplus
 }
 #endif

Modified: scummvm/trunk/backends/PalmOS/Src/missing/string.h
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/missing/string.h	2006-06-03 10:57:22 UTC (rev 22861)
+++ scummvm/trunk/backends/PalmOS/Src/missing/string.h	2006-06-03 11:00:15 UTC (rev 22862)
@@ -22,8 +22,8 @@
  *
  */
 
-#ifndef STRING_H
-#define STRING_H
+#ifndef PALM_STRING_H
+#define PALM_STRING_H
 
 #include "palmversion.h"
 
@@ -31,6 +31,7 @@
 extern "C" {
 #endif
 
+/* mapped to system functions */
 #define memcmp			MemCmp
 #define memcpy			MemMove
 #define memmove			MemMove
@@ -47,16 +48,17 @@
 #define strncmp			StrNCompare
 #define strstr			StrStr
 
+/* missing functions in 68k MSL */
+void 	*memchr		(const void *s, int c, UInt32 n);
+Char 	*strdup		(const Char *strSource);
 
-void 	*memchr		(const void *s, int c, UInt32 n);
+/* already defined in MSL */
 Char 	*strtok		(Char *str, const Char *sep);
 Char 	*strrchr	(const Char *s, int c);
-Char 	*strdup		(const Char *strSource);
 Char 	*strpbrk	(const Char *s1, const Char *s2);
-UInt32	 strspn		(const char *s1, const char *s2);
+UInt32	 strspn		(const Char *s1, const Char *s2);
+UInt32	 strcspn	(const Char *s1, const Char *s2);
 
-#define StrTok			strtok
-
 #ifdef __cplusplus
 }
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list