Index: common/shared.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/shared.c,v retrieving revision 1.90 diff -u -r1.90 shared.c --- common/shared.c 2002/08/23 03:52:12 1.90 +++ common/shared.c 2002/09/01 16:31:45 @@ -64,6 +64,12 @@ static char *grouping_sep = ","; static size_t grouping_sep_len = 1; +/* For error reporting */ +void (*real_error_handler) (bool condition, const char *file, + int line, const char *date, + const char *errmsg, char *function) + = real_error_printf; + /*************************************************************** Take a string containing multiple lines and create a copy where each line is padded to the length of the longest line and centered. @@ -1234,4 +1240,29 @@ if (vec1[l] & vec2[l]) return TRUE; } while(l); return FALSE; +} + +/*************************************************************************** + We use this before we've set up proper error reporting facilities on + client or server. +***************************************************************************/ +void real_error_printf(bool condition, const char *file, + int line, const char *date, + const char *errmsg, char *function) +{ + if (!condition) { + printf("\nOoops, error detected: %s\nThis happened in function %s in %s " + "line %d\nThe error has successfully been avoided.\nPlease report" + " to bugs@xxxxxxxxxxxxxxxxxxx!\n\n", errmsg, function, file, line); + } +} + +/*************************************************************************** + ... +***************************************************************************/ +bool real_error(bool condition, const char *file, int line, + const char *date, const char *errmsg, char *function) +{ + real_error_handler(condition, file, line, date, errmsg, function); + return (!condition); } Index: common/shared.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v retrieving revision 1.101 diff -u -r1.101 shared.h --- common/shared.h 2002/08/21 22:40:07 1.101 +++ common/shared.h 2002/09/01 16:31:45 @@ -171,4 +171,23 @@ const char *freeciv_motto(void); +/* Debugging */ +#ifdef __GNUC__ +#define error(condition) real_error(condition, __FILE__, __LINE__, __DATE__, \ + "" # condition, __func__) +#else +#define error(condition) (!condition) +#endif + +bool real_error(bool condition, const char *file, int line, + const char *date, const char *errmsg, char *function); + +void real_error_printf(bool condition, const char *file, + int line, const char *date, + const char *errmsg, char *function); + +extern void (*real_error_handler) (bool condition, const char *file, + int line, const char *date, + const char *errmsg, char *function); + #endif /* FC__SHARED_H */ Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.94 diff -u -r1.94 srv_main.c --- server/srv_main.c 2002/09/01 03:43:48 1.94 +++ server/srv_main.c 2002/09/01 16:31:46 @@ -148,6 +148,34 @@ /* server initialized flag */ static bool has_been_srv_init = FALSE; +/*************************************************************************** + Error reporting function for the server +***************************************************************************/ +void real_error_server(bool condition, const char *file, int line, + const char *date, const char *errmsg, char *function) +{ + if (!condition) { + FILE *f; + con_puts(C_GENFAIL, ""); + con_puts(C_GENFAIL, _(" *** Server error detected! ***")); + con_write(C_GENFAIL, _(" Error in %s in %s line %d"), function, file, line); + con_write(C_GENFAIL, _(" The check was: %s"), errmsg); + con_puts(C_GENFAIL, _(" The error has been dodged and a savegame will " + "be created.")); + con_puts(C_GENFAIL, _(" Please send it along with this message to " + "bugs@xxxxxxxxxxxxxxxxxxx!")); + con_puts(C_GENFAIL, ""); + save_game("error.sav"); + f = fopen("error.txt", "a"); + if (f) { + fprintf(f, "Server error detected: %s\n", errmsg); + fprintf(f, "%s in %s line %d\n\n", function, file, line); + fclose(f); + } + con_flush(); + } +} + /************************************************************************** ... **************************************************************************/ @@ -1801,6 +1829,10 @@ init_our_capability(); game_init(); + + /* set up error handler */ + real_error_handler = real_error_server; + error(FALSE); /* init network */ init_connections();