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
32 #define InitEngineRandom(seed) init_random_number(RANDOM_ENGINE, seed)
33 #define InitSimpleRandom(seed) init_random_number(RANDOM_SIMPLE, seed)
34 #define GetEngineRandom(max) get_random_number(RANDOM_ENGINE, max)
35 #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
37 // values for getFile...() and putFile...()
38 #define BYTE_ORDER_BIG_ENDIAN 0
39 #define BYTE_ORDER_LITTLE_ENDIAN 1
41 // values for cursor bitmap creation
42 #define BIT_ORDER_MSB 0
43 #define BIT_ORDER_LSB 1
45 // values for createDirectory()
46 #define PERMS_PRIVATE 0
47 #define PERMS_PUBLIC 1
49 // values for general file handling stuff
50 #define MAX_FILENAME_LEN 256
51 #define MAX_LINE_LEN 1024
53 // values for general username handling stuff
54 #define MAX_USERNAME_LEN 1024
56 #if defined(PLATFORM_ANDROID)
57 // values for Android asset handling
58 #define ASSET_TOC_BASENAME ".toc"
62 // structure definitions
70 #if defined(PLATFORM_ANDROID)
71 boolean file_is_asset;
72 SDL_RWops *asset_file;
87 DirectoryEntry *dir_entry;
89 #if defined(PLATFORM_ANDROID)
90 boolean directory_is_asset;
91 SDL_RWops *asset_toc_file;
97 // function definitions
99 void fprintf_line(FILE *, char *, int);
100 void fprintf_line_with_prefix(FILE *, char *, char *, int);
101 void printf_line(char *, int);
102 void printf_line_with_prefix(char *, char *, int);
104 void Print(char *, ...);
105 void PrintNoLog(char *, ...);
106 void PrintLine(char *, int);
107 void PrintLineWithPrefix(char *, char *, int);
109 void DebugContinued(char *, char *, ...);
110 void Debug(char *, char *, ...);
111 void Info(char *, ...);
112 void Warn(char *, ...);
113 void Error(char *, ...);
114 void Fail(char *, ...);
115 void FailWithHelp(char *, ...);
117 char *int2str(int, int);
118 char *i_to_a(unsigned int);
119 int log_2(unsigned int);
121 boolean getTokenValueFromString(char *, char **, char **);
125 void InitCounter(void);
126 unsigned int Counter(void);
127 void Delay(unsigned int);
128 boolean DelayReachedExt(unsigned int *, unsigned int, unsigned int);
129 boolean FrameReached(unsigned int *, unsigned int);
130 boolean DelayReached(unsigned int *, unsigned int);
131 void ResetDelayCounterExt(unsigned int *, unsigned int);
132 void ResetFrameCounter(unsigned int *);
133 void ResetDelayCounter(unsigned int *);
134 int WaitUntilDelayReached(unsigned int *, unsigned int);
135 void SkipUntilDelayReached(unsigned int *, unsigned int, int *, int);
137 unsigned int init_random_number(int, int);
138 unsigned int get_random_number(int, int);
140 #if defined(PLATFORM_UNIX)
141 char *getUnixLoginName(void);
142 char *getUnixRealName(void);
143 char *getUnixHomeDir(void);
146 char *getLoginName(void);
147 char *getRealName(void);
148 char *getFixedUserName(char *);
149 char *getDefaultUserName(int);
151 char *getTimestampFromEpoch(time_t);
152 char *getCurrentTimestamp(void);
154 time_t getFileTimestampEpochSeconds(char *);
156 char *getBasePath(char *);
157 char *getBaseName(char *);
158 char *getBaseNamePtr(char *);
159 char *getBaseNameNoSuffix(char *);
161 char *getStringCat2WithSeparator(char *, char *, char *);
162 char *getStringCat3WithSeparator(char *, char *, char *, char *);
163 char *getStringCat2(char *, char *);
164 char *getStringCat3(char *, char *, char *);
165 char *getPath2(char *, char *);
166 char *getPath3(char *, char *, char*);
167 char *getImg2(char *, char *);
168 char *getImg3(char *, char *, char*);
169 char *getStringCopy(const char *);
170 char *getStringCopyN(const char *, int);
171 char *getStringCopyNStatic(const char *, int);
172 char *getStringToLower(const char *);
173 void setString(char **, char *);
174 boolean strEqual(char *, char *);
175 boolean strEqualN(char *, char *, int);
176 boolean strEqualCase(char *, char *);
177 boolean strEqualCaseN(char *, char *, int);
178 boolean strPrefix(char *, char *);
179 boolean strSuffix(char *, char *);
180 boolean strPrefixLower(char *, char *);
181 boolean strSuffixLower(char *, char *);
183 void GetOptions(int, char **,
184 void (*print_usage_function)(void),
185 void (*print_version_function)(void));
187 void *checked_malloc(unsigned int);
188 void *checked_calloc(unsigned int);
189 void *checked_realloc(void *, unsigned int);
190 void checked_free(void *);
191 void clear_mem(void *, unsigned int);
193 void swap_numbers(int *, int *);
194 void swap_number_pairs(int *, int *, int *, int *);
196 int getFile8BitInteger(File *);
197 int putFile8BitInteger(FILE *, int);
198 int getFile16BitInteger(File *, int);
199 int putFile16BitInteger(FILE *, int, int);
200 int getFile32BitInteger(File *, int);
201 int putFile32BitInteger(FILE *, int, int);
203 boolean getFileChunk(File *, char *, int *, int);
204 int putFileChunk(FILE *, char *, int, int);
205 int getFileVersion(File *);
206 int putFileVersion(FILE *, int);
208 void ReadBytesFromFile(File *, byte *, unsigned int);
209 void WriteBytesToFile(FILE *, byte *, unsigned int);
211 void ReadUnusedBytesFromFile(File *, unsigned int);
212 void WriteUnusedBytesToFile(FILE *, unsigned int);
214 #define getFile8Bit(f) getFile8BitInteger(f)
215 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
216 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
217 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
218 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
219 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
220 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
221 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
222 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
223 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
225 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
226 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
227 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
228 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
230 char *getUTF8FromLatin1(char *);
231 char *getLatin1FromUTF8(char *);
232 char *getEscapedJSON(char *);
234 char *getKeyNameFromKey(Key);
235 char *getX11KeyNameFromKey(Key);
236 Key getKeyFromKeyName(char *);
237 Key getKeyFromX11KeyName(char *);
238 char getCharFromKey(Key);
239 char getValidConfigValueChar(char);
241 int get_integer_from_string(char *);
242 boolean get_boolean_from_string(char *);
243 int get_switch3_from_string(char *);
244 int get_player_nr_from_string(char *);
246 ListNode *newListNode(void);
247 void addNodeToList(ListNode **, char *, void *);
248 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
249 ListNode *getNodeFromKey(ListNode *, char *);
250 int getNumNodes(ListNode *);
252 File *openFile(char *, char *);
253 int closeFile(File *);
254 int checkEndOfFile(File *);
255 size_t readFile(File *, void *, size_t, size_t);
256 size_t writeFile(File *, void *, size_t, size_t);
257 int seekFile(File *, long, int);
258 int getByteFromFile(File *);
259 char *getStringFromFile(File *, char *, int);
260 int copyFile(char *, char *);
262 Directory *openDirectory(char *);
263 int closeDirectory(Directory *);
264 DirectoryEntry *readDirectory(Directory *);
265 void freeDirectoryEntry(DirectoryEntry *);
267 boolean directoryExists(char *);
268 boolean fileExists(char *);
269 boolean FileIsGraphic(char *);
270 boolean FileIsSound(char *);
271 boolean FileIsMusic(char *);
272 boolean FileIsArtworkType(char *, int);
274 char *get_mapped_token(char *);
276 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
277 struct ConfigTypeInfo *,
279 void LoadArtworkConfig(struct ArtworkListInfo *);
280 void ReloadCustomArtworkList(struct ArtworkListInfo *);
281 void FreeCustomArtworkLists(struct ArtworkListInfo *);
283 char *getLogFilename(char *);
284 void OpenLogFiles(void);
285 void CloseLogFiles(void);
286 void DumpLogFile(int);
288 void NotifyUserAboutErrorFile(void);
291 void debug_print_timestamp(int, char *);
293 void print_timestamp_init(char *);
294 void print_timestamp_time(char *);
295 void print_timestamp_done(char *);