~ubuntu-branches/ubuntu/maverick/asc/maverick

« back to all changes in this revision

Viewing changes to source/basestrm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff, Moritz Muehlenhoff, Barry deFreese, Alexander Reichle-Schmehl
  • Date: 2010-01-01 22:11:14 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100101221114-qfg9ogppdfcte4m7
Tags: 2.4.0.0-1
[ Moritz Muehlenhoff ]
* New upstream release. (2.4.0)
  - Drop obsolete patches
  - Initializes map_edit properly. (Closes: #534171).
* Update to standards version 3.8.3
* Switch to source format 3.0 (quilt) (Closes: #538430)
* Adding myself to uploaders

[ Barry deFreese ]
* New upstream release. (2.2.0)

[ Alexander Reichle-Schmehl ]
* Adopt debian/control to my new name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#include <sys/stat.h>
40
40
 
 
41
#include <bzlib.h>
 
42
 
41
43
#include "global.h"
42
44
#include "basestrm.h"
43
45
 
57
59
#include <SDL_endian.h>
58
60
 
59
61
 
60
 
#include "messaginghub.h"
 
62
#include "util/messaginghub.h"
61
63
 
62
64
 
63
65
 const int maxSearchDirNum = 30;
274
276
}
275
277
 
276
278
 
277
 
ASCString tnstream::getDeviceName ( void )
278
 
{
279
 
   return devicename;
280
 
}
281
 
 
282
 
ASCString tnstream::getLocation ( void )
283
 
{
284
 
   return devicename;
 
279
ASCString tnstream::getDeviceName()
 
280
{
 
281
   return devicename;
 
282
}
 
283
 
 
284
ASCString tnstream::getLocation()
 
285
{
 
286
   return devicename;
 
287
}
 
288
 
 
289
ASCString tnstream::getArchive()
 
290
{
 
291
   return "";
285
292
}
286
293
 
287
294
int  tnstream::readInt  ( void )
643
650
 
644
651
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
645
652
 
646
 
#ifdef _SDL_
647
653
 
648
654
static int stream_seek( struct SDL_RWops *context, int offset, int whence)
649
655
{
699
705
        return(rwops);
700
706
}
701
707
 
702
 
#endif
703
708
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
704
709
 
705
710
 
772
777
   if ( i >= num )
773
778
      throw tfileerror ( name );
774
779
 
 
780
   displayLogMessage( 9, ASCString("opencontainerfile ") + name );
 
781
   containerfilepos = 0;
 
782
   seek ( index[i].start );
775
783
   actfile = &index[i];
776
 
   containerfilepos = 0;
777
 
   seek ( actfile->start );
778
784
}
779
785
 
780
786
int tncontainerstream :: readcontainerdata ( void* buf, int size, bool excpt  )
1158
1164
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1159
1165
 
1160
1166
 
 
1167
class PrivateCompressionData {
 
1168
   public:  
 
1169
      bz_stream bzs;
 
1170
      static const int outputbufsize = 100000;
 
1171
      char outputbuf[outputbufsize];
 
1172
      
 
1173
      PrivateCompressionData() {
 
1174
         bzs.bzalloc = NULL;
 
1175
         bzs.bzfree = NULL;
 
1176
         bzs.opaque = NULL;
 
1177
      };
 
1178
      
 
1179
      ~PrivateCompressionData() {
 
1180
         BZ2_bzCompressEnd ( &bzs );
 
1181
      }
 
1182
};
1161
1183
 
1162
1184
libbzip_compression :: libbzip_compression ( p_compressor_stream_interface strm  )
1163
1185
{
1164
 
   bzs.bzalloc = NULL;
1165
 
   bzs.bzfree = NULL;
1166
 
   bzs.opaque = NULL;
1167
 
 
1168
 
   BZ2_bzCompressInit ( &bzs, 5, 0, 0 );
1169
 
 
1170
 
   outputbufsize = 100000;
1171
 
   outputbuf = new char [ outputbufsize ];
 
1186
   data = new PrivateCompressionData();
 
1187
   BZ2_bzCompressInit ( &data->bzs, 5, 0, 0 );
1172
1188
 
1173
1189
   stream = strm;
1174
1190
}
1178
1194
{
1179
1195
   char* cbuf = (char*) buf;
1180
1196
 
1181
 
   bzs.next_in = cbuf ;
1182
 
   bzs.avail_in = size ;
1183
 
   bzs.total_in_lo32 = 0 ;
1184
 
   bzs.total_in_hi32 = 0 ;
1185
 
 
1186
 
   while ( bzs.total_in_lo32 < size ) {
1187
 
 
1188
 
     bzs.next_out = outputbuf;
1189
 
     bzs.avail_out = outputbufsize;
1190
 
     bzs.total_out_lo32 = 0;
1191
 
     bzs.total_out_hi32 = 0;
1192
 
 
1193
 
     int res = BZ2_bzCompress ( &bzs, BZ_RUN );
 
1197
   data->bzs.next_in = cbuf ;
 
1198
   data->bzs.avail_in = size ;
 
1199
   data->bzs.total_in_lo32 = 0 ;
 
1200
   data->bzs.total_in_hi32 = 0 ;
 
1201
 
 
1202
   while ( data->bzs.total_in_lo32 < size ) {
 
1203
 
 
1204
     data->bzs.next_out = data->outputbuf;
 
1205
     data->bzs.avail_out = data->outputbufsize;
 
1206
     data->bzs.total_out_lo32 = 0;
 
1207
     data->bzs.total_out_hi32 = 0;
 
1208
 
 
1209
     int res = BZ2_bzCompress ( &data->bzs, BZ_RUN );
1194
1210
     if ( res < 0 )
1195
1211
        throw tcompressionerror ( "MBZLB2 compression :: writedata", res );
1196
1212
 
1197
 
     for ( int i = 0; i < bzs.total_out_lo32; i++ )
1198
 
        outputbuf[i] ^= bzip_xor_byte;
 
1213
     for ( int i = 0; i < data->bzs.total_out_lo32; i++ )
 
1214
        data->outputbuf[i] ^= bzip_xor_byte;
1199
1215
 
1200
 
     stream->writecmpdata ( outputbuf, bzs.total_out_lo32 );
 
1216
     stream->writecmpdata ( data->outputbuf, data->bzs.total_out_lo32 );
1201
1217
   }
1202
1218
}
1203
1219
 
1206
1222
{
1207
1223
   int res;
1208
1224
   do {
1209
 
     bzs.next_in = outputbuf;
1210
 
     bzs.avail_in = 0;
1211
 
 
1212
 
     bzs.next_out = outputbuf;
1213
 
     bzs.avail_out = outputbufsize;
1214
 
     bzs.total_out_lo32 = 0;
1215
 
     bzs.total_out_hi32 = 0;
1216
 
 
1217
 
     res = BZ2_bzCompress ( &bzs, BZ_FINISH );
 
1225
     data->bzs.next_in = data->outputbuf;
 
1226
     data->bzs.avail_in = 0;
 
1227
 
 
1228
     data->bzs.next_out = data->outputbuf;
 
1229
     data->bzs.avail_out = data->outputbufsize;
 
1230
     data->bzs.total_out_lo32 = 0;
 
1231
     data->bzs.total_out_hi32 = 0;
 
1232
 
 
1233
     res = BZ2_bzCompress ( &data->bzs, BZ_FINISH );
1218
1234
     if ( res < 0 )
1219
1235
        throw tcompressionerror ( "MBZLB2 compression :: closecompression", res );
1220
1236
 
1221
 
     for ( int i = 0; i < bzs.total_out_lo32; i++ )
1222
 
        outputbuf[i] ^= bzip_xor_byte;
1223
 
     stream->writecmpdata ( outputbuf, bzs.total_out_lo32 );
 
1237
     for ( int i = 0; i < data->bzs.total_out_lo32; i++ )
 
1238
        data->outputbuf[i] ^= bzip_xor_byte;
 
1239
     stream->writecmpdata ( data->outputbuf, data->bzs.total_out_lo32 );
1224
1240
 
1225
1241
   } while ( res != BZ_STREAM_END );
1226
1242
 
1227
1243
 
1228
 
   BZ2_bzCompressEnd ( &bzs );
 
1244
   BZ2_bzCompressEnd ( &data->bzs );
1229
1245
}
1230
1246
 
1231
1247
libbzip_compression :: ~libbzip_compression ( )
1232
1248
{
1233
 
   if ( outputbuf ) {
1234
 
      delete[] outputbuf;
1235
 
      outputbuf = NULL;
1236
 
   }
 
1249
   delete data;
1237
1250
}
1238
1251
 
1239
1252
 
1240
1253
 
1241
 
 
 
1254
class PrivateDecompressionData {
 
1255
   public: 
 
1256
      bz_stream bzs;
 
1257
      static const int inputbufsize = 100000;
 
1258
      char inputbuf[inputbufsize];
 
1259
      int inputbufused;
 
1260
      int inputbufread;
 
1261
      
 
1262
      PrivateDecompressionData() {
 
1263
         bzs.bzalloc = NULL;
 
1264
         bzs.bzfree = NULL;
 
1265
         bzs.opaque = NULL;
 
1266
         
 
1267
         inputbufused = 0;
 
1268
         inputbufread = 0;
 
1269
         
 
1270
      }
 
1271
      
 
1272
      ~PrivateDecompressionData() {
 
1273
         BZ2_bzDecompressEnd ( &bzs );
 
1274
      }
 
1275
      
 
1276
};
 
1277
      
1242
1278
libbzip_decompression :: libbzip_decompression ( p_compressor_stream_interface strm  )
1243
1279
{
1244
 
   bzs.bzalloc = NULL;
1245
 
   bzs.bzfree = NULL;
1246
 
   bzs.opaque = NULL;
1247
 
 
1248
 
   BZ2_bzDecompressInit ( &bzs, 0, 0 );
1249
 
 
1250
 
   inputbufsize = 100000;
1251
 
   inputbuf = new char [ inputbufsize ];
1252
 
   inputbufused = 0;
1253
 
   inputbufread = 0;
1254
 
 
 
1280
   data = new PrivateDecompressionData();
 
1281
   BZ2_bzDecompressInit ( &data->bzs, 0, 0 );
1255
1282
   stream = strm;
1256
1283
}
1257
1284
 
1261
1288
   int decompressed = 0;
1262
1289
   char* cbuf = (char*) buf;
1263
1290
 
1264
 
   bzs.next_in = cbuf ;
1265
 
   bzs.avail_in = size ;
1266
 
   bzs.total_in_lo32 = 0 ;
1267
 
   bzs.total_in_hi32 = 0 ;
 
1291
   data->bzs.next_in = cbuf ;
 
1292
   data->bzs.avail_in = size ;
 
1293
   data->bzs.total_in_lo32 = 0 ;
 
1294
   data->bzs.total_in_hi32 = 0 ;
1268
1295
 
1269
1296
   int abrt = 0;
1270
1297
 
1271
1298
   while ( decompressed < size  && !abrt ) {
1272
 
     if ( inputbufread >= inputbufused ) {
1273
 
        inputbufused = stream->readcmpdata ( inputbuf, inputbufsize, 0 );
 
1299
     if ( data->inputbufread >= data->inputbufused ) {
 
1300
        data->inputbufused = stream->readcmpdata ( data->inputbuf, data->inputbufsize, 0 );
1274
1301
 
1275
 
        if ( !inputbufused && excpt )
 
1302
        if ( !data->inputbufused && excpt )
1276
1303
           throw tcompressionerror ( "Decompressor :: out of data", 0 );
1277
1304
 
1278
1305
 
1279
 
        for ( int i = 0; i < inputbufused; i++ )
1280
 
           inputbuf[i] ^= bzip_xor_byte;
 
1306
        for ( int i = 0; i < data->inputbufused; i++ )
 
1307
           data->inputbuf[i] ^= bzip_xor_byte;
1281
1308
 
1282
 
        inputbufread = 0;
 
1309
        data->inputbufread = 0;
1283
1310
     }
1284
 
     bzs.next_in = inputbuf + inputbufread;
1285
 
     bzs.avail_in = inputbufused - inputbufread;
1286
 
     bzs.total_in_lo32 = 0;
1287
 
     bzs.total_in_hi32 = 0;
1288
 
 
1289
 
     bzs.next_out = cbuf + decompressed;
1290
 
     bzs.avail_out = size - decompressed;
1291
 
     bzs.total_out_lo32 = 0;
1292
 
     bzs.total_out_hi32 = 0;
1293
 
 
1294
 
     int res = BZ2_bzDecompress ( &bzs );
1295
 
     decompressed += bzs.total_out_lo32;
1296
 
     inputbufread += bzs.total_in_lo32;
 
1311
     data->bzs.next_in = data->inputbuf + data->inputbufread;
 
1312
     data->bzs.avail_in = data->inputbufused - data->inputbufread;
 
1313
     data->bzs.total_in_lo32 = 0;
 
1314
     data->bzs.total_in_hi32 = 0;
 
1315
 
 
1316
     data->bzs.next_out = cbuf + decompressed;
 
1317
     data->bzs.avail_out = size - decompressed;
 
1318
     data->bzs.total_out_lo32 = 0;
 
1319
     data->bzs.total_out_hi32 = 0;
 
1320
 
 
1321
     int res = BZ2_bzDecompress ( &data->bzs );
 
1322
     decompressed += data->bzs.total_out_lo32;
 
1323
     data->inputbufread += data->bzs.total_in_lo32;
1297
1324
 
1298
1325
     if ( decompressed < size  ) {
1299
1326
        if ( res == BZ_STREAM_END ) {
1319
1346
 
1320
1347
libbzip_decompression :: ~libbzip_decompression ( )
1321
1348
{
1322
 
   if ( inputbuf ) {
1323
 
      BZ2_bzDecompressEnd ( &bzs );
1324
 
      delete[] inputbuf;
1325
 
      inputbuf = NULL;
1326
 
   }
 
1349
   delete data;
1327
1350
}
1328
1351
 
1329
1352
 
1596
1619
   } else {
1597
1620
      containerstream = fl.container;
1598
1621
      if ( containerstream ) {
 
1622
         inp = 2;
1599
1623
         containerstream->opencontainerfile ( name.c_str() );
1600
1624
         devicename = name;
1601
1625
         location = name + " located inside " + containerstream->getDeviceName();
1602
 
         inp = 2;
1603
1626
      } else
1604
1627
         throw tfileerror ( name );
1605
1628
   }
1608
1631
   tanycompression :: init (  );
1609
1632
}
1610
1633
 
 
1634
ASCString tn_c_lzw_filestream::getArchive()
 
1635
{
 
1636
   if ( containerstream )
 
1637
      return containerstream->getDeviceName();
 
1638
   else
 
1639
      return "";
 
1640
}
 
1641
 
 
1642
 
1611
1643
ASCString tn_c_lzw_filestream::getLocation()
1612
1644
{
1613
1645
   return location;
1665
1697
 
1666
1698
tn_c_lzw_filestream :: ~tn_c_lzw_filestream()
1667
1699
{
1668
 
   close_compression ();
1669
 
   close();
1670
 
   if ( inp == 1 ) {
1671
 
      delete strm;
1672
 
      strm = NULL;
1673
 
   } else
1674
 
      containerstream->closecontainerfile();
 
1700
   try {
 
1701
      displayLogMessage( 9, "~tn_c_lzw_filestream " + getLocation() );
 
1702
      
 
1703
      close_compression ();
 
1704
      close();
 
1705
      if ( inp == 1 ) {
 
1706
         delete strm;
 
1707
         strm = NULL;
 
1708
      } else {
 
1709
         displayLogMessage( 9, ASCString("~tn_c_lzw_filestream -> closecontainerfile ") );
 
1710
         containerstream->closecontainerfile();
 
1711
      }
 
1712
   } catch ( ... ) {
 
1713
      displayLogMessage( 9, ASCString("~tn_c_lzw_filestream : caught exception") );
 
1714
      throw;
 
1715
   }
1675
1716
}
1676
1717
 
1677
1718
 
2067
2108
 
2068
2109
  tmemorystreambuf :: tmemorystreambuf ( void )
2069
2110
  {
2070
 
     initialized = false;
2071
2111
     used = 0;
2072
2112
     allocated = 0;
2073
2113
     buf = 0;
2085
2125
  void tmemorystreambuf :: writetostream ( pnstream stream )
2086
2126
  {
2087
2127
     if ( stream ) {
2088
 
        stream->writeInt ( initialized );
 
2128
        stream->writeInt ( 0 );
2089
2129
        stream->writeInt ( used );
2090
2130
        stream->writeInt ( allocated );
2091
2131
        for ( int i = 0; i < 10; i++ )
2098
2138
  void tmemorystreambuf :: readfromstream ( pnstream stream )
2099
2139
  {
2100
2140
     if ( stream ) {
2101
 
        initialized = stream->readInt();
 
2141
        stream->readInt();
2102
2142
        used        = stream->readInt();
2103
2143
        allocated   = stream->readInt();
2104
2144
        for ( int i = 0; i< 10; i++ )