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 ***********************************************************/
23 /* values for InitCounter() and Counter() */
24 #define INIT_COUNTER 0
25 #define READ_COUNTER 1
27 /* values for InitRND() */
28 #define NEW_RANDOMIZE 0
30 #define RANDOM_ENGINE 0
31 #define RANDOM_SIMPLE 1
33 #define InitEngineRandom(seed) init_random_number(RANDOM_ENGINE, seed)
34 #define InitSimpleRandom(seed) init_random_number(RANDOM_SIMPLE, seed)
35 #define GetEngineRandom(max) get_random_number(RANDOM_ENGINE, max)
36 #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
38 /* values for Error() */
40 #define ERR_INFO_LINE (1 << 0)
41 #define ERR_WARN (1 << 1)
42 #define ERR_EXIT (1 << 2)
43 #define ERR_HELP (1 << 3)
44 #define ERR_SOUND_SERVER (1 << 4)
45 #define ERR_NETWORK_SERVER (1 << 5)
46 #define ERR_NETWORK_CLIENT (1 << 6)
47 #define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER)
48 #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP)
49 #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER)
50 #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER)
51 #define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT)
53 /* values for getFile...() and putFile...() */
54 #define BYTE_ORDER_BIG_ENDIAN 0
55 #define BYTE_ORDER_LITTLE_ENDIAN 1
57 /* values for cursor bitmap creation */
58 #define BIT_ORDER_MSB 0
59 #define BIT_ORDER_LSB 1
61 /* values for createDirectory() */
62 #define PERMS_PRIVATE 0
63 #define PERMS_PUBLIC 1
65 /* values for general file handling stuff */
66 #define MAX_FILENAME_LEN 256
67 #define MAX_LINE_LEN 1024
69 /* values for general username handling stuff */
70 #define MAX_USERNAME_LEN 1024
73 void fprintf_line(FILE *, char *, int);
74 void printf_line(char *, int);
75 void printf_line_with_prefix(char *, char *, int);
76 char *int2str(int, int);
77 char *i_to_a(unsigned int);
78 int log_2(unsigned int);
80 boolean getTokenValueFromString(char *, char **, char **);
82 void InitCounter(void);
83 unsigned long Counter(void);
84 void Delay(unsigned long);
85 boolean FrameReached(unsigned long *, unsigned long);
86 boolean DelayReached(unsigned long *, unsigned long);
87 void WaitUntilDelayReached(unsigned long *, unsigned long);
89 unsigned int init_random_number(int, long);
90 unsigned int get_random_number(int, int);
92 char *getLoginName(void);
93 char *getRealName(void);
95 time_t getFileTimestampEpochSeconds(char *);
97 char *getBasePath(char *);
98 char *getBaseName(char *);
99 char *getBaseNamePtr(char *);
101 char *getStringCat2WithSeparator(char *, char *, char *);
102 char *getStringCat3WithSeparator(char *, char *, char *, char *);
103 char *getStringCat2(char *, char *);
104 char *getStringCat3(char *, char *, char *);
105 char *getPath2(char *, char *);
106 char *getPath3(char *, char *, char*);
107 char *getStringCopy(char *);
108 char *getStringCopyN(char *, int);
109 char *getStringToLower(char *);
110 void setString(char **, char *);
111 boolean strEqual(char *, char *);
112 boolean strEqualN(char *, char *, int);
113 boolean strPrefix(char *, char *);
114 boolean strSuffix(char *, char *);
115 boolean strPrefixLower(char *, char *);
116 boolean strSuffixLower(char *, char *);
118 void GetOptions(char **, void (*print_usage_function)(void));
120 void SetError(char *, ...);
121 char *GetError(void);
122 void Error(int, char *, ...);
124 void *checked_malloc(unsigned long);
125 void *checked_calloc(unsigned long);
126 void *checked_realloc(void *, unsigned long);
127 void checked_free(void *);
128 void clear_mem(void *, unsigned long);
130 void swap_numbers(int *, int *);
131 void swap_number_pairs(int *, int *, int *, int *);
133 int getFile8BitInteger(FILE *);
134 int putFile8BitInteger(FILE *, int);
135 int getFile16BitInteger(FILE *, int);
136 int putFile16BitInteger(FILE *, int, int);
137 int getFile32BitInteger(FILE *, int);
138 int putFile32BitInteger(FILE *, int, int);
140 boolean getFileChunk(FILE *, char *, int *, int);
141 int putFileChunk(FILE *, char *, int, int);
142 int getFileVersion(FILE *);
143 int putFileVersion(FILE *, int);
145 void ReadBytesFromFile(FILE *, byte *, unsigned long);
146 void WriteBytesToFile(FILE *, byte *, unsigned long);
148 void ReadUnusedBytesFromFile(FILE *, unsigned long);
149 void WriteUnusedBytesToFile(FILE *, unsigned long);
151 #define getFile8Bit(f) getFile8BitInteger(f)
152 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
153 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
154 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
155 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
156 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
157 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
158 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
159 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
160 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
162 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
163 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
164 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
165 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
167 char *getKeyNameFromKey(Key);
168 char *getX11KeyNameFromKey(Key);
169 Key getKeyFromKeyName(char *);
170 Key getKeyFromX11KeyName(char *);
171 char getCharFromKey(Key);
172 char getValidConfigValueChar(char);
174 int get_integer_from_string(char *);
175 boolean get_boolean_from_string(char *);
176 int get_switch3_from_string(char *);
178 ListNode *newListNode(void);
179 void addNodeToList(ListNode **, char *, void *);
180 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
181 ListNode *getNodeFromKey(ListNode *, char *);
182 int getNumNodes(ListNode *);
184 boolean fileExists(char *);
185 boolean FileIsGraphic(char *);
186 boolean FileIsSound(char *);
187 boolean FileIsMusic(char *);
188 boolean FileIsArtworkType(char *, int);
190 char *get_mapped_token(char *);
192 int get_parameter_value(char *, char *, int);
194 struct ScreenModeInfo *get_screen_mode_from_string(char *);
195 void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *, int *x, int *y);
197 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
198 struct ConfigTypeInfo *,
200 void LoadArtworkConfig(struct ArtworkListInfo *);
201 void ReloadCustomArtworkList(struct ArtworkListInfo *);
202 void FreeCustomArtworkLists(struct ArtworkListInfo *);
204 char *getErrorFilename(char *);
205 void openErrorFile();
206 void closeErrorFile();
207 void dumpErrorFile();
208 void NotifyUserAboutErrorFile();
210 void debug_print_timestamp(int, char *);