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 | **************************************************************************/
|
---|
21 |
|
---|
22 | #include "sysfuncs.h"
|
---|
23 |
|
---|
24 | #include <stdarg.h>
|
---|
25 | #include "messages.h"
|
---|
26 |
|
---|
27 | char *msg_prefix = "";
|
---|
28 |
|
---|
29 |
|
---|
30 | void VOLATILE
|
---|
31 | FatalError (int ExitCode, const char *fmt,...)
|
---|
32 | {
|
---|
33 | char buf[1024];
|
---|
34 | char *s, *pfx;
|
---|
35 | va_list args;
|
---|
36 | va_start (args, fmt);
|
---|
37 | vsprintf (buf, fmt, args);
|
---|
38 | s = strrchr (buf, '\n');
|
---|
39 | if (!s || *(s + 1) != '\0')
|
---|
40 | strcat (buf, "\n");
|
---|
41 | pfx = strrchr (msg_prefix, '/');
|
---|
42 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
43 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
44 | exit (ExitCode);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * This function writes messages to stderr. Due to the fact that I can't
|
---|
51 | * guarantee that the fprintf call is monatomic I have to implement a
|
---|
52 | * semaphore system.
|
---|
53 | */
|
---|
54 | void
|
---|
55 | Message (const char *fmt,...)
|
---|
56 | {
|
---|
57 | char buf[1024];
|
---|
58 | char *s, *pfx;
|
---|
59 | va_list args;
|
---|
60 |
|
---|
61 | #ifdef SILENT
|
---|
62 | return; /* stop those messages!!!! */
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | va_start (args, fmt);
|
---|
66 | vsprintf (buf, fmt, args);
|
---|
67 | s = strrchr (buf, '\n');
|
---|
68 | if (!s || *(s + 1) != '\0')
|
---|
69 | strcat (buf, "\n");
|
---|
70 |
|
---|
71 | pfx = strrchr (msg_prefix, '/');
|
---|
72 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
73 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
74 |
|
---|
75 | }
|
---|