1 : /* -*- mode: C -*-
2 : *
3 : * File: pdf-error.c
4 : * Date: Sun Feb 24 20:22:05 2008
5 : *
6 : * GNU PDF Library - Implementation for the Error module
7 : *
8 : */
9 :
10 : /* Copyright (C) 2008 Free Software Foundation, Inc. */
11 :
12 : /* This program is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU General Public License as published by
14 : * the Free Software Foundation, either version 3 of the License, or
15 : * (at your option) any later version.
16 : *
17 : * This program is distributed in the hope that it will be useful,
18 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : * GNU General Public License for more details.
21 : *
22 : * You should have received a copy of the GNU General Public License
23 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 : */
25 :
26 : #include <config.h>
27 :
28 : #include <stdio.h>
29 : #include <stdlib.h>
30 : #include <stdarg.h>
31 :
32 : #include <pdf-global.h>
33 : #include <pdf-error.h>
34 :
35 : extern char *pdf_library_name;
36 :
37 : /* Update this list according to pdf_status_t. */
38 : #define ERROR_ENTRY(id, string) string
39 : const char * pdf_error_stlist [] =
40 : {
41 : PDF_ERROR_LIST
42 : };
43 : #undef ERROR_ENTRY
44 :
45 : void
46 : pdf_perror (const pdf_status_t status, const char *str)
47 2 : {
48 2 : pdf_error ((int) status, stderr, str);
49 2 : }
50 :
51 :
52 : void
53 : pdf_error (const pdf_status_t status, FILE * fd, const char *format, ...)
54 20 : {
55 : va_list args;
56 : int errnum;
57 :
58 20 : errnum = (int) status;
59 :
60 20 : if (fd == NULL)
61 : {
62 1 : fd = stderr;
63 : }
64 :
65 20 : fprintf (fd, "%s", pdf_library_name);
66 :
67 20 : if (format != NULL)
68 : {
69 18 : fprintf (fd, ": ");
70 18 : va_start (args, format);
71 18 : vfprintf (fd, format, args);
72 18 : va_end (args);
73 : }
74 :
75 20 : if (errnum > 0 && errnum < PDF_STATUS_ITEMS)
76 14 : fprintf (fd, ": %s", pdf_error_stlist[errnum-1]);
77 :
78 20 : fprintf (fd, ".\n");
79 20 : fflush (fd);
80 :
81 20 : }
82 :
83 : /* End of pdf-error.c */
|