]> git.pond.sub.org Git - empserver/blob - include/misc.h
Update copyright notice
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  misc.h: Misc. definitions which don't really belong anywhere,
28  *          but have to go somewhere!
29  *
30  *  Known contributors to this file:
31  *     Doug Hay, 1998
32  */
33
34 #ifndef MISC_H
35 #define MISC_H
36
37 #define MAX(a,b) ((a) > (b) ? (a) : (b))
38 #define MIN(a,b) ((a) < (b) ? (a) : (b))
39
40 #ifdef _WIN32
41 #include "w32misc.h"
42 #endif /* _WIN32 */
43
44 #ifdef __GNUC__
45 #define ATTRIBUTE(attrs) __attribute__ (attrs)
46 #else
47 #define ATTRIBUTE(attrs)
48 #endif
49
50 /*
51  * This uses a lot of thread stack with some versions of GNU libc,
52  * which can lead to nasty heap smashes (observed with 2.2.93).
53  * Disabled for now, until we readjust thread stack sizes.
54  */
55 #if 0
56 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
57 #endif
58
59 #ifndef bit
60 #define bit(x)          (1<<(x))
61 #endif
62
63 #define minutes(x)      (60*(x))
64 #define hours(x)        (60*60*(x))
65 #define days(x)         (60*60*24*(x))
66
67 /*
68  * If EXPR is true, an internal error occured.
69  * Return EXPR != 0.
70  * Usage: if (CANT_HAPPEN(...)) <recovery code>;
71  */
72 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__), 1 : 0)
73
74 /*
75  * Report internal error.
76  * Usage: CANT_REACH(); <recovery code>;
77  */
78 #define CANT_REACH() oops(NULL, __FILE__, __LINE__)
79
80 extern void oops(char *, char *, int);
81 extern void (*oops_handler)(void);
82
83 void exit_nomem(void) ATTRIBUTE((noreturn));
84
85         /* return codes from command routines */
86 #define RET_OK          0       /* command completed sucessfully */
87 #define RET_FAIL        1       /* command completed unsucessfully [?] */
88 #define RET_SYN         2       /* syntax error in command */
89
90 extern char *getstarg(char *input, char *prompt, char buf[]);
91 extern char *getstring(char *prompt, char buf[]);
92 extern char *ugetstring(char *prompt, char buf[]);
93
94 extern char *prbuf(char *format, ...)
95     ATTRIBUTE((format (printf, 1, 2)));
96
97 #define AGREE_FREE      0
98 #define AGREE_PROPOSED  1
99 #define AGREE_SIGNED    2
100
101 #endif