added optional button to restart game (door, panel and touch variants)
[rocksndiamonds.git] / src / libgame / misc.h
index 32097e0c8c953101c13c6751609cfaedb1641161..2893ba0f6e00ae3569b7d1d1fb6525d52812af75 100644 (file)
@@ -4,7 +4,7 @@
 // (c) 1995-2014 by Artsoft Entertainment
 //                         Holger Schemel
 //                 info@artsoft.org
-//                 http://www.artsoft.org/
+//                 https://www.artsoft.org/
 // ----------------------------------------------------------------------------
 // misc.h
 // ============================================================================
 #include "system.h"
 
 
-/* values for InitCounter() and Counter() */
+// values for InitCounter() and Counter()
 #define INIT_COUNTER                   0
 #define READ_COUNTER                   1
 
-/* values for InitRND() */
+// values for InitRND()
 #define NEW_RANDOMIZE                  0
 
 #define RANDOM_ENGINE                  0
 #define RANDOM_SIMPLE                  1
+#define RANDOM_BETTER                  2
 
 #define InitEngineRandom(seed)         init_random_number(RANDOM_ENGINE, seed)
 #define InitSimpleRandom(seed)         init_random_number(RANDOM_SIMPLE, seed)
+#define InitBetterRandom(seed)         init_random_number(RANDOM_BETTER, seed)
 #define GetEngineRandom(max)           get_random_number(RANDOM_ENGINE, max)
 #define GetSimpleRandom(max)           get_random_number(RANDOM_SIMPLE, max)
+#define GetBetterRandom(max)           get_random_number(RANDOM_BETTER, max)
 
-/* values for Error() */
-#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)
-
-/* values for getFile...() and putFile...() */
+// values for getFile...() and putFile...()
 #define BYTE_ORDER_BIG_ENDIAN          0
 #define BYTE_ORDER_LITTLE_ENDIAN       1
 
-/* values for cursor bitmap creation */
+// values for cursor bitmap creation
 #define BIT_ORDER_MSB                  0
 #define BIT_ORDER_LSB                  1
 
-/* values for createDirectory() */
+// values for character encoding
+#define TEXT_ENCODING_UNKNOWN          0
+#define TEXT_ENCODING_ASCII            1
+#define TEXT_ENCODING_UTF_8            2
+
+// values for createDirectory()
 #define PERMS_PRIVATE                  0
 #define PERMS_PUBLIC                   1
 
-/* values for general file handling stuff */
+// values for general file handling stuff
 #define MAX_FILENAME_LEN               256
 #define MAX_LINE_LEN                   1024
 
-/* values for general username handling stuff */
+// values for general username handling stuff
 #define MAX_USERNAME_LEN               1024
 
 #if defined(PLATFORM_ANDROID)
-/* values for Android asset handling */
+// values for Android asset handling
 #define ASSET_TOC_BASENAME             ".toc"
 #endif
 
 
-/* structure definitions */
+// structure definitions
 
 typedef struct
 {
@@ -111,66 +102,99 @@ typedef struct
 } Directory;
 
 
-/* function definitions */
+// function definitions
 
 void fprintf_line(FILE *, char *, int);
 void fprintf_line_with_prefix(FILE *, char *, char *, int);
 void printf_line(char *, int);
 void printf_line_with_prefix(char *, char *, int);
 
+void Print(char *, ...);
+void PrintNoLog(char *, ...);
+void PrintLine(char *, int);
+void PrintLineWithPrefix(char *, char *, int);
+
+void DebugContinued(char *, char *, ...);
+void Debug(char *, char *, ...);
+void Info(char *, ...);
+void Warn(char *, ...);
+void Error(char *, ...);
+void Fail(char *, ...);
+void FailWithHelp(char *, ...);
+
 char *int2str(int, int);
 char *i_to_a(unsigned int);
 int log_2(unsigned int);
 
 boolean getTokenValueFromString(char *, char **, char **);
 
+char *getUUIDExt(unsigned int (*function)(int));
+char *getUUID(void);
+
 void InitCounter(void);
 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);
+boolean DelayReachedExt2(unsigned int *, unsigned int, unsigned int);
+boolean DelayReachedExt(DelayCounter *, unsigned int);
+boolean FrameReached(DelayCounter *);
+boolean DelayReached(DelayCounter *);
+void ResetDelayCounterExt(DelayCounter *, unsigned int);
+void ResetFrameCounter(DelayCounter *);
+void ResetDelayCounter(DelayCounter *);
+int WaitUntilDelayReached(DelayCounter *);
+void SkipUntilDelayReached(DelayCounter *, int *, int);
 
 unsigned int init_random_number(int, int);
 unsigned int get_random_number(int, int);
 
+#if defined(PLATFORM_UNIX)
+char *getUnixLoginName(void);
+char *getUnixRealName(void);
+char *getUnixHomeDir(void);
+#endif
+
 char *getLoginName(void);
 char *getRealName(void);
+char *getFixedUserName(char *);
+char *getDefaultUserName(int);
+
+char *getTimestampFromEpoch(time_t);
+char *getCurrentTimestamp(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 *getImg2(char *, char *);
-char *getImg3(char *, char *, char*);
+char *getBaseNameNoSuffix(char *);
+
+char *getStringCat2WithSeparator(const char *, const char *, const char *);
+char *getStringCat3WithSeparator(const char *, const char *, const char *, const char *);
+char *getStringCat2(const char *, const char *);
+char *getStringCat3(const char *, const char *, const char *);
+char *getPath2(const char *, const char *);
+char *getPath3(const char *, const char *, const char *);
+char *getImg2(const char *, const char *);
+char *getImg3(const char *, const char *, const 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);
-boolean strPrefix(char *, char *);
-boolean strSuffix(char *, char *);
-boolean strPrefixLower(char *, char *);
-boolean strSuffixLower(char *, char *);
-
-void GetOptions(char **,
+void setString(char **, const char *);
+boolean strEqual(const char *, const char *);
+boolean strEqualN(const char *, const char *, int);
+boolean strEqualCase(const char *, const char *);
+boolean strEqualCaseN(const char *, const char *, int);
+boolean strPrefix(const char *, const char *);
+boolean strSuffix(const char *, const char *);
+boolean strPrefixLower(const char *, const char *);
+boolean strSuffixLower(const char *, const char *);
+boolean isURL(const char *);
+
+void GetOptions(int, char **,
                void (*print_usage_function)(void),
                void (*print_version_function)(void));
 
-void SetError(char *, ...);
-char *GetError(void);
-void Error(int, char *, ...);
-
 void *checked_malloc(unsigned int);
 void *checked_calloc(unsigned int);
 void *checked_realloc(void *, unsigned int);
@@ -179,6 +203,7 @@ void clear_mem(void *, unsigned int);
 
 void swap_numbers(int *, int *);
 void swap_number_pairs(int *, int *, int *, int *);
+int get_number_of_bits(int);
 
 int getFile8BitInteger(File *);
 int putFile8BitInteger(FILE *, int);
@@ -214,6 +239,12 @@ void WriteUnusedBytesToFile(FILE *, unsigned int);
 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
 
+char *getUTF8FromLatin1(char *);
+char *getLatin1FromUTF8(char *);
+int getTextEncoding(char *);
+
+char *getEscapedJSON(char *);
+
 char *getKeyNameFromKey(Key);
 char *getX11KeyNameFromKey(Key);
 Key getKeyFromKeyName(char *);
@@ -224,6 +255,7 @@ char getValidConfigValueChar(char);
 int get_integer_from_string(char *);
 boolean get_boolean_from_string(char *);
 int get_switch3_from_string(char *);
+int get_player_nr_from_string(char *);
 
 ListNode *newListNode(void);
 void addNodeToList(ListNode **, char *, void *);
@@ -235,17 +267,21 @@ File *openFile(char *, char *);
 int closeFile(File *);
 int checkEndOfFile(File *);
 size_t readFile(File *, void *, size_t, size_t);
+size_t writeFile(File *, void *, size_t, size_t);
 int seekFile(File *, long, int);
 int getByteFromFile(File *);
 char *getStringFromFile(File *, char *, int);
+int copyFile(char *, char *);
+boolean touchFile(char *);
 
 Directory *openDirectory(char *);
 int closeDirectory(Directory *);
 DirectoryEntry *readDirectory(Directory *);
 void freeDirectoryEntry(DirectoryEntry *);
 
-boolean directoryExists(char *);
-boolean fileExists(char *);
+boolean directoryExists(const char *);
+boolean fileExists(const char *);
+
 boolean FileIsGraphic(char *);
 boolean FileIsSound(char *);
 boolean FileIsMusic(char *);
@@ -253,11 +289,6 @@ boolean FileIsArtworkType(char *, int);
 
 char *get_mapped_token(char *);
 
-int get_parameter_value(char *, char *, int);
-
-struct ScreenModeInfo *get_screen_mode_from_string(char *);
-void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *, int *x, int *y);
-
 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
                                           struct ConfigTypeInfo *,
                                           char **, int);
@@ -265,11 +296,13 @@ void LoadArtworkConfig(struct ArtworkListInfo *);
 void ReloadCustomArtworkList(struct ArtworkListInfo *);
 void FreeCustomArtworkLists(struct ArtworkListInfo *);
 
-char *getErrorFilename(char *);
-void openErrorFile();
-void closeErrorFile();
-void dumpErrorFile();
-void NotifyUserAboutErrorFile();
+char *getLogBasename(char *);
+char *getLogFilename(char *);
+void OpenLogFile(void);
+void CloseLogFile(void);
+void DumpLogFile(void);
+
+void NotifyUserAboutErrorFile(void);
 
 #if DEBUG
 void debug_print_timestamp(int, char *);
@@ -279,4 +312,4 @@ void print_timestamp_time(char *);
 void print_timestamp_done(char *);
 
 
-#endif /* MISC_H */
+#endif // MISC_H