source: trunk/libdjvu/DjVuMessageLite.h @ 206

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

DJVU plugin: djvulibre updated to version 3.5.19

File size: 8.8 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: DjVuMessageLite.h,v 1.10 2007/03/25 20:48:31 leonb Exp $
57// $Name: release_3_5_19 $
58
59#ifndef __DJVU_MESSAGE_LITE_H__
60#define __DJVU_MESSAGE_LITE_H__
61#ifdef HAVE_CONFIG_H
62#include "config.h"
63#endif
64#if NEED_GNUG_PRAGMAS
65# pragma interface
66#endif
67
68// From: Leon Bottou, 1/31/2002
69// All these I18N XML messages are Lizardtech innovations.
70// For DjvuLibre, I changed the path extraction logic
71// and added support for non I18N messages.
72
73
74#include "GString.h"
75
76#ifdef HAVE_NAMESPACES
77namespace DJVU {
78# ifdef NOT_DEFINED // Just to fool emacs c++ mode
79}
80#endif
81#endif
82
83class lt_XMLTags;
84class ByteStream;
85
86/** Exception causes and external messages are passed as message lists which
87    have the following syntax:
88 
89    message_list ::= single_message |
90                     single_message separator message_list
91   
92    separator ::= newline |
93                  newline | separator
94   
95    single_message ::= message_ID |
96                       message_ID parameters
97   
98    parameters ::= tab string |
99                   tab string parameters
100   
101    Message_IDs are looked up an external file and replaced by the message
102    text strings they are mapped to. The message text may contain the
103    following:
104   
105    Parameter specifications: These are modelled after printf format
106    specifications and have one of the following forms:
107 
108      %n!s! %n!d! %n!i! %n!u! %n!x! %n!X!
109 
110    where n is the parameter number. The parameter number is indicated
111    explicitly to allow for the possibility that the parameter order may
112    change when the message text is translated into another language.
113    The final letter ('s', 'd', 'i', 'u', 'x', or 'X') indicates the form
114    of the parameter (string, integer, integer, unsigned integer, lowercase
115    hexadecimal, or uppercase hexadecimal, respectively).  In addition
116    formating options such as precision available in sprintf, may be used.
117    So, to print the third argument as 5 digit unsigned number, with leading
118    zero's one could use:
119      %3!05u!
120
121    All of the arguments are actually strings.  For forms that don't take
122    string input ('d', 'i', 'u', 'x', or 'X'), and atoi() conversion is done
123    on the string before formatting.  In addition the form indicates to the
124    translater whether to expect a word or a number.
125
126    The strings are read in from XML.  To to format the strings, use the
127    relavent XML escape sequences, such as follows:
128
129            
        [line feed]
130            	        [horizontal tab]
131            '       [single quote]
132            "        [double quote]
133            <         [less than sign]
134            >         [greater than sign]
135 
136    After parameters have been inserted in the message text, the formatting
137    strings are replaced by their usual equivalents (newline and tab
138    respectively).
139
140    If a message_id cannot be found in the external file, a message text
141    is fabricated giving the message_id and the parameters (if any).
142
143    Separators (newlines) are preserved in the translated message list.
144
145    Expands message lists by looking up the message IDs and inserting
146    arguments into the retrieved messages.
147
148    N.B. The resulting string may be encoded in UTF-8 format (ISO 10646-1
149    Annex R) and SHOULD NOT BE ASSUMED TO BE ASCII.
150  */
151
152class DjVuMessageLite : public GPEnabled
153{
154protected:
155  // Constructor:
156  DjVuMessageLite( void );
157  GMap<GUTF8String,GP<lt_XMLTags> > Map;
158  GUTF8String errors;
159  /// Creates a DjVuMessage class.
160  static const DjVuMessageLite &real_create(void);
161
162public:
163  /// Creates a DjVuMessage class.
164  static const DjVuMessageLite& (*create)(void);
165
166  /// Creates this class specifically.
167  static const DjVuMessageLite &create_lite(void);
168
169  /** Adds a byte stream to be parsed whenever the next DjVuMessage::create()
170      call is made. */
171  static void AddByteStreamLater(const GP<ByteStream> &bs);
172
173  /** Destructor: Does any necessary cleanup. Actions depend on how the message
174      file is implemented. */
175  ~DjVuMessageLite();
176
177  /// Lookup the relavent string and parse the message.
178  GUTF8String LookUp( const GUTF8String & MessageList ) const;
179
180  //// Same as LookUp, but this is a static method.
181  static GUTF8String LookUpUTF8( const GUTF8String & MessageList )
182  { return create().LookUp(MessageList); }
183
184  /** Same as Lookup, but returns the a multibyte character string in the
185      current locale. */
186  static GNativeString LookUpNative( const GUTF8String & MessageList )
187  { return create().LookUp(MessageList).getUTF82Native(); }
188
189  /// This is a simple alias to the above class, but does an fprintf to stderr.
190  static void perror( const GUTF8String & MessageList );
191
192protected:
193
194  /*  Looks up the msgID in the file of messages. The strings message_text
195      and message_number are returned if found. If not found, these strings
196      are empty. */
197  void LookUpID( const GUTF8String & msgID,
198    GUTF8String &message_text, GUTF8String &message_number ) const;
199
200  /*  Expands a single message and inserts the arguments. Single_Message
201      contains no separators (newlines), but includes all the parameters
202      separated by tabs. */
203  GUTF8String LookUpSingle( const GUTF8String & Single_Message ) const;
204
205  /*  Insert a string into the message text. Will insert into any field
206      description.  Except for an ArgId of zero (message number), if the
207      #ArgId# is not found, the routine adds a line with the parameter
208      so information will not be lost. */
209  void InsertArg(
210    GUTF8String &message, const int ArgId, const GUTF8String &arg ) const;
211
212  void AddByteStream(const GP<ByteStream> &bs);
213
214protected:
215  /*  Static storage of the DjVuMessage class. */
216  static GP<DjVuMessageLite> &getDjVuMessageLite(void);
217  /*  Static storage of the ByteStream list. */
218  static GPList<ByteStream> &getByteStream(void);
219};
220
221
222#ifdef HAVE_NAMESPACES
223}
224# ifndef NOT_USING_DJVU_NAMESPACE
225using namespace DJVU;
226# endif
227#endif
228#endif /* __DJVU_MESSAGE_LITE_H__ */
229
Note: See TracBrowser for help on using the repository browser.