2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
47 #include "gmx_fatal.h"
50 typedef struct warninp {
51 gmx_bool bAllowWarnings;
60 warninp_t init_warning(gmx_bool bAllowWarnings,int maxwarning)
66 wi->bAllowWarnings = bAllowWarnings;
67 wi->maxwarn = maxwarning;
71 strcpy(wi->filenm,"unknown");
77 void set_warning_line(warninp_t wi,const char *s,int line)
81 gmx_incons("Calling set_warning_line with NULL pointer");
88 int get_warning_line(warninp_t wi)
93 const char *get_warning_file(warninp_t wi)
98 static void low_warning(warninp_t wi,const char *wtype,int n,const char *s)
106 s = "Empty error message.";
108 snew(temp,strlen(s)+indent+1);
109 for(i=0; i<indent; i++)
115 temp2 = wrap_lines(temp,78-indent,indent,FALSE);
116 if (strlen(wi->filenm) > 0)
118 if (wi->lineno != -1)
120 fprintf(stderr,"\n%s %d [file %s, line %d]:\n%s\n\n",
121 wtype,n,wi->filenm,wi->lineno,temp2);
125 fprintf(stderr,"\n%s %d [file %s]:\n%s\n\n",
126 wtype,n,wi->filenm,temp2);
131 fprintf(stderr,"\n%s %d:\n%s\n\n",wtype,n,temp2);
137 void warning(warninp_t wi,const char *s)
139 if (wi->bAllowWarnings)
142 low_warning(wi,"WARNING",wi->nwarn_warn,s);
150 void warning_note(warninp_t wi,const char *s)
153 low_warning(wi,"NOTE",wi->nwarn_note,s);
156 void warning_error(warninp_t wi,const char *s)
159 low_warning(wi,"ERROR",wi->nwarn_error,s);
162 static void print_warn_count(const char *type,int n)
166 fprintf(stderr,"\nThere %s %d %s%s\n",
167 (n==1) ? "was" : "were", n, type, (n==1) ? "" : "s");
171 void check_warning_error(warninp_t wi,int f_errno,const char *file,int line)
173 if (wi->nwarn_error > 0)
175 print_warn_count("note",wi->nwarn_note);
176 print_warn_count("warning",wi->nwarn_warn);
178 gmx_fatal(f_errno,file,line,"There %s %d error%s in input file(s)",
179 (wi->nwarn_error==1) ? "was" : "were",wi->nwarn_error,
180 (wi->nwarn_error==1) ? "" : "s");
184 void done_warning(warninp_t wi,int f_errno,const char *file,int line)
186 print_warn_count("note",wi->nwarn_note);
187 print_warn_count("warning",wi->nwarn_warn);
189 check_warning_error(wi,f_errno,file,line);
191 if (wi->maxwarn >= 0 && wi->nwarn_warn > wi->maxwarn)
193 gmx_fatal(f_errno,file,line,
194 "Too many warnings (%d), %s terminated.\n"
195 "If you are sure all warnings are harmless, use the -maxwarn option.",
196 wi->nwarn_warn,Program());
202 void _too_few(warninp_t wi,const char *fn,int line)
207 "Too few parameters on line (source file %s, line %d)",
212 void _incorrect_n_param(warninp_t wi,const char *fn,int line)
217 "Incorrect number of parameters on line (source file %s, line %d)",