File: gap-error.c

package info (click to toggle)
staden 2.0.0%2Bb11-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 21,556 kB
  • sloc: ansic: 240,603; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (144 lines) | stat: -rw-r--r-- 3,146 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * File: gap-error.c
 * Version:
 *
 * Orig. Author: Simon Dear
 *               MRC Laboratory of Molecular Biology
 *	         Hills Road
 *	         Cambridge CB2 2QH
 *	         United Kingdom
 *
 * Description:
 *
 * Created:
 * Updated: jkb 16/8/94 
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>

/* 11/1/99 johnt - defines for Windows support */
#ifdef _WIN32
#  define WIN32_LEAN_AND_MEAN
#  include <windows.h>
#endif

#include "misc.h"
#include "gap-error.h"
#include "g-error.h"
#include "array.h"
#include "bitmap.h"
#include "stack_dump.h"

char *GapErrorString(int err) {
    if (err >= GAPERR_BASE) {
	switch(err) {
	case GAPERR_NO_ERROR:		return "no error";
	case GAPERR_INVALID_TYPE:	return "invalid type";
	case GAPERR_NOT_FOUND:		return "does not exist";
	case GAPERR_TRUSTME:		return "you just can't!";
	default:			return "unknown error";
	}
    }

    if (err >= ARRAY_ERR_START)
	return ArrayErrorString(err);

    if (err >= BITMAP_ERR_START) {
	return BitmapErrorString(err);
    }

    return gerrors[err];
}

int gap_fatal_errors = 1;

/*************************************************************
 * Error reporting routines
 *************************************************************/

void error_sig(int sig) {
    verror(ERR_FATAL, "signal_handler",
	   "Program terminated unexpectedly with signal %d.", sig);
    if (sig != SIGINT
#if defined(SIGQUIT)
	&& sig != SIGQUIT
#endif
	) {
	verror(ERR_FATAL, "signal_handler",
	       "This is probably a bug.");
	verror(ERR_FATAL, "signal_handler",
	       "Please report all bug reports at "
	       "https://sourceforge.net/projects/staden/");
	/*
	 * Force crash.
	 */
/* 11/1/99 johnt - no SIGBUS under WINNT */
	signal(SIGSEGV, SIG_DFL);
#if defined(SIGBUS)
	signal(SIGBUS, SIG_DFL);
#endif
	stack_trace();
	abort();
    } else {
	exit(1);
    }
}

static void xperror_out_func(char *name, char *str) {
    verror(ERR_FATAL, name, "%s", str);
}

/* NOT FATAL */
__PRINTF_FORMAT__(1,2)
void GAP_ERROR(char *reason, ...) {
    char buf[8192];
    va_list args;

    va_start(args, reason);
    vsprintf(buf, reason, args);

    xperror(buf, xperror_out_func);
}

/* FATAL */
__PRINTF_FORMAT__(1,2)
void GAP_ERROR_FATAL(char *reason, ...) {
    char buf[8192];
    va_list args;

    va_start(args, reason);
    vsprintf(buf, reason, args);

    xperror(buf, xperror_out_func);

    if (gap_fatal_errors) {
#ifdef _WIN32
	/* 11/1/99 johnt - WINNT will not have stdout/err defined unless running in console mode
	 * so use a message box
	 */
	if( fileno(stderr) == -1 ){
	    MessageBox(NULL,buf,"Gap5 Error",MB_OK|MB_ICONERROR|MB_TASKMODAL);
	    return;
	}
#endif
	fputs("Gap5 has found an unrecoverable error - These are usually bugs.\nPlease submit all errors at https://sourceforge.net/projects/staden/\n", stderr);
	signal(SIGSEGV, SIG_DFL);
/* 11/1/99 johnt - No SIGBUS on WINNT */
#if defined(SIGBUS)
	signal(SIGBUS, SIG_DFL);
#endif
	stack_trace();
	abort();
    } else {
	verror(ERR_FATAL, "NOTE  ", "Continue at own risk!");
    }
}

void set_gap_fatal_errors(int val) {
    gap_fatal_errors = val ? 1 : 0;
}