updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / var / da / makedepf90-2.8.8 / errormesg.c
blob5217d61f6e3ad508479a4369dbb1ac097b076131
1 /*
2 * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License version 2 as published by the Free Software
7 * Foundation;
9 * This program is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <assert.h>
25 #include "config.h"
28 static const char *progname;
31 void set_progname (const char *prog)
33 progname = prog;
36 static void print_errmesg (const char *kind, const char *fmt, va_list ap)
38 char *s;
39 int n;
40 unsigned u;
41 double d;
42 char c;
44 fprintf (stderr, "\n%s: %s: ", progname, kind);
46 for (; *fmt; fmt++) {
47 if (*fmt != '%') {
48 fputc (*fmt, stderr);
49 } else {
50 fmt++;
51 switch (*fmt) {
52 case 's':
53 s = va_arg (ap, char *);
54 fputs (s, stderr);
55 break;
56 case 'c':
57 c = va_arg (ap, int);
58 fputc(c, stderr);
59 break;
60 case 'd':
61 case 'i':
62 n = va_arg (ap, int);
63 fprintf (stderr,"%i", n);
64 break;
65 case 'u':
66 u = va_arg (ap, unsigned);
67 fprintf (stderr, "%u", u);
68 break;
69 case 'f':
70 d = va_arg (ap, double);
71 fprintf (stderr, "%f", d);
72 break;
73 case 'g':
74 d = va_arg (ap, double);
75 fprintf (stderr, "%g", d);
76 break;
77 case '%':
78 fputc ('%', stderr);
79 break;
80 case '\0':
81 break;
82 default:
83 assert (0);
84 break;
88 fputc ('\n', stderr);
93 void fatal_error (const char *fmt, ...)
94 /*
95 * Print a message on stderr and exit with exitcode 'EXIT_FAILURE'
98 va_list ap;
100 va_start (ap, fmt);
101 print_errmesg ("ERROR", fmt, ap);
102 va_end(ap);
103 exit (EXIT_FAILURE);
107 void warning (const char *fmt, ...)
109 * Print a message on stderr.
112 va_list ap;
114 va_start (ap, fmt);
115 print_errmesg ("WARNING", fmt, ap);
116 va_end(ap);