Add missing definition of _ macro.
[pspp] / lib / verror.c
1 /* va_list error handler for noninteractive utilities
2    Copyright (C) 2006-2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License along
15    with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Eric Blake.  */
19
20 #include <config.h>
21
22 #include "verror.h"
23 #include "xvasprintf.h"
24
25 #include <errno.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28
29 #if ENABLE_NLS
30 # include "gettext.h"
31 # define _(msgid) gettext (msgid)
32 #endif
33
34 #ifndef _
35 # define _(String) String
36 #endif
37
38 /* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
39    if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
40    If STATUS is nonzero, terminate the program with `exit (STATUS)'.
41    Use the globals error_print_progname and error_message_count similarly
42    to error().  */
43 void
44 verror (int status, int errnum, const char *format, va_list args)
45 {
46   verror_at_line (status, errnum, NULL, 0, format, args);
47 }
48
49 /* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
50    if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
51    If STATUS is nonzero, terminate the program with `exit (STATUS)'.
52    If FNAME is not NULL, prepend the message with `FNAME:LINENO:'.
53    Use the globals error_print_progname, error_message_count, and
54    error_one_per_line similarly to error_at_line().  */
55 void
56 verror_at_line (int status, int errnum, const char *file,
57                 unsigned int line_number, const char *format, va_list args)
58 {
59   char *message = xvasprintf (format, args);
60   if (message)
61     {
62       /* Until http://sourceware.org/bugzilla/show_bug.cgi?id=2997 is fixed,
63          glibc violates GNU Coding Standards when the file argument to
64          error_at_line is NULL.  */
65       if (file)
66         error_at_line (status, errnum, file, line_number, "%s", message);
67       else
68         error (status, errnum, "%s", message);
69     }
70   else
71     {
72       /* EOVERFLOW, EINVAL, and EILSEQ from xvasprintf are signs of
73          serious programmer errors.  */
74       error (0, errno, _("unable to display error message"));
75       abort ();
76     }
77   free (message);
78 }