1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005, 2007 Jeff Muizelaar <jeff@infidigm.net>
17 // Copyright (C) 2005 Albert Astals Cid <aacid@kde.org>
18 // Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
19 // Copyright (C) 2012 Marek Kasik <mkasik@redhat.com>
20 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
22 // To see a description of the changes please see the Changelog file that
23 // came with your tarball or type make ChangeLog if you are building from git
25 //========================================================================
29 #ifdef USE_GCC_PRAGMAS
30 #pragma implementation
36 #include "GooString.h"
37 #include "GlobalParams.h"
40 static const char *errorCategoryNames
[] = {
47 "Unimplemented Feature",
51 static void (*errorCbk
)(void *data
, ErrorCategory category
,
52 Goffset pos
, char *msg
) = NULL
;
53 static void *errorCbkData
= NULL
;
55 void setErrorCallback(void (*cbk
)(void *data
, ErrorCategory category
,
56 Goffset pos
, char *msg
),
62 void CDECL
error(ErrorCategory category
, Goffset pos
, const char *msg
, ...) {
64 GooString
*s
, *sanitized
;
66 // NB: this can be called before the globalParams object is created
67 if (!errorCbk
&& globalParams
&& globalParams
->getErrQuiet()) {
71 s
= GooString::formatv(msg
, args
);
74 sanitized
= new GooString ();
75 for (int i
= 0; i
< s
->getLength(); ++i
) {
76 const char c
= s
->getChar(i
);
77 if (c
< (char)0x20 || c
>= (char)0x7f) {
78 sanitized
->appendf("<{0:02x}>", c
& 0xff);
85 (*errorCbk
)(errorCbkData
, category
, pos
, sanitized
->getCString());
88 fprintf(stderr
, "%s (%lld): %s\n",
89 errorCategoryNames
[category
], (long long)pos
, sanitized
->getCString());
91 fprintf(stderr
, "%s: %s\n",
92 errorCategoryNames
[category
], sanitized
->getCString());