]> git.pond.sub.org Git - empserver/blob - include/misc.h
32817f825fa9866d85fdd49a425c13a6c9c6aad4
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, 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 #define MAX(a,b) ((a) > (b) ? (a) : (b))
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
40
41 #ifdef _WIN32
42 #include "w32misc.h"
43 #endif /* _WIN32 */
44
45 #ifdef __GNUC__
46 #define ATTRIBUTE(attrs) __attribute__ (attrs)
47 #else
48 #define ATTRIBUTE(attrs)
49 #endif
50
51 /*
52  * This uses a lot of thread stack with some versions of GNU libc,
53  * which can lead to nasty heap smashes (observed with 2.2.93).
54  * Disabled for now, until we readjust thread stack sizes.
55  */
56 #if 0
57 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
58 #endif
59
60 #ifndef bit
61 #define bit(x)          (1<<(x))
62 #endif
63
64 #define minutes(x)      (60*(x))
65 #define hours(x)        (60*60*(x))
66 #define days(x)         (60*60*24*(x))
67
68 /*
69  * If EXPR is true, an internal error occured.
70  * Return EXPR != 0.
71  * Usage: if (CANT_HAPPEN(...)) <recovery code>;
72  */
73 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
74
75 /*
76  * Report internal error.
77  * Usage: CANT_REACH(); <recovery code>;
78  */
79 #define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__)
80
81 extern int oops(char *, char *, int);
82 extern void (*oops_handler)(void);
83
84 void exit_nomem(void) ATTRIBUTE((noreturn));
85
86         /* return codes from command routines */
87 #define RET_OK          0       /* command completed sucessfully */
88 #define RET_FAIL        1       /* command completed unsucessfully [?] */
89 #define RET_SYN         2       /* syntax error in command */
90
91 extern char *getstarg(char *input, char *prompt, char buf[]);
92 extern char *getstring(char *prompt, char buf[]);
93 extern char *ugetstring(char *prompt, char buf[]);
94
95 extern char *prbuf(char *format, ...)
96     ATTRIBUTE((format (printf, 1, 2)));
97
98 #define AGREE_FREE      0
99 #define AGREE_PROPOSED  1
100 #define AGREE_SIGNED    2
101
102 #endif