source: trunk/libdjvu/DjVmDir0.cpp @ 269

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

DJVU plugin: djvulibre updated to version 3.5.19

File size: 5.4 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: DjVmDir0.cpp,v 1.9 2007/03/25 20:48:29 leonb Exp $
57// $Name: release_3_5_19 $
58
59#ifdef HAVE_CONFIG_H
60# include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma implementation
64#endif
65
66#include "DjVmDir0.h"
67#include "ByteStream.h"
68#include "debug.h"
69
70
71#ifdef HAVE_NAMESPACES
72namespace DJVU {
73# ifdef NOT_DEFINED // Just to fool emacs c++ mode
74}
75#endif
76#endif
77
78int
79DjVmDir0::get_size(void) const
80      // WARNING! make sure, that get_size(), encode() and decode() are in sync
81{
82   int size=0;
83
84   size+=2;     // number of files
85   for(int i=0;i<num2file.size();i++)
86   {
87      FileRec & file=*num2file[i];
88      size+=file.name.length()+1;       // file name
89      size+=1;                          // is IFF file
90      size+=4;                          // file offset
91      size+=4;                          // file size
92   };
93
94   return size;
95}
96
97#ifndef NEED_DECODER_ONLY
98void
99DjVmDir0::encode(ByteStream & bs)
100      // WARNING! make sure, that get_size(), encode() and decode() are in sync
101{
102   bs.write16(num2file.size());
103   for(int i=0;i<num2file.size();i++)
104   {
105      FileRec & file=*num2file[i];
106      bs.writestring(file.name);
107      bs.write8(0);
108      bs.write8(file.iff_file);
109      bs.write32(file.offset);
110      bs.write32(file.size);
111   }
112}
113#endif
114
115void
116DjVmDir0::decode(ByteStream & bs)
117      // WARNING! make sure, that get_size(), encode() and decode() are in sync
118{
119   name2file.empty();
120   num2file.empty();
121
122   for(int i=bs.read16();i>0;i--)
123   {
124      GUTF8String name;
125      char ch;
126      while(bs.read(&ch, 1) && ch) name+=ch;
127      bool iff_file=bs.read8()?true:false;
128      int offset=bs.read32();
129      int size=bs.read32();
130      add_file(name, iff_file, offset, size);
131   };
132}
133
134GP<DjVmDir0::FileRec>
135DjVmDir0::get_file(const GUTF8String &name)
136{
137   if (name2file.contains(name))
138     return name2file[name];
139   return 0;
140}
141
142GP<DjVmDir0::FileRec>
143DjVmDir0::get_file(int file_num)
144{
145   if (file_num<num2file.size()) return num2file[file_num];
146   return 0;
147}
148
149void
150DjVmDir0::add_file(
151  const GUTF8String &name, bool iff_file, int offset, int size)
152{
153   DEBUG_MSG("DjVmDir0::add_file(): name='" << name << "', iff=" << iff_file <<
154             ", offset=" << offset << "\n");
155   
156   if (name.search('/') >= 0)
157     G_THROW( ERR_MSG("DjVmDir0.no_slash") );
158   
159   GP<FileRec> file=new FileRec(name, iff_file, offset, size);
160   name2file[name]=file;
161   num2file.resize(num2file.size());
162   num2file[num2file.size()-1]=file;
163}
164
165
166#ifdef HAVE_NAMESPACES
167}
168# ifndef NOT_USING_DJVU_NAMESPACE
169using namespace DJVU;
170# endif
171#endif
Note: See TracBrowser for help on using the repository browser.