X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.h;h=244a3992d2e02b725dd6cc0be3d17db758c865ce;hb=7ecf99096c7c23909ada034e05d971464f66552f;hp=009350c025afb7eb9c1823f29bf8c0759a110c7e;hpb=ac86d841daa4ecafff3128110a1db109e03fb355;p=rocksndiamonds.git diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 009350c0..244a3992 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -16,6 +16,7 @@ #include #include +#include #include "system.h" @@ -25,7 +26,7 @@ #define READ_COUNTER 1 /* values for InitRND() */ -#define NEW_RANDOMIZE -1 +#define NEW_RANDOMIZE 0 #define RANDOM_ENGINE 0 #define RANDOM_SIMPLE 1 @@ -36,19 +37,26 @@ #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max) /* values for Error() */ -#define ERR_RETURN 0 -#define ERR_RETURN_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 @@ -69,6 +77,48 @@ /* values for general username handling stuff */ #define MAX_USERNAME_LEN 1024 +#if defined(PLATFORM_ANDROID) +/* values for Android asset handling */ +#define ASSET_TOC_BASENAME ".toc" +#endif + + +/* structure definitions */ + +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; + +typedef struct +{ + char *filename; + DIR *dir; + DirectoryEntry *dir_entry; + +#if defined(PLATFORM_ANDROID) + boolean directory_is_asset; + SDL_RWops *asset_toc_file; + char *current_entry; +#endif +} Directory; + + +/* function definitions */ void fprintf_line(FILE *, char *, int); void printf_line(char *, int); @@ -77,30 +127,43 @@ char *int2str(int, int); char *i_to_a(unsigned int); int log_2(unsigned int); +boolean getTokenValueFromString(char *, char **, char **); + void InitCounter(void); -unsigned long Counter(void); -void Delay(unsigned long); -boolean FrameReached(unsigned long *, unsigned long); -boolean DelayReached(unsigned long *, unsigned long); -void WaitUntilDelayReached(unsigned long *, unsigned long); +unsigned int Counter(void); +void Delay(unsigned int); +boolean FrameReached(unsigned int *, unsigned int); +boolean DelayReached(unsigned int *, unsigned int); +void WaitUntilDelayReached(unsigned int *, unsigned int); -unsigned int init_random_number(int, long); +unsigned int init_random_number(int, int); unsigned int get_random_number(int, int); char *getLoginName(void); char *getRealName(void); +time_t getFileTimestampEpochSeconds(char *); + char *getBasePath(char *); char *getBaseName(char *); char *getBaseNamePtr(char *); +char *getStringCat2WithSeparator(char *, char *, char *); +char *getStringCat3WithSeparator(char *, char *, char *, char *); +char *getStringCat2(char *, char *); +char *getStringCat3(char *, char *, char *); char *getPath2(char *, char *); char *getPath3(char *, char *, char*); -char *getStringCat2(char *, char *); char *getStringCopy(char *); +char *getStringCopyN(char *, int); char *getStringToLower(char *); void setString(char **, char *); boolean strEqual(char *, char *); +boolean strEqualN(char *, char *, int); +boolean strPrefix(char *, char *); +boolean strSuffix(char *, char *); +boolean strPrefixLower(char *, char *); +boolean strSuffixLower(char *, char *); void GetOptions(char **, void (*print_usage_function)(void)); @@ -108,10 +171,11 @@ void SetError(char *, ...); char *GetError(void); void Error(int, char *, ...); -void *checked_malloc(unsigned long); -void *checked_calloc(unsigned long); -void *checked_realloc(void *, unsigned long); +void *checked_malloc(unsigned int); +void *checked_calloc(unsigned int); +void *checked_realloc(void *, unsigned int); void checked_free(void *); +void clear_mem(void *, unsigned int); void swap_numbers(int *, int *); void swap_number_pairs(int *, int *, int *, int *); @@ -128,11 +192,11 @@ int putFileChunk(FILE *, char *, int, int); int getFileVersion(FILE *); int putFileVersion(FILE *, int); -void ReadBytesFromFile(FILE *, byte *, unsigned long); -void WriteBytesToFile(FILE *, byte *, unsigned long); +void ReadBytesFromFile(FILE *, byte *, unsigned int); +void WriteBytesToFile(FILE *, byte *, unsigned int); -void ReadUnusedBytesFromFile(FILE *, unsigned long); -void WriteUnusedBytesToFile(FILE *, unsigned long); +void ReadUnusedBytesFromFile(FILE *, unsigned int); +void WriteUnusedBytesToFile(FILE *, unsigned int); #define getFile8Bit(f) getFile8BitInteger(f) #define putFile8Bit(f,x) putFile8BitInteger(f,x) @@ -155,9 +219,11 @@ char *getX11KeyNameFromKey(Key); Key getKeyFromKeyName(char *); Key getKeyFromX11KeyName(char *); char getCharFromKey(Key); +char getValidConfigValueChar(char); int get_integer_from_string(char *); boolean get_boolean_from_string(char *); +int get_switch3_from_string(char *); ListNode *newListNode(void); void addNodeToList(ListNode **, char *, void *); @@ -165,6 +231,17 @@ void deleteNodeFromList(ListNode **, char *, void (*function)(void *)); ListNode *getNodeFromKey(ListNode *, char *); int getNumNodes(ListNode *); +File *openFile(char *, char *); +int closeFile(File *); +int checkEndOfFile(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 *); @@ -174,7 +251,6 @@ boolean FileIsArtworkType(char *, int); char *get_mapped_token(char *); int get_parameter_value(char *, char *, int); -int get_auto_parameter_value(char *, char *); struct ScreenModeInfo *get_screen_mode_from_string(char *); void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *, int *x, int *y); @@ -192,6 +268,13 @@ void closeErrorFile(); void dumpErrorFile(); void NotifyUserAboutErrorFile(); +#if DEBUG void debug_print_timestamp(int, char *); +void print_timestamp_init(char *); +void print_timestamp_time(char *); +void print_timestamp_done(char *); +#endif /* DEBUG */ + + #endif /* MISC_H */