2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Some simple physfs extensions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PHYSFSX_H
|
|
|
|
#define PHYSFSX_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-09-17 10:44:21 +00:00
|
|
|
// When PhysicsFS can *easily* be built as a framework on Mac OS X,
|
|
|
|
// the framework form will be supported again -kreatordxx
|
|
|
|
#if 1 //!(defined(__APPLE__) && defined(__MACH__))
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <physfs.h>
|
2007-04-09 02:41:45 +00:00
|
|
|
#else
|
|
|
|
#include <physfs/physfs.h>
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-08 23:37:40 +00:00
|
|
|
#include "fmtcheck.h"
|
2013-06-27 02:35:22 +00:00
|
|
|
#include "dxxsconf.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
2007-11-10 08:51:30 +00:00
|
|
|
#include "strutil.h"
|
|
|
|
#include "u_mem.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "vecmat.h"
|
2008-01-23 17:28:28 +00:00
|
|
|
#include "ignorecase.h"
|
2009-10-05 02:51:37 +00:00
|
|
|
#include "byteswap.h"
|
2006-10-02 13:55:58 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2010-08-09 14:04:22 +00:00
|
|
|
extern void PHYSFSX_init(int argc, char *argv[]);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2009-10-05 02:51:37 +00:00
|
|
|
static inline int PHYSFSX_readSXE16(PHYSFS_file *file, int swap)
|
|
|
|
{
|
|
|
|
PHYSFS_sint16 val;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2009-10-05 02:51:37 +00:00
|
|
|
PHYSFS_read(file, &val, sizeof(val), 1);
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2009-10-05 02:51:37 +00:00
|
|
|
return swap ? SWAPSHORT(val) : val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_readSXE32(PHYSFS_file *file, int swap)
|
|
|
|
{
|
|
|
|
PHYSFS_sint32 val;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2009-10-05 02:51:37 +00:00
|
|
|
PHYSFS_read(file, &val, sizeof(val), 1);
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2009-10-05 02:51:37 +00:00
|
|
|
return swap ? SWAPINT(val) : val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void PHYSFSX_readVectorX(PHYSFS_file *file, vms_vector *v, int swap)
|
|
|
|
{
|
|
|
|
v->x = PHYSFSX_readSXE32(file, swap);
|
|
|
|
v->y = PHYSFSX_readSXE32(file, swap);
|
|
|
|
v->z = PHYSFSX_readSXE32(file, swap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void PHYSFSX_readAngleVecX(PHYSFS_file *file, vms_angvec *v, int swap)
|
|
|
|
{
|
|
|
|
v->p = PHYSFSX_readSXE16(file, swap);
|
|
|
|
v->b = PHYSFSX_readSXE16(file, swap);
|
|
|
|
v->h = PHYSFSX_readSXE16(file, swap);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
static inline int PHYSFSX_readString(PHYSFS_file *file, char *s)
|
|
|
|
{
|
|
|
|
char *ptr = s;
|
|
|
|
|
|
|
|
if (PHYSFS_eof(file))
|
|
|
|
*ptr = 0;
|
|
|
|
else
|
|
|
|
do
|
|
|
|
PHYSFS_read(file, ptr, 1, 1);
|
|
|
|
while (!PHYSFS_eof(file) && *ptr++ != 0);
|
|
|
|
|
|
|
|
return strlen(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_gets(PHYSFS_file *file, char *s)
|
|
|
|
{
|
|
|
|
char *ptr = s;
|
|
|
|
|
|
|
|
if (PHYSFS_eof(file))
|
|
|
|
*ptr = 0;
|
|
|
|
else
|
|
|
|
do
|
|
|
|
PHYSFS_read(file, ptr, 1, 1);
|
|
|
|
while (!PHYSFS_eof(file) && *ptr++ != '\n');
|
|
|
|
|
|
|
|
return strlen(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_writeU8(PHYSFS_file *file, PHYSFS_uint8 val)
|
|
|
|
{
|
|
|
|
return PHYSFS_write(file, &val, 1, 1);
|
|
|
|
}
|
|
|
|
|
2012-07-22 23:17:54 +00:00
|
|
|
static inline int PHYSFSX_writeString(PHYSFS_file *file, const char *s)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
return PHYSFS_write(file, s, 1, strlen(s) + 1);
|
|
|
|
}
|
|
|
|
|
2012-07-22 23:17:54 +00:00
|
|
|
static inline int PHYSFSX_puts(PHYSFS_file *file, const char *s)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
return PHYSFS_write(file, s, 1, strlen(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_putc(PHYSFS_file *file, int c)
|
|
|
|
{
|
|
|
|
unsigned char ch = (unsigned char)c;
|
|
|
|
|
|
|
|
if (PHYSFS_write(file, &ch, 1, 1) < 1)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return (int)c;
|
|
|
|
}
|
|
|
|
|
2011-06-01 07:59:55 +00:00
|
|
|
static inline int PHYSFSX_fgetc(PHYSFS_file *const fp)
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
if (PHYSFS_read(fp, &c, 1, 1) != 1)
|
|
|
|
return EOF;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_fseek(PHYSFS_file *fp, long int offset, int where)
|
|
|
|
{
|
|
|
|
int c, goal_position;
|
|
|
|
|
|
|
|
switch(where)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
|
|
|
goal_position = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
goal_position = PHYSFS_tell(fp) + offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
goal_position = PHYSFS_fileLength(fp) + offset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
c = PHYSFS_seek(fp, goal_position);
|
|
|
|
return !c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char * PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
for (i = 0; i < n - 1; i++)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = PHYSFSX_fgetc(fp);
|
|
|
|
if (c == EOF)
|
|
|
|
{
|
|
|
|
*buf = 0;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (c == 0 || c == 10) // Unix line ending
|
|
|
|
break;
|
|
|
|
if (c == 13) // Mac or DOS line ending
|
|
|
|
{
|
|
|
|
int c1;
|
|
|
|
|
|
|
|
c1 = PHYSFSX_fgetc(fp);
|
|
|
|
if (c1 != EOF) // The file could end with a Mac line ending
|
|
|
|
PHYSFSX_fseek(fp, -1, SEEK_CUR);
|
|
|
|
if (c1 == 10) // DOS line ending
|
|
|
|
continue;
|
|
|
|
else // Mac line ending
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (c == 13);
|
|
|
|
if (c == 13) // because cr-lf is a bad thing on the mac
|
|
|
|
c = '\n'; // and anyway -- 0xod is CR on mac, not 0x0a
|
|
|
|
if (c == '\n')
|
|
|
|
break;
|
|
|
|
*buf++ = c;
|
|
|
|
}
|
|
|
|
*buf = 0;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:13:36 +00:00
|
|
|
template <size_t n>
|
|
|
|
static inline char * PHYSFSX_fgets(char (&buf)[n], PHYSFS_file *const fp)
|
|
|
|
{
|
|
|
|
return PHYSFSX_fgets(buf, n, fp);
|
|
|
|
}
|
|
|
|
|
2013-06-27 02:35:22 +00:00
|
|
|
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...) __attribute_format_printf(2, 3);
|
2012-07-22 23:17:54 +00:00
|
|
|
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...)
|
2013-12-08 23:37:40 +00:00
|
|
|
#define PHYSFSX_printf(A1,F,...) dxx_call_printf_checked(PHYSFSX_printf,PHYSFSX_puts,(A1),(F),##__VA_ARGS__)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2012-06-30 05:05:33 +00:00
|
|
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
2013-12-01 18:27:54 +00:00
|
|
|
va_end(args);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
return PHYSFSX_puts(file, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PHYSFSX_writeFix PHYSFS_writeSLE32
|
|
|
|
#define PHYSFSX_writeFixAng PHYSFS_writeSLE16
|
|
|
|
|
|
|
|
static inline int PHYSFSX_writeVector(PHYSFS_file *file, vms_vector *v)
|
|
|
|
{
|
|
|
|
if (PHYSFSX_writeFix(file, v->x) < 1 ||
|
|
|
|
PHYSFSX_writeFix(file, v->y) < 1 ||
|
|
|
|
PHYSFSX_writeFix(file, v->z) < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_writeAngleVec(PHYSFS_file *file, vms_angvec *v)
|
|
|
|
{
|
|
|
|
if (PHYSFSX_writeFixAng(file, v->p) < 1 ||
|
|
|
|
PHYSFSX_writeFixAng(file, v->b) < 1 ||
|
|
|
|
PHYSFSX_writeFixAng(file, v->h) < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int PHYSFSX_writeMatrix(PHYSFS_file *file, vms_matrix *m)
|
|
|
|
{
|
|
|
|
if (PHYSFSX_writeVector(file, &m->rvec) < 1 ||
|
|
|
|
PHYSFSX_writeVector(file, &m->uvec) < 1 ||
|
|
|
|
PHYSFSX_writeVector(file, &m->fvec) < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-01 07:59:55 +00:00
|
|
|
static inline int PHYSFSX_readInt(PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!PHYSFS_readSLE32(file, &i))
|
|
|
|
{
|
|
|
|
Error("Error reading int in PHYSFSX_readInt()");
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline short PHYSFSX_readShort(PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
int16_t s;
|
|
|
|
|
|
|
|
if (!PHYSFS_readSLE16(file, &s))
|
|
|
|
{
|
|
|
|
Error("Error reading short in PHYSFSX_readShort()");
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline sbyte PHYSFSX_readByte(PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
sbyte b;
|
|
|
|
|
|
|
|
if (PHYSFS_read(file, &b, sizeof(b), 1) != 1)
|
|
|
|
{
|
|
|
|
Error("Error reading byte in PHYSFSX_readByte()");
|
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline fix PHYSFSX_readFix(PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
int f; // a fix is defined as a long for Mac OS 9, and MPW can't convert from (long *) to (int *)
|
|
|
|
|
|
|
|
if (!PHYSFS_readSLE32(file, &f))
|
|
|
|
{
|
|
|
|
Error("Error reading fix in PHYSFSX_readFix()");
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline fixang PHYSFSX_readFixAng(PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
fixang f;
|
|
|
|
|
|
|
|
if (!PHYSFS_readSLE16(file, &f))
|
|
|
|
{
|
|
|
|
Error("Error reading fixang in PHYSFSX_readFixAng()");
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void PHYSFSX_readVector(vms_vector *v, PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
v->x = PHYSFSX_readFix(file);
|
|
|
|
v->y = PHYSFSX_readFix(file);
|
|
|
|
v->z = PHYSFSX_readFix(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void PHYSFSX_readAngleVec(vms_angvec *v, PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
v->p = PHYSFSX_readFixAng(file);
|
|
|
|
v->b = PHYSFSX_readFixAng(file);
|
|
|
|
v->h = PHYSFSX_readFixAng(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void PHYSFSX_readMatrix(vms_matrix *m,PHYSFS_file *file)
|
|
|
|
{
|
|
|
|
PHYSFSX_readVector(&m->rvec,file);
|
|
|
|
PHYSFSX_readVector(&m->uvec,file);
|
|
|
|
PHYSFSX_readVector(&m->fvec,file);
|
|
|
|
}
|
|
|
|
|
2012-03-03 08:03:03 +00:00
|
|
|
#define PHYSFSX_contfile_init PHYSFSX_addRelToSearchPath
|
|
|
|
#define PHYSFSX_contfile_close PHYSFSX_removeRelFromSearchPath
|
|
|
|
|
2013-11-26 22:19:52 +00:00
|
|
|
typedef char file_extension_t[5];
|
2013-11-26 22:10:57 +00:00
|
|
|
int PHYSFSX_checkMatchingExtension(const file_extension_t *exts, const char *filename) __attribute_nonnull();
|
2012-07-22 23:17:54 +00:00
|
|
|
extern int PHYSFSX_addRelToSearchPath(const char *relname, int add_to_end);
|
|
|
|
extern int PHYSFSX_removeRelFromSearchPath(const char *relname);
|
|
|
|
extern int PHYSFSX_fsize(const char *hogname);
|
2010-11-26 11:50:18 +00:00
|
|
|
extern void PHYSFSX_listSearchPathContent();
|
|
|
|
extern int PHYSFSX_checkSupportedArchiveTypes();
|
2010-08-09 14:04:22 +00:00
|
|
|
extern int PHYSFSX_getRealPath(const char *stdPath, char *realPath);
|
2012-07-22 23:17:54 +00:00
|
|
|
extern int PHYSFSX_isNewPath(const char *path);
|
|
|
|
extern int PHYSFSX_rename(const char *oldpath, const char *newpath);
|
2013-11-26 22:10:57 +00:00
|
|
|
extern char **PHYSFSX_findFiles(const char *path, const file_extension_t *exts) __attribute_nonnull();
|
|
|
|
extern char **PHYSFSX_findabsoluteFiles(const char *path, const char *realpath, const file_extension_t *exts) __attribute_nonnull();
|
2010-08-09 14:04:22 +00:00
|
|
|
extern PHYSFS_sint64 PHYSFSX_getFreeDiskSpace();
|
2011-06-01 07:59:55 +00:00
|
|
|
extern int PHYSFSX_exists(const char *filename, int ignorecase);
|
2012-07-22 23:17:54 +00:00
|
|
|
extern PHYSFS_file *PHYSFSX_openReadBuffered(const char *filename);
|
|
|
|
extern PHYSFS_file *PHYSFSX_openWriteBuffered(const char *filename);
|
2010-08-15 06:57:51 +00:00
|
|
|
extern void PHYSFSX_addArchiveContent();
|
|
|
|
extern void PHYSFSX_removeArchiveContent();
|
2007-05-20 02:00:57 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
#endif /* PHYSFSX_H */
|