diff options
author | Chris Apers | 2006-06-03 11:00:15 +0000 |
---|---|---|
committer | Chris Apers | 2006-06-03 11:00:15 +0000 |
commit | 0d51dc4b228c6a48e81b5b9a16a9a25605864408 (patch) | |
tree | 1ed4cd35f9f62bf8d0cec46057395494626cf0d4 /backends | |
parent | ca84620745a134b58fb0cb102be2f50c41ca45c8 (diff) | |
download | scummvm-rg350-0d51dc4b228c6a48e81b5b9a16a9a25605864408.tar.gz scummvm-rg350-0d51dc4b228c6a48e81b5b9a16a9a25605864408.tar.bz2 scummvm-rg350-0d51dc4b228c6a48e81b5b9a16a9a25605864408.zip |
Don't reinvent the wheel, use MSL functions when available for better compatibility and smaller code size
svn-id: r22862
Diffstat (limited to 'backends')
-rw-r--r-- | backends/PalmOS/Src/missing/ext_stdio.c | 13 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/ext_stdlib.c | 17 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/ext_string.c | 82 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/stdio.h | 70 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/stdlib.h | 32 | ||||
-rw-r--r-- | backends/PalmOS/Src/missing/string.h | 16 |
6 files changed, 81 insertions, 149 deletions
diff --git a/backends/PalmOS/Src/missing/ext_stdio.c b/backends/PalmOS/Src/missing/ext_stdio.c index c973e64552..f7d37a9140 100644 --- a/backends/PalmOS/Src/missing/ext_stdio.c +++ b/backends/PalmOS/Src/missing/ext_stdio.c @@ -381,6 +381,9 @@ Int32 printf(const Char *format, ...) { // DONE 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 @@ Int32 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam) { 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 @@ Int32 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam) { // 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 diff --git a/backends/PalmOS/Src/missing/ext_stdlib.c b/backends/PalmOS/Src/missing/ext_stdlib.c index d1d0ce61af..8c8fbd50bd 100644 --- a/backends/PalmOS/Src/missing/ext_stdlib.c +++ b/backends/PalmOS/Src/missing/ext_stdlib.c @@ -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 @@ long strtol(const char *s, char **endptr, int base) { return val; } +#endif MemPtr __malloc(UInt32 size) { MemPtr newP = NULL; diff --git a/backends/PalmOS/Src/missing/ext_string.c b/backends/PalmOS/Src/missing/ext_string.c index a02c360ceb..319017f790 100644 --- a/backends/PalmOS/Src/missing/ext_string.c +++ b/backends/PalmOS/Src/missing/ext_string.c @@ -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 @@ void *memchr(const void *s, int c, UInt32 n) { 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 @@ Char *strdup(const Char *s1) { StrCopy(buf, s1); return buf; -}
\ No newline at end of file +} +#endif diff --git a/backends/PalmOS/Src/missing/stdio.h b/backends/PalmOS/Src/missing/stdio.h index 558231e250..490da720a5 100644 --- a/backends/PalmOS/Src/missing/stdio.h +++ b/backends/PalmOS/Src/missing/stdio.h @@ -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 @@ typedef struct { 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 - -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); +extern FILE gStdioOutput; 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 diff --git a/backends/PalmOS/Src/missing/stdlib.h b/backends/PalmOS/Src/missing/stdlib.h index 84f386e781..2037856632 100644 --- a/backends/PalmOS/Src/missing/stdlib.h +++ b/backends/PalmOS/Src/missing/stdlib.h @@ -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 @@ extern "C" { # 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 @@ Err free (MemPtr memP); 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 diff --git a/backends/PalmOS/Src/missing/string.h b/backends/PalmOS/Src/missing/string.h index dff87ff99d..bb250dfe9b 100644 --- a/backends/PalmOS/Src/missing/string.h +++ b/backends/PalmOS/Src/missing/string.h @@ -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,15 +48,16 @@ extern "C" { #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); + +/* 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); - -#define StrTok strtok +UInt32 strspn (const Char *s1, const Char *s2); +UInt32 strcspn (const Char *s1, const Char *s2); #ifdef __cplusplus } |