Fix remaining copyright headers
[alexxy/gromacs.git] / src / gromacs / legacyheaders / gmx_fatal.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2012, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 #ifndef _fatal_h
39 #define _fatal_h
40
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <errno.h>
44 #include "types/simple.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 #ifndef __has_feature      // Optional.
51 #define __has_feature(x) 0 // Compatibility with non-clang compilers.
52 #endif
53
54 /* This documentation block seems to produce warnings with some Doxygen
55  * versions, so it's disabled for now.  Maybe because the file itself
56  * is not documented. */
57 /* \def GMX_ATTRIBUTE_NORETURN
58  * \brief
59  * Indicate that a function is not expected to return.
60  *
61  * WARNING: In general this flag should not be used for compiler
62  * optimizations, since set_gmx_error_handler can be set to a
63  * handler which does not quit.
64  */
65 #ifndef GMX_ATTRIBUTE_NORETURN
66 #if __has_feature(attribute_analyzer_noreturn)
67 #define GMX_ATTRIBUTE_NORETURN __attribute__((analyzer_noreturn))
68 #else
69 #define GMX_ATTRIBUTE_NORETURN
70 #endif
71 #endif
72
73 void
74 _where(const char *file, int line);
75 #define where() _where(__FILE__, __LINE__)
76 /* Prints filename and line to stdlog and only on amba memvail */
77
78 void
79 _set_fatal_tmp_file(const char *fn, const char *file, int line);
80 #define set_fatal_tmp_file(fn) _set_fatal_tmp_file(fn, __FILE__, __LINE__)
81 /* set filename to be removed when fatal_error is called */
82
83 void
84 _unset_fatal_tmp_file(const char *fn, const char *file, int line);
85 #define unset_fatal_tmp_file(fn) _unset_fatal_tmp_file(fn, __FILE__, __LINE__)
86 /* unsets filename to be removed */
87
88 void
89 gmx_fatal(int fatal_errno, const char *file, int line, const char *fmt, ...) GMX_ATTRIBUTE_NORETURN;
90 #define FARGS 0, __FILE__, __LINE__
91 /*
92  * Routine gmx_fatal prints
93  *
94  *  "fatal error file %s line %s \n\t "
95  *
96  * followed by the string specified by fmt and supplied parameters. If
97  * errno is 0, only the message and arguments are printed. If errno is
98  * a legal system errno or -1, a perror like message is printed after the
99  * first message, if errno is -1, the last system errno will be used.
100  * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
101  * are allowed as format specifiers.
102  *
103  * In case all MPI processes want to stop with the same fatal error,
104  * use gmx_fatal_collective, declared in gmx_fatal_collective.h,
105  * to avoid having as many error messages as processes.
106  *
107  * Tip of the week:
108  * call this function using the FARGS macro:
109  * gmx_fatal(FARGS,fmt,...)
110  *
111  */
112
113 void
114 gmx_fatal_set_log_file(FILE *fp);
115 /* Set the log file for printing error messages */
116
117 void
118 _invalid_case(const char *fn, int line);
119 #define invalid_case() _invalid_case(__FILE__, __LINE__)
120 /* Issue a warning stating 'Invalid case in switch' */
121
122 void _unexpected_eof(const char *fn, int line, const char *srcfn, int srcline);
123 #define unexpected_eof(fn, line) _unexpected_eof(fn, line, __FILE__, __LINE__)
124
125 /*
126  * Functions can write to this file for debug info
127  * Before writing to it, it should be checked whether
128  * the file is not NULL:
129  * if (debug) fprintf(debug,"%s","Hallo");
130  */
131 extern FILE    *debug;
132 extern gmx_bool gmx_debug_at;
133
134 void init_debug (const int dbglevel, const char *dbgfile);
135
136 gmx_bool bDebugMode(void);
137 /* Return TRUE when the program was started in debug mode */
138
139 #if (defined __sgi && defined USE_SGI_FPE)
140 void doexceptions(void);
141 /* Set exception handlers for debugging */
142 #endif
143
144 /* warn_str is allowed to be NULL.
145  */
146 void _range_check(int n, int n_min, int n_max, const char *warn_str,
147                   const char *var,
148                   const char *file, int line);
149
150 #define range_check_mesg(n, n_min, n_max, str) _range_check(n, n_min, n_max, str,#n, __FILE__, __LINE__)
151 /* Range check will terminate with an error message if not
152  * n E [ n_min, n_max >
153  * That is n_min is inclusive but not n_max.
154  */
155
156 #define range_check(n, n_min, n_max) _range_check(n, n_min, n_max, NULL,#n, __FILE__, __LINE__)
157 /* Range check will terminate with an error message if not
158  * n E [ n_min, n_max >
159  * That is n_min is inclusive but not n_max.
160  */
161
162 char *gmx_strerror(const char *key);
163 /* Return error message corresponding to the key.
164  * Maybe a multi-line message.
165  * The messages are stored in src/gmxlib/fatal.c
166  */
167
168 void _gmx_error(const char *key, const char *msg, const char *file, int line) GMX_ATTRIBUTE_NORETURN;
169 #define gmx_error(key, msg) _gmx_error(key, msg, __FILE__, __LINE__)
170 /* Error msg of type key is generated and the program is
171  * terminated unless and error handle is set (see below)
172  */
173
174 /* Some common error types */
175 #define gmx_bug(msg)    gmx_error("bug", msg)
176 #define gmx_call(msg)   gmx_error("call", msg)
177 #define gmx_comm(msg)   gmx_error("comm", msg)
178 #define gmx_file(msg)   gmx_error("file", msg)
179 #define gmx_cmd(msg)    gmx_error("cmd", msg)
180 #define gmx_impl(msg)   gmx_error("impl", msg)
181 #define gmx_incons(msg) gmx_error("incons", msg)
182 #define gmx_input(msg)  gmx_error("input", msg)
183 #define gmx_mem(msg)    gmx_error("mem", msg)
184 #define gmx_open(fn)    gmx_error("open", fn)
185
186 void
187 set_gmx_error_handler(void (*func)(const char *msg));
188 /* An error function will be called that terminates the program
189  * with a fatal error, unless you override it with another function.
190  * i.e.:
191  * set_gmx_error_handler(my_func);
192  * where my_func is a function that takes a string as an argument.
193  * The string may be a multi-line string.
194  */
195
196 void gmx_warning(const char *fmt, ...);
197 /* Print a warning message to stderr.
198  * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
199  * are allowed as format specifiers.
200  * The message string should NOT start with "WARNING"
201  * and should NOT end with a newline.
202  */
203
204
205 #ifdef __cplusplus
206 }
207 #endif
208
209 #endif  /* _fatal_h */