1 /* 2 $Id: panic.c,v 1.1 2003/05/03 11:12:28 j_ali Exp $ 3 */ 4 /* 5 GTK+ NetHack Copyright (c) Issei Numata 1999-2000 6 Copyright (c) Slash'EM Development Team 2001-2002 7 GTK+ NetHack may be freely redistributed. See license for details. 8 */ 9 10 /* #define DEBUG */ /* Uncomment for debugging */ 11 12 /* 13 * This module implements panic() and friends for when linked as an 14 * external proxy module. Based on util/panic.c and src/pline.c 15 */ 16 17 #include <sys/types.h> 18 #include <signal.h> 19 20 #define NEED_VARARGS 21 #include "config.h" 22 23 #ifdef AZTEC 24 #define abort() exit() 25 #endif 26 #ifdef VMS 27 extern void NDECL(vms_abort); 28 #endif 29 30 /*VARARGS1*/ 31 boolean panicking; 32 void VDECL(panic, (const char *,...)); 33 34 void 35 panic VA_DECL(const char *,str) 36 VA_START(str); 37 VA_INIT(str, char *); 38 if(panicking++) 39 #ifdef SYSV 40 (void) 41 #endif 42 abort(); /* avoid loops - this should never happen*/ 43 44 (void) fputs(" ERROR: ", stderr); 45 Vfprintf(stderr, str, VA_ARGS); 46 (void) fputc('\n', stderr); 47 (void) fflush(stderr); 48 #if defined(UNIX) || defined(VMS) 49 # ifdef SYSV 50 (void) 51 # endif 52 abort(); /* generate core dump */ 53 #endif 54 VA_END(); 55 exit(EXIT_FAILURE); /* redundant */ 56 return; 57 } 58 59 /*VARARGS1*/ 60 /* Note that these declarations rely on knowledge of the internals 61 * of the variable argument handling stuff in "tradstdc.h" 62 */ 63 64 #if defined(USE_STDARG) || defined(USE_VARARGS) 65 static void FDECL(vpline, (const char *, va_list)); 66 67 void 68 pline VA_DECL(const char *, line) 69 VA_START(line); 70 VA_INIT(line, char *); 71 vpline(line, VA_ARGS); 72 VA_END(); 73 } 74 75 # ifdef USE_STDARG 76 static void 77 vpline(const char *line, va_list the_args) { 78 # else 79 static void 80 vpline(line, the_args) const char *line; va_list the_args; { 81 # endif 82 83 #else /* USE_STDARG | USE_VARARG */ 84 85 #define vpline pline 86 87 void 88 pline VA_DECL(const char *, line) 89 #endif /* USE_STDARG | USE_VARARG */ 90 91 char pbuf[BUFSZ]; 92 extern int GTK_initialized; 93 /* Do NOT use VA_START and VA_END in here... see above */ 94 95 if (!line || !*line) return; 96 if (index(line, '%')) { 97 Vsprintf(pbuf,line,VA_ARGS); 98 line = pbuf; 99 } 100 if (!GTK_initialized) { 101 puts(line); 102 (void) fflush(stdout); 103 } else { 104 nh_map_flush(); 105 nh_message_putstr(line); 106 } 107 } 108 109 /*VARARGS1*/ 110 void 111 impossible VA_DECL(const char *, s) 112 VA_START(s); 113 VA_INIT(s, const char *); 114 vpline(s,VA_ARGS); 115 pline("External interface in disorder - perhaps you'd better #quit."); 116 VA_END(); 117 } 118 119 /*panic.c*/ 120