2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
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.
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.
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/>.
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.
27 * misc.h: Misc. definitions which don't really belong anywhere,
28 * but have to go somewhere!
30 * Known contributors to this file:
32 * Markus Armbruster, 2004-2014
38 #define MAX(a,b) ((a) > (b) ? (a) : (b))
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 #define LIMIT_TO(val, min, max) \
42 ((val) < (min) ? (min) : (val) > (max) ? (max) : (val))
49 #define ATTRIBUTE(attrs) __attribute__ (attrs)
51 #define ATTRIBUTE(attrs)
55 #define bit(x) (1U<<(x))
58 #define minutes(x) (60*(x))
59 #define hours(x) (60*60*(x))
60 #define days(x) (60*60*24*(x))
63 * If @expr is true, an internal error occured.
65 * Usage: if (CANT_HAPPEN(...)) <recovery code>;
67 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__), 1 : 0)
70 * Report internal error.
71 * Usage: CANT_REACH(); <recovery code>;
73 #define CANT_REACH() oops(NULL, __FILE__, __LINE__)
75 extern void oops(char *, char *, int);
76 extern void (*oops_handler)(void);
79 * Assert constant expression @cond, return 1.
80 * If @cond is zero, force a compilation error.
82 #define BUILD_ASSERT_ONE(cond) \
83 (sizeof(char[1 - 2 * !(cond)]))
86 * Assert constant expression @cond.
87 * If @cond is zero, force a compilation error.
89 #define BUILD_ASSERT(cond) \
90 ((void)BUILD_ASSERT_ONE(cond))
92 void exit_nomem(void) ATTRIBUTE((noreturn));
94 /* return codes from command routines */
95 #define RET_OK 0 /* command completed sucessfully */
96 #define RET_FAIL 1 /* command completed unsucessfully [?] */
97 #define RET_SYN 2 /* syntax error in command */
99 extern char *getstarg(char *input, char *prompt, char buf[]);
100 extern char *getstring(char *prompt, char buf[]);
101 extern char *ugetstring(char *prompt, char buf[]);
103 extern char *prbuf(char *format, ...)
104 ATTRIBUTE((format (printf, 1, 2)));
107 #define AGREE_PROPOSED 1
108 #define AGREE_SIGNED 2