~ubuntu-branches/ubuntu/intrepid/enigma/intrepid

« back to all changes in this revision

Viewing changes to lib-src/zipios++/src/zipinputstreambuf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Erich Schubert
  • Date: 2005-08-28 15:30:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050828153009-sky64kb6tcq37xt5
Tags: 0.92.1-1
* New upstream subversion checkout
* Remove menu.s3m, which we are allowed to distributed but not to modify
  also copyright notice is confusing... (Closes: #321669)
* Rebuild with new libzipios (Closes: #325405)
  I hope this works without a versioned build-dependency
* Added "enigma replaces enigma-data" for upgrades (Closes: #308558)
* Added notes about the fonts copyright.
* updated to policy 3.6.2.1 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include "zipios++/zipios-config.h"
3
 
 
4
 
#include <algorithm>
5
 
#include "zipios++/meta-iostreams.h"
6
 
 
7
 
#include <zlib.h>
8
 
 
9
 
#include "zipios++/zipinputstreambuf.h"
10
 
#include "zipios_common.h"
11
 
 
12
 
namespace zipios {
13
 
 
14
 
using std::ios ;
15
 
using std::cerr ;
16
 
using std::endl ;
17
 
 
18
 
ZipInputStreambuf::ZipInputStreambuf( streambuf *inbuf, int s_pos, bool del_inbuf ) 
19
 
  : InflateInputStreambuf( inbuf, s_pos, del_inbuf ),
20
 
    _open_entry( false                   ) 
21
 
{
22
 
  ConstEntryPointer entry = getNextEntry() ;
23
 
  
24
 
  if ( ! entry->isValid() ) {
25
 
    ; // FIXME: throw something?
26
 
  }
27
 
}
28
 
 
29
 
void ZipInputStreambuf::closeEntry() {
30
 
  if ( ! _open_entry )
31
 
    return ;
32
 
  
33
 
  // check if we're positioned correctly, otherwise position us correctly
34
 
  int position = _inbuf->pubseekoff(0, ios::cur, 
35
 
                                    ios::in);
36
 
  if ( position != _data_start + static_cast< int >( _curr_entry.getCompressedSize() ) )
37
 
    _inbuf->pubseekoff(_data_start + _curr_entry.getCompressedSize(), 
38
 
                       ios::beg, ios::in) ;
39
 
 
40
 
}
41
 
 
42
 
void ZipInputStreambuf::close() {
43
 
}
44
 
 
45
 
ConstEntryPointer ZipInputStreambuf::getNextEntry() {
46
 
  if ( _open_entry )
47
 
    closeEntry() ;
48
 
 
49
 
  // read the zip local header
50
 
  istream is( _inbuf ) ; // istream does not destroy the streambuf.
51
 
  is >> _curr_entry ;
52
 
  if ( _curr_entry.isValid() ) {
53
 
    _data_start = _inbuf->pubseekoff(0, ios::cur, 
54
 
                                     ios::in);
55
 
    if ( _curr_entry.getMethod() == DEFLATED ) {
56
 
      _open_entry = true ;
57
 
      reset() ; // reset inflatestream data structures 
58
 
//        cerr << "deflated" << endl ;
59
 
    } else if ( _curr_entry.getMethod() == STORED ) {
60
 
      _open_entry = true ;
61
 
      _remain = _curr_entry.getSize() ;
62
 
      // Force underflow on first read:
63
 
      setg( &( _outvec[ 0 ] ),
64
 
            &( _outvec[ 0 ] ) + _outvecsize,
65
 
            &( _outvec[ 0 ] ) + _outvecsize ) ;
66
 
//        cerr << "stored" << endl ;
67
 
    } else {
68
 
      _open_entry = false ; // Unsupported compression format.
69
 
      throw FCollException( "Unsupported compression format" ) ;
70
 
    }
71
 
  } else {
72
 
    _open_entry = false ;
73
 
  }
74
 
 
75
 
  if ( _curr_entry.isValid() && _curr_entry.trailingDataDescriptor() )
76
 
    throw FCollException( "Trailing data descriptor in zip file not supported" ) ; 
77
 
  return new ZipLocalEntry( _curr_entry ) ;
78
 
}
79
 
 
80
 
 
81
 
ZipInputStreambuf::~ZipInputStreambuf() {
82
 
}
83
 
 
84
 
 
85
 
int ZipInputStreambuf::underflow() {
86
 
  if ( ! _open_entry )
87
 
    return EOF ; // traits_type::eof() 
88
 
  if ( _curr_entry.getMethod() == DEFLATED )
89
 
    return InflateInputStreambuf::underflow() ;
90
 
 
91
 
  // Ok, we're are stored, so we handle it ourselves.
92
 
  int num_b = min( _remain, _outvecsize ) ;
93
 
  int g = _inbuf->sgetn( &(_outvec[ 0 ] ) , num_b ) ;
94
 
  setg( &( _outvec[ 0 ] ),
95
 
        &( _outvec[ 0 ] ),
96
 
        &( _outvec[ 0 ] ) + g ) ;
97
 
  _remain -= g ;
98
 
  if ( g > 0 )
99
 
    return static_cast< unsigned char >( *gptr() ) ;
100
 
  else
101
 
    return EOF ; // traits_type::eof() 
102
 
}
103
 
 
104
 
 
105
 
// FIXME: We need to check somew
106
 
//  
107
 
//    // gp_bitfield bit 3 is one, if the length of the zip entry
108
 
//    // is stored in a trailer.
109
 
//    if ( is->good  && ( _curr_entry.gp_bitfield & 4 ) != 1 )
110
 
//      return true ;
111
 
//    else {
112
 
//      is->clear() ;
113
 
//      return false ;
114
 
//    }
115
 
 
116
 
 
117
 
} // namespace
118
 
 
119
 
/** \file
120
 
    Implementation of ZipInputStreambuf.
121
 
*/
122
 
 
123
 
/*
124
 
  Zipios++ - a small C++ library that provides easy access to .zip files.
125
 
  Copyright (C) 2000  Thomas S�ndergaard
126
 
  
127
 
  This library is free software; you can redistribute it and/or
128
 
  modify it under the terms of the GNU Lesser General Public
129
 
  License as published by the Free Software Foundation; either
130
 
  version 2 of the License, or (at your option) any later version.
131
 
  
132
 
  This library is distributed in the hope that it will be useful,
133
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
134
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
135
 
  Lesser General Public License for more details.
136
 
  
137
 
  You should have received a copy of the GNU Lesser General Public
138
 
  License along with this library; if not, write to the Free Software
139
 
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
140
 
*/