Files
wmaker/WINGs/error.c
T

203 lines
5.3 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/*
1998-10-21 14:43:47 +00:00
* Window Maker miscelaneous function library
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1997-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
2001-07-23 20:31:32 +00:00
#include "wconfig.h"
1998-09-29 22:36:29 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
extern char *_WINGS_progname;
1998-09-29 22:36:29 +00:00
#define MAXLINE 1024
/*********************************************************************
* Returns the system error message associated with error code 'errnum'
*********************************************************************/
char*
wstrerror(int errnum)
{
#if defined(HAVE_STRERROR)
return strerror(errnum);
#elif !defined(HAVE_STRERROR) && defined(BSD)
extern int errno, sys_nerr;
# ifndef __DECC
extern char *sys_errlist[];
# endif
1999-12-12 20:35:12 +00:00
static char buf[] = "Unknown error 12345678901234567890";
if (errno < sys_nerr)
return sys_errlist[errnum];
2001-07-23 20:31:32 +00:00
sprintf (buf, _("Unknown error %d"), errnum);
return buf;
#else /* no strerror() and no sys_errlist[] */
1999-12-12 20:35:12 +00:00
static char buf[] = "Error 12345678901234567890";
2001-07-23 20:31:32 +00:00
sprintf(buf, _("Error %d"), errnum);
return buf;
#endif
}
/*********************************************************************
* Prints a message with variable arguments
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* msg - message to print with optional formatting
* ... - arguments to use on formatting
*********************************************************************/
void
wmessage(const char *msg, ...)
1998-09-29 22:36:29 +00:00
{
va_list args;
char buf[MAXLINE];
va_start(args, msg);
2000-10-01 03:05:25 +00:00
vsnprintf(buf, MAXLINE-3, msg, args);
1998-09-29 22:36:29 +00:00
strcat(buf,"\n");
fflush(stdout);
fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
fputs(": ",stderr);
1998-09-29 22:36:29 +00:00
fputs(buf, stderr);
1998-10-21 14:43:47 +00:00
fflush(stdout);
fflush(stderr);
1998-09-29 22:36:29 +00:00
va_end(args);
}
/*********************************************************************
2004-10-12 21:28:27 +00:00
* Prints a warning message with variable arguments
*
1998-09-29 22:36:29 +00:00
* msg - message to print with optional formatting
* ... - arguments to use on formatting
*********************************************************************/
2004-10-12 21:28:27 +00:00
void
1998-09-29 22:36:29 +00:00
wwarning(const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
va_start(args, msg);
2004-10-12 21:28:27 +00:00
2000-10-01 03:05:25 +00:00
vsnprintf(buf, MAXLINE-3, msg, args);
1998-09-29 22:36:29 +00:00
strcat(buf,"\n");
fflush(stdout);
fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
2001-07-23 20:31:32 +00:00
fputs(_(" warning: "),stderr);
1998-09-29 22:36:29 +00:00
fputs(buf, stderr);
1998-10-21 14:43:47 +00:00
fflush(stdout);
fflush(stderr);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
va_end(args);
}
/**************************************************************************
* Prints a fatal error message with variable arguments and terminates
2004-10-12 21:28:27 +00:00
*
* msg - message to print with optional formatting
2004-10-12 21:28:27 +00:00
* ... - arguments to use on formatting
**************************************************************************/
2004-10-12 21:28:27 +00:00
void
wfatal(const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
va_start(args, msg);
vsnprintf(buf, MAXLINE-3, msg, args);
strcat(buf,"\n");
fflush(stdout);
fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
2001-07-23 20:31:32 +00:00
fputs(_(" fatal error: "),stderr);
fputs(buf, stderr);
fflush(stdout);
fflush(stderr);
va_end(args);
}
1998-09-29 22:36:29 +00:00
/*********************************************************************
2004-10-12 21:28:27 +00:00
* Prints a system error message with variable arguments
*
1998-09-29 22:36:29 +00:00
* msg - message to print with optional formatting
* ... - arguments to use on formatting
*********************************************************************/
2004-10-12 21:28:27 +00:00
void
1998-09-29 22:36:29 +00:00
wsyserror(const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
int error=errno;
1998-09-29 22:36:29 +00:00
va_start(args, msg);
2000-10-01 03:05:25 +00:00
vsnprintf(buf, MAXLINE-3, msg, args);
1998-09-29 22:36:29 +00:00
fflush(stdout);
fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
2001-07-23 20:31:32 +00:00
fputs(_(" error: "), stderr);
1998-09-29 22:36:29 +00:00
fputs(buf, stderr);
2000-10-01 03:05:25 +00:00
fputs(": ", stderr);
fputs(wstrerror(error), stderr);
fputs("\n", stderr);
1998-10-21 14:43:47 +00:00
fflush(stderr);
fflush(stdout);
1998-09-29 22:36:29 +00:00
va_end(args);
}
/*********************************************************************
* Prints a system error message with variable arguments, being given
* the error code.
2004-10-12 21:28:27 +00:00
*
* error - the error code foe which to print the message
* msg - message to print with optional formatting
* ... - arguments to use on formatting
*********************************************************************/
2004-10-12 21:28:27 +00:00
void
wsyserrorwithcode(int error, const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
va_start(args, msg);
2000-10-01 03:05:25 +00:00
vsnprintf(buf, MAXLINE-3, msg, args);
fflush(stdout);
fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
2001-07-23 20:31:32 +00:00
fputs(_(" error: "), stderr);
fputs(buf, stderr);
2000-10-01 03:05:25 +00:00
fputs(": ", stderr);
fputs(wstrerror(error), stderr);
fputs("\n", stderr);
fflush(stderr);
fflush(stdout);
va_end(args);
}