|
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 __DJVU_MESSAGE_LITE_H__
|
|
Packit |
df99a1 |
#define __DJVU_MESSAGE_LITE_H__
|
|
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 |
// From: Leon Bottou, 1/31/2002
|
|
Packit |
df99a1 |
// All these I18N XML messages are Lizardtech innovations.
|
|
Packit |
df99a1 |
// For DjvuLibre, I changed the path extraction logic
|
|
Packit |
df99a1 |
// and added support for non I18N messages.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include "GString.h"
|
|
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 |
class lt_XMLTags;
|
|
Packit |
df99a1 |
class ByteStream;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Exception causes and external messages are passed as message lists which
|
|
Packit |
df99a1 |
have the following syntax:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
message_list ::= single_message |
|
|
Packit |
df99a1 |
single_message separator message_list
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
separator ::= newline |
|
|
Packit |
df99a1 |
newline | separator
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
single_message ::= message_ID |
|
|
Packit |
df99a1 |
message_ID parameters
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
parameters ::= tab string |
|
|
Packit |
df99a1 |
tab string parameters
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Message_IDs are looked up an external file and replaced by the message
|
|
Packit |
df99a1 |
text strings they are mapped to. The message text may contain the
|
|
Packit |
df99a1 |
following:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Parameter specifications: These are modelled after printf format
|
|
Packit |
df99a1 |
specifications and have one of the following forms:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
%n!s! %n!d! %n!i! %n!u! %n!x! %n!X!
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
where n is the parameter number. The parameter number is indicated
|
|
Packit |
df99a1 |
explicitly to allow for the possibility that the parameter order may
|
|
Packit |
df99a1 |
change when the message text is translated into another language.
|
|
Packit |
df99a1 |
The final letter ('s', 'd', 'i', 'u', 'x', or 'X') indicates the form
|
|
Packit |
df99a1 |
of the parameter (string, integer, integer, unsigned integer, lowercase
|
|
Packit |
df99a1 |
hexadecimal, or uppercase hexadecimal, respectively). In addition
|
|
Packit |
df99a1 |
formating options such as precision available in sprintf, may be used.
|
|
Packit |
df99a1 |
So, to print the third argument as 5 digit unsigned number, with leading
|
|
Packit |
df99a1 |
zero's one could use:
|
|
Packit |
df99a1 |
%3!05u!
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
All of the arguments are actually strings. For forms that don't take
|
|
Packit |
df99a1 |
string input ('d', 'i', 'u', 'x', or 'X'), and atoi() conversion is done
|
|
Packit |
df99a1 |
on the string before formatting. In addition the form indicates to the
|
|
Packit |
df99a1 |
translater whether to expect a word or a number.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
The strings are read in from XML. To to format the strings, use the
|
|
Packit |
df99a1 |
relavent XML escape sequences, such as follows:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
[line feed]
|
|
Packit |
df99a1 |
[horizontal tab]
|
|
Packit |
df99a1 |
' [single quote]
|
|
Packit |
df99a1 |
" [double quote]
|
|
Packit |
df99a1 |
< [less than sign]
|
|
Packit |
df99a1 |
> [greater than sign]
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
After parameters have been inserted in the message text, the formatting
|
|
Packit |
df99a1 |
strings are replaced by their usual equivalents (newline and tab
|
|
Packit |
df99a1 |
respectively).
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
If a message_id cannot be found in the external file, a message text
|
|
Packit |
df99a1 |
is fabricated giving the message_id and the parameters (if any).
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Separators (newlines) are preserved in the translated message list.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Expands message lists by looking up the message IDs and inserting
|
|
Packit |
df99a1 |
arguments into the retrieved messages.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
N.B. The resulting string may be encoded in UTF-8 format (ISO 10646-1
|
|
Packit |
df99a1 |
Annex R) and SHOULD NOT BE ASSUMED TO BE ASCII.
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DJVUAPI DjVuMessageLite : public GPEnabled
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
// Constructor:
|
|
Packit |
df99a1 |
DjVuMessageLite( void );
|
|
Packit |
df99a1 |
GMap<GUTF8String,GP<lt_XMLTags> > Map;
|
|
Packit |
df99a1 |
GUTF8String errors;
|
|
Packit |
df99a1 |
/// Creates a DjVuMessage class.
|
|
Packit |
df99a1 |
static const DjVuMessageLite &real_create(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
/// Creates a DjVuMessage class.
|
|
Packit |
df99a1 |
static const DjVuMessageLite& (*create)(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Creates this class specifically.
|
|
Packit |
df99a1 |
static const DjVuMessageLite &create_lite(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Adds a byte stream to be parsed whenever the next DjVuMessage::create()
|
|
Packit |
df99a1 |
call is made. */
|
|
Packit |
df99a1 |
static void AddByteStreamLater(const GP<ByteStream> &bs);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Destructor: Does any necessary cleanup. Actions depend on how the message
|
|
Packit |
df99a1 |
file is implemented. */
|
|
Packit |
df99a1 |
~DjVuMessageLite();
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Lookup the relavent string and parse the message.
|
|
Packit |
df99a1 |
GUTF8String LookUp( const GUTF8String & MessageList ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
//// Same as LookUp, but this is a static method.
|
|
Packit |
df99a1 |
static GUTF8String LookUpUTF8( const GUTF8String & MessageList )
|
|
Packit |
df99a1 |
{ return create().LookUp(MessageList); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Same as Lookup, but returns the a multibyte character string in the
|
|
Packit |
df99a1 |
current locale. */
|
|
Packit |
df99a1 |
static GNativeString LookUpNative( const GUTF8String & MessageList )
|
|
Packit |
df99a1 |
{ return create().LookUp(MessageList).getUTF82Native(); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// This is a simple alias to the above class, but does an fprintf to stderr.
|
|
Packit |
df99a1 |
static void perror( const GUTF8String & MessageList );
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/* Looks up the msgID in the file of messages. The strings message_text
|
|
Packit |
df99a1 |
and message_number are returned if found. If not found, these strings
|
|
Packit |
df99a1 |
are empty. */
|
|
Packit |
df99a1 |
void LookUpID( const GUTF8String & msgID,
|
|
Packit |
df99a1 |
GUTF8String &message_text, GUTF8String &message_number ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/* Expands a single message and inserts the arguments. Single_Message
|
|
Packit |
df99a1 |
contains no separators (newlines), but includes all the parameters
|
|
Packit |
df99a1 |
separated by tabs. */
|
|
Packit |
df99a1 |
GUTF8String LookUpSingle( const GUTF8String & Single_Message ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/* Insert a string into the message text. Will insert into any field
|
|
Packit |
df99a1 |
description. Except for an ArgId of zero (message number), if the
|
|
Packit |
df99a1 |
#ArgId# is not found, the routine adds a line with the parameter
|
|
Packit |
df99a1 |
so information will not be lost. */
|
|
Packit |
df99a1 |
void InsertArg(
|
|
Packit |
df99a1 |
GUTF8String &message, const int ArgId, const GUTF8String &arg ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
void AddByteStream(const GP<ByteStream> &bs);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
/* Static storage of the DjVuMessage class. */
|
|
Packit |
df99a1 |
static GP<DjVuMessageLite> &getDjVuMessageLite(void);
|
|
Packit |
df99a1 |
/* Static storage of the ByteStream list. */
|
|
Packit |
df99a1 |
static GPList<ByteStream> &getByteStream(void);
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
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 |
#endif /* __DJVU_MESSAGE_LITE_H__ */
|
|
Packit |
df99a1 |
|