~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WINGs/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Window Maker miscelaneous function library
 
3
 *
 
4
 *  Copyright (c) 1997-2003 Alfredo K. Kojima
 
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 "wconfig.h"
 
23
 
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <stdarg.h>
 
27
#include <string.h>
 
28
#include <errno.h>
 
29
 
 
30
extern char *_WINGS_progname;
 
31
 
 
32
 
 
33
#define MAXLINE 1024
 
34
 
 
35
 
 
36
/*********************************************************************
 
37
 * Returns the system error message associated with error code 'errnum'
 
38
 *********************************************************************/
 
39
char*
 
40
wstrerror(int errnum)
 
41
{
 
42
#if defined(HAVE_STRERROR)
 
43
    return strerror(errnum);
 
44
#elif !defined(HAVE_STRERROR) && defined(BSD)
 
45
    extern int errno, sys_nerr;
 
46
#  ifndef __DECC
 
47
    extern char *sys_errlist[];
 
48
#  endif
 
49
    static char buf[] = "Unknown error 12345678901234567890";
 
50
 
 
51
    if (errno < sys_nerr)
 
52
        return sys_errlist[errnum];
 
53
 
 
54
    snprintf(buf, sizeof(buf), _("Unknown error %d"), errnum);
 
55
    return buf;
 
56
#else /* no strerror() and no sys_errlist[] */
 
57
    static char buf[] = "Error 12345678901234567890";
 
58
 
 
59
    snprintf(buf, sizeof(buf), _("Error %d"), errnum);
 
60
    return buf;
 
61
#endif
 
62
}
 
63
 
 
64
 
 
65
/*********************************************************************
 
66
 * Prints a message with variable arguments
 
67
 *
 
68
 * msg - message to print with optional formatting
 
69
 * ... - arguments to use on formatting
 
70
 *********************************************************************/
 
71
void
 
72
wmessage(const char *msg, ...)
 
73
{
 
74
    va_list args;
 
75
    char buf[MAXLINE];
 
76
 
 
77
    va_start(args, msg);
 
78
 
 
79
    vsnprintf(buf, MAXLINE-3, msg, args);
 
80
    strcat(buf,"\n");
 
81
    fflush(stdout);
 
82
    fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
 
83
    fputs(": ",stderr);
 
84
    fputs(buf, stderr);
 
85
    fflush(stdout);
 
86
    fflush(stderr);
 
87
 
 
88
    va_end(args);
 
89
}
 
90
 
 
91
 
 
92
/*********************************************************************
 
93
 * Prints a warning message with variable arguments
 
94
 *
 
95
 * msg - message to print with optional formatting
 
96
 * ... - arguments to use on formatting
 
97
 *********************************************************************/
 
98
void
 
99
wwarning(const char *msg, ...)
 
100
{
 
101
    va_list args;
 
102
    char buf[MAXLINE];
 
103
 
 
104
    va_start(args, msg);
 
105
 
 
106
    vsnprintf(buf, MAXLINE-3, msg, args);
 
107
    strcat(buf,"\n");
 
108
    fflush(stdout);
 
109
    fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
 
110
    fputs(_(" warning: "),stderr);
 
111
    fputs(buf, stderr);
 
112
    fflush(stdout);
 
113
    fflush(stderr);
 
114
 
 
115
    va_end(args);
 
116
}
 
117
 
 
118
 
 
119
/**************************************************************************
 
120
 * Prints a fatal error message with variable arguments and terminates
 
121
 *
 
122
 * msg - message to print with optional formatting
 
123
 * ... - arguments to use on formatting
 
124
 **************************************************************************/
 
125
void
 
126
wfatal(const char *msg, ...)
 
127
{
 
128
    va_list args;
 
129
    char buf[MAXLINE];
 
130
 
 
131
    va_start(args, msg);
 
132
 
 
133
    vsnprintf(buf, MAXLINE-3, msg, args);
 
134
    strcat(buf,"\n");
 
135
    fflush(stdout);
 
136
    fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
 
137
    fputs(_(" fatal error: "),stderr);
 
138
    fputs(buf, stderr);
 
139
    fflush(stdout);
 
140
    fflush(stderr);
 
141
 
 
142
    va_end(args);
 
143
}
 
144
 
 
145
 
 
146
/*********************************************************************
 
147
 * Prints a system error message with variable arguments
 
148
 *
 
149
 * msg - message to print with optional formatting
 
150
 * ... - arguments to use on formatting
 
151
 *********************************************************************/
 
152
void
 
153
wsyserror(const char *msg, ...)
 
154
{
 
155
    va_list args;
 
156
    char buf[MAXLINE];
 
157
    int error=errno;
 
158
 
 
159
    va_start(args, msg);
 
160
    vsnprintf(buf, MAXLINE-3, msg, args);
 
161
    fflush(stdout);
 
162
    fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
 
163
    fputs(_(" error: "), stderr);
 
164
    fputs(buf, stderr);
 
165
    fputs(": ", stderr);
 
166
    fputs(wstrerror(error), stderr);
 
167
    fputs("\n", stderr);
 
168
    fflush(stderr);
 
169
    fflush(stdout);
 
170
    va_end(args);
 
171
}
 
172
 
 
173
 
 
174
/*********************************************************************
 
175
 * Prints a system error message with variable arguments, being given
 
176
 * the error code.
 
177
 *
 
178
 * error - the error code foe which to print the message
 
179
 * msg   - message to print with optional formatting
 
180
 * ...   - arguments to use on formatting
 
181
 *********************************************************************/
 
182
void
 
183
wsyserrorwithcode(int error, const char *msg, ...)
 
184
{
 
185
    va_list args;
 
186
    char buf[MAXLINE];
 
187
 
 
188
    va_start(args, msg);
 
189
    vsnprintf(buf, MAXLINE-3, msg, args);
 
190
    fflush(stdout);
 
191
    fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
 
192
    fputs(_(" error: "), stderr);
 
193
    fputs(buf, stderr);
 
194
    fputs(": ", stderr);
 
195
    fputs(wstrerror(error), stderr);
 
196
    fputs("\n", stderr);
 
197
    fflush(stderr);
 
198
    fflush(stdout);
 
199
    va_end(args);
 
200
}
 
201
 
 
202