Fixed segfaults with empty selections.
[gromacs/qmmm-gamess-us.git] / include / gmx_fatal.h
blob74405e9d9d17762beea4e79d856bf156fad23233
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gromacs Runs On Most of All Computer Systems
36 #ifndef _fatal_h
37 #define _fatal_h
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 #include <stdio.h>
48 #include <stdarg.h>
49 #include <errno.h>
51 void
52 _where(const char *file,int line);
53 #define where() _where(__FILE__,__LINE__)
54 /* Prints filename and line to stdlog and only on amba memvail */
56 void
57 _set_fatal_tmp_file(const char *fn, const char *file, int line);
58 #define set_fatal_tmp_file(fn) _set_fatal_tmp_file(fn,__FILE__,__LINE__)
59 /* set filename to be removed when fatal_error is called */
61 void
62 _unset_fatal_tmp_file(const char *fn, const char *file, int line);
63 #define unset_fatal_tmp_file(fn) _unset_fatal_tmp_file(fn,__FILE__,__LINE__)
64 /* unsets filename to be removed */
66 void
67 gmx_fatal(int fatal_errno,const char *file,int line,const char *fmt,...);
68 #define FARGS 0,__FILE__,__LINE__
70 * Routine gmx_fatal prints
72 * "fatal error file %s line %s \n\t "
74 * followed by the string specified by fmt and supplied parameters. If
75 * errno is 0, only the message and arguments are printed. If errno is
76 * a legal system errno or -1, a perror like message is printed after the
77 * first message, if errno is -1, the last system errno will be used.
78 * The format of fmt is that like printf etc, only %d, %x, %c, %f and %s
79 * are allowed as format specifiers.
81 * Tip of the week:
82 * call this function using the FARGS macro:
83 * gmx_fatal(FARGS,fmt,...)
86 /* This include must not be moved upwards, to prevent compilation problems */
87 #include "typedefs.h"
89 void
90 gmx_fatal_set_log_file(FILE *fp);
91 /* Set the log file for printing error messages */
93 void
94 init_warning(int maxwarning);
95 /* Set the max number of warnings */
97 void
98 set_warning_line(const char *fn,int line);
99 /* Set filename and linenumber for the warning */
101 int
102 get_warning_line(void);
103 /* Get linenumber for the warning */
106 const char *
107 get_warning_file(void);
108 /* Get filename for the warning */
110 extern char
111 warn_buf[1024];
112 /* Warning buffer of 1024 bytes, which can be used to print messages to */
114 void
115 warning(const char *s);
116 /* Issue a warning, with the string s. If s == NULL, then warn_buf
117 * will be printed instead. The file and line set by set_warning_line
118 * are printed, nwarn_warn (local) is incremented.
119 * A fatal error will be generated after processing the input
120 * when nwarn_warn is larger than maxwarning passed to init_warning.
121 * So warning should only be called for issues that should be resolved,
122 * otherwise warning_note should be called.
125 void
126 warning_note(const char *s);
127 /* Issue a note, with the string s. If s == NULL, then warn_buf
128 * will be printed instead. The file and line set by set_warning_line
129 * are printed, nwarn_note (local) is incremented.
130 * This is for issues which could be a problem for some systems,
131 * but 100% ok for other systems.
134 void
135 warning_error(const char *s);
136 /* Issue an error, with the string s. If s == NULL, then warn_buf
137 * will be printed instead. The file and line set by set_warning_line
138 * are printed, nwarn_error (local) is incremented.
141 void
142 check_warning_error(int f_errno,const char *file,int line);
143 /* When warning_error has been called at least once gmx_fatal is called,
144 * otherwise does nothing.
147 void
148 print_warn_num(bool bFatalError);
149 /* Print the total number of warnings, if larger than 0.
150 * When bFatalError == TRUE generates a fatal error
151 * when the number is larger than maxwarn.
154 void
155 _too_few(const char *fn,int line);
156 #define too_few() _too_few(__FILE__,__LINE__)
157 /* Issue a warning stating 'Too few parameters' */
159 void
160 _incorrect_n_param(const char *fn,int line);
161 #define incorrect_n_param() _incorrect_n_param(__FILE__,__LINE__)
162 /* Issue a warning stating 'Incorrect number of parameters' */
164 void
165 _invalid_case(const char *fn,int line);
166 #define invalid_case() _invalid_case(__FILE__,__LINE__)
167 /* Issue a warning stating 'Invalid case in switch' */
169 extern void _unexpected_eof(const char *fn,int line,const char *srcfn,int srcline);
170 #define unexpected_eof(fn,line) _unexpected_eof(fn,line,__FILE__,__LINE__)
173 * Functions can write to this file for debug info
174 * Before writing to it, it should be checked whether
175 * the file is not NULL:
176 * if (debug) fprintf(debug,"%s","Hallo");
178 extern FILE *debug;
179 extern bool gmx_debug_at;
181 void init_debug (const int dbglevel,const char *dbgfile);
183 extern bool bDebugMode(void);
184 /* Return TRUE when the program was started in debug mode */
186 #if (defined __sgi && defined USE_SGI_FPE)
187 extern void doexceptions(void);
188 /* Set exception handlers for debugging */
189 #endif
191 /* If msg == NULL, then warn_buf will be printed instead.
193 extern void _range_check(int n,int n_min,int n_max,const char *var,
194 const char *file,int line);
195 #define range_check(n,n_min,n_max) _range_check(n,n_min,n_max,#n,__FILE__,__LINE__)
196 /* Range check will terminate with an error message if not
197 * n E [ n_min, n_max >
198 * That is n_min is inclusive but not n_max.
201 extern char *gmx_strerror(const char *key);
202 /* Return error message corresponding to the key.
203 * Maybe a multi-line message.
204 * The messages are stored in src/gmxlib/fatal.c
207 extern void _gmx_error(const char *key,const char *msg,const char *file,int line);
208 #define gmx_error(key,msg) _gmx_error(key,msg,__FILE__,__LINE__)
209 /* Error msg of type key is generated and the program is
210 * terminated unless and error handle is set (see below)
213 /* Some common error types */
214 #define gmx_bug(msg) gmx_error("bug",msg)
215 #define gmx_call(msg) gmx_error("call",msg)
216 #define gmx_comm(msg) gmx_error("comm",msg)
217 #define gmx_file(msg) gmx_error("file",msg)
218 #define gmx_cmd(msg) gmx_error("cmd",msg)
219 #define gmx_impl(msg) gmx_error("impl",msg)
220 #define gmx_incons(msg) gmx_error("incons",msg)
221 #define gmx_input(msg) gmx_error("input",msg)
222 #define gmx_mem(msg) gmx_error("mem",msg)
223 #define gmx_open(fn) gmx_error("open",fn)
225 void
226 set_gmx_error_handler(void (*func)(const char *msg));
227 /* An error function will be called that terminates the program
228 * with a fatal error, unless you override it with another function.
229 * i.e.:
230 * set_gmx_error_handler(my_func);
231 * where my_func is a function that takes a string as an argument.
232 * The string may be a multi-line string.
235 #ifdef __cplusplus
237 #endif
239 #endif /* _fatal_h */