common/util.cpp needs fprintf; various std I/O functions are not used by anything in our code, so there is no need to emulate them -- mark these; my previous commits likely broke compilation of the DS backend, try to reduce the brokeness a bit

svn-id: r26023
This commit is contained in:
Max Horn 2007-03-08 17:36:52 +00:00
parent 8778f121e2
commit d19adc0514
3 changed files with 86 additions and 45 deletions

View file

@ -27,8 +27,34 @@
#include "dsmain.h" #include "dsmain.h"
#include "gba_nds_fat.h" #include "gba_nds_fat.h"
namespace DS { namespace DS {
struct fileHandle {
int pos;
bool used;
char* data;
int size;
DSSaveFile* sramFile;
};
#define FILE DS::fileHandle
// FIXME: The following definition for stdin etc. are duplicated in common/util.cpp.
// This should be fixed, e.g. by moving this (and the declarations of fileHandle,
// the various functions etc.) into a separate header file which includes by util.cpp,
// file.cpp and ds-fs.cpp
#undef stderr
#undef stdout
#undef stdin
#define stdout ((DS::fileHandle*) -1)
#define stderr ((DS::fileHandle*) -2)
#define stdin ((DS::fileHandle*) -3)
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// DSFileSystemNode - Flash ROM file system using Zip files // DSFileSystemNode - Flash ROM file system using Zip files
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
@ -434,7 +460,7 @@ FILE* std_fopen(const char* name, const char* mode) {
} }
// MT_memoryReport(); // MT_memoryReport();
return (fileHandle *) result; return (FILE *) result;
} }

View file

@ -38,31 +38,25 @@
#define fopen(a, b) ps2_fopen(a, b) #define fopen(a, b) ps2_fopen(a, b)
#define fclose(a) ps2_fclose(a) #define fclose(a) ps2_fclose(a)
#define fflush(a) ps2_fflush(a)
#define fseek(a, b, c) ps2_fseek(a, b, c) #define fseek(a, b, c) ps2_fseek(a, b, c)
#define ftell(a) ps2_ftell(a) #define ftell(a) ps2_ftell(a)
#define feof(a) ps2_feof(a) #define feof(a) ps2_feof(a)
#define fread(a, b, c, d) ps2_fread(a, b, c, d) #define fread(a, b, c, d) ps2_fread(a, b, c, d)
#define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d) #define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d)
#define fgetc(a) ps2_fgetc(a)
#define fgets(a, b, c) ps2_fgets(a, b, c) //#define fprintf ps2_fprintf // used in common/util.cpp
#define fputc(a, b) ps2_fputc(a, b) //#define fflush(a) ps2_fflush(a) // used in common/util.cpp
#define fputs(a, b) ps2_fputs(a, b)
#define fprintf ps2_fprintf //#define fgetc(a) ps2_fgetc(a) // not used
#define fsize(a) ps2_fsize(a) //#define fgets(a, b, c) ps2_fgets(a, b, c) // not used
//#define fputc(a, b) ps2_fputc(a, b) // not used
//#define fputs(a, b) ps2_fputs(a, b) // not used
//#define fsize(a) ps2_fsize(a) // not used -- and it is not a standard function either
#endif #endif
#ifdef __DS__ #ifdef __DS__
struct fileHandle {
int pos;
bool used;
char* data;
int size;
DSSaveFile* sramFile;
};
// These functions replease the standard library functions of the same name. // These functions replease the standard library functions of the same name.
// As this header is included after the standard one, I have the chance to #define // As this header is included after the standard one, I have the chance to #define
// all of these to my own code. // all of these to my own code.
@ -72,37 +66,29 @@
// These functions need to be #undef'ed, as their original definition // These functions need to be #undef'ed, as their original definition
// in devkitarm is done with #includes (ugh!) // in devkitarm is done with #includes (ugh!)
#undef feof #undef feof
#undef stderr
#undef stdout
#undef stdin
#undef clearerr #undef clearerr
#undef getc //#undef getc
#undef ferror //#undef ferror
#define stdout ((DS::fileHandle*) -1) #define FILE void
#define stderr ((DS::fileHandle*) -2)
#define stdin ((DS::fileHandle*) -3)
#define FILE DS::fileHandle
//#define size_t int
//#define FAT_chdir FAT_CWD
FILE* std_fopen(const char* name, const char* mode); FILE* std_fopen(const char* name, const char* mode);
void std_fclose(FILE* handle); void std_fclose(FILE* handle);
size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle); size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle);
size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle); size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle);
void std_fprintf(FILE* handle, const char* fmt, ...);
bool std_feof(FILE* handle); bool std_feof(FILE* handle);
void std_fflush(FILE* handle);
char* std_fgets(char* str, int size, FILE* file);
long int std_ftell(FILE* handle); long int std_ftell(FILE* handle);
int std_fseek(FILE* handle, long int offset, int whence); int std_fseek(FILE* handle, long int offset, int whence);
void std_clearerr(FILE* handle); void std_clearerr(FILE* handle);
int std_getc(FILE* handle);
char* std_getcwd(char* dir, int dunno); //void std_fprintf(FILE* handle, const char* fmt, ...); // used in common/util.cpp
void std_cwd(char* dir); //void std_fflush(FILE* handle); // used in common/util.cpp
int std_ferror(FILE* handle);
//char* std_fgets(char* str, int size, FILE* file); // not used
//int std_getc(FILE* handle); // not used
//char* std_getcwd(char* dir, int dunno); // not used
//void std_cwd(char* dir); // not used
//int std_ferror(FILE* handle); // not used
// Only functions used in the ScummVM source have been defined here! // Only functions used in the ScummVM source have been defined here!
#define fopen(name, mode) DS::std_fopen(name, mode) #define fopen(name, mode) DS::std_fopen(name, mode)
@ -110,17 +96,19 @@
#define fread(ptr, size, items, file) DS::std_fread(ptr, size, items, file) #define fread(ptr, size, items, file) DS::std_fread(ptr, size, items, file)
#define fwrite(ptr, size, items, file) DS::std_fwrite(ptr, size, items, file) #define fwrite(ptr, size, items, file) DS::std_fwrite(ptr, size, items, file)
#define feof(handle) DS::std_feof(handle) #define feof(handle) DS::std_feof(handle)
//#define fprintf(file, fmt, ...) DS::fprintf(file, fmt, ##__VA_ARGS__)
#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
#define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
#define fflush(file) DS::std_fflush(file)
#define fgets(str, size, file) DS::std_fgets(str, size, file)
#define ftell(handle) DS::std_ftell(handle) #define ftell(handle) DS::std_ftell(handle)
#define fseek(handle, offset, whence) DS::std_fseek(handle, offset, whence) #define fseek(handle, offset, whence) DS::std_fseek(handle, offset, whence)
#define clearerr(handle) DS::std_clearerr(handle) #define clearerr(handle) DS::std_clearerr(handle)
#define getc(handle) DS::std_getc(handle)
#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
#define ferror(handle) DS::std_ferror(handle)
//#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
//#define fflush(file) DS::std_fflush(file) // used in common/util.cpp
//#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used
//#define getc(handle) DS::std_getc(handle) // not used
//#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) // not used
//#define ferror(handle) DS::std_ferror(handle) // not used
#endif #endif

View file

@ -30,6 +30,33 @@
extern bool isSmartphone(void); extern bool isSmartphone(void);
#endif #endif
#ifdef __PLAYSTATION2__
// for those replaced fopen/fread/etc functions
typedef unsigned long uint64;
typedef signed long int64;
#include "backends/platform/ps2/fileio.h"
#define fprintf ps2_fprintf
#define fflush(a) ps2_fflush(a)
#endif
#ifdef __DS__
#undef stderr
#undef stdout
#undef stdin
#define stdout ((DS::fileHandle*) -1)
#define stderr ((DS::fileHandle*) -2)
#define stdin ((DS::fileHandle*) -3)
void std_fprintf(FILE* handle, const char* fmt, ...);
void std_fflush(FILE* handle);
#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
#define fflush(file) DS::std_fflush(file)
#endif
namespace Common { namespace Common {
// //