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