"Fossies" - the Fresh Open Source Software Archive

Member "poppler-0.82.0/poppler/Error.cc" (25 Oct 2019, 2726 Bytes) of package /linux/misc/poppler-0.82.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Error.cc" see the Fossies "Dox" file reference documentation.

    1 //========================================================================
    2 //
    3 // Error.cc
    4 //
    5 // Copyright 1996-2003 Glyph & Cog, LLC
    6 //
    7 //========================================================================
    8 
    9 //========================================================================
   10 //
   11 // Modified under the Poppler project - http://poppler.freedesktop.org
   12 //
   13 // All changes made under the Poppler project to this file are licensed
   14 // under GPL version 2 or later
   15 //
   16 // Copyright (C) 2005, 2007 Jeff Muizelaar <jeff@infidigm.net>
   17 // Copyright (C) 2005, 2018 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, 2017 Adrian Johnson <ajohnson@redneon.com>
   21 //
   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
   24 //
   25 //========================================================================
   26 
   27 #include <config.h>
   28 #include <poppler-config.h>
   29 
   30 #include <stdio.h>
   31 #include <stddef.h>
   32 #include <stdarg.h>
   33 #include "GooString.h"
   34 #include "GlobalParams.h"
   35 #include "Error.h"
   36 
   37 static const char *errorCategoryNames[] = {
   38   "Syntax Warning",
   39   "Syntax Error",
   40   "Config Error",
   41   "Command Line Error",
   42   "I/O Error",
   43   "Permission Error",
   44   "Unimplemented Feature",
   45   "Internal Error"
   46 };
   47 
   48 static void (*errorCbk)(void *data, ErrorCategory category,
   49             Goffset pos, const char *msg) = nullptr;
   50 static void *errorCbkData = nullptr;
   51 
   52 void setErrorCallback(void (*cbk)(void *data, ErrorCategory category,
   53                   Goffset pos, const char *msg),
   54               void *data) {
   55   errorCbk = cbk;
   56   errorCbkData = data;
   57 }
   58 
   59 void CDECL error(ErrorCategory category, Goffset pos, const char *msg, ...) {
   60   va_list args;
   61   GooString *s, *sanitized;
   62 
   63   // NB: this can be called before the globalParams object is created
   64   if (!errorCbk && globalParams && globalParams->getErrQuiet()) {
   65     return;
   66   }
   67   va_start(args, msg);
   68   s = GooString::formatv(msg, args);
   69   va_end(args);
   70 
   71   sanitized = new GooString ();
   72   for (int i = 0; i < s->getLength(); ++i) {
   73     const char c = s->getChar(i);
   74     if (c < (char)0x20 || c >= (char)0x7f) {
   75       sanitized->appendf("<{0:02x}>", c & 0xff);
   76     } else {
   77       sanitized->append(c);
   78     }
   79   }
   80 
   81   if (errorCbk) {
   82     (*errorCbk)(errorCbkData, category, pos, sanitized->c_str());
   83   } else {
   84     if (pos >= 0) {
   85       fprintf(stderr, "%s (%lld): %s\n",
   86           errorCategoryNames[category], (long long)pos, sanitized->c_str());
   87     } else {
   88       fprintf(stderr, "%s: %s\n",
   89           errorCategoryNames[category], sanitized->c_str());
   90     }
   91     fflush(stderr);
   92   }
   93   delete s;
   94   delete sanitized;
   95 }