[13] | 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.c 23 1998-11-23 03:42:14Z rjmcnab $
|
---|
| 21 | *
|
---|
| 22 | **************************************************************************/
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | $Log$
|
---|
[23] | 26 | Revision 1.2 1998/11/23 03:38:06 rjmcnab
|
---|
[13] | 27 |
|
---|
[23] | 28 | combined unix and windows versions of mg
|
---|
| 29 |
|
---|
| 30 | Revision 1.1 1998/11/19 03:00:32 sjboddie
|
---|
| 31 | Added windows gdbm and mg versions
|
---|
| 32 |
|
---|
[13] | 33 | * Revision 1.1 1994/08/22 00:24:48 tes
|
---|
| 34 | * Initial placement under CVS.
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | static char *RCSID = "$Id: messages.c 23 1998-11-23 03:42:14Z rjmcnab $";
|
---|
| 39 |
|
---|
| 40 | #include "sysfuncs.h"
|
---|
| 41 |
|
---|
| 42 | #include <stdarg.h>
|
---|
| 43 | #include "messages.h"
|
---|
| 44 |
|
---|
| 45 | char *msg_prefix = "";
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | void VOLATILE
|
---|
| 49 | FatalError (int ExitCode, const char *fmt,...)
|
---|
| 50 | {
|
---|
| 51 | char buf[1024];
|
---|
| 52 | char *s, *pfx;
|
---|
| 53 | va_list args;
|
---|
| 54 | va_start (args, fmt);
|
---|
| 55 | vsprintf (buf, fmt, args);
|
---|
| 56 | s = strrchr (buf, '\n');
|
---|
| 57 | if (!s || *(s + 1) != '\0')
|
---|
| 58 | strcat (buf, "\n");
|
---|
| 59 | pfx = strrchr (msg_prefix, '/');
|
---|
| 60 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
| 61 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
| 62 | exit (ExitCode);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | /*
|
---|
| 68 | * This function writes messages to stderr. Due to the fact that I can't
|
---|
| 69 | * guarantee that the fprintf call is monatomic I have to implement a
|
---|
| 70 | * semaphore system.
|
---|
| 71 | */
|
---|
| 72 | void
|
---|
| 73 | Message (const char *fmt,...)
|
---|
| 74 | {
|
---|
| 75 | char buf[1024];
|
---|
| 76 | char *s, *pfx;
|
---|
| 77 | va_list args;
|
---|
[23] | 78 |
|
---|
| 79 | #ifdef QUIET
|
---|
| 80 | return; /* stop those messages!!!! */
|
---|
| 81 | #endif
|
---|
| 82 |
|
---|
[13] | 83 | va_start (args, fmt);
|
---|
| 84 | vsprintf (buf, fmt, args);
|
---|
| 85 | s = strrchr (buf, '\n');
|
---|
| 86 | if (!s || *(s + 1) != '\0')
|
---|
| 87 | strcat (buf, "\n");
|
---|
| 88 |
|
---|
| 89 | pfx = strrchr (msg_prefix, '/');
|
---|
| 90 | pfx = pfx ? pfx + 1 : msg_prefix;
|
---|
| 91 | fprintf (stderr, "%s%s%s", pfx, *pfx ? " : " : "", buf);
|
---|
| 92 |
|
---|
| 93 | }
|
---|