(debug): New.

(main): Set it on -d.
(oops, CANT_HAPPEN): New.
This commit is contained in:
Markus Armbruster 2004-04-02 15:40:43 +00:00
parent f1edf905e9
commit 47c8a32ae3
4 changed files with 29 additions and 1 deletions

View file

@ -123,6 +123,15 @@ typedef short coord;
#define hours(x) (60*60*(x))
#define days(x) (60*60*24*(x))
extern int debug;
/*
* If EXPR is true, an internal error occured.
* Return EXPR != 0.
* Usage: if (CANT_HAPPEN(...)) recovery_code();
*/
#define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
typedef int (*qsort_func_t) (const void *, const void *);
/* return codes from command routines */

View file

@ -128,6 +128,7 @@ extern int has_helpful_engineer(coord x, coord y, natid cn);
/* log.c */
extern void loginit(s_char *);
extern void logerror(s_char *, ...) ATTRIBUTE((format (printf, 1, 2)));
extern int oops(char *, char *, int);
/* maps.c */
extern int draw_map(int, s_char, int, struct nstr_sect *, int);
extern int unit_map(int, int, struct nstr_sect *, s_char *);

View file

@ -99,3 +99,15 @@ logerror(s_char *format, ...)
#endif
va_end(list);
}
/*
* Log internal error MSG occured in FILE:LINE.
* If debugging, call abort(), else return 1.
*/
int
oops(char *msg, char *file, int line)
{
logerror("Oops: %s in %s:%d\n", msg, file, line);
if (debug) abort();
return 1;
}

View file

@ -80,13 +80,19 @@ static void loc_NTTerm(void);
static int mainpid = 0;
#endif
/*
* Debugging?
* If yes, don't fork into background, don't catch certain signals,
* call abort() on internal error.
*/
int debug = 0;
int
main(int argc, char **argv)
{
time_t now;
int hour[2];
int flags = 0;
int debug = 0;
int op;
char *config_file = NULL;
extern char *optarg;