]> git.pond.sub.org Git - empserver/blob - include/misc.h
Normalize inclusion guards: use NAME_H for name.h. Some headers
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 <ctype.h>
39 #include <string.h>
40 #include <sys/types.h>
41
42 #if defined(_WIN32)
43 typedef unsigned char u_char;
44 typedef unsigned short u_short;
45 typedef unsigned int u_int;
46 typedef long ssize_t;
47
48 /* integral mismatch, due to misuse of sector short */
49 #ifndef __GNUC__
50 #pragma warning (disable : 4761 )
51 #endif
52
53 #include <windef.h>
54 #include <io.h>
55
56 #define random rand
57 #define srandom srand
58
59 #define strncasecmp(s1, s2, s3) _strnicmp(s1, s2, s3)
60 #define mkdir(dir,perm) _mkdir(dir)
61 /* used for access */
62 #ifndef F_OK
63 #define F_OK 0  /* FILE existence */
64 #endif
65 #ifndef W_OK
66 #define W_OK 02 /* Write permission */
67 #endif
68 #ifndef R_OK
69 #define R_OK 04 /* Read permission */
70 #endif
71
72 typedef int pid_t;
73 #define vsnprintf _vsnprintf
74
75 /*#define _POSIX_ */
76 #endif
77
78 /* This is the structure we use to keep track of the global mobility
79    things, such as when the server is supposed to start/stop updating
80    mobility and the timestamp of when the game was last up.  These
81    times are in seconds. */
82 struct mob_acc_globals {
83     time_t timestamp;           /* Last timestamp of when the game was up */
84     time_t starttime;           /* When we should start updating mobility again. */
85 };
86
87 #ifdef __GNUC__
88 #define ATTRIBUTE(attrs) __attribute__ (attrs)
89 #else
90 #define ATTRIBUTE(attrs)
91 #endif
92
93 /* This uses a lot of thread stack with some versions of GNU libc,
94    which can lead to nasty heap smashes (observed with 2.2.93).
95    Disabled for now, until we readjust thread stack sizes.  */
96 #if 0
97 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
98 #endif
99
100 typedef u_char natid;           /* NSC_NATID must match this */
101
102 /*
103  * TODO s_char has to go.  Use plain char for characters and strings,
104  * signed char for small integers.
105  */
106 #ifdef __CHAR_UNSIGNED__
107 typedef signed char s_char;
108 #else
109 typedef char s_char;
110 #endif
111
112 typedef short coord;
113
114 #ifndef bit
115 #define bit(x)          (1<<(x))
116 #endif
117
118 #define minutes(x)      (60*(x))
119 #define hours(x)        (60*60*(x))
120 #define days(x)         (60*60*24*(x))
121
122 extern int debug;
123 extern int daemonize;
124
125 /*
126  * If EXPR is true, an internal error occured.
127  * Return EXPR != 0.
128  * Usage: if (CANT_HAPPEN(...)) recovery_code();
129  */
130 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
131 extern int oops(char *, char *, int);
132
133         /* return codes from command routines */
134 #define RET_OK          0       /* command completed sucessfully */
135 #define RET_FAIL        1       /* command completed unsucessfully [?] */
136 #define RET_SYN         2       /* syntax error in command */
137 #define RET_SYS         3       /* system error (missing file, etc) */
138
139 double dmax(double n1, double n2);
140 double dmin(double n1, double n2);
141
142 extern char *getstarg(char *input, char *prompt, char buf[]);
143 extern char *getstring(char *prompt, char buf[]);
144 extern char *ugetstring(char *prompt, char buf[]);
145              
146 extern char *prbuf(char *format, ...)
147     ATTRIBUTE((format (printf, 1, 2)));
148
149 #define AGREE_FREE      0
150 #define AGREE_PROPOSED  1
151 #define AGREE_SIGNED    2
152
153 #endif