source: trunk/libdjvu/DjVuGlobal.h @ 269

Last change on this file since 269 was 206, checked in by Eugene Romanenko, 14 years ago

DJVU plugin: djvulibre updated to version 3.5.19

File size: 14.0 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, either Version 2 of the license,
9//C- or (at your option) any later version. The license should have
10//C- accompanied the software or you may obtain a copy of the license
11//C- from the Free Software Foundation at http://www.fsf.org .
12//C-
13//C- This program is distributed in the hope that it will be useful,
14//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//C- GNU General Public License for more details.
17//C-
18//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19//C- Lizardtech Software.  Lizardtech Software has authorized us to
20//C- replace the original DjVu(r) Reference Library notice by the following
21//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
22//C-
23//C-  ------------------------------------------------------------------
24//C- | DjVu (r) Reference Library (v. 3.5)
25//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27//C- | 6,058,214 and patents pending.
28//C- |
29//C- | This software is subject to, and may be distributed under, the
30//C- | GNU General Public License, either Version 2 of the license,
31//C- | or (at your option) any later version. The license should have
32//C- | accompanied the software or you may obtain a copy of the license
33//C- | from the Free Software Foundation at http://www.fsf.org .
34//C- |
35//C- | The computer code originally released by LizardTech under this
36//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37//C- | ORIGINAL CODE."  Subject to any third party intellectual property
38//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42//C- | General Public License.   This grant only confers the right to
43//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44//C- | the extent such infringement is reasonably necessary to enable
45//C- | recipient to make, have made, practice, sell, or otherwise dispose
46//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47//C- | any greater extent that may be necessary to utilize further
48//C- | modifications or combinations.
49//C- |
50//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54//C- +------------------------------------------------------------------
55//
56// $Id: DjVuGlobal.h,v 1.11 2007/03/25 20:48:30 leonb Exp $
57// $Name: release_3_5_19 $
58
59#ifndef _DJVUGLOBAL_H
60#define _DJVUGLOBAL_H
61#ifdef HAVE_CONFIG_H
62# include "config.h"
63#endif
64#if NEED_GNUG_PRAGMAS
65# pragma interface
66#endif
67
68#if defined(UNDER_CE)
69# ifndef __WCEALT_H__
70inline void * operator new(size_t, void * ptr) { return ptr; }
71# endif
72#elif defined(AUTOCONF) && defined(HAVE_STDINCLUDES)
73# include <new>
74#else
75# include <new.h>
76#endif
77
78#ifdef WIN32
79# ifdef DLL_EXPORT
80#  define DJVUAPI __declspec(dllexport)
81# else
82#  ifdef LIBDJVU_DLL_IMPORT
83#   define DJVUAPI __declspec(dllimport)
84#  endif
85# endif
86#endif
87#ifndef DJVUAPI
88# define DJVUAPI
89#endif
90
91
92/** @name DjVuGlobal.h
93
94    This file is included by all include files in the DjVu reference library.
95   
96        If compilation symbols #NEED_DJVU_MEMORY#, #NEED_DJVU_PROGRESS#
97        or #NEED_DJVU_NAMES# are defined, this file enables
98        features which are useful for certain applications of the
99    DjVu Reference Library.  These features are still experimental and
100    therefore poorly documented.
101   
102    @memo
103    Global definitions.
104    @version
105    #$Id: DjVuGlobal.h,v 1.11 2007/03/25 20:48:30 leonb Exp $#
106    @author
107    L\'eon Bottou <leonb@research.att.com> -- empty file.\\
108    Bill Riemers <docbill@sourceforge.net> -- real work.  */
109//@{
110
111
112/** @name DjVu Memory
113
114    This section is enabled when compilation symbol #NEED_DJVU_MEMORY# is
115    defined.  Function #_djvu_memory_callback# can be used to redefine the C++
116    memory allocation operators.  Some operating systems (e.g. Macintoshes)
117    require very peculiar memory allocation in shared objects.  We redefine
118    the operators #new# and #delete# as #STATIC_INLINE# because we do not
119    want to export these redefined versions to other libraries.  */
120//@{
121//@}
122
123#ifdef NEED_DJVU_MEMORY
124
125# include "DjVu.h"
126
127// These define the two callbacks needed for C++
128typedef void djvu_delete_callback(void *);
129typedef void *djvu_new_callback(size_t);
130
131// These functions allow users to set the callbacks.
132int djvu_memoryObject_callback ( djvu_delete_callback*, djvu_new_callback*);
133int djvu_memoryArray_callback ( djvu_delete_callback*, djvu_new_callback*);
134
135// We need to use this inline function in all modules, but we never want it to
136// appear in the symbol table.  It seems different compilers need different
137// directives to do this...
138# ifndef STATIC_INLINE
139#  ifdef __GNUC__
140#   define STATIC_INLINE extern inline
141#  else /* !__GNUC__ */
142#   define STATIC_INLINE static inline
143#  endif /* __GNUC__ */
144# endif /* STATIC_INLINE */
145
146// This clause is used when overriding operator new
147// because the standard has slightly changed.
148# if defined( __GNUC__ ) && ( __GNUC__*1000 + __GNUC_MINOR__ >= 2091 )
149#  ifndef new_throw_spec
150#   define new_throw_spec throw(std::bad_alloc)
151#  endif /* new_throw_spec */
152#  ifndef delete_throw_spec
153#   define delete_throw_spec throw()
154#  endif /* delete_throw_spec */
155# endif /* __GNUC__ ... */
156// Old style
157# ifndef new_throw_spec
158#  define new_throw_spec
159# endif /* new_throw_spec */
160# ifndef delete_throw_spec
161#  define delete_throw_spec
162# endif  /* delete_throw_spec */
163
164# ifdef UNIX
165extern djvu_new_callback *_djvu_new_ptr;
166extern djvu_new_callback *_djvu_newArray_ptr;
167extern djvu_delete_callback *_djvu_delete_ptr;
168extern djvu_delete_callback *_djvu_deleteArray_ptr;
169
170#  ifndef NEED_DJVU_MEMORY_IMPLEMENTATION
171void *operator new (size_t) new_throw_spec;
172void *operator new[] (size_t) new_throw_spec;
173void operator delete (void *) delete_throw_spec;
174void operator delete[] (void *) delete_throw_spec;
175
176STATIC_INLINE void *
177operator new(size_t sz) new_throw_spec
178{ return (*_djvu_new_ptr)(sz); }
179STATIC_INLINE void
180operator delete(void *addr) delete_throw_spec
181{ return (*_djvu_delete_ptr)(addr); }
182STATIC_INLINE void *
183operator new [] (size_t sz) new_throw_spec
184{ return (*_djvu_newArray_ptr)(sz); }
185STATIC_INLINE void
186operator delete [] (void *addr) delete_throw_spec
187{ return (*_djvu_deleteArray_ptr)(addr); }
188#  endif /* NEED_DJVU_MEMORY_IMPLEMENTATION */
189
190# else /* UNIX */
191
192#  ifndef NEED_DJVU_MEMORY_IMPLEMENTATION
193STATIC_INLINE void *
194operator new(size_t sz) new_throw_spec
195{ return _djvu_new(sz); }
196inline_as_macro void
197operator delete(void *addr) delete_throw_spec
198{ return _djvu_delete(addr); }
199inline_as_macro void *
200operator new [] (size_t sz) new_throw_spec
201{ return _djvu_new(sz); }
202inline_as_macro void
203operator delete [] (void *addr) delete_throw_spec
204{ _djvu_deleteArray(addr); }
205#  endif /* !NEED_DJVU_MEMORY_IMPLEMENTATION */
206
207# endif /* UNIX */
208
209#else
210
211# define _djvu_free(ptr) free((ptr))
212# define _djvu_malloc(siz) malloc((siz))
213# define _djvu_realloc(ptr,siz) realloc((ptr),(siz))
214# define _djvu_calloc(siz,items) calloc((siz),(items))
215
216#endif /* NEED_DJVU_MEMORY */
217
218/** @name DjVu Progress 
219
220    This section is enabled when compilation symbol #NEED_DJVU_PROGRESS# is
221    defined.  This macro setups callback function that may be used to
222    implement a progress indicator for the encoding routines.  The decoding
223    routines do not need such a facility because it is sufficient to monitor
224    the calls to function \Ref{ByteStream::read} in class \Ref{ByteStream}.
225   
226    {\bf Code tracing macros} ---
227    Monitoring the progress of such complex algorithms requires significant
228    code support.  This is achieved by inserting {\em code tracing macros}
229    in strategic regions of the code. 
230    \begin{description}
231    \item[DJVU_PROGRESS_TASK(name,task,nsteps)]  indicates that the current
232         scope performs a task roughly divided in #nsteps# equal steps, with
233               the specified #task# string used in the callback.
234    \item[DJVU_PROGRESS_RUN(name,tostep)] indicates that we are starting
235         an operation which will take us to step #tostep#.  The operation
236         will be considered finished when #DJVU_PROGRESS_RUN# will be called
237         again with an argument greater than #tostep#.  The execution of
238         this operation of course can be described by one subtask and so on.
239    \end{description}
240 
241    {\bf Progress callback} --- Before defining the outermost task, you can
242    store a callback function pointer into the static member variable
243    #DjVuProgressTask::callback#.  This callback function is called
244    periodically with two unsigned long arguments.  The first argument is the
245    elapsed time. The second argument is the estimated total execution time.
246    Both times are given in milliseconds.
247
248    {\bf Important Note} --- This monitoring mechanism should not be used by
249    multithreaded programs.  */
250//@{
251
252#ifndef HAS_DJVU_PROGRESS_CALLBACKS
253# define HAS_DJVU_PROGRESS_CALLBACKS
254
255# ifdef NEED_DJVU_PROGRESS
256#  include "DjVu.h"
257
258extern djvu_progress_callback *_djvu_progress_ptr;
259
260#  define DJVU_PROGRESS_TASK(name,task,nsteps)  DjVuProgressTask task_##name(task,nsteps)
261#  define DJVU_PROGRESS_RUN(name,tostep)   { task_##name.run(tostep); }
262
263class DjVuProgressTask
264{
265public:
266  class Data;
267  ~DjVuProgressTask();
268  DjVuProgressTask(const char *task,int nsteps);
269  void run(int tostep);
270  const char *task;
271  static djvu_progress_callback *set_callback(djvu_progress_callback *ptr=0);
272private:
273  DjVuProgressTask *parent;
274  int nsteps;
275  int runtostep;
276  unsigned long startdate;
277  // Statics
278  void *gdata;
279  Data *data;
280  // Helpers
281  void signal(unsigned long curdate, unsigned long estdate);
282};
283
284# else  // ! NEED_DJVU_PROGRESS
285
286#  define DJVU_PROGRESS_TASK(name,task,nsteps)
287#  define DJVU_PROGRESS_RUN(name,step)
288
289# endif // ! NEED_DJVU_PROGRESS
290#endif // HAS_DJVU_PROGRESS_CALLBACKS
291//@}
292
293
294/** @name General functions.
295
296    This section contains functions that replace some of the standard
297    system calls without any other header file dependancies.
298 */
299
300#ifdef __cplusplus
301# define DJVUEXTERNCAPI(x) extern "C" DJVUAPI x;
302#else
303# define DJVUEXTERNCAPI(x) extern DJVUAPI x
304#endif
305
306/** This replaces fprintf(stderr,...), but with UTF8 encoded strings. */
307DJVUEXTERNCAPI(void DjVuPrintErrorUTF8(const char *fmt, ...));
308
309/** This replaces fprintf(stderr,...), but with UTF8 encoded strings. */
310DJVUEXTERNCAPI(void DjVuPrintErrorNative(const char *fmt, ...));
311
312/** This replaces printf(...), but requires UTF8 encoded strings. */
313DJVUEXTERNCAPI(void DjVuPrintMessageUTF8(const char *fmt, ...));
314
315/** This replaces printf(...), but requires UTF8 encoded strings. */
316DJVUEXTERNCAPI(void DjVuPrintMessageNative(const char *fmt, ...));
317
318/** The format (fmt) and arguments define a MessageList to be looked
319    up in the external messages and printed to stderr. */
320DJVUEXTERNCAPI(void DjVuFormatErrorUTF8(const char *fmt, ...));
321
322/** The format (fmt) and arguments define a MessageList to be looked
323    up in the external messages and printed to stderr. */
324DJVUEXTERNCAPI(void DjVuFormatErrorNative(const char *fmt, ...));
325
326/** Prints the translation of message to stderr. */
327DJVUEXTERNCAPI(void DjVuWriteError( const char *message ));
328
329/** Prints the translation of message to stdout. */
330DJVUEXTERNCAPI(void DjVuWriteMessage( const char *message ));
331
332/** A C function to perform a message lookup. Arguments are a buffer to
333  received the translated message, a buffer size (bytes), and a
334  message_list. The translated result is returned in msg_buffer encoded
335  in UTF-8. In case of error, msg_buffer is empty
336  (i.e., msg_buffer[0] == '\0').
337*/
338DJVUEXTERNCAPI(void DjVuMessageLookUpUTF8(
339  char *msg_buffer, const unsigned int buffer_size, 
340  const char *message ));
341DJVUEXTERNCAPI(void DjVuMessageLookUpNative(
342  char *msg_buffer, const unsigned int buffer_size, 
343  const char *message ));
344
345/** This function sets the program name used when
346    searching for language files.
347*/
348DJVUEXTERNCAPI(const char *djvu_programname(const char *programname));
349
350
351/** @name DjVu Names 
352
353    This section is enabled when compilation symbol #NEED_DJVU_NAMES# is
354    defined.  This section redefines class names in order to unclutter the
355    name space of shared objects.  This is useful on systems which
356    automatically export all global symbols when building a shared object.
357    @args */
358//@{
359//@}
360
361#ifdef NEED_DJVU_NAMES
362/* The contents of this section may be generated by this shell command :
363 * % egrep -h '^(class|struct) +[A-Z_][A-Za-z0-9_]*' *.h *.cpp |\
364 *   sed -e 's:[a-z]*  *\([A-Za-z_][A-Za-z0-9_]*\).*:#define \1 DJVU_\1:g' |\
365 *   sort
366 */
367#endif // NEED_DJVU_NAMES
368
369//@}
370
371#if defined(macintosh)
372# define EMPTY_LOOP continue
373#else
374# define EMPTY_LOOP /* nop */
375#endif
376
377//  The ERR_MSG(x) macro is intended to permit automated checking of the
378//  externalized error message names against the source code. It has no
379//  effect on the executed program. It should be used to surround each
380//  message name that will need to be looked up in the external message
381//  files. In particular, it should use on all strings passed to G_THROW.
382#ifndef HAS_CTRL_C_IN_ERR_MSG
383# define HAS_CTRL_C_IN_ERR_MSG 1
384#endif
385#ifndef ERR_MSG
386# if HAS_CTRL_C_IN_ERR_MSG
387// This hack allows for the coexistence of internationalized
388// and non-internationalized code.  All internationalized error
389// message names are prefixed with a ctrl-c.  Only these will
390// be looked for in the message files.  Messages that do no
391// start with a ctrl-c will remain untranslated.
392#  define ERR_MSG(x) "\003" x
393# else
394#  define ERR_MSG(x) x
395# endif
396#endif
397
398#endif /* _DJVUGLOBAL_H_ */
399
400
Note: See TracBrowser for help on using the repository browser.