Blame libdjvu/DjVmDir0.cpp

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
#ifdef HAVE_CONFIG_H
Packit df99a1
# include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma implementation
Packit df99a1
#endif
Packit df99a1
Packit df99a1
#include "DjVmDir0.h"
Packit df99a1
#include "ByteStream.h"
Packit df99a1
#include "debug.h"
Packit df99a1
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
int
Packit df99a1
DjVmDir0::get_size(void) const
Packit df99a1
      // WARNING! make sure, that get_size(), encode() and decode() are in sync
Packit df99a1
{
Packit df99a1
   int size=0;
Packit df99a1
Packit df99a1
   size+=2;	// number of files
Packit df99a1
   for(int i=0;i
Packit df99a1
   {
Packit df99a1
      FileRec & file=*num2file[i];
Packit df99a1
      size+=file.name.length()+1;	// file name
Packit df99a1
      size+=1;				// is IFF file
Packit df99a1
      size+=4;				// file offset
Packit df99a1
      size+=4;				// file size
Packit df99a1
   };
Packit df99a1
Packit df99a1
   return size;
Packit df99a1
}
Packit df99a1
Packit df99a1
#ifndef NEED_DECODER_ONLY
Packit df99a1
void
Packit df99a1
DjVmDir0::encode(ByteStream & bs)
Packit df99a1
      // WARNING! make sure, that get_size(), encode() and decode() are in sync
Packit df99a1
{
Packit df99a1
   bs.write16(num2file.size());
Packit df99a1
   for(int i=0;i
Packit df99a1
   {
Packit df99a1
      FileRec & file=*num2file[i];
Packit df99a1
      bs.writestring(file.name);
Packit df99a1
      bs.write8(0);
Packit df99a1
      bs.write8(file.iff_file);
Packit df99a1
      bs.write32(file.offset);
Packit df99a1
      bs.write32(file.size);
Packit df99a1
   }
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
Packit df99a1
void
Packit df99a1
DjVmDir0::decode(ByteStream & bs)
Packit df99a1
      // WARNING! make sure, that get_size(), encode() and decode() are in sync
Packit df99a1
{
Packit df99a1
   name2file.empty();
Packit df99a1
   num2file.empty();
Packit df99a1
Packit df99a1
   for(int i=bs.read16();i>0;i--)
Packit df99a1
   {
Packit df99a1
      GUTF8String name;
Packit df99a1
      char ch;
Packit df99a1
      while(bs.read(&ch, 1) && ch) name+=ch;
Packit df99a1
      bool iff_file=bs.read8()?true:false;
Packit df99a1
      int offset=bs.read32();
Packit df99a1
      int size=bs.read32();
Packit df99a1
      add_file(name, iff_file, offset, size);
Packit df99a1
   };
Packit df99a1
}
Packit df99a1
Packit df99a1
GP<DjVmDir0::FileRec>
Packit df99a1
DjVmDir0::get_file(const GUTF8String &name)
Packit df99a1
{
Packit df99a1
   if (name2file.contains(name))
Packit df99a1
     return name2file[name];
Packit df99a1
   return 0;
Packit df99a1
}
Packit df99a1
Packit df99a1
GP<DjVmDir0::FileRec>
Packit df99a1
DjVmDir0::get_file(int file_num)
Packit df99a1
{
Packit df99a1
   if (file_num
Packit df99a1
   return 0;
Packit df99a1
}
Packit df99a1
Packit df99a1
void
Packit df99a1
DjVmDir0::add_file(
Packit df99a1
  const GUTF8String &name, bool iff_file, int offset, int size)
Packit df99a1
{
Packit df99a1
   DEBUG_MSG("DjVmDir0::add_file(): name='" << name << "', iff=" << iff_file <<
Packit df99a1
	     ", offset=" << offset << "\n");
Packit df99a1
   
Packit df99a1
   if (name.search('/') >= 0)
Packit df99a1
     G_THROW( ERR_MSG("DjVmDir0.no_slash") );
Packit df99a1
   
Packit df99a1
   GP<FileRec> file=new FileRec(name, iff_file, offset, size);
Packit df99a1
   name2file[name]=file;
Packit df99a1
   num2file.resize(num2file.size());
Packit df99a1
   num2file[num2file.size()-1]=file;
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