1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
22 // values for InitCounter() and Counter()
23 #define INIT_COUNTER 0
24 #define READ_COUNTER 1
26 // values for InitRND()
27 #define NEW_RANDOMIZE 0
29 #define RANDOM_ENGINE 0
30 #define RANDOM_SIMPLE 1
31 #define RANDOM_BETTER 2
33 #define InitEngineRandom(seed) init_random_number(RANDOM_ENGINE, seed)
34 #define InitSimpleRandom(seed) init_random_number(RANDOM_SIMPLE, seed)
35 #define InitBetterRandom(seed) init_random_number(RANDOM_BETTER, seed)
36 #define GetEngineRandom(max) get_random_number(RANDOM_ENGINE, max)
37 #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
38 #define GetBetterRandom(max) get_random_number(RANDOM_BETTER, max)
40 // values for getFile...() and putFile...()
41 #define BYTE_ORDER_BIG_ENDIAN 0
42 #define BYTE_ORDER_LITTLE_ENDIAN 1
44 // values for cursor bitmap creation
45 #define BIT_ORDER_MSB 0
46 #define BIT_ORDER_LSB 1
48 // values for character encoding
49 #define TEXT_ENCODING_UNKNOWN 0
50 #define TEXT_ENCODING_ASCII 1
51 #define TEXT_ENCODING_UTF_8 2
53 // values for createDirectory()
54 #define PERMS_PRIVATE 0
55 #define PERMS_PUBLIC 1
57 // values for general file handling stuff
58 #define MAX_FILENAME_LEN 256
59 #define MAX_LINE_LEN 1024
61 // values for general username handling stuff
62 #define MAX_USERNAME_LEN 1024
64 #if defined(PLATFORM_ANDROID)
65 // values for Android asset handling
66 #define ASSET_TOC_BASENAME ".toc"
70 // structure definitions
78 #if defined(PLATFORM_ANDROID)
79 boolean file_is_asset;
80 SDL_RWops *asset_file;
95 DirectoryEntry *dir_entry;
97 #if defined(PLATFORM_ANDROID)
98 boolean directory_is_asset;
99 SDL_RWops *asset_toc_file;
105 // function definitions
107 void fprintf_line(FILE *, char *, int);
108 void fprintf_line_with_prefix(FILE *, char *, char *, int);
109 void printf_line(char *, int);
110 void printf_line_with_prefix(char *, char *, int);
112 void Print(char *, ...);
113 void PrintNoLog(char *, ...);
114 void PrintLine(char *, int);
115 void PrintLineWithPrefix(char *, char *, int);
117 void DebugContinued(char *, char *, ...);
118 void Debug(char *, char *, ...);
119 void Info(char *, ...);
120 void Warn(char *, ...);
121 void Error(char *, ...);
122 void Fail(char *, ...);
123 void FailWithHelp(char *, ...);
125 char *int2str(int, int);
126 char *i_to_a(unsigned int);
127 int log_2(unsigned int);
129 boolean getTokenValueFromString(char *, char **, char **);
131 char *getUUIDExt(unsigned int (*function)(int));
134 void InitCounter(void);
135 unsigned int Counter(void);
136 void Delay(unsigned int);
137 boolean DelayReachedExt2(unsigned int *, unsigned int, unsigned int);
138 boolean DelayReachedExt(DelayCounter *, unsigned int);
139 boolean FrameReached(DelayCounter *);
140 boolean DelayReached(DelayCounter *);
141 void ResetDelayCounterExt(DelayCounter *, unsigned int);
142 void ResetFrameCounter(DelayCounter *);
143 void ResetDelayCounter(DelayCounter *);
144 int WaitUntilDelayReached(DelayCounter *);
145 void SkipUntilDelayReached(DelayCounter *, int *, int);
147 unsigned int init_random_number(int, int);
148 unsigned int get_random_number(int, int);
150 #if defined(PLATFORM_UNIX)
151 char *getUnixLoginName(void);
152 char *getUnixRealName(void);
153 char *getUnixHomeDir(void);
156 char *getLoginName(void);
157 char *getRealName(void);
158 char *getFixedUserName(char *);
159 char *getDefaultUserName(int);
161 char *getTimestampFromEpoch(time_t);
162 char *getCurrentTimestamp(void);
164 time_t getFileTimestampEpochSeconds(char *);
166 char *getBasePath(char *);
167 char *getBaseName(char *);
168 char *getBaseNamePtr(char *);
169 char *getBaseNameNoSuffix(char *);
171 void *getMemCopy(const void *, size_t);
173 char *getStringCat2WithSeparator(const char *, const char *, const char *);
174 char *getStringCat3WithSeparator(const char *, const char *, const char *, const char *);
175 char *getStringCat2(const char *, const char *);
176 char *getStringCat3(const char *, const char *, const char *);
177 char *getPath2(const char *, const char *);
178 char *getPath3(const char *, const char *, const char *);
179 char *getImg2(const char *, const char *);
180 char *getImg3(const char *, const char *, const char *);
181 char *getStringCopy(const char *);
182 char *getStringCopyN(const char *, int);
183 char *getStringCopyNStatic(const char *, int);
184 char *getStringToUpper(const char *);
185 char *getStringToLower(const char *);
186 void setString(char **, const char *);
187 char **getSplitStringArray(const char *s, const char *, int);
188 int getStringArrayLength(char **);
189 void freeStringArray(char **);
190 char *getUnescapedString(const char *);
191 boolean strEqual(const char *, const char *);
192 boolean strEqualN(const char *, const char *, int);
193 boolean strEqualCase(const char *, const char *);
194 boolean strEqualCaseN(const char *, const char *, int);
195 boolean strPrefix(const char *, const char *);
196 boolean strSuffix(const char *, const char *);
197 boolean strPrefixLower(const char *, const char *);
198 boolean strSuffixLower(const char *, const char *);
199 boolean isURL(const char *);
201 void GetOptions(int, char **,
202 void (*print_usage_function)(void),
203 void (*print_version_function)(void));
205 void *checked_malloc(unsigned int);
206 void *checked_calloc(unsigned int);
207 void *checked_realloc(void *, unsigned int);
208 void checked_free(void *);
209 void clear_mem(void *, unsigned int);
211 void swap_numbers(int *, int *);
212 void swap_number_pairs(int *, int *, int *, int *);
213 int get_number_of_bits(int);
215 int getFile8BitInteger(File *);
216 int putFile8BitInteger(FILE *, int);
217 int getFile16BitInteger(File *, int);
218 int putFile16BitInteger(FILE *, int, int);
219 int getFile32BitInteger(File *, int);
220 int putFile32BitInteger(FILE *, int, int);
222 boolean getFileChunk(File *, char *, int *, int);
223 int putFileChunk(FILE *, char *, int, int);
224 int getFileVersion(File *);
225 int putFileVersion(FILE *, int);
227 void ReadBytesFromFile(File *, byte *, unsigned int);
228 void WriteBytesToFile(FILE *, byte *, unsigned int);
230 void ReadUnusedBytesFromFile(File *, unsigned int);
231 void WriteUnusedBytesToFile(FILE *, unsigned int);
233 #define getFile8Bit(f) getFile8BitInteger(f)
234 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
235 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
236 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
237 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
238 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
239 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
240 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
241 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
242 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
244 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
245 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
246 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
247 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
249 char *getUTF8FromLatin1(char *);
250 char *getLatin1FromUTF8(char *);
251 int getTextEncoding(char *);
253 char *getEscapedJSON(char *);
255 char *getKeyNameFromKey(Key);
256 char *getX11KeyNameFromKey(Key);
257 Key getKeyFromKeyName(char *);
258 Key getKeyFromX11KeyName(char *);
259 char getCharFromKey(Key);
260 char getValidConfigValueChar(char);
262 int get_integer_from_string(char *);
263 boolean get_boolean_from_string(char *);
264 int get_switch3_from_string(char *);
265 int get_player_nr_from_string(char *);
267 ListNode *newListNode(void);
268 void addNodeToList(ListNode **, char *, void *);
269 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
270 ListNode *getNodeFromKey(ListNode *, char *);
271 int getNumNodes(ListNode *);
273 File *openFile(char *, char *);
274 int closeFile(File *);
275 int checkEndOfFile(File *);
276 size_t readFile(File *, void *, size_t, size_t);
277 size_t writeFile(File *, void *, size_t, size_t);
278 int seekFile(File *, long, int);
279 int getByteFromFile(File *);
280 char *getStringFromFile(File *, char *, int);
281 int copyFile(char *, char *);
282 boolean touchFile(char *);
284 Directory *openDirectory(char *);
285 int closeDirectory(Directory *);
286 DirectoryEntry *readDirectory(Directory *);
287 void freeDirectoryEntry(DirectoryEntry *);
289 boolean directoryExists(const char *);
290 boolean fileExists(const char *);
292 boolean FileIsGraphic(char *);
293 boolean FileIsSound(char *);
294 boolean FileIsMusic(char *);
295 boolean FileIsArtworkType(char *, int);
297 char *get_mapped_token(char *);
299 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
300 struct ConfigTypeInfo *,
302 void LoadArtworkConfig(struct ArtworkListInfo *);
303 void ReloadCustomArtworkList(struct ArtworkListInfo *);
304 void FreeCustomArtworkLists(struct ArtworkListInfo *);
306 char *getLogBasename(char *);
307 char *getLogFilename(char *);
308 void OpenLogFile(void);
309 void CloseLogFile(void);
310 void DumpLogFile(void);
312 void NotifyUserAboutErrorFile(void);
315 void debug_print_timestamp(int, char *);
317 void print_timestamp_init(char *);
318 void print_timestamp_time(char *);
319 void print_timestamp_done(char *);