rnd-20060828-1-src
[rocksndiamonds.git] / src / libgame / misc.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * misc.h                                                   *
12 ***********************************************************/
13
14 #ifndef MISC_H
15 #define MISC_H
16
17 #include <stdlib.h>
18 #include <stdio.h>
19
20 #include "system.h"
21
22
23 /* values for InitCounter() and Counter() */
24 #define INIT_COUNTER                    0
25 #define READ_COUNTER                    1
26
27 /* values for InitRND() */
28 #define NEW_RANDOMIZE                   -1
29
30 #define RANDOM_ENGINE                   0
31 #define RANDOM_SIMPLE                   1
32
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)
37
38 /* values for Error() */
39 #define ERR_RETURN                      0
40 #define ERR_RETURN_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)
52
53 /* values for getFile...() and putFile...() */
54 #define BYTE_ORDER_BIG_ENDIAN           0
55 #define BYTE_ORDER_LITTLE_ENDIAN        1
56
57 /* values for cursor bitmap creation */
58 #define BIT_ORDER_MSB                   0
59 #define BIT_ORDER_LSB                   1
60
61 /* values for createDirectory() */
62 #define PERMS_PRIVATE                   0
63 #define PERMS_PUBLIC                    1
64
65 /* values for general file handling stuff */
66 #define MAX_FILENAME_LEN                256
67 #define MAX_LINE_LEN                    1024
68
69 /* values for general username handling stuff */
70 #define MAX_USERNAME_LEN                1024
71
72
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);
79
80 void InitCounter(void);
81 unsigned long Counter(void);
82 void Delay(unsigned long);
83 boolean FrameReached(unsigned long *, unsigned long);
84 boolean DelayReached(unsigned long *, unsigned long);
85 void WaitUntilDelayReached(unsigned long *, unsigned long);
86
87 unsigned int init_random_number(int, long);
88 unsigned int get_random_number(int, int);
89
90 char *getLoginName(void);
91 char *getRealName(void);
92
93 char *getBasePath(char *);
94 char *getBaseName(char *);
95 char *getBaseNamePtr(char *);
96
97 char *getPath2(char *, char *);
98 char *getPath3(char *, char *, char*);
99 char *getStringCat2(char *, char *);
100 char *getStringCopy(char *);
101 char *getStringToLower(char *);
102 void setString(char **, char *);
103 boolean strEqual(char *, char *);
104
105 void GetOptions(char **, void (*print_usage_function)(void));
106
107 void SetError(char *, ...);
108 char *GetError(void);
109 void Error(int, char *, ...);
110
111 void *checked_malloc(unsigned long);
112 void *checked_calloc(unsigned long);
113 void *checked_realloc(void *, unsigned long);
114 void checked_free(void *);
115
116 void swap_numbers(int *, int *);
117 void swap_number_pairs(int *, int *, int *, int *);
118
119 int getFile8BitInteger(FILE *);
120 int putFile8BitInteger(FILE *, int);
121 int getFile16BitInteger(FILE *, int);
122 int putFile16BitInteger(FILE *, int, int);
123 int getFile32BitInteger(FILE *, int);
124 int putFile32BitInteger(FILE *, int, int);
125
126 boolean getFileChunk(FILE *, char *, int *, int);
127 int putFileChunk(FILE *, char *, int, int);
128 int getFileVersion(FILE *);
129 int putFileVersion(FILE *, int);
130
131 void ReadBytesFromFile(FILE *, byte *, unsigned long);
132 void WriteBytesToFile(FILE *, byte *, unsigned long);
133
134 void ReadUnusedBytesFromFile(FILE *, unsigned long);
135 void WriteUnusedBytesToFile(FILE *, unsigned long);
136
137 #define getFile8Bit(f)        getFile8BitInteger(f)
138 #define putFile8Bit(f,x)      putFile8BitInteger(f,x)
139 #define getFile16BitBE(f)     getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
140 #define getFile16BitLE(f)     getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
141 #define putFile16BitBE(f,x)   putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
142 #define putFile16BitLE(f,x)   putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
143 #define getFile32BitBE(f)     getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
144 #define getFile32BitLE(f)     getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
145 #define putFile32BitBE(f,x)   putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
146 #define putFile32BitLE(f,x)   putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
147
148 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
149 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
150 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
151 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
152
153 char *getKeyNameFromKey(Key);
154 char *getX11KeyNameFromKey(Key);
155 Key getKeyFromKeyName(char *);
156 Key getKeyFromX11KeyName(char *);
157 char getCharFromKey(Key);
158
159 int get_integer_from_string(char *);
160 boolean get_boolean_from_string(char *);
161
162 ListNode *newListNode(void);
163 void addNodeToList(ListNode **, char *, void *);
164 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
165 ListNode *getNodeFromKey(ListNode *, char *);
166 int getNumNodes(ListNode *);
167
168 boolean fileExists(char *);
169 boolean FileIsGraphic(char *);
170 boolean FileIsSound(char *);
171 boolean FileIsMusic(char *);
172 boolean FileIsArtworkType(char *, int);
173
174 char *get_mapped_token(char *);
175
176 int get_parameter_value(char *, char *, int);
177 int get_auto_parameter_value(char *, char *);
178
179 struct ScreenModeInfo *get_screen_mode_from_string(char *);
180 void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *, int *x, int *y);
181
182 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
183                                            struct ConfigTypeInfo *,
184                                            char **, int);
185 void LoadArtworkConfig(struct ArtworkListInfo *);
186 void ReloadCustomArtworkList(struct ArtworkListInfo *);
187 void FreeCustomArtworkLists(struct ArtworkListInfo *);
188
189 char *getErrorFilename(char *);
190 void openErrorFile();
191 void closeErrorFile();
192 void dumpErrorFile();
193 void NotifyUserAboutErrorFile();
194
195 void debug_print_timestamp(int, char *);
196
197 #endif /* MISC_H */