|
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 _UNICODEBYTESTREAM_H_
|
|
Packit |
df99a1 |
#define _UNICODEBYTESTREAM_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 |
|
|
Packit |
df99a1 |
/** @name UnicodeByteStream.h
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Files #"UnicodeByteStream.h"# and #"UnicodeByteStream.cpp"#
|
|
Packit |
df99a1 |
implement a parser for files structured W3C Extensible Markup
|
|
Packit |
df99a1 |
Language (XML) 1.0 (Second Edition).
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Class \Ref{UnicodeByteStream} provides a way to read or write XML files.
|
|
Packit |
df99a1 |
files. Member functions provide an easy mean to position the underlying
|
|
Packit |
df99a1 |
\Ref{ByteStream}.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf References:}
|
|
Packit |
df99a1 |
W3C Extensible Markup Language (XML) 1.0 (Second Edition)
|
|
Packit |
df99a1 |
\URL{http://www.w3.org/TR/2000/REC-xml-20001006.html}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
@memo
|
|
Packit |
df99a1 |
XML file parser.
|
|
Packit |
df99a1 |
@author
|
|
Packit |
df99a1 |
Bill C Riemers <docbill@sourceforge.net>
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
//@{
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include "DjVuGlobal.h"
|
|
Packit |
df99a1 |
#include "GString.h"
|
|
Packit |
df99a1 |
#include "ByteStream.h"
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include <stddef.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 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** ByteStream interface for an Unicode file.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Class #UnicodeByteStream# augments the #ByteStream# interface with
|
|
Packit |
df99a1 |
functions for navigating Unicode documents. It works in relation
|
|
Packit |
df99a1 |
with a ByteStream specified at construction time.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf Reading an Unicode file} --- You can read an Unicode file by
|
|
Packit |
df99a1 |
constructing an #UnicodeByteStream# object attached to the ByteStream
|
|
Packit |
df99a1 |
containing the Unicode file.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf Writing an Unicode file} --- You can write an Unicode file by
|
|
Packit |
df99a1 |
constructing an #UnicodeByteStream# object attached to the seekable
|
|
Packit |
df99a1 |
ByteStream object that will contain the XML file.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Writing an XML file requires a seekable ByteStream (see
|
|
Packit |
df99a1 |
\Ref{ByteStream::is_seekable}). This is not much of a problem because you
|
|
Packit |
df99a1 |
can always create the XML file into a \Ref{MemoryByteStream} and then use
|
|
Packit |
df99a1 |
\Ref{ByteStream::copy} to transfer the XML file into a non seekable
|
|
Packit |
df99a1 |
ByteStream. */
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class UnicodeByteStream : public ByteStream
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
UnicodeByteStream(const UnicodeByteStream &bs);
|
|
Packit |
df99a1 |
UnicodeByteStream(GP<ByteStream> bs,
|
|
Packit |
df99a1 |
const GStringRep::EncodeType encodetype=GStringRep::XUTF8);
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
/** Constructs an UnicodeByteStream object attached to ByteStream #bs#.
|
|
Packit |
df99a1 |
Any ByteStream can be used when reading an XML file. Writing
|
|
Packit |
df99a1 |
an XML file however requires a seekable ByteStream. */
|
|
Packit |
df99a1 |
static GP<UnicodeByteStream> create(GP<ByteStream> bs,
|
|
Packit |
df99a1 |
const GStringRep::EncodeType encodetype=GStringRep::XUTF8)
|
|
Packit |
df99a1 |
{ return new UnicodeByteStream(bs,encodetype); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// --- BYTESTREAM INTERFACE
|
|
Packit |
df99a1 |
~UnicodeByteStream();
|
|
Packit |
df99a1 |
/// Sets the encoding type and seek's to position 0.
|
|
Packit |
df99a1 |
void set_encodetype(const GStringRep::EncodeType et=GStringRep::XUTF8);
|
|
Packit |
df99a1 |
void set_encoding(const GUTF8String &encoding);
|
|
Packit |
df99a1 |
/// Simmular to fgets(), except read aheads effect the tell() position.
|
|
Packit |
df99a1 |
virtual GUTF8String gets(size_t const t=0,unsigned long const stopat='\n',bool const inclusive=true);
|
|
Packit |
df99a1 |
/// Resets the gets buffering as well as physically seeking.
|
|
Packit |
df99a1 |
virtual int seek(long offset, int whence = SEEK_SET, bool nothrow=false);
|
|
Packit |
df99a1 |
/** Physically reads the specified bytes, and truncate the read ahead buffer.
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
virtual size_t read(void *buffer, size_t size);
|
|
Packit |
df99a1 |
/// Not correctly implimented...
|
|
Packit |
df99a1 |
virtual size_t write(const void *buffer, size_t size);
|
|
Packit |
df99a1 |
/// tell will tell you the read position, including read ahead for gets()...
|
|
Packit |
df99a1 |
virtual long tell(void) const;
|
|
Packit |
df99a1 |
/// Does a flush, and clears the read ahead buffer.
|
|
Packit |
df99a1 |
virtual void flush(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Find out how many lines have been read with gets.
|
|
Packit |
df99a1 |
int get_lines_read(void) const { return linesread; }
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
/// The real byte stream.
|
|
Packit |
df99a1 |
GP<ByteStream> bs;
|
|
Packit |
df99a1 |
GUTF8String buffer;
|
|
Packit |
df99a1 |
int bufferpos;
|
|
Packit |
df99a1 |
int linesread;
|
|
Packit |
df99a1 |
long startpos;
|
|
Packit |
df99a1 |
private:
|
|
Packit |
df99a1 |
// Cancel C++ default stuff
|
|
Packit |
df99a1 |
UnicodeByteStream & operator=(UnicodeByteStream &);
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class XMLByteStream : public UnicodeByteStream
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
XMLByteStream(GP<ByteStream> &bs);
|
|
Packit |
df99a1 |
XMLByteStream(UnicodeByteStream &bs);
|
|
Packit |
df99a1 |
void init(void);
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
static GP<XMLByteStream> create(GP<ByteStream> bs);
|
|
Packit |
df99a1 |
static GP<XMLByteStream> create(UnicodeByteStream &bs);
|
|
Packit |
df99a1 |
// --- BYTESTREAM INTERFACE
|
|
Packit |
df99a1 |
~XMLByteStream();
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GP<XMLByteStream>
|
|
Packit |
df99a1 |
XMLByteStream::create(UnicodeByteStream &bs)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return new XMLByteStream(bs);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
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
|
|
Packit |
df99a1 |
|