]> git.pond.sub.org Git - empserver/blob - include/misc.h
(main) [_WIN32]: Switch to Unix style function for access and mkdir.
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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
47 /* integral mismatch, due to misuse of sector short */
48 #pragma warning (disable : 4761 )
49
50 #include <minmax.h>
51 #include <io.h>
52
53 #define random rand
54 #define srandom srand
55
56 #define strncasecmp(s1, s2, s3) _strnicmp(s1, s2, s3)
57 #define mkdir(dir,perm) _mkdir(dir)
58 /* used for access */
59 #define F_OK 0  // FILE existence
60 #define W_OK 02 // Write permission
61 #define R_OK 04 // Read permission
62
63 /*#define _POSIX_ */
64 #endif
65
66 #include "options.h"
67
68 /* This is the structure we use to keep track of the global mobility
69    things, such as when the server is supposed to start/stop updating
70    mobility and the timestamp of when the game was last up.  These
71    times are in seconds. */
72 struct mob_acc_globals {
73     time_t timestamp;           /* Last timestamp of when the game was up */
74     time_t starttime;           /* When we should start updating mobility again. */
75 };
76
77 #ifdef __GNUC__
78 #define ATTRIBUTE(attrs) __attribute__ (attrs)
79 #else
80 #define ATTRIBUTE(attrs)
81 #endif
82
83 /* This uses a lot of thread stack with some versions of GNU libc,
84    which can lead to nasty heap smashes (observed with 2.2.93).
85    Disabled for now, until we readjust thread stack sizes.  */
86 #if 0
87 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
88 #endif
89
90 typedef u_char natid;           /* NSC_NATID must match this */
91
92 #if defined(__linux__ ) || defined(__osf__)
93 #define POSIXSIGNALS 1
94 #endif
95
96 #if !defined (_EMPTH_LWP) && !defined (_EMPTH_POSIX)
97 #define _EMPTH_LWP     1
98 #endif
99
100 #if defined(_EMPTH_POSIX) && !defined(POSIXSIGNALS)
101 #define POSIXSIGNALS
102 #endif
103
104
105 #if !defined(aix) && !defined(sgi)
106 #ifndef ultrix                  /* already defined in ultrix */
107 typedef char s_char;            /* change to signed char for aix */
108 #endif /* ultrix */
109 #else
110 typedef signed char s_char;
111 /* gcc __attribute__((format ...)) chokes on s_char * format strings */
112 #undef ATTRIBUTE
113 #define ATTRIBUTE(attr)
114 #endif /* !aix && !sgi */
115 typedef short coord;
116
117 #ifndef bit
118 #define bit(x)          (1<<(x))
119 #endif
120
121 #define minutes(x)      (60*(x))
122 #define hours(x)        (60*60*(x))
123 #define days(x)         (60*60*24*(x))
124
125 extern int debug;
126
127 /*
128  * If EXPR is true, an internal error occured.
129  * Return EXPR != 0.
130  * Usage: if (CANT_HAPPEN(...)) recovery_code();
131  */
132 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
133
134 typedef int (*qsort_func_t) (const void *, const void *);
135
136         /* return codes from command routines */
137 #define RET_OK          0       /* command completed sucessfully */
138 #define RET_FAIL        1       /* command completed unsucessfully [?] */
139 #define RET_SYN         2       /* syntax error in command */
140 #define RET_SYS         3       /* system error (missing file, etc) */
141
142 double dmax(double n1, double n2);
143 double dmin(double n1, double n2);
144
145 extern s_char *numstr(s_char buf[], int n);
146 extern s_char *esplur(int n);
147 extern s_char *splur(int n);
148 extern s_char *iesplur(int n);
149 extern s_char *plur(int n, s_char *no, s_char *yes);
150 extern char *getstarg(char *input, char *prompt, char buf[]);
151 extern char *getstring(char *prompt, char buf[]);
152 extern s_char *prbuf(s_char *format, ...)
153     ATTRIBUTE((format (printf, 1, 2)));
154
155 #include "prototypes.h"         /* must come at end, after defines and typedefs */
156
157 #endif /* _MISC_H_ */