X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fmisc.h;h=d83a6563909264579b4bd3964fa1d40d1393b68d;hp=12c28c3264c8a0b69fd79f77cb1c8c3735419e6a;hb=abe44529b439ad39b4d8dbf19cbd67c9b9844279;hpb=297ee9b33dab3bca9433befc81d7c7ce91450dd0 diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 12c28c32..d83a6563 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -1,15 +1,13 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2006 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* misc.h * -***********************************************************/ +// ============================================================================ +// Artsoft Retro-Game Library +// ---------------------------------------------------------------------------- +// (c) 1995-2014 by Artsoft Entertainment +// Holger Schemel +// info@artsoft.org +// http://www.artsoft.org/ +// ---------------------------------------------------------------------------- +// misc.h +// ============================================================================ #ifndef MISC_H #define MISC_H @@ -37,19 +35,26 @@ #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max) /* values for Error() */ -#define ERR_INFO 0 -#define ERR_INFO_LINE (1 << 0) -#define ERR_WARN (1 << 1) -#define ERR_EXIT (1 << 2) -#define ERR_HELP (1 << 3) -#define ERR_SOUND_SERVER (1 << 4) -#define ERR_NETWORK_SERVER (1 << 5) -#define ERR_NETWORK_CLIENT (1 << 6) +#define ERR_UNKNOWN 0 +#define ERR_DEBUG (1 << 0) +#define ERR_INFO (1 << 1) +#define ERR_INFO_LINE (1 << 2) +#define ERR_WARN (1 << 3) +#define ERR_EXIT (1 << 4) +#define ERR_HELP (1 << 5) +#define ERR_SOUND_SERVER (1 << 6) +#define ERR_NETWORK_SERVER (1 << 7) +#define ERR_NETWORK_CLIENT (1 << 8) #define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER) #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) #define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT) +#if 0 +#define ERR_ERROR (ERR_UNKNOWN) +#define ERR_FATAL (ERR_EXIT) +#define ERR_VERBOSE (ERR_INFO) +#endif /* values for getFile...() and putFile...() */ #define BYTE_ORDER_BIG_ENDIAN 0 @@ -78,25 +83,37 @@ /* structure definitions */ -struct DirectoryEntry +typedef struct +{ + char *filename; + FILE *file; + boolean end_of_file; + +#if defined(PLATFORM_ANDROID) + boolean file_is_asset; + SDL_RWops *asset_file; +#endif +} File; + +typedef struct { boolean is_directory; char *basename; char *filename; -}; +} DirectoryEntry; -struct Directory +typedef struct { char *filename; DIR *dir; - struct DirectoryEntry *dir_entry; + DirectoryEntry *dir_entry; #if defined(PLATFORM_ANDROID) boolean directory_is_asset; SDL_RWops *asset_toc_file; char *current_entry; #endif -}; +} Directory; /* function definitions */ @@ -135,9 +152,10 @@ char *getStringCat2(char *, char *); char *getStringCat3(char *, char *, char *); char *getPath2(char *, char *); char *getPath3(char *, char *, char*); -char *getStringCopy(char *); -char *getStringCopyN(char *, int); -char *getStringToLower(char *); +char *getStringCopy(const char *); +char *getStringCopyN(const char *, int); +char *getStringCopyNStatic(const char *, int); +char *getStringToLower(const char *); void setString(char **, char *); boolean strEqual(char *, char *); boolean strEqualN(char *, char *, int); @@ -146,7 +164,9 @@ boolean strSuffix(char *, char *); boolean strPrefixLower(char *, char *); boolean strSuffixLower(char *, char *); -void GetOptions(char **, void (*print_usage_function)(void)); +void GetOptions(char **, + void (*print_usage_function)(void), + void (*print_version_function)(void)); void SetError(char *, ...); char *GetError(void); @@ -161,6 +181,28 @@ void clear_mem(void *, unsigned int); void swap_numbers(int *, int *); void swap_number_pairs(int *, int *, int *, int *); +#if 1 + +int getFile8BitInteger(File *); +int putFile8BitInteger(FILE *, int); +int getFile16BitInteger(File *, int); +int putFile16BitInteger(FILE *, int, int); +int getFile32BitInteger(File *, int); +int putFile32BitInteger(FILE *, int, int); + +boolean getFileChunk(File *, char *, int *, int); +int putFileChunk(FILE *, char *, int, int); +int getFileVersion(File *); +int putFileVersion(FILE *, int); + +void ReadBytesFromFile(File *, byte *, unsigned int); +void WriteBytesToFile(FILE *, byte *, unsigned int); + +void ReadUnusedBytesFromFile(File *, unsigned int); +void WriteUnusedBytesToFile(FILE *, unsigned int); + +#else + int getFile8BitInteger(FILE *); int putFile8BitInteger(FILE *, int); int getFile16BitInteger(FILE *, int); @@ -179,6 +221,8 @@ void WriteBytesToFile(FILE *, byte *, unsigned int); void ReadUnusedBytesFromFile(FILE *, unsigned int); void WriteUnusedBytesToFile(FILE *, unsigned int); +#endif + #define getFile8Bit(f) getFile8BitInteger(f) #define putFile8Bit(f,x) putFile8BitInteger(f,x) #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN) @@ -212,11 +256,20 @@ void deleteNodeFromList(ListNode **, char *, void (*function)(void *)); ListNode *getNodeFromKey(ListNode *, char *); int getNumNodes(ListNode *); -struct Directory *openDirectory(char *); -int closeDirectory(struct Directory *); -struct DirectoryEntry *readDirectory(struct Directory *); -void freeDirectoryEntry(struct DirectoryEntry *); +File *openFile(char *, char *); +int closeFile(File *); +int checkEndOfFile(File *); +size_t readFile(File *, void *, size_t, size_t); +int seekFile(File *, long, int); +int getByteFromFile(File *); +char *getStringFromFile(File *, char *, int); +Directory *openDirectory(char *); +int closeDirectory(Directory *); +DirectoryEntry *readDirectory(Directory *); +void freeDirectoryEntry(DirectoryEntry *); + +boolean directoryExists(char *); boolean fileExists(char *); boolean FileIsGraphic(char *); boolean FileIsSound(char *); @@ -243,6 +296,12 @@ void closeErrorFile(); void dumpErrorFile(); void NotifyUserAboutErrorFile(); +#if DEBUG void debug_print_timestamp(int, char *); +#endif +void print_timestamp_init(char *); +void print_timestamp_time(char *); +void print_timestamp_done(char *); + #endif /* MISC_H */