source: trunk/libdjvu/DjVuMessageLite.h @ 136

Last change on this file since 136 was 17, checked in by Eugene Romanenko, 16 years ago

update makefiles, remove absolute paths, update djvulibre to version 3.5.17

File size: 8.9 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, Version 2. The license should have
9//C- accompanied the software or you may obtain a copy of the license
10//C- from the Free Software Foundation at http://www.fsf.org .
11//C-
12//C- This program is distributed in the hope that it will be useful,
13//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//C- GNU General Public License for more details.
16//C-
17//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
18//C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech
19//C- Software authorized us to replace the original DjVu(r) Reference
20//C- Library notice by the following text (see doc/lizard2002.djvu):
21//C-
22//C-  ------------------------------------------------------------------
23//C- | DjVu (r) Reference Library (v. 3.5)
24//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
25//C- | The DjVu Reference Library is protected by U.S. Pat. No.
26//C- | 6,058,214 and patents pending.
27//C- |
28//C- | This software is subject to, and may be distributed under, the
29//C- | GNU General Public License, Version 2. The license should have
30//C- | accompanied the software or you may obtain a copy of the license
31//C- | from the Free Software Foundation at http://www.fsf.org .
32//C- |
33//C- | The computer code originally released by LizardTech under this
34//C- | license and unmodified by other parties is deemed "the LIZARDTECH
35//C- | ORIGINAL CODE."  Subject to any third party intellectual property
36//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
37//C- | non-exclusive license to make, use, sell, or otherwise dispose of
38//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
39//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
40//C- | General Public License.   This grant only confers the right to
41//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
42//C- | the extent such infringement is reasonably necessary to enable
43//C- | recipient to make, have made, practice, sell, or otherwise dispose
44//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
45//C- | any greater extent that may be necessary to utilize further
46//C- | modifications or combinations.
47//C- |
48//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
49//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
50//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
51//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52//C- +------------------------------------------------------------------
53//
54// $Id: DjVuMessageLite.h,v 1.9 2003/11/07 22:08:21 leonb Exp $
55// $Name:  $
56
57#ifndef __DJVU_MESSAGE_LITE_H__
58#define __DJVU_MESSAGE_LITE_H__
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma interface
64#endif
65
66// From: Leon Bottou, 1/31/2002
67// All these I18N XML messages are Lizardtech innovations.
68// For DjvuLibre, I changed the path extraction logic
69// and added support for non I18N messages.
70
71
72#include "GString.h"
73
74#ifdef HAVE_NAMESPACES
75namespace DJVU {
76# ifdef NOT_DEFINED // Just to fool emacs c++ mode
77}
78#endif
79#endif
80
81class lt_XMLTags;
82class ByteStream;
83
84/** Exception causes and external messages are passed as message lists which
85    have the following syntax:
86 
87    message_list ::= single_message |
88                     single_message separator message_list
89   
90    separator ::= newline |
91                  newline | separator
92   
93    single_message ::= message_ID |
94                       message_ID parameters
95   
96    parameters ::= tab string |
97                   tab string parameters
98   
99    Message_IDs are looked up an external file and replaced by the message
100    text strings they are mapped to. The message text may contain the
101    following:
102   
103    Parameter specifications: These are modelled after printf format
104    specifications and have one of the following forms:
105 
106      %n!s! %n!d! %n!i! %n!u! %n!x! %n!X!
107 
108    where n is the parameter number. The parameter number is indicated
109    explicitly to allow for the possibility that the parameter order may
110    change when the message text is translated into another language.
111    The final letter ('s', 'd', 'i', 'u', 'x', or 'X') indicates the form
112    of the parameter (string, integer, integer, unsigned integer, lowercase
113    hexadecimal, or uppercase hexadecimal, respectively).  In addition
114    formating options such as precision available in sprintf, may be used.
115    So, to print the third argument as 5 digit unsigned number, with leading
116    zero's one could use:
117      %3!05u!
118
119    All of the arguments are actually strings.  For forms that don't take
120    string input ('d', 'i', 'u', 'x', or 'X'), and atoi() conversion is done
121    on the string before formatting.  In addition the form indicates to the
122    translater whether to expect a word or a number.
123
124    The strings are read in from XML.  To to format the strings, use the
125    relavent XML escape sequences, such as follows:
126
127            
        [line feed]
128            	        [horizontal tab]
129            '       [single quote]
130            "        [double quote]
131            <         [less than sign]
132            >         [greater than sign]
133 
134    After parameters have been inserted in the message text, the formatting
135    strings are replaced by their usual equivalents (newline and tab
136    respectively).
137
138    If a message_id cannot be found in the external file, a message text
139    is fabricated giving the message_id and the parameters (if any).
140
141    Separators (newlines) are preserved in the translated message list.
142
143    Expands message lists by looking up the message IDs and inserting
144    arguments into the retrieved messages.
145
146    N.B. The resulting string may be encoded in UTF-8 format (ISO 10646-1
147    Annex R) and SHOULD NOT BE ASSUMED TO BE ASCII.
148  */
149
150class DjVuMessageLite : public GPEnabled
151{
152protected:
153  // Constructor:
154  DjVuMessageLite( void );
155  GMap<GUTF8String,GP<lt_XMLTags> > Map;
156  GUTF8String errors;
157  /// Creates a DjVuMessage class.
158  static const DjVuMessageLite &real_create(void);
159
160public:
161  /// Creates a DjVuMessage class.
162  static const DjVuMessageLite& (*create)(void);
163
164  /// Creates this class specifically.
165  static const DjVuMessageLite &create_lite(void);
166
167  /** Adds a byte stream to be parsed whenever the next DjVuMessage::create()
168      call is made. */
169  static void AddByteStreamLater(const GP<ByteStream> &bs);
170
171  /** Destructor: Does any necessary cleanup. Actions depend on how the message
172      file is implemented. */
173  ~DjVuMessageLite();
174
175  /// Lookup the relavent string and parse the message.
176  GUTF8String LookUp( const GUTF8String & MessageList ) const;
177
178  //// Same as LookUp, but this is a static method.
179  static GUTF8String LookUpUTF8( const GUTF8String & MessageList )
180  { return create().LookUp(MessageList); }
181
182  /** Same as Lookup, but returns the a multibyte character string in the
183      current locale. */
184  static GNativeString LookUpNative( const GUTF8String & MessageList )
185  { return create().LookUp(MessageList).getUTF82Native(); }
186
187  /// This is a simple alias to the above class, but does an fprintf to stderr.
188  static void perror( const GUTF8String & MessageList );
189
190protected:
191
192  /*  Looks up the msgID in the file of messages. The strings message_text
193      and message_number are returned if found. If not found, these strings
194      are empty. */
195  void LookUpID( const GUTF8String & msgID,
196    GUTF8String &message_text, GUTF8String &message_number ) const;
197
198  /*  Expands a single message and inserts the arguments. Single_Message
199      contains no separators (newlines), but includes all the parameters
200      separated by tabs. */
201  GUTF8String LookUpSingle( const GUTF8String & Single_Message ) const;
202
203  /*  Insert a string into the message text. Will insert into any field
204      description.  Except for an ArgId of zero (message number), if the
205      #ArgId# is not found, the routine adds a line with the parameter
206      so information will not be lost. */
207  void InsertArg(
208    GUTF8String &message, const int ArgId, const GUTF8String &arg ) const;
209
210  void AddByteStream(const GP<ByteStream> &bs);
211
212protected:
213  /*  Static storage of the DjVuMessage class. */
214  static GP<DjVuMessageLite> &getDjVuMessageLite(void);
215  /*  Static storage of the ByteStream list. */
216  static GPList<ByteStream> &getByteStream(void);
217};
218
219
220#ifdef HAVE_NAMESPACES
221}
222# ifndef NOT_USING_DJVU_NAMESPACE
223using namespace DJVU;
224# endif
225#endif
226#endif /* __DJVU_MESSAGE_LITE_H__ */
227
Note: See TracBrowser for help on using the repository browser.