rnd-20060727-2-src
[rocksndiamonds.git] / src / libgame / misc.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 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 InitEngineRND(seed)             init_random_number(0, seed)
31 #define InitSimpleRND(seed)             init_random_number(1, seed)
32 #define RND(max)                        get_random_number(0, max)
33 #define SimpleRND(max)                  get_random_number(1, max)
34
35 /* values for Error() */
36 #define ERR_RETURN                      0
37 #define ERR_RETURN_LINE                 (1 << 0)
38 #define ERR_WARN                        (1 << 1)
39 #define ERR_EXIT                        (1 << 2)
40 #define ERR_HELP                        (1 << 3)
41 #define ERR_SOUND_SERVER                (1 << 4)
42 #define ERR_NETWORK_SERVER              (1 << 5)
43 #define ERR_NETWORK_CLIENT              (1 << 6)
44 #define ERR_FROM_SERVER                 (ERR_SOUND_SERVER | ERR_NETWORK_SERVER)
45 #define ERR_EXIT_HELP                   (ERR_EXIT | ERR_HELP)
46 #define ERR_EXIT_SOUND_SERVER           (ERR_EXIT | ERR_SOUND_SERVER)
47 #define ERR_EXIT_NETWORK_SERVER         (ERR_EXIT | ERR_NETWORK_SERVER)
48 #define ERR_EXIT_NETWORK_CLIENT         (ERR_EXIT | ERR_NETWORK_CLIENT)
49
50 /* values for getFile...() and putFile...() */
51 #define BYTE_ORDER_BIG_ENDIAN           0
52 #define BYTE_ORDER_LITTLE_ENDIAN        1
53
54 /* values for cursor bitmap creation */
55 #define BIT_ORDER_MSB                   0
56 #define BIT_ORDER_LSB                   1
57
58 /* values for createDirectory() */
59 #define PERMS_PRIVATE                   0
60 #define PERMS_PUBLIC                    1
61
62 /* values for general file handling stuff */
63 #define MAX_FILENAME_LEN                256
64 #define MAX_LINE_LEN                    1024
65
66 /* values for general username handling stuff */
67 #define MAX_USERNAME_LEN                1024
68
69
70 void fprintf_line(FILE *, char *, int);
71 void printf_line(char *, int);
72 void printf_line_with_prefix(char *, char *, int);
73 char *int2str(int, int);
74 char *i_to_a(unsigned int);
75 int log_2(unsigned int);
76
77 void InitCounter(void);
78 unsigned long Counter(void);
79 void Delay(unsigned long);
80 boolean FrameReached(unsigned long *, unsigned long);
81 boolean DelayReached(unsigned long *, unsigned long);
82 void WaitUntilDelayReached(unsigned long *, unsigned long);
83
84 #if 0
85 unsigned int SimpleRND(unsigned int);
86 unsigned int InitSimpleRND(long);
87 unsigned int RND(unsigned int);
88 unsigned int InitRND(long);
89 #endif
90
91 unsigned int init_random_number(int, long);
92 unsigned int get_random_number(int, int);
93
94 char *getLoginName(void);
95 char *getRealName(void);
96 char *getHomeDir(void);
97
98 char *getBasePath(char *);
99 char *getBaseName(char *);
100 char *getBaseNamePtr(char *);
101
102 char *getPath2(char *, char *);
103 char *getPath3(char *, char *, char*);
104 char *getStringCat2(char *, char *);
105 char *getStringCopy(char *);
106 char *getStringToLower(char *);
107 void setString(char **, char *);
108 boolean strEqual(char *, char *);
109
110 void GetOptions(char **, void (*print_usage_function)(void));
111
112 void SetError(char *, ...);
113 char *GetError(void);
114 void Error(int, char *, ...);
115
116 void *checked_malloc(unsigned long);
117 void *checked_calloc(unsigned long);
118 void *checked_realloc(void *, unsigned long);
119 void checked_free(void *);
120
121 void swap_numbers(int *, int *);
122 void swap_number_pairs(int *, int *, int *, int *);
123
124 int getFile8BitInteger(FILE *);
125 int putFile8BitInteger(FILE *, int);
126 int getFile16BitInteger(FILE *, int);
127 int putFile16BitInteger(FILE *, int, int);
128 int getFile32BitInteger(FILE *, int);
129 int putFile32BitInteger(FILE *, int, int);
130
131 boolean getFileChunk(FILE *, char *, int *, int);
132 int putFileChunk(FILE *, char *, int, int);
133 int getFileVersion(FILE *);
134 int putFileVersion(FILE *, int);
135
136 void ReadBytesFromFile(FILE *, byte *, unsigned long);
137 void WriteBytesToFile(FILE *, byte *, unsigned long);
138
139 void ReadUnusedBytesFromFile(FILE *, unsigned long);
140 void WriteUnusedBytesToFile(FILE *, unsigned long);
141
142 #define getFile8Bit(f)        getFile8BitInteger(f)
143 #define putFile8Bit(f,x)      putFile8BitInteger(f,x)
144 #define getFile16BitBE(f)     getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
145 #define getFile16BitLE(f)     getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
146 #define putFile16BitBE(f,x)   putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
147 #define putFile16BitLE(f,x)   putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
148 #define getFile32BitBE(f)     getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
149 #define getFile32BitLE(f)     getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
150 #define putFile32BitBE(f,x)   putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
151 #define putFile32BitLE(f,x)   putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
152
153 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
154 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
155 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
156 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
157
158 char *getKeyNameFromKey(Key);
159 char *getX11KeyNameFromKey(Key);
160 Key getKeyFromKeyName(char *);
161 Key getKeyFromX11KeyName(char *);
162 char getCharFromKey(Key);
163
164 int get_integer_from_string(char *);
165 boolean get_boolean_from_string(char *);
166
167 ListNode *newListNode(void);
168 void addNodeToList(ListNode **, char *, void *);
169 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
170 ListNode *getNodeFromKey(ListNode *, char *);
171 int getNumNodes(ListNode *);
172
173 boolean fileExists(char *);
174 boolean FileIsGraphic(char *);
175 boolean FileIsSound(char *);
176 boolean FileIsMusic(char *);
177 boolean FileIsArtworkType(char *, int);
178
179 char *get_mapped_token(char *);
180
181 int get_parameter_value(char *, char *, int);
182 int get_auto_parameter_value(char *, char *);
183
184 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
185                                            struct ConfigTypeInfo *,
186                                            char **, int);
187 void LoadArtworkConfig(struct ArtworkListInfo *);
188 void ReloadCustomArtworkList(struct ArtworkListInfo *);
189 void FreeCustomArtworkLists(struct ArtworkListInfo *);
190
191 char *getErrorFilename(char *);
192 void openErrorFile();
193 void closeErrorFile();
194 void dumpErrorFile();
195 void NotifyUserAboutErrorFile();
196
197 void debug_print_timestamp(int, char *);
198
199 #endif /* MISC_H */