Revert "Cfile module update"

This commit is contained in:
Edu Garcia 2024-04-19 13:57:55 +01:00 committed by GitHub
parent 82ca58219a
commit 066b436fd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
99 changed files with 378 additions and 314 deletions

View File

@ -102,7 +102,7 @@
#include "renderer.h"
#include "gr.h"
#include "mono.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "bitmap.h"
#include "mem.h"

View File

@ -69,7 +69,7 @@ ENDIF ()
MESSAGE("Install will copy files to ${D3_GAMEDIR}")
include_directories("${CMAKE_SOURCE_DIR}" "lib" "Descent3" ${PLATFORM_INCLUDES})
include_directories("lib" "Descent3" ${PLATFORM_INCLUDES})
# file(GLOB_RECURSE INCS "*.h")

View File

@ -47,7 +47,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "game.h"
#include "mem.h"
@ -224,7 +224,7 @@ int ReadFullLine(char **data, CFILE *ifile) {
// read in a byte
c = cfgetc(ifile);
if ((c == EOF) || (!(ifile->flags & CFF_TEXT) && (c == 0)) || ((ifile->flags & CFF_TEXT) && (c == '\n'))) {
if ((c == EOF) || (!(ifile->flags & CF_TEXT) && (c == 0)) || ((ifile->flags & CF_TEXT) && (c == '\n'))) {
// we've hit the end of the line
done = true;
} else {

View File

@ -77,7 +77,7 @@
#include "ddio.h"
#include "gamefont.h"
#include "multi_ui.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mem.h"
#include "game.h"
#include "stringtable.h"

View File

@ -1,7 +1,7 @@
#include "DllWrappers.h"
#include "pserror.h"
#include "pstring.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "gamefont.h"
#include "grdefs.h"
#include "descent.h"

View File

@ -2,7 +2,7 @@
#define DLLWRAPPERS_H_
#include "pserror.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "gamefont.h"
#include "grdefs.h"
#include "descent.h"

View File

@ -164,7 +164,7 @@
#define __INVENTORY_H__
#include "pstypes.h"
#include "cfile/cfile.h"
#include "CFILE.H"
struct object;

View File

@ -1230,7 +1230,7 @@
#include "LoadLevel.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "descent.h"
#include "object.h"

View File

@ -425,7 +425,7 @@
* $NoKeywords: $
*/
#include "cfile/cfile.h"
#include "CFILE.H"
#include "room.h"
// Chunk types

View File

@ -622,7 +622,7 @@
#include "3d.h"
#include "LoadLevel.h"
#include "pserror.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "gamefont.h"
#include "grdefs.h"
#include "descent.h"

View File

@ -384,7 +384,7 @@
#include "osiris_dll.h"
#include "pserror.h"
#include "mono.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "ddio.h"
#include "manage.h"
#include <stdlib.h>
@ -898,11 +898,11 @@ int _get_full_path_to_module(char *module_name, char *fullpath, char *basename)
int exist = cfexist(modfilename);
switch (exist) {
case CFES_ON_DISK:
case CF_ON_DISK:
ddio_MakePath(fullpath, LocalScriptDir, modfilename, NULL);
return -1;
break;
case CFES_IN_LIBRARY: {
case CF_IN_LIBRARY: {
ASSERT(OSIRIS_Extracted_script_dir);
if (!OSIRIS_Extracted_script_dir)
return -2;

View File

@ -45,7 +45,7 @@
#include "bitmap.h"
#include "player.h"
#include "pilot.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mono.h"
#include "ddio.h"
#include "manage.h"

View File

@ -483,7 +483,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include "TelCom.h"
#include "TelComEffects.h"

View File

@ -133,7 +133,7 @@
#include <string.h>
#include <ctype.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "ddio.h"
#include "bitmap.h"

View File

@ -64,7 +64,7 @@
#include <string.h>
#include <ctype.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "ddio.h"
#include "bitmap.h"

View File

@ -67,7 +67,7 @@
#include <string.h>
#include <ctype.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "ddio.h"
#include "bitmap.h"

View File

@ -1,7 +1,7 @@
#include <stdlib.h>
#include "aiambient.h"
#include "string.h"
#include "objinfo.h"
#include <stdlib.h>
#include "game.h"
#include "psrand.h"

View File

@ -1,7 +1,7 @@
#ifndef _AIAMBIENT_H_
#define _AIAMBIENT_H_
#include "cfile/cfile.h"
#include "CFILE.H"
#define MAX_AL_TYPES 6
#define MAX_ALS_PER_TYPE 130

View File

@ -138,6 +138,7 @@ void InitAmbientSounds() {
}
#include "ddio.h"
#include "CFILE.H"
#include "soundload.h"
#include "descent.h"
#include "mem.h"

View File

@ -6,7 +6,7 @@
#include "pserror.h"
#include "pstypes.h"
#include "audiotaunts.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "audio_encode.h"
#include "byteswap.h"
#include "mem.h"

View File

@ -25,7 +25,7 @@
#include "list.h"
#include "vecmat.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#define BSP_IN_FRONT 1
#define BSP_BEHIND 2

View File

@ -41,7 +41,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include <stdlib.h>
#include <string.h>

View File

@ -278,7 +278,7 @@
#include "cinematics.h"
#include "hlsoundlib.h"
#include "terrain.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mem.h"
#include "lighting.h"
#include "PHYSICS.H"

View File

@ -65,7 +65,7 @@
#include "descent.h"
#include <time.h>
#include "mono.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "program.h"
#include <fcntl.h>

View File

@ -94,8 +94,8 @@ typedef int socklen_t;
#include "pstypes.h"
#include "pserror.h"
#include "pstring.h"
#include "cfile/cfile.h"
#include "cfile/inffile.h"
#include "CFILE.H"
#include "InfFile.h"
#include "dedicated_server.h"
#include "multi.h"
#include "args.h"

View File

@ -248,7 +248,7 @@
*/
#include <stdio.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "objinfo.h"
#include "ship.h"
#include "ui.h"

View File

@ -367,7 +367,7 @@
#include "pserror.h"
#include "grdefs.h"
#include "mono.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "init.h"
#include "game.h"

View File

@ -658,7 +658,7 @@
#include "cinematics.h"
#include "SmallViews.h"
#include "Mission.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "gameloop.h"
#include "cockpit.h"
#include "game2dll.h"

View File

@ -248,7 +248,7 @@
#include "gamesave.h"
#include "descent.h"
#include "newui.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "Mission.h"
#include "gamesequence.h"
#include "gameevent.h"

View File

@ -67,7 +67,7 @@
#define GAMESAVE_H
#include "pstypes.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "object.h"
#include "objinfo.h"

View File

@ -114,7 +114,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include <stdlib.h>
#include <string.h>

View File

@ -87,7 +87,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include <stdlib.h>
#include <string.h>

View File

@ -2,7 +2,7 @@
#define _LEVELGOAL_H_
#include "object.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#if defined(MACOSX)
#include <malloc/malloc.h>
#else

View File

@ -17,7 +17,6 @@
#include <dirent.h>
#define _GNU_SOURCE
#include <fnmatch.h>
#include "cfile/hogfile.h"
#endif
#include "SDL.h"
@ -313,6 +312,8 @@ void StartDedicatedServer();
static void hogfileRefresh(const char *x) { printf(" - %s\n", x); } // hogfileRefresh
int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *));
// hack of the century.
static void buildNewHogFromFileList(char *fileName) {
setbuf(stdout, NULL);
@ -403,7 +404,7 @@ static void buildNewHogFromFileList(char *fileName) {
} // for
} while (swapped);
NewHogFile("new.hog", i, (const char **)files, (void (*)(char *))hogfileRefresh);
CreateNewHogFile("new.hog", i, (const char **)files, (void (*)(char *))hogfileRefresh);
} // buildNewHogFileFromList
#endif

View File

@ -163,7 +163,7 @@
#include "gamesave.h"
#include "descent.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "Mission.h"
#include "gamesequence.h"
#include "gameevent.h"

View File

@ -73,7 +73,7 @@
#include "game.h"
#include "descent.h"
#include "mono.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "localization.h"
#include "mem.h"
#include "ddio.h"

View File

@ -1,7 +1,7 @@
#ifndef _MATCEN_H_
#define _MATCEN_H_
#include "cfile/cfile.h"
#include "CFILE.H"
#include "vecmat.h"
#include "matcen_external.h"

View File

@ -7613,7 +7613,7 @@ void MultiAskForFile(ushort file_id, ushort file_who, ushort who) {
// Check to see if this file exists already
char *p = GetFileNameFromPlayerAndID(file_who, file_id);
if (*p) {
if (CFES_ON_DISK == cfexist(p)) {
if (CF_ON_DISK == cfexist(p)) {
char szcrc[_MAX_PATH];
char path[_MAX_PATH];
char ext[_MAX_PATH];

View File

@ -95,7 +95,7 @@
#include "pstypes.h"
#include "manage_external.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "networking.h"
#include "descent.h" //for MSN_NAMELEN
#include "byteswap.h"

View File

@ -50,7 +50,7 @@
*/
#include <stdio.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "multi.h"
#include "objinfo.h"
#include "ship.h"

View File

@ -88,7 +88,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include <stdlib.h>
#include <string.h>

View File

@ -98,7 +98,7 @@
#include "object_external_struct.h"
#include "osiris_share.h"
#include "module.h"
#include "cfile/cfile.h"
#include "CFILE.H"
extern uint Osiris_game_checksum;

View File

@ -156,7 +156,7 @@
#define __OSIRIS_PREDEF_H_
#include "osiris_dll.h"
#include "cfile/cfile.h"
#include "CFILE.H"
// osipf_CallObjectEvent
// Sends an event to an object. Returns true if the default action should

View File

@ -563,7 +563,7 @@
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "application.h"
#include "manage.h"
#include "newui.h"
@ -933,7 +933,7 @@ void PilotSelect(void) {
int res = -1;
bool done = false;
if (cfexist(Default_pilot) != CFES_NOT_FOUND) {
if (cfexist(Default_pilot) != CF_NOT_FOUND) {
// ok so the default pilot file is around, mark this as the current pilot
Current_pilot.set_filename(Default_pilot);
PltReadFile(&Current_pilot);
@ -984,7 +984,7 @@ void PilotSelect(void) {
// use this in case they cancel out
Current_pilot.get_filename(pfilename);
if (cfexist(pfilename) != CFES_NOT_FOUND) {
if (cfexist(pfilename) != CF_NOT_FOUND) {
strcpy(old_file, pfilename);
} else {
old_file[0] = '\0';
@ -1040,7 +1040,7 @@ void PilotSelect(void) {
case UID_CANCEL: {
// Cancel out
bool found_old = (cfexist(old_file) != CFES_NOT_FOUND);
bool found_old = (cfexist(old_file) != CF_NOT_FOUND);
bool display_error;
if (filecount && found_old)
@ -1494,7 +1494,7 @@ void NewPltUpdate(newuiListBox *list, char **flist, int filecount, int selected,
list->SetCurrentIndex(selected);
if (filename && (cfexist(filename) != CFES_NOT_FOUND)) {
if (filename && (cfexist(filename) != CF_NOT_FOUND)) {
// get the selected pilot from the filename
mprintf((0, "Looking for Pilot: %s\n", filename));
for (int d = 0; d < filecount; d++) {
@ -2212,7 +2212,7 @@ bool CreateCRCFileName(const char *src, char *dest) {
ASSERT(src);
ASSERT(dest);
if (cfexist(src) != CFES_ON_DISK)
if (cfexist(src) != CF_ON_DISK)
return false;
unsigned int crc_value = cf_GetfileCRC((char *)src);
@ -2243,7 +2243,7 @@ bool CreateCRCFileName(const char *src, char *base, char *newfilename) {
ASSERT(base);
ASSERT(newfilename);
if (cfexist(src) != CFES_ON_DISK)
if (cfexist(src) != CF_ON_DISK)
return false;
unsigned int crc_value = cf_GetfileCRC((char *)src);
@ -2345,7 +2345,7 @@ float getdist(angle ang, float height) {
// newfile = on return true is the filename of the new bitmap
bool ImportGraphic(char *pathname, char *newfile) {
ASSERT(pathname);
if (cfexist(pathname) != CFES_ON_DISK) {
if (cfexist(pathname) != CF_ON_DISK) {
mprintf((0, "'%s' not found\n", pathname));
return false;
}

View File

@ -72,7 +72,7 @@
#include "pstypes.h"
#include "controls.h"
#include "Controller.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "weapon.h"
#include "config.h"

View File

@ -142,7 +142,7 @@
#include "pserror.h"
#include "bitmap.h"
#include "vclip.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mono.h"
#include "ddio.h"
#include "gametexture.h"

View File

@ -338,7 +338,7 @@
#include "sounds.h"
#include "stringtable.h"
#include "Macros.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "AIMain.h"
#include <algorithm>

View File

@ -282,7 +282,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "texture.h"
#include "bitmap.h"
#include "pstypes.h"

View File

@ -56,7 +56,7 @@
#include "mem.h"
#include "iff.h"
#include "byteswap.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "pstypes.h"
#include "bitmap.h"

View File

@ -1,7 +1,7 @@
#ifndef _IFF_H
#define _IFF_H
#include "cfile/cfile.h"
#include "CFILE.H"
// Error codes for read & write routines

View File

@ -114,7 +114,7 @@
* $NoKeywords: $
*/
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "pstypes.h"
#include "bitmap.h"

View File

@ -15,15 +15,13 @@
// Linux Build Includes
#include "linux/linux_fix.h"
#endif
#include "byteswap.h"
#include "pserror.h"
#include "ddio.h"
#include "psglob.h"
#include "cfile/cfile.h"
#include "cfile/hogfile.h" //info about library file
#include "CFILE.H"
#include "hogfile.h" //info about library file
#include "mem.h"
// Library structures
typedef struct {
char name[PSFILENAME_LEN + 1]; // just the filename part
@ -32,30 +30,25 @@ typedef struct {
ulong timestamp; // time and date of file
int flags; // misc flags
} library_entry;
typedef struct library {
char name[_MAX_PATH]; // includes path + filename
int nfiles;
library_entry *entries;
struct library *next;
int handle; // identifier for this lib
int handle; // indentifier for this lib
FILE *file; // pointer to file for this lib, if no one using it
} library;
// entry in extension->path table
typedef struct {
char ext[_MAX_EXT];
ubyte pathnum;
} ext_entry;
// entry in list of paths
typedef struct {
char path[_MAX_PATH];
ubyte specific; // if non-zero, only for specific extensions
} path_entry;
#define MAX_PATHS 100
path_entry paths[MAX_PATHS];
int N_paths = 0;
#define MAX_EXTENSIONS 100
@ -63,12 +56,11 @@ ext_entry extensions[MAX_EXTENSIONS];
int N_extensions;
library *Libraries = NULL;
int lib_handle = 0;
void cf_Close();
// Structure thrown on disk error
cfile_error cfe;
// The message for unexpected end of file
char *eof_error = "Unexpected end of file";
// Generates a cfile error
void ThrowCFileError(int type, CFILE *file, char *msg) {
cfe.read_write = type;
@ -76,9 +68,6 @@ void ThrowCFileError(int type, CFILE *file, char *msg) {
cfe.file = file;
throw &cfe;
}
void cf_Close();
// Opens a HOG file. Future calls to cfopen(), etc. will look in this HOG.
// Parameters: libname - the path & filename of the HOG file
// NOTE: libname must be valid for the entire execution of the program. Therefore, it should either
@ -94,7 +83,7 @@ int cf_OpenLibrary(const char *libname) {
tHogFileEntry entry;
fp = fopen(libname, "rb");
if (fp == nullptr)
if (fp == NULL)
return 0; // CF_NO_FILE;
fread(id, strlen(HOG_TAG_STR), 1, fp);
if (strncmp(id, HOG_TAG_STR, strlen(HOG_TAG_STR))) {
@ -159,13 +148,10 @@ int cf_OpenLibrary(const char *libname) {
// Sucess. Return the handle
return lib->handle;
}
/**
* Closes a library file.
* @param handle the handle returned by cf_OpenLibrary()
*/
// Closes a library file.
// Parameters: handle: the handle returned by cf_OpenLibrary()
void cf_CloseLibrary(int handle) {
library *lib, *prev = nullptr;
library *lib, *prev = NULL;
for (lib = Libraries; lib; prev = lib, lib = lib->next) {
if (lib->handle == handle) {
if (prev)
@ -176,11 +162,10 @@ void cf_CloseLibrary(int handle) {
fclose(lib->file);
mem_free(lib->entries);
mem_free(lib);
return; // successful close
return; // sucessful close
}
}
}
// Closes down the CFILE system, freeing up all data, etc.
void cf_Close() {
library *next;
@ -229,23 +214,16 @@ int cf_SetSearchPath(const char *path, ...) {
return 1;
}
/**
* Removes all search paths that have been added by cf_SetSearchPath
*/
void cf_ClearAllSearchPaths() {
// Removes all search paths that have been added by cf_SetSearchPath
void cf_ClearAllSearchPaths(void) {
N_paths = 0;
N_extensions = 0;
}
/**
* Opens a file for reading in a library, given the library id
* @param filename
* @param libhandle
* @return
*/
// Opens a file for reading in a library, given the library id
CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) {
if (libhandle <= 0)
return nullptr;
return NULL;
library *lib;
CFILE *cfile;
@ -258,9 +236,9 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) {
lib = lib->next;
}
if (nullptr == lib) {
if (NULL == lib) {
// couldn't find the library handle
return nullptr;
return NULL;
}
// now do a binary search for the file entry
@ -280,10 +258,10 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) {
first = i + 1;
else // search key before check key
last = i - 1;
} while (true);
} while (1);
if (!found)
return nullptr; // file not in library
return NULL; // file not in library
// open the file for reading
FILE *fp;
@ -291,13 +269,13 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) {
// See if there's an available FILE
if (lib->file) {
fp = lib->file;
lib->file = nullptr;
lib->file = NULL;
} else {
fp = fopen(lib->name, "rb");
if (!fp) {
mprintf((1, "Error opening library <%s> when opening file <%s>; errno=%d.", lib->name, filename, errno));
Int3();
return nullptr;
return NULL;
}
}
cfile = (CFILE *)mem_malloc(sizeof(*cfile));
@ -337,20 +315,20 @@ CFILE *open_file_in_lib(const char *filename) {
first = i + 1;
else // search key before check key
last = i - 1;
} while (true);
} while (1);
if (found) {
FILE *fp;
int r;
// See if there's an available FILE
if (lib->file) {
fp = lib->file;
lib->file = nullptr;
lib->file = NULL;
} else {
fp = fopen(lib->name, "rb");
if (!fp) {
mprintf((1, "Error opening library <%s> when opening file <%s>; errno=%d.", lib->name, filename, errno));
Int3();
return nullptr;
return NULL;
}
}
cfile = (CFILE *)mem_malloc(sizeof(*cfile));
@ -369,7 +347,7 @@ CFILE *open_file_in_lib(const char *filename) {
}
lib = lib->next;
}
return nullptr;
return NULL;
}
#ifdef __LINUX__
@ -386,7 +364,7 @@ public:
bool Start(const char *wildcard, char *namebuf);
bool Next(char *namebuf);
void Close();
void Close(void);
private:
int globindex;
@ -415,7 +393,7 @@ bool CFindFiles::Start(const char *wildcard, char *namebuf) {
globindex = 0;
char ext[256];
ddio_SplitPath(ffres.gl_pathv[0], nullptr, namebuf, ext);
ddio_SplitPath(ffres.gl_pathv[0], NULL, namebuf, ext);
strcat(namebuf, ext);
return true;
}
@ -429,12 +407,12 @@ bool CFindFiles::Next(char *namebuf) {
return false;
char ext[256];
ddio_SplitPath(ffres.gl_pathv[globindex], nullptr, namebuf, ext);
ddio_SplitPath(ffres.gl_pathv[globindex], NULL, namebuf, ext);
strcat(namebuf, ext);
return true;
}
void CFindFiles::Close() {
void CFindFiles::Close(void) {
if (globindex == -1)
return;
globindex = -1;
@ -471,7 +449,7 @@ bool cf_FindRealFileNameCaseInsenstive(const char *directory, const char *fname,
mprintf((1, "CFILE: Found directory \"%s\" in filename, new filename is \"%s\"\n", real_dir, real_file));
} else {
use_dir = false;
real_dir = nullptr;
real_dir = NULL;
real_file = (char *)fname;
}
}
@ -578,7 +556,7 @@ FILE *open_file_in_directory_case_sensitive(const char *directory, const char *f
if (cf_FindRealFileNameCaseInsenstive(directory, filename, new_filename)) {
// we have a file, open it open and use it
char full_path[_MAX_PATH * 2];
if (directory != nullptr) {
if (directory != NULL) {
ddio_MakePath(full_path, directory, new_filename, NULL);
} else {
strcpy(full_path, new_filename);
@ -587,7 +565,7 @@ FILE *open_file_in_directory_case_sensitive(const char *directory, const char *f
return fopen(full_path, mode);
}
return nullptr;
return NULL;
}
#endif
@ -597,7 +575,7 @@ CFILE *open_file_in_directory(const char *filename, const char *mode, const char
CFILE *cfile;
char path[_MAX_PATH * 2];
char tmode[3] = "rb";
if (directory != nullptr) {
if (directory != NULL) {
// Make a full path
ddio_MakePath(path, directory, filename, NULL);
} else // no directory specified, so just use filename passed
@ -638,7 +616,7 @@ CFILE *open_file_in_directory(const char *filename, const char *mode, const char
fp = open_file_in_directory_case_sensitive(directory, filename, tmode, using_filename);
if (!fp) {
// no dice
return nullptr;
return NULL;
} else {
// found a version of the file!
mprintf((0, "CFILE: Unable to find %s, but using %s instead\n", filename, using_filename));
@ -696,9 +674,9 @@ CFILE *cfopen(const char *filename, const char *mode) {
ddio_SplitPath(filename, path, fname, ext);
// if there is a path specified, use it instead of the libraries, search dirs, etc.
// if the file is writable, just open it, instead of looking in libs, etc.
if (strlen(path) || (mode[0] == 'w')) { // found a path
cfile = open_file_in_directory(filename, mode, nullptr); // use path specified with file
goto got_file; // don't look in libs, etc.
if (strlen(path) || (mode[0] == 'w')) { // found a path
cfile = open_file_in_directory(filename, mode, NULL); // use path specified with file
goto got_file; // don't look in libs, etc.
}
//@@ Don't look in current dir. mt, 3-12-97
//@@ //first look in current directory
@ -726,17 +704,15 @@ CFILE *cfopen(const char *filename, const char *mode) {
got_file:;
if (cfile) {
if (mode[0] == 'w')
cfile->flags |= CFF_WRITING;
cfile->flags |= CF_WRITING;
if (mode[1] == 't')
cfile->flags |= CFF_TEXT;
cfile->flags |= CF_TEXT;
}
return cfile;
}
// Returns the length of the specified file
// Parameters: cfp - the file pointer returned by cfopen()
int cfilelength(CFILE *cfp) { return cfp->size; }
// Closes an open CFILE.
// Parameters: cfile - the file pointer returned by cfopen()
void cfclose(CFILE *cfp) {
@ -746,9 +722,9 @@ void cfclose(CFILE *cfp) {
for (lib = Libraries; lib; lib = lib->next) {
if (lib->handle == cfp->lib_handle) { // found the library
// if library doesn't already have a file, give it this one
if (lib->file == nullptr) {
if (lib->file == NULL) {
lib->file = cfp->file;
cfp->file = nullptr;
cfp->file = NULL;
}
break;
}
@ -763,7 +739,6 @@ void cfclose(CFILE *cfp) {
// free the cfile struct
mem_free(cfp);
}
// Just like stdio fgetc(), except works on a CFILE
// Returns a char or EOF
int cfgetc(CFILE *cfp) {
@ -782,7 +757,7 @@ int cfgetc(CFILE *cfp) {
// do special newline handling for text files:
// if CR or LF by itself, return as newline
// if CR/LF pair, return as newline
if (cfp->flags & CFF_TEXT) {
if (cfp->flags & CF_TEXT) {
if (c == 10) // return LF as newline
c = '\n';
else if (c == 13) { // check for CR/LF pair
@ -823,13 +798,10 @@ int cfseek(CFILE *cfp, long int offset, int where) {
cfp->position = ftell(cfp->file) - cfp->lib_offset;
return c;
}
// Just like stdio ftell(), except works on a CFILE
int cftell(CFILE *cfp) { return cfp->position; }
// Returns true if at EOF
int cfeof(CFILE *cfp) { return (cfp->position >= cfp->size); }
// Tells if the file exists
// Returns non-zero if file exists. Also tells if the file is on disk
// or in a hog - See return values in cfile.h
@ -840,12 +812,12 @@ int cfexist(const char *filename) {
cfp = cfopen(filename, "rb");
if (!cfp) { // Didn't get file. Why?
if (errno == EACCES) // File exists, but couldn't open it
return CFES_ON_DISK; // so say it exists on the disk
return CF_ON_DISK; //..so say it exists on the disk
// DAJ if (errno != ENOENT) //Check if error is "file not found"
// DAJ Int3(); //..warn if not
return CFES_NOT_FOUND; // Say we didn't find the file
return CF_NOT_FOUND; // Say we didn't find the file
}
ret = cfp->lib_offset ? CFES_IN_LIBRARY : CFES_ON_DISK;
ret = cfp->lib_offset ? CF_IN_LIBRARY : CF_ON_DISK;
cfclose(cfp);
return ret;
}
@ -857,7 +829,7 @@ int cfexist(const char *filename) {
int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp) {
int i;
char *error_msg = eof_error; // default error
ASSERT(!(cfp->flags & CFF_TEXT));
ASSERT(!(cfp->flags & CF_TEXT));
if (cfp->position + count <= cfp->size) {
i = fread(buf, 1, count, cfp->file);
if (i == count) {
@ -881,22 +853,22 @@ int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp) {
// to be present.
// Read and return an integer (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int32_t cf_ReadInt(CFILE *cfp) {
int32_t i;
int cf_ReadInt(CFILE *cfp) {
int i;
cf_ReadBytes((ubyte *)&i, sizeof(i), cfp);
return INTEL_INT(i);
}
// Read and return a short (16 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int16_t cf_ReadShort(CFILE *cfp) {
int16_t i;
short cf_ReadShort(CFILE *cfp) {
short i;
cf_ReadBytes((ubyte *)&i, sizeof(i), cfp);
return INTEL_SHORT(i);
}
// Read and return a byte (8 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int8_t cf_ReadByte(CFILE *cfp) {
int8_t i;
sbyte cf_ReadByte(CFILE *cfp) {
int i;
i = cfgetc(cfp);
if (i == EOF)
ThrowCFileError(CFE_READING, cfp, cfeof(cfp) ? eof_error : strerror(errno));
@ -904,8 +876,8 @@ int8_t cf_ReadByte(CFILE *cfp) {
}
// Read and return a float (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
float_t cf_ReadFloat(CFILE *cfp) {
float_t f;
float cf_ReadFloat(CFILE *cfp) {
float f;
cf_ReadBytes((ubyte *)&f, sizeof(f), cfp);
#ifdef MACINTOSH
float e = INTEL_FLOAT(f); // DAJ bash to zero if reads a NaN
@ -918,8 +890,8 @@ float_t cf_ReadFloat(CFILE *cfp) {
}
// Read and return a double (64 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
double_t cf_ReadDouble(CFILE *cfp) {
double_t f;
double cf_ReadDouble(CFILE *cfp) {
double f;
cf_ReadBytes((ubyte *)&f, sizeof(f), cfp);
#ifdef BIG_ENDIAN
{
@ -957,7 +929,7 @@ int cf_ReadString(char *buf, size_t n, CFILE *cfp) {
break;
}
if ((!(cfp->flags & CFF_TEXT) && (c == 0)) || ((cfp->flags & CFF_TEXT) && (c == '\n')))
if ((!(cfp->flags & CF_TEXT) && (c == 0)) || ((cfp->flags & CF_TEXT) && (c == '\n')))
break; // end-of-string
if (count < n - 1) // store char if room in buffer
*bp++ = c;
@ -972,7 +944,7 @@ int cf_ReadString(char *buf, size_t n, CFILE *cfp) {
// Throws an exception of type (cfile_error *) if the OS returns an error on write
int cf_WriteBytes(const ubyte *buf, int count, CFILE *cfp) {
int i;
if (!(cfp->flags & CFF_WRITING))
if (!(cfp->flags & CF_WRITING))
return 0;
ASSERT(count > 0);
i = fwrite(buf, 1, count, cfp->file);
@ -994,10 +966,9 @@ int cf_WriteString(CFILE *cfp, const char *buf) {
if (len != 0) // write string
cf_WriteBytes((ubyte *)buf, len, cfp);
// Terminate with newline (text file) or NULL (binary file)
cf_WriteByte(cfp, (cfp->flags & CFF_TEXT) ? '\n' : 0);
cf_WriteByte(cfp, (cfp->flags & CF_TEXT) ? '\n' : 0);
return len + 1;
}
// Just like stdio fprintf(), except works on a CFILE
int cfprintf(CFILE *cfp, const char *format, ...) {
#ifndef MACINTOSH
@ -1010,45 +981,40 @@ int cfprintf(CFILE *cfp, const char *format, ...) {
return count;
#endif
}
// The following functions write numeric vales to a CFILE. All values are
// stored to the file in Intel (little-endian) format.
// All these throw an exception if there's an error on write.
// Write an integer (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteInt(CFILE *cfp, int32_t i) {
void cf_WriteInt(CFILE *cfp, int i) {
int t = INTEL_INT(i);
cf_WriteBytes((ubyte *)&t, sizeof(t), cfp);
}
// Write a short (16 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteShort(CFILE *cfp, int16_t s) {
void cf_WriteShort(CFILE *cfp, short s) {
short t = INTEL_SHORT(s);
cf_WriteBytes((ubyte *)&t, sizeof(t), cfp);
}
// Write a byte (8 bits).
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteByte(CFILE *cfp, int8_t b) {
void cf_WriteByte(CFILE *cfp, sbyte b) {
if (fputc(b, cfp->file) == EOF)
ThrowCFileError(CFE_WRITING, cfp, strerror(errno));
cfp->position++;
// If text file & writing newline, increment again for LF
if ((cfp->flags & CFF_TEXT) && (b == '\n')) // check for text mode newline
if ((cfp->flags & CF_TEXT) && (b == '\n')) // check for text mode newline
cfp->position++;
}
// Write a float (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteFloat(CFILE *cfp, float_t f) {
void cf_WriteFloat(CFILE *cfp, float f) {
float t = INTEL_FLOAT(f);
cf_WriteBytes((ubyte *)&t, sizeof(t), cfp);
}
// Write a double (64 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteDouble(CFILE *cfp, double_t d) {
void cf_WriteDouble(CFILE *cfp, double d) {
#ifdef BIG_ENDIAN
{
double t;
@ -1061,20 +1027,19 @@ void cf_WriteDouble(CFILE *cfp, double_t d) {
#endif
cf_WriteBytes((ubyte *)&d, sizeof(d), cfp);
}
// Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file.
// Throws an exception of type (cfile_error *) if the OS returns an error on read or write
bool cf_CopyFile(char *dest, const char *src, int copytime) {
CFILE *infile, *outfile;
if (!stricmp(dest, src))
return true; // don't copy files if they are the same
return 1; // don't copy files if they are the same
infile = (CFILE *)cfopen(src, "rb");
if (!infile)
return false;
return 0;
outfile = (CFILE *)cfopen(dest, "wb");
if (!outfile) {
cfclose(infile);
return false;
return 0;
}
int progress = 0;
int readcount = 0;
@ -1100,16 +1065,13 @@ bool cf_CopyFile(char *dest, const char *src, int copytime) {
if (!infile_lib_offset && copytime) {
cf_CopyFileTime(dest, src);
}
return true;
return 1;
}
// Checks to see if two files are different.
// Returns TRUE if the files are different, or FALSE if they are the same.
bool cf_Diff(const char *a, const char *b) { return (ddio_FileDiff(a, b)); }
// Copies the file time from one file to another
void cf_CopyFileTime(char *dest, const char *src) { ddio_CopyFileTime(dest, src); }
// Changes a files attributes (ie read/write only)
void cf_ChangeFileAttributes(const char *name, int attr) {
#ifdef MACINTOSH
@ -1119,7 +1081,6 @@ void cf_ChangeFileAttributes(const char *name, int attr) {
Int3(); // Get Jason or Matt, file not found!
#endif
}
// rewinds cfile position
void cf_Rewind(CFILE *fp) {
if (fp->lib_offset) {
@ -1130,8 +1091,7 @@ void cf_Rewind(CFILE *fp) {
}
fp->position = 0;
}
// Calculates a 32-bit CRC for the specified file. a return code of -1 means file note found
// Calculates a 32 bit CRC for the specified file. a return code of -1 means file note found
#define CRC32_POLYNOMIAL 0xEDB88320L
#define CRC_BUFFER_SIZE 5000
@ -1196,7 +1156,7 @@ unsigned int cf_GetfileCRC(char *src) {
}
char cfile_search_wildcard[256];
library *cfile_search_library = nullptr;
library *cfile_search_library = NULL;
int cfile_search_curr_index = 0;
bool cfile_search_ispattern = false;
// the following cf_LibraryFind function are similar to the ddio_Find functions as they look
@ -1242,7 +1202,6 @@ bool cf_LibraryFindFirst(int handle, const char *wildcard, char *buffer) {
// we didn't find a match
return false;
}
bool cf_LibraryFindNext(char *buffer) {
while (cfile_search_curr_index < cfile_search_library->nfiles) {
if (cfile_search_ispattern) {
@ -1263,9 +1222,8 @@ bool cf_LibraryFindNext(char *buffer) {
}
return false;
}
void cf_LibraryFindClose() {
cfile_search_library = nullptr;
void cf_LibraryFindClose(void) {
cfile_search_library = NULL;
cfile_search_curr_index = 0;
cfile_search_ispattern = false;
}
@ -1301,7 +1259,7 @@ bool cf_ReadHogFileEntry(int libr, const char *filename, tHogFileEntry *entry, i
else // search key before check key
last = i - 1;
} while (true);
} while (1);
if (found) {
strcpy(entry->name, lib->entries[i].name);

View File

@ -1,6 +1,7 @@
set(CPPS
cfile.cpp
hogfile.cpp
inffile.cpp)
SET (HEADERS )
SET (CPPS
CFILE.cpp
hog.cpp
InfFile.cpp)
add_library(cfile STATIC ${CPPS})
ADD_LIBRARY(cfile STATIC ${HEADERS} ${CPPS})

View File

@ -2,21 +2,21 @@
//
//////////////////////////////////////////////////////////////////////
#include "cfile/inffile.h"
#include "InfFile.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstring.h"
#include "pserror.h"
#include <string.h>
#define INFFILE_NULL (-1024)
#define INFFILE_NULL -1024
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
InfFile::InfFile() { m_fp = nullptr; }
InfFile::InfFile() { m_fp = NULL; }
InfFile::~InfFile() {
// close file and free symbol lists
@ -56,7 +56,7 @@ const char *InfFile::GetSymbolText(const char *name) {
return (const char *)sym->t.text;
}
return nullptr;
return NULL;
}
// opens an inf file, pass in a lexical analyzer that will return a command index.

View File

@ -84,7 +84,7 @@
#include "linux/linux_fix.h"
#endif
#include "byteswap.h"
#include "cfile/hogfile.h"
#include "hogfile.h"
#include "pstypes.h"
#include "Macros.h"
#include "mem.h"
@ -134,7 +134,7 @@ bool FileCopy(FILE *ofp, FILE *ifp, int length) {
return true;
}
bool ReadHogHeader(FILE *fp, tHogHeader *header) {
int res;
int res = 0;
res = fread(&header->nfiles, sizeof(header->nfiles), 1, fp);
header->nfiles = INTEL_INT(header->nfiles);
res = fread(&header->file_data_offset, sizeof(header->file_data_offset), 1, fp);
@ -146,7 +146,7 @@ bool ReadHogHeader(FILE *fp, tHogHeader *header) {
return false;
}
bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) {
int res;
int res = 0;
res = fread(entry->name, sizeof(char), HOG_FILENAME_LEN, fp);
res = fread(&entry->flags, sizeof(entry->flags), 1, fp);
entry->flags = INTEL_INT(entry->flags);
@ -161,8 +161,8 @@ bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) {
return false;
}
bool WriteHogEntry(FILE *fp, tHogFileEntry *entry) {
int res;
bool WRITE_FILE_ENTRY(FILE *fp, tHogFileEntry *entry) {
int res = 0;
res = fwrite(entry->name, sizeof(char), HOG_FILENAME_LEN, fp);
res = fwrite(&entry->flags, sizeof(entry->flags), 1, fp);
res = fwrite(&entry->len, sizeof(entry->len), 1, fp);
@ -173,11 +173,9 @@ bool WriteHogEntry(FILE *fp, tHogFileEntry *entry) {
else
return false;
}
// A modified version of NewHogFile()
// This one also takes a pointer to a function that will perform
// progress updates (for the user)
int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)) {
////////////////////////////////////////////////////////////////////////
// create new hog file
int NewHogFile(const char *hogname, int nfiles, const char **filenames) {
unsigned i;
int table_pos;
FILE *hog_fp;
@ -185,7 +183,7 @@ int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*U
tHogFileEntry *table;
char ext[_MAX_EXT];
hogerr_filename[0] = '\0';
// allocate file table
// allocate file table
if (nfiles <= 0)
return HOGMAKER_ERROR;
table = new tHogFileEntry[nfiles];
@ -233,7 +231,125 @@ int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*U
table_pos = strlen(HOG_TAG_STR) + HOG_HDR_SIZE;
memset(&table[0], 0, sizeof(table[0]));
for (i = 0; i < header.nfiles; i++) {
if (!WriteHogEntry(hog_fp, &table[0])) {
if (!WRITE_FILE_ENTRY(hog_fp, &table[0])) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
}
// write files (& build index)
for (i = 0; i < header.nfiles; i++) {
FILE *ifp;
#if defined(__LINUX__) || defined(MACINTOSH)
struct stat mystat;
#else
struct _stat32 mystat;
#endif
ifp = fopen(filenames[i], "rb");
if (ifp == NULL) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, filenames[i]);
return HOGMAKER_INFILE;
}
// JEFF: make call to ddio lib, linux doesn't have _splitpath
//_splitpath(filenames[i],NULL,NULL,table[i].name,ext);
ddio_SplitPath(filenames[i], NULL, table[i].name, ext);
_fstat32(fileno(ifp), &mystat);
strcat(table[i].name, ext);
table[i].flags = 0;
#ifdef MACINTOSH
table[i].len = mystat.st_size;
#else
table[i].len = _filelength(fileno(ifp));
#endif
table[i].timestamp = mystat.st_mtime;
if (!FileCopy(hog_fp, ifp, table[i].len)) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, filenames[i]);
return HOGMAKER_COPY;
}
fclose(ifp);
}
// now write the real index
fseek(hog_fp, table_pos, SEEK_SET);
for (i = 0; i < header.nfiles; i++) {
if (!WRITE_FILE_ENTRY(hog_fp, &table[i])) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
}
// cleanup
fclose(hog_fp);
delete[] table;
return HOGMAKER_OK;
}
// A modifed version of NewHogFile()
// This one also takes a pointer to a function that will perform
// progress updates (for the user)
int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)) {
unsigned i;
int table_pos;
FILE *hog_fp;
tHogHeader header;
tHogFileEntry *table;
char ext[_MAX_EXT];
hogerr_filename[0] = '\0';
// allocate file table
if (nfiles <= 0)
return HOGMAKER_ERROR;
table = new tHogFileEntry[nfiles];
if (!table)
return HOGMAKER_MEMORY;
// create new file
hog_fp = fopen(hogname, "wb");
if (hog_fp == NULL) {
delete[] table;
strcpy(hogerr_filename, hogname);
return HOGMAKER_OPENOUTFILE;
}
// write the tag
if (!fwrite(HOG_TAG_STR, strlen(HOG_TAG_STR), 1, hog_fp)) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
// write number of files
ubyte filler = 0xff;
header.nfiles = (unsigned)nfiles;
header.file_data_offset = strlen(HOG_TAG_STR) + HOG_HDR_SIZE + (sizeof(tHogFileEntry) * header.nfiles);
if (!fwrite(&header.nfiles, sizeof(header.nfiles), 1, hog_fp)) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
if (!fwrite(&header.file_data_offset, sizeof(header.file_data_offset), 1, hog_fp)) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
// write out filler
for (i = 0; i < HOG_HDR_SIZE - sizeof(tHogHeader); i++)
if (!fwrite(&filler, sizeof(ubyte), 1, hog_fp)) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
// save file position of index table and write out dummy table
table_pos = strlen(HOG_TAG_STR) + HOG_HDR_SIZE;
memset(&table[0], 0, sizeof(table[0]));
for (i = 0; i < header.nfiles; i++) {
if (!WRITE_FILE_ENTRY(hog_fp, &table[0])) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
@ -274,32 +390,30 @@ int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*U
return HOGMAKER_COPY;
}
fclose(ifp);
if (UpdateFunction != nullptr) {
// Setup the update message and send it
char msg[256];
int ipct = int(100.0 * (double(i) / double(header.nfiles)));
sprintf(msg, "Creating Hog File... (%d%% done)", ipct);
// Setup the update message and send it
char msg[256];
int ipct = int(100.0 * (double(i) / double(header.nfiles)));
sprintf(msg, "Creating Hog File... (%d%% done)", ipct);
if (UpdateFunction != NULL)
UpdateFunction(msg);
}
}
// now write the real index
fseek(hog_fp, table_pos, SEEK_SET);
for (i = 0; i < header.nfiles; i++) {
if (!WriteHogEntry(hog_fp, &table[i])) {
if (!WRITE_FILE_ENTRY(hog_fp, &table[i])) {
delete[] table;
fclose(hog_fp);
strcpy(hogerr_filename, hogname);
return HOGMAKER_OUTFILE;
}
}
// cleanup
// cleanup
fclose(hog_fp);
delete[] table;
if (UpdateFunction != nullptr) {
// Setup the update message and send it
char msg[256];
sprintf(msg, "Done Creating Hog File.");
// Setup the update message and send it
char msg[256];
sprintf(msg, "Done Creating Hog File.");
if (UpdateFunction != NULL)
UpdateFunction(msg);
}
return HOGMAKER_OK;
}

View File

@ -90,7 +90,7 @@
#include <linux/soundcard.h>
#include <stdarg.h>
#include <errno.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "mono.h"
#include "soundload.h"

View File

@ -12,7 +12,7 @@
#include <dlfcn.h>
#include <stdarg.h>
#include <errno.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "mono.h"
#include "soundload.h"

View File

@ -193,7 +193,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include "cfile/cfile.h"
#include "cfile.h"
#include "pserror.h"
#include "mono.h"
#include "soundload.h"

View File

@ -80,7 +80,7 @@
#include "pserror.h"
#include "logfile.h"
#include "Macros.h"
#include "cfile/inffile.h"
#include "inffile.h"
typedef struct tA3D
{

View File

@ -83,7 +83,7 @@
#else
#include <malloc.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mem.h"
#include "pserror.h"
#include <string.h>

View File

@ -64,7 +64,7 @@
#include "ddio_mac.h"
#include "psglob.h"
#include "mem.h"
#include "cfile/cfile.h"
#include "cfile.h"
// ---------------------------------------------------------------------------
// File Level Globals
// ---------------------------------------------------------------------------

View File

@ -90,7 +90,7 @@
*/
#include "grtextlib.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "bitmap.h"
#include "pserror.h"
#include "renderer.h"

View File

@ -76,9 +76,7 @@
#ifndef CFILE_H
#define CFILE_H
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <stdio.h>
#include "pstypes.h"
@ -96,10 +94,8 @@ typedef struct CFILE {
} CFILE;
// Defines for cfile_error
enum CFileError {
CFE_READING = 1,
CFE_WRITING,
};
#define CFE_READING 1
#define CFE_WRITING 2
// The structure thrown by a cfile error
typedef struct {
@ -109,17 +105,8 @@ typedef struct {
} cfile_error;
// Flags for CFILE struct
enum CFileFlags {
CFF_TEXT = 1, // if this bit set, file is text
CFF_WRITING, // if bit set, file opened for writing
};
// return values for cfexist()
enum CFileExitStatus {
CFES_NOT_FOUND = 0,
CFES_ON_DISK,
CFES_IN_LIBRARY,
};
#define CF_TEXT 1 // if this bit set, file is text
#define CF_WRITING 2 // if bit set, file opened for writing
// See if a file is in a hog
bool cf_IsFileInHog(char *filename, char *hogname);
@ -143,7 +130,7 @@ void cf_CloseLibrary(int handle);
int cf_SetSearchPath(const char *path, ...);
// Removes all search paths that have been added by cf_SetSearchPath
void cf_ClearAllSearchPaths();
void cf_ClearAllSearchPaths(void);
// Opens a file for reading or writing
// If a path is specified, will try to open the file only in that path.
@ -180,6 +167,11 @@ int cftell(CFILE *cfp);
// Returns true if at EOF
int cfeof(CFILE *cfp);
// return values for cfexist()
#define CF_NOT_FOUND 0
#define CF_ON_DISK 1
#define CF_IN_LIBRARY 2
// Tells if the file exists
// Returns non-zero if file exists. Also tells if the file is on disk
// or in a hog - See return values in cfile.h
@ -200,23 +192,23 @@ int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp);
// Read and return an integer (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int32_t cf_ReadInt(CFILE *cfp);
int cf_ReadInt(CFILE *cfp);
// Read and return a short (16 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int16_t cf_ReadShort(CFILE *cfp);
short cf_ReadShort(CFILE *cfp);
// Read and return a byte (8 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
int8_t cf_ReadByte(CFILE *cfp);
sbyte cf_ReadByte(CFILE *cfp);
// Read and return a float (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
float_t cf_ReadFloat(CFILE *cfp);
float cf_ReadFloat(CFILE *cfp);
// Read and return a double (64 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on read
double_t cf_ReadDouble(CFILE *cfp);
double cf_ReadDouble(CFILE *cfp);
// Reads a string from a CFILE. If the file is type binary, this
// function reads until a NULL or EOF is found. If the file is text,
@ -254,23 +246,23 @@ int cfprintf(CFILE *cfp, const char *format, ...);
// Write an integer (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteInt(CFILE *cfp, int32_t i);
void cf_WriteInt(CFILE *cfp, int i);
// Write a short (16 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteShort(CFILE *cfp, int16_t s);
void cf_WriteShort(CFILE *cfp, short s);
// Write a byte (8 bits). If the byte is a newline & the file is a text file, writes a CR/LF pair.
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteByte(CFILE *cfp, int8_t b);
void cf_WriteByte(CFILE *cfp, sbyte b);
// Write a float (32 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteFloat(CFILE *cfp, float_t f);
void cf_WriteFloat(CFILE *cfp, float f);
// Write a double (64 bits)
// Throws an exception of type (cfile_error *) if the OS returns an error on write
void cf_WriteDouble(CFILE *cfp, double_t d);
void cf_WriteDouble(CFILE *cfp, double d);
// Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file.
// Throws an exception of type (cfile_error *) if the OS returns an error on read or write
@ -287,17 +279,17 @@ void cf_CopyFileTime(char *dest, const char *src);
// Changes a files attributes (ie read/write only)
void cf_ChangeFileAttributes(const char *name, int attr);
// rewinds cfile position
// rewinds cfile position
void cf_Rewind(CFILE *fp);
// Calculates a 32 bit CRC
unsigned int cf_GetfileCRC(char *src);
unsigned int cf_CalculateFileCRC(CFILE *fp); // same as cf_GetfileCRC, except works with CFILE pointers
// the following cf_LibraryFind function are similar to the ddio_Find functions as they look
// for files that match the wildcard passed in, however, this is to be used for hog files.
// the following cf_LibraryFind function are similar to the ddio_Find functions as they look
// for files that match the wildcard passed in, however, this is to be used for hog files.
bool cf_LibraryFindFirst(int handle, const char *wildcard, char *buffer);
bool cf_LibraryFindNext(char *buffer);
void cf_LibraryFindClose();
void cf_LibraryFindClose(void);
#endif

View File

@ -2,8 +2,8 @@
//
//////////////////////////////////////////////////////////////////////
#ifndef INFFILE_H
#define INFFILE_H
#if !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_)
#define AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
@ -14,14 +14,12 @@
struct CFILE;
enum InfFileError {
INFFILE_LINELEN = 256,
INFFILE_CUSTOM = -128,
INFFILE_ERROR = -1,
INFFILE_COMMENT = -2,
INFFILE_EOL = -3,
INFFILE_SYMBOL = 1024,
};
#define INFFILE_LINELEN 256
#define INFFILE_CUSTOM -128
#define INFFILE_ERROR -1
#define INFFILE_COMMENT -2
#define INFFILE_EOL -3
#define INFFILE_SYMBOL 1024
class InfFile {
public:
@ -70,4 +68,4 @@ public:
int line() const { return m_line; };
};
#endif
#endif // !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_)

View File

@ -1,7 +1,7 @@
#ifndef PSBITMAP_H
#define PSBITMAP_H
#include "pstypes.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#ifdef __LINUX__
#include "linux/linux_fix.h" //needed for stricmp's throughout bitmap lib
#endif

View File

@ -42,7 +42,6 @@
#ifndef HOGFILE_H
#define HOGFILE_H
#include <cstdint>
#include "pstypes.h"
#define HOG_HDR_SIZE (64)
@ -50,37 +49,37 @@
#define HOG_FILENAME_LEN (36)
typedef struct tHogHeader {
uint32_t nfiles; // number of files in header
uint32_t file_data_offset; // offset in file to filedata.
unsigned nfiles; // number of files in header
unsigned file_data_offset; // offset in file to filedata.
} tHogHeader;
typedef struct tHogFileEntry {
char name[HOG_FILENAME_LEN]; // file name
uint32_t flags; // extra info
uint32_t len; // length of file
uint32_t timestamp; // time of file.
unsigned flags; // extra info
unsigned len; // length of file
unsigned timestamp; // time of file.
} tHogFileEntry;
enum HogErrors {
HOGMAKER_ERROR = 0, // Incorrect number of files passed in
HOGMAKER_OK, // Hog file was created successfully
HOGMAKER_MEMORY, // Could not allocate hog entry table
HOGMAKER_OUTFILE, // Error occurred writing to output hog file
HOGMAKER_INFILE, // An input file could not be found (filename is stored in hogerr_filename)
HOGMAKER_COPY, // An error occurred copying an input file into the hog file
HOGMAKER_OPENOUTFILE, // The specified hog file could not be opened for output
};
#define HOGMAKER_ERROR 0 // Incorrect number of files passed in
#define HOGMAKER_OK 1 // Hog file was created successfully
#define HOGMAKER_MEMORY 2 // Could not allocated hog entry table
#define HOGMAKER_OUTFILE 3 // Error occurred writing to output hog file
#define HOGMAKER_INFILE 4 // An input file could not be found (filename is stored in hogerr_filename)
#define HOGMAKER_COPY 5 // An error occurred copying an input file into the hog file
#define HOGMAKER_OPENOUTFILE 6 // The specified hog file could not be opened for output
// Used to return filenames involved in a NewHogFile() error
extern char hogerr_filename[PSPATHNAME_LEN];
int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *) = nullptr);
int NewHogFile(const char *hogname, int nfiles, const char **filenames);
bool ReadHogHeader(FILE *fp, tHogHeader *header);
bool ReadHogEntry(FILE *fp, tHogFileEntry *entry);
bool WriteHogEntry(FILE *fp, tHogFileEntry *entry);
bool WRITE_FILE_ENTRY(FILE *fp, tHogFileEntry *entry);
bool FileCopy(FILE *ofp, FILE *ifp, int length);
int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *));
// returns hog cfile info, using a library handle opened via cf_OpenLibrary.
bool cf_ReadHogFileEntry(int library, const char *filename, tHogFileEntry *entry, int *fileoffset);
#endif
#endif

View File

@ -3,7 +3,7 @@
#define MANAGE_H
#include <stdio.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "bitmap.h"
#include "manage_external.h"

View File

@ -29,7 +29,7 @@
#include "ddio.h"
#include "pserror.h"
#include "joystick.h"
#include "cfile/inffile.h"
#include "InfFile.h"
// Sorry! This is needed for the semi-hacky mouselook support
#include "descent.h"

View File

@ -8,7 +8,7 @@
#include "appdatabase.h"
#include <string.h>
#include "mem.h"
#include "cfile/cfile.h"
#include "cfile.h"
#include "ddio.h"
#include "ddio_mac.h"
#include "descent.h"

View File

@ -32,7 +32,7 @@
#include "descent.h"
#include "ddio.h"
#include "args.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "program.h"
#include <stdlib.h>
#include <memory.h>

View File

@ -25,7 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
// #include <process.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include "mono.h"
#include "soundload.h"

View File

@ -149,7 +149,7 @@
#include <sound.h>
#include "streamaudio.h"
#include "pserror.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mem.h"
#include "Macros.h"
#include "ddio.h"

View File

@ -129,7 +129,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "door.h"
#include "doorpage.h"

View File

@ -3,7 +3,7 @@
#include "manage.h"
#include "door.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
typedef struct {

View File

@ -2,7 +2,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "mono.h"
#include "pserror.h"

View File

@ -2,7 +2,7 @@
#define GAMEFILEPAGE_H
#include "manage.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
#include "gamefile.h"

View File

@ -337,7 +337,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "genericpage.h"
#include "soundpage.h"

View File

@ -2,7 +2,7 @@
#define GENERICPAGE_H
#include "manage.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
#include "objinfo.h"
#include "robotfirestruct.h"

View File

@ -438,7 +438,7 @@
#include "mono.h"
#include "object.h"
#include "ddio.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "appdatabase.h"
#include "genericpage.h"
#include "mem.h"

View File

@ -46,7 +46,7 @@
#if defined(WIN32)
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "megacell.h"
#include "megapage.h"

View File

@ -3,7 +3,7 @@
#include "manage.h"
#include "megacell.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
typedef struct {

View File

@ -160,7 +160,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "pstypes.h"
#include "pserror.h"

View File

@ -2,7 +2,7 @@
#define POWERPAGE_H
#include "manage.h"
#include "cfile/cfile.h"
#include "cfile.h"
#include "pstypes.h"
#include "powerup.h"

View File

@ -3,7 +3,7 @@
#include "manage.h"
#include "robot.h"
#include "cfile/cfile.h"
#include "cfile.h"
#include "pstypes.h"
#include "objinfo.h"

View File

@ -183,7 +183,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "ship.h"
#include "shippage.h"

View File

@ -3,7 +3,7 @@
#include "manage.h"
#include "ship.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
typedef struct {

View File

@ -102,7 +102,7 @@
#if defined(WIN32)
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "soundpage.h"
#include "mono.h"

View File

@ -3,7 +3,7 @@
#include "manage.h"
#include "soundload.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
typedef struct {

View File

@ -243,7 +243,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "gametexture.h"
#include "bitmap.h"

View File

@ -2,7 +2,7 @@
#define TEXPAGE_H
#include "manage.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
#include "procedurals.h"

View File

@ -272,7 +272,7 @@
#include <windows.h>
#endif
#include "cfile/cfile.h"
#include "CFILE.H"
#include "manage.h"
#include "weapon.h"
#include "weaponpage.h"

View File

@ -4,7 +4,7 @@
#include "manage.h"
#include "weapon.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pstypes.h"
typedef struct {

View File

@ -55,7 +55,7 @@
#include "music.h"
#include "musiclib.h"
#include "cfile/inffile.h"
#include "InfFile.h"
#include "mem.h"
#include <string.h>

View File

@ -132,7 +132,7 @@
#include "pserror.h"
#include "ddio.h"
#include "Macros.h"
#include "cfile/inffile.h"
#include "InfFile.h"
#include "streamaudio.h"
#include "mem.h"
#include <string.h>

View File

@ -46,7 +46,7 @@
#include "descent.h"
#include "manage.h"
#include "ddio.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include <stdlib.h>
#include <stdio.h>

View File

@ -216,7 +216,7 @@
#include <string.h>
#include "ssl_lib.h"
#include "object.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "ddio.h"
#include "soundload.h"
#include "weapon.h"

View File

@ -33,7 +33,7 @@
*/
#include "streamaudio.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "pserror.h"
#include <string.h>

View File

@ -148,7 +148,7 @@
*/
#include "streamaudio.h"
#include "pserror.h"
#include "cfile/cfile.h"
#include "CFILE.H"
#include "mem.h"
#include "Macros.h"
#include "ddio.h"

View File

@ -302,7 +302,7 @@
#include "ddio.h"
#include "joystick.h"
#include "Macros.h"
#include "cfile/inffile.h"
#include "inffile.h"
// Sorry! This is needed for the semi-hacky mouselook support
#include "descent.h"