1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
24 /* values for InitCounter() and Counter() */
25 #define INIT_COUNTER 0
26 #define READ_COUNTER 1
28 /* values for InitRND() */
29 #define NEW_RANDOMIZE 0
31 #define RANDOM_ENGINE 0
32 #define RANDOM_SIMPLE 1
34 #define InitEngineRandom(seed) init_random_number(RANDOM_ENGINE, seed)
35 #define InitSimpleRandom(seed) init_random_number(RANDOM_SIMPLE, seed)
36 #define GetEngineRandom(max) get_random_number(RANDOM_ENGINE, max)
37 #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
39 /* values for Error() */
41 #define ERR_DEBUG (1 << 0)
42 #define ERR_INFO (1 << 1)
43 #define ERR_INFO_LINE (1 << 2)
44 #define ERR_WARN (1 << 3)
45 #define ERR_EXIT (1 << 4)
46 #define ERR_HELP (1 << 5)
47 #define ERR_SOUND_SERVER (1 << 6)
48 #define ERR_NETWORK_SERVER (1 << 7)
49 #define ERR_NETWORK_CLIENT (1 << 8)
50 #define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER)
51 #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP)
52 #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER)
53 #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER)
54 #define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT)
56 #define ERR_ERROR (ERR_UNKNOWN)
57 #define ERR_FATAL (ERR_EXIT)
58 #define ERR_VERBOSE (ERR_INFO)
61 /* values for getFile...() and putFile...() */
62 #define BYTE_ORDER_BIG_ENDIAN 0
63 #define BYTE_ORDER_LITTLE_ENDIAN 1
65 /* values for cursor bitmap creation */
66 #define BIT_ORDER_MSB 0
67 #define BIT_ORDER_LSB 1
69 /* values for createDirectory() */
70 #define PERMS_PRIVATE 0
71 #define PERMS_PUBLIC 1
73 /* values for general file handling stuff */
74 #define MAX_FILENAME_LEN 256
75 #define MAX_LINE_LEN 1024
77 /* values for general username handling stuff */
78 #define MAX_USERNAME_LEN 1024
80 #if defined(PLATFORM_ANDROID)
81 /* values for Android asset handling */
82 #define ASSET_TOC_BASENAME ".toc"
86 /* structure definitions */
94 #if defined(PLATFORM_ANDROID)
95 boolean file_is_asset;
96 SDL_RWops *asset_file;
102 boolean is_directory;
111 DirectoryEntry *dir_entry;
113 #if defined(PLATFORM_ANDROID)
114 boolean directory_is_asset;
115 SDL_RWops *asset_toc_file;
121 /* function definitions */
123 void fprintf_line(FILE *, char *, int);
124 void printf_line(char *, int);
125 void printf_line_with_prefix(char *, char *, int);
126 char *int2str(int, int);
127 char *i_to_a(unsigned int);
128 int log_2(unsigned int);
130 boolean getTokenValueFromString(char *, char **, char **);
132 void InitCounter(void);
133 unsigned int Counter(void);
134 void Delay(unsigned int);
135 boolean FrameReached(unsigned int *, unsigned int);
136 boolean DelayReached(unsigned int *, unsigned int);
137 void WaitUntilDelayReached(unsigned int *, unsigned int);
139 unsigned int init_random_number(int, int);
140 unsigned int get_random_number(int, int);
142 char *getLoginName(void);
143 char *getRealName(void);
145 time_t getFileTimestampEpochSeconds(char *);
147 char *getBasePath(char *);
148 char *getBaseName(char *);
149 char *getBaseNamePtr(char *);
151 char *getStringCat2WithSeparator(char *, char *, char *);
152 char *getStringCat3WithSeparator(char *, char *, char *, char *);
153 char *getStringCat2(char *, char *);
154 char *getStringCat3(char *, char *, char *);
155 char *getPath2(char *, char *);
156 char *getPath3(char *, char *, char*);
157 char *getStringCopy(char *);
158 char *getStringCopyN(char *, int);
159 char *getStringToLower(char *);
160 void setString(char **, char *);
161 boolean strEqual(char *, char *);
162 boolean strEqualN(char *, char *, int);
163 boolean strPrefix(char *, char *);
164 boolean strSuffix(char *, char *);
165 boolean strPrefixLower(char *, char *);
166 boolean strSuffixLower(char *, char *);
168 void GetOptions(char **, void (*print_usage_function)(void));
170 void SetError(char *, ...);
171 char *GetError(void);
172 void Error(int, char *, ...);
174 void *checked_malloc(unsigned int);
175 void *checked_calloc(unsigned int);
176 void *checked_realloc(void *, unsigned int);
177 void checked_free(void *);
178 void clear_mem(void *, unsigned int);
180 void swap_numbers(int *, int *);
181 void swap_number_pairs(int *, int *, int *, int *);
183 int getFile8BitInteger(FILE *);
184 int putFile8BitInteger(FILE *, int);
185 int getFile16BitInteger(FILE *, int);
186 int putFile16BitInteger(FILE *, int, int);
187 int getFile32BitInteger(FILE *, int);
188 int putFile32BitInteger(FILE *, int, int);
190 boolean getFileChunk(FILE *, char *, int *, int);
191 int putFileChunk(FILE *, char *, int, int);
192 int getFileVersion(FILE *);
193 int putFileVersion(FILE *, int);
195 void ReadBytesFromFile(FILE *, byte *, unsigned int);
196 void WriteBytesToFile(FILE *, byte *, unsigned int);
198 void ReadUnusedBytesFromFile(FILE *, unsigned int);
199 void WriteUnusedBytesToFile(FILE *, unsigned int);
201 #define getFile8Bit(f) getFile8BitInteger(f)
202 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
203 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
204 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
205 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
206 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
207 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
208 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
209 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
210 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
212 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
213 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
214 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
215 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
217 char *getKeyNameFromKey(Key);
218 char *getX11KeyNameFromKey(Key);
219 Key getKeyFromKeyName(char *);
220 Key getKeyFromX11KeyName(char *);
221 char getCharFromKey(Key);
222 char getValidConfigValueChar(char);
224 int get_integer_from_string(char *);
225 boolean get_boolean_from_string(char *);
226 int get_switch3_from_string(char *);
228 ListNode *newListNode(void);
229 void addNodeToList(ListNode **, char *, void *);
230 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
231 ListNode *getNodeFromKey(ListNode *, char *);
232 int getNumNodes(ListNode *);
234 File *openFile(char *, char *);
235 int closeFile(File *);
236 int checkEndOfFile(File *);
237 char *getStringFromFile(File *, char *, int);
239 Directory *openDirectory(char *);
240 int closeDirectory(Directory *);
241 DirectoryEntry *readDirectory(Directory *);
242 void freeDirectoryEntry(DirectoryEntry *);
244 boolean directoryExists(char *);
245 boolean fileExists(char *);
246 boolean FileIsGraphic(char *);
247 boolean FileIsSound(char *);
248 boolean FileIsMusic(char *);
249 boolean FileIsArtworkType(char *, int);
251 char *get_mapped_token(char *);
253 int get_parameter_value(char *, char *, int);
255 struct ScreenModeInfo *get_screen_mode_from_string(char *);
256 void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *, int *x, int *y);
258 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
259 struct ConfigTypeInfo *,
261 void LoadArtworkConfig(struct ArtworkListInfo *);
262 void ReloadCustomArtworkList(struct ArtworkListInfo *);
263 void FreeCustomArtworkLists(struct ArtworkListInfo *);
265 char *getErrorFilename(char *);
266 void openErrorFile();
267 void closeErrorFile();
268 void dumpErrorFile();
269 void NotifyUserAboutErrorFile();
272 void debug_print_timestamp(int, char *);
273 void print_timestamp_init(char *);
274 void print_timestamp_time(char *);
275 void print_timestamp_done(char *);