source: trunk/libdjvu/DjVmDir0.cpp @ 101

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

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

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