1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * messages.c -- Message and error functions
|
---|
4 | * Copyright (C) 1994 Neil Sharman
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: messages.cpp 860 2000-01-18 03:53:24Z rjmcnab $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | /*
|
---|
25 | $Log$
|
---|
26 | Revision 1.2 2000/01/18 03:53:19 rjmcnab
|
---|
27 | Fixed a couple of bugs and made building silent if needed.
|
---|
28 |
|
---|
29 | Revision 1.1 2000/01/14 02:17:10 sjboddie
|
---|
30 | Rodgers new C++ mg
|
---|
31 |
|
---|
32 | Revision 1.1 1999/10/11 02:55:16 cs025
|
---|
33 | Base install of MG-PP
|
---|
34 |
|
---|
35 | Revision 1.1 1999/08/10 21:16:55 sjboddie
|
---|
36 | renamed mg-1.3d directory mg
|
---|
37 |
|
---|
38 | Revision 1.2 1998/11/23 03:38:06 rjmcnab
|
---|
39 |
|
---|
40 | combined unix and windows versions of mg
|
---|
41 |
|
---|
42 | Revision 1.1 1998/11/19 03:00:32 sjboddie
|
---|
43 | Added windows gdbm and mg versions
|
---|
44 |
|
---|
45 | * Revision 1.1 1994/08/22 00:24:48 tes
|
---|
46 | * Initial placement under CVS.
|
---|
47 | *
|
---|
48 | */
|
---|
49 |
|
---|
50 | static char *RCSID = "$Id: messages.cpp 860 2000-01-18 03:53:24Z rjmcnab $";
|
---|
51 |
|
---|
52 | #include "sysfuncs.h"
|
---|
53 |
|
---|
54 | #include <stdarg.h>
|
---|
55 | #include "messages.h"
|
---|
56 |
|
---|
57 | char *msg_prefix = "";
|
---|
58 |
|
---|
59 |
|
---|
60 | void VOLATILE
|
---|
61 | FatalError (int ExitCode, const char *fmt,...)
|
---|
62 | {
|
---|
63 | char buf[1024];
|
---|
64 | char *s, *pfx;
|
---|
65 | va_list args;
|
---|
66 | va_start (args, fmt);
|
---|
67 | vsprintf (buf, fmt, args);
|
---|
68 | s = strrchr (buf, '\n');
|
---|
69 | if (!s || *(s + 1) != '\0')
|
---|
70 | strcat (buf, "\n");
|
---|
71 | pfx = strrchr (msg_prefix, '/');
|
---|
72 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
73 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
74 | exit (ExitCode);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * This function writes messages to stderr. Due to the fact that I can't
|
---|
81 | * guarantee that the fprintf call is monatomic I have to implement a
|
---|
82 | * semaphore system.
|
---|
83 | */
|
---|
84 | void
|
---|
85 | Message (const char *fmt,...)
|
---|
86 | {
|
---|
87 | char buf[1024];
|
---|
88 | char *s, *pfx;
|
---|
89 | va_list args;
|
---|
90 |
|
---|
91 | #ifdef SILENT
|
---|
92 | return; /* stop those messages!!!! */
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | va_start (args, fmt);
|
---|
96 | vsprintf (buf, fmt, args);
|
---|
97 | s = strrchr (buf, '\n');
|
---|
98 | if (!s || *(s + 1) != '\0')
|
---|
99 | strcat (buf, "\n");
|
---|
100 |
|
---|
101 | pfx = strrchr (msg_prefix, '/');
|
---|
102 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
103 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
104 |
|
---|
105 | }
|
---|