]> git.pond.sub.org Git - empserver/blob - include/misc.h
[_WIN32, __GNUC__]: Reorganize the include files for WIN32 to
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  misc.h: Misc. definitions which don't really belong anywhere,
29  *          but have to go somewhere!
30  * 
31  *  Known contributors to this file:
32  *       Doug Hay, 1998
33  */
34
35 #ifndef MISC_H
36 #define MISC_H
37
38 #include <time.h>
39
40 #define MAX(a,b) ((a) > (b) ? (a) : (b))
41 #define MIN(a,b) ((a) < (b) ? (a) : (b))
42
43 #ifdef _WIN32
44 #ifndef __GNUC__
45
46 typedef long ssize_t;
47
48 /* integral mismatch, due to misuse of sector short */
49 #pragma warning (disable : 4761 )
50
51 #define strncasecmp(s1, s2, s3) _strnicmp((s1), (s2), (s3))
52
53 typedef int pid_t;
54 #define vsnprintf _vsnprintf
55 #define snprintf _snprintf
56
57 #endif /* !__GNUC__ */
58
59 #define mkdir(dir,perm) _mkdir((dir))
60 #define random rand
61 #define srandom srand
62
63 #endif /* _WIN32 */
64
65 /* This is the structure we use to keep track of the global mobility
66    things, such as when the server is supposed to start/stop updating
67    mobility and the timestamp of when the game was last up.  These
68    times are in seconds. */
69 struct mob_acc_globals {
70     time_t timestamp;           /* Last timestamp of when the game was up */
71     time_t starttime;           /* When we should start updating mobility again. */
72 };
73
74 #ifdef __GNUC__
75 #define ATTRIBUTE(attrs) __attribute__ (attrs)
76 #else
77 #define ATTRIBUTE(attrs)
78 #endif
79
80 /*
81  * This uses a lot of thread stack with some versions of GNU libc,
82  * which can lead to nasty heap smashes (observed with 2.2.93).
83  * Disabled for now, until we readjust thread stack sizes.
84  */
85 #if 0
86 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
87 #endif
88
89 #ifndef bit
90 #define bit(x)          (1<<(x))
91 #endif
92
93 #define minutes(x)      (60*(x))
94 #define hours(x)        (60*60*(x))
95 #define days(x)         (60*60*24*(x))
96
97 extern int debug;
98
99 /*
100  * If EXPR is true, an internal error occured.
101  * Return EXPR != 0.
102  * Usage: if (CANT_HAPPEN(...)) <recovery code>;
103  */
104 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
105
106 /*
107  * Report internal error.
108  * Usage: CANT_REACH(); <recovery code>;
109  */
110 #define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__)
111
112 extern int oops(char *, char *, int);
113
114         /* return codes from command routines */
115 #define RET_OK          0       /* command completed sucessfully */
116 #define RET_FAIL        1       /* command completed unsucessfully [?] */
117 #define RET_SYN         2       /* syntax error in command */
118 #define RET_SYS         3       /* system error (missing file, etc) */
119
120 extern char *getstarg(char *input, char *prompt, char buf[]);
121 extern char *getstring(char *prompt, char buf[]);
122 extern char *ugetstring(char *prompt, char buf[]);
123              
124 extern char *prbuf(char *format, ...)
125     ATTRIBUTE((format (printf, 1, 2)));
126
127 #define AGREE_FREE      0
128 #define AGREE_PROPOSED  1
129 #define AGREE_SIGNED    2
130
131 #endif