|
Packit |
df99a1 |
//C- -*- C++ -*-
|
|
Packit |
df99a1 |
//C- -------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5
|
|
Packit |
df99a1 |
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
|
|
Packit |
df99a1 |
//C- Copyright (c) 2001 AT&T
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This program is distributed in the hope that it will be useful,
|
|
Packit |
df99a1 |
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
df99a1 |
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
df99a1 |
//C- GNU General Public License for more details.
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
|
|
Packit |
df99a1 |
//C- Lizardtech Software. Lizardtech Software has authorized us to
|
|
Packit |
df99a1 |
//C- replace the original DjVu(r) Reference Library notice by the following
|
|
Packit |
df99a1 |
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- ------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- | DjVu (r) Reference Library (v. 3.5)
|
|
Packit |
df99a1 |
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
|
|
Packit |
df99a1 |
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
|
|
Packit |
df99a1 |
//C- | 6,058,214 and patents pending.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- | GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- | or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- | accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- | from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The computer code originally released by LizardTech under this
|
|
Packit |
df99a1 |
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
|
|
Packit |
df99a1 |
//C- | ORIGINAL CODE." Subject to any third party intellectual property
|
|
Packit |
df99a1 |
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
|
|
Packit |
df99a1 |
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
|
|
Packit |
df99a1 |
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
|
|
Packit |
df99a1 |
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
|
|
Packit |
df99a1 |
//C- | General Public License. This grant only confers the right to
|
|
Packit |
df99a1 |
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
|
|
Packit |
df99a1 |
//C- | the extent such infringement is reasonably necessary to enable
|
|
Packit |
df99a1 |
//C- | recipient to make, have made, practice, sell, or otherwise dispose
|
|
Packit |
df99a1 |
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
|
|
Packit |
df99a1 |
//C- | any greater extent that may be necessary to utilize further
|
|
Packit |
df99a1 |
//C- | modifications or combinations.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
|
|
Packit |
df99a1 |
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
Packit |
df99a1 |
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
|
|
Packit |
df99a1 |
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
df99a1 |
//C- +------------------------------------------------------------------
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifndef _DEBUG_H_
|
|
Packit |
df99a1 |
#define _DEBUG_H_
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
df99a1 |
# include "config.h"
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if NEED_GNUG_PRAGMAS
|
|
Packit |
df99a1 |
# pragma interface
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include <stdio.h>
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_NAMESPACES
|
|
Packit |
df99a1 |
namespace DJVU {
|
|
Packit |
df99a1 |
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** @name debug.h
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Files #"debug.h"# and #"debug.cpp"# implement means to print debug
|
|
Packit |
df99a1 |
messages in a multithread safe way. Message are also marked with a thread
|
|
Packit |
df99a1 |
identifier. Under Windows, debug messages are directly sent to the
|
|
Packit |
df99a1 |
debugger using the Win32 function #OutputDebugString#. Under Unix, debug
|
|
Packit |
df99a1 |
messages are printed on the controlling terminal, preferably using device
|
|
Packit |
df99a1 |
#/dev/tty#.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
The preprocessor variable #DEBUGLVL# defines which debug code is going to
|
|
Packit |
df99a1 |
be compiled. Selecting #-DDEBUGLVL=0# (the default) disables all
|
|
Packit |
df99a1 |
debugging code. Selecting a positive values (e.g. #-DDEBUGLVL=4#) enables
|
|
Packit |
df99a1 |
more and more debugging code.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Message output is controlled by the current debugging level (an integer
|
|
Packit |
df99a1 |
between #0# and #DEBUGLVL#). Greater values enable more messages. The
|
|
Packit |
df99a1 |
initial debugging level is set to the maximum value. The debugging level
|
|
Packit |
df99a1 |
can be changed using macro \Ref{DEBUG_SET_LEVEL}.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Message indentation can be modified using macro \Ref{DEBUG_MAKE_INDENT}.
|
|
Packit |
df99a1 |
Messages are generated by macro \Ref{DEBUG_MSG} or its variants. The
|
|
Packit |
df99a1 |
argument of the macro can contain several components separated by operator
|
|
Packit |
df99a1 |
#<<#, as demonstrated in the example below:
|
|
Packit |
df99a1 |
\begin{verbatim}
|
|
Packit |
df99a1 |
DEBUG_MSG("The value of a[" << n << "] is " << a[n] << '\n');
|
|
Packit |
df99a1 |
\end{verbatim}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
One more preprocessor variable #RUNTIME_DEBUG_ONLY# enables compilation
|
|
Packit |
df99a1 |
of debug code, but does not enable the debug messages automatically.
|
|
Packit |
df99a1 |
In order to see them the program should use \Ref{DEBUG_SET_LEVEL} to
|
|
Packit |
df99a1 |
change the level to anything greater than 0. Normally this happens when
|
|
Packit |
df99a1 |
user specifies option #-debug# in the command line. Usage of
|
|
Packit |
df99a1 |
#RUNTIME_DEBUG_ONLY# implies #DEBUGLVL=1# if not specified otherwise.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Finally, #-DNO_DEBUG# or #-DNDEBUG# can be used instead of #-DDEBUGLVL=0#,
|
|
Packit |
df99a1 |
and #-D_DEBUG# can be used instead of #-DDEBUGLVL=0#.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf Historical Comment} --- Debug macros are rarely used in the reference
|
|
Packit |
df99a1 |
DjVu library because Leon thinks that debugging messages unnecessarily
|
|
Packit |
df99a1 |
clutter the code. Debug macros are used everywhere in the plugin code
|
|
Packit |
df99a1 |
because Andrew thinks that code without debugging messages is close to
|
|
Packit |
df99a1 |
useless. No agreement could be reached. Neither could they agree on
|
|
Packit |
df99a1 |
if cluttering header files with huge documentation chunks helps to
|
|
Packit |
df99a1 |
improve code readability.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
@memo
|
|
Packit |
df99a1 |
Macros for printing debug messages.
|
|
Packit |
df99a1 |
@author
|
|
Packit |
df99a1 |
Andrew Erofeev <eaf@geocities.com> -- initial implementation \\
|
|
Packit |
df99a1 |
Leon Bottou <leonb@research.att.com> -- cleanups */
|
|
Packit |
df99a1 |
//@{
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifndef DEBUGLVL
|
|
Packit |
df99a1 |
# ifdef NDEBUG
|
|
Packit |
df99a1 |
# define DEBUGLVL 0
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#ifndef DEBUGLVL
|
|
Packit |
df99a1 |
# ifdef NO_DEBUG
|
|
Packit |
df99a1 |
# define DEBUGLVL 0
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#ifndef DEBUGLVL
|
|
Packit |
df99a1 |
# ifdef RUNTIME_DEBUG_ONLY
|
|
Packit |
df99a1 |
# define DEBUGLVL 1
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#ifndef DEBUGLVL
|
|
Packit |
df99a1 |
# ifdef _DEBUG
|
|
Packit |
df99a1 |
# define DEBUGLVL 1
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#ifndef DEBUGLVL
|
|
Packit |
df99a1 |
# define DEBUGLVL 0
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if DEBUGLVL <= 0
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
# ifndef NO_DEBUG
|
|
Packit |
df99a1 |
# define NO_DEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
# ifndef NDEBUG
|
|
Packit |
df99a1 |
# define NDEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
# ifdef _DEBUG
|
|
Packit |
df99a1 |
# undef _DEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
# define DEBUG_MAKE_INDENT(x)
|
|
Packit |
df99a1 |
# define DEBUG_SET_LEVEL(level)
|
|
Packit |
df99a1 |
# define DEBUG_MSG_LVL(level,x)
|
|
Packit |
df99a1 |
# define DEBUG_MSGN_LVL(level,x)
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
# ifdef NO_DEBUG
|
|
Packit |
df99a1 |
# undef NO_DEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
# ifdef NDEBUG
|
|
Packit |
df99a1 |
# undef NDEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
# ifndef _DEBUG
|
|
Packit |
df99a1 |
# define _DEBUG
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class GUTF8String;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// ------------ SUPPORT
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DjVuDebug // DJVU_CLASS
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
private:
|
|
Packit |
df99a1 |
int id;
|
|
Packit |
df99a1 |
int block;
|
|
Packit |
df99a1 |
int indent;
|
|
Packit |
df99a1 |
void format(const char *fmt, ... );
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
// construction
|
|
Packit |
df99a1 |
DjVuDebug();
|
|
Packit |
df99a1 |
~DjVuDebug();
|
|
Packit |
df99a1 |
// access
|
|
Packit |
df99a1 |
static void set_debug_level(int lvl);
|
|
Packit |
df99a1 |
static void set_debug_file(FILE * file);
|
|
Packit |
df99a1 |
void modify_indent(int rindent);
|
|
Packit |
df99a1 |
static DjVuDebug& lock(int lvl, int noindent);
|
|
Packit |
df99a1 |
void unlock();
|
|
Packit |
df99a1 |
// printing
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(bool b);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(char c);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(unsigned char c);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(int i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(unsigned int i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(short int i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(unsigned short int i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(long i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(unsigned long i);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(const char * const ptr);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(const unsigned char * const ptr);
|
|
Packit |
df99a1 |
DjVuDebug& operator<<(const GUTF8String &ptr);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(float f);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(double d);
|
|
Packit |
df99a1 |
DjVuDebug & operator<<(const void * const p);
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DjVuDebugIndent // DJVU_CLASS
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
private:
|
|
Packit |
df99a1 |
int inc;
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
DjVuDebugIndent(int inc=2);
|
|
Packit |
df99a1 |
~DjVuDebugIndent();
|
|
Packit |
df99a1 |
//#define DEBUG_MAKE_INDENT_2(x, y) DjVuDebugIndent debug_indent ## y (x)
|
|
Packit |
df99a1 |
//#define DEBUG_MAKE_INDENT_1(x, y) DEBUG_MAKE_INDENT_2(x, y)
|
|
Packit |
df99a1 |
#define DEBUG_MAKE_INDENT_1(x, y) DjVuDebugIndent debug_indent ## y (x)
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// ------------ MAIN MACROS
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
# define DEBUG_MAKE_INDENT(x) DEBUG_MAKE_INDENT_1(x, __LINE__)
|
|
Packit |
df99a1 |
# define DEBUG_SET_LEVEL(level) DjVuDebug::set_debug_level(level)
|
|
Packit |
df99a1 |
# define DEBUG_MSG_LVL(level,x) { ( DjVuDebug::lock(level,0) << x ).unlock(); }
|
|
Packit |
df99a1 |
# define DEBUG_MSGN_LVL(level,x) { ( DjVuDebug::lock(level,1) << x ).unlock(); }
|
|
Packit |
df99a1 |
# define DEBUG_MSGF_LVL(level,x) { ( DjVuDebug::lock(level,1) << x ).unlock(); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// ------------ EAF MACROS
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if ( DEBUGLVL >= 1 )
|
|
Packit |
df99a1 |
/** Generates a level 1 message */
|
|
Packit |
df99a1 |
# define DEBUG1_MSG(x) DEBUG_MSG_LVL(1,x)
|
|
Packit |
df99a1 |
# define DEBUG1_MSGF(x) DEBUG_MSGF_LVL(1,x)
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
# define DEBUG1_MSG(x)
|
|
Packit |
df99a1 |
# define DEBUG1_MSGF(x)
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if ( DEBUGLVL >= 2 )
|
|
Packit |
df99a1 |
/** Generates a level 2 message */
|
|
Packit |
df99a1 |
# define DEBUG2_MSG(x) DEBUG_MSG_LVL(2,x)
|
|
Packit |
df99a1 |
# define DEBUG2_MSGF(x) DEBUG_MSGF_LVL(2,x)
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
# define DEBUG2_MSG(x)
|
|
Packit |
df99a1 |
# define DEBUG2_MSGF(x)
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if ( DEBUGLVL >= 3 )
|
|
Packit |
df99a1 |
/** Generates a level 3 message */
|
|
Packit |
df99a1 |
# define DEBUG3_MSG(x) DEBUG_MSG_LVL(3,x)
|
|
Packit |
df99a1 |
# define DEBUG3_MSGF(x) DEBUG_MSGF_LVL(3,x)
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
# define DEBUG3_MSG(x)
|
|
Packit |
df99a1 |
# define DEBUG3_MSGF(x)
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if ( DEBUGLVL >= 4 )
|
|
Packit |
df99a1 |
/** Generates a level 4 message */
|
|
Packit |
df99a1 |
# define DEBUG4_MSG(x) DEBUG_MSG_LVL(4,x)
|
|
Packit |
df99a1 |
# define DEBUG4_MSGF(x) DEBUG_MSGF_LVL(4,x)
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
# define DEBUG4_MSG(x)
|
|
Packit |
df99a1 |
# define DEBUG4_MSGF(x)
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#define DEBUG_RUNTIME_SET_LEVEL(level) DEBUG_SET_LEVEL(level)
|
|
Packit |
df99a1 |
/** Generates a level 1 message. */
|
|
Packit |
df99a1 |
#define DEBUG_MSG(x) DEBUG1_MSG(x)
|
|
Packit |
df99a1 |
/** Generates a level 1 message without indentation. */
|
|
Packit |
df99a1 |
#define DEBUG_MSGF(x) DEBUG1_MSGF(x)
|
|
Packit |
df99a1 |
/** Generates a level 1 message terminated with a newline. */
|
|
Packit |
df99a1 |
#define DEBUG_MSGN(x) DEBUG_MSG(x<<'\n')
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
//@}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// ------------ THE END
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_NAMESPACES
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
# ifndef NOT_USING_DJVU_NAMESPACE
|
|
Packit |
df99a1 |
using namespace DJVU;
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#endif // DEBUG_H
|