177 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			177 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| //
 | |
| // EX16CON.CPP
 | |
| //
 | |
| //  C++/DOS Example program for ArchiveLib 2.0
 | |
| //
 | |
| //  Copyright (c) Greenleaf Software, Inc. 1994 - 1996
 | |
| //  All Rights Reserved
 | |
| //
 | |
| // MEMBERS/FUNCTIONS DEMONSTRATED
 | |
| //
 | |
| //   ALEntry::~ALEntry()
 | |
| //   ALEntry::ClearMark()
 | |
| //   ALEntry::CompressionRatio()
 | |
| //   ALEntry::GetCrc32()
 | |
| //   ALEntry::SetMarkState()
 | |
| //   ALStatus::GetStatusDetail()
 | |
| //   ALStatus::GetStatusString()
 | |
| //
 | |
| // DESCRIPTION
 | |
| //
 | |
| //  This example is a grab-bag, designed to highlight a bunch of barely
 | |
| //  related functions.  So don't look for any sort of intelligence at
 | |
| //  work here, you won't find it.  The program first creates a whole
 | |
| //  bunch of ALMemory objects, initializing them with a bunch of fixed
 | |
| //  data so that they compress fairly well.  It then does a bunch of
 | |
| //  manipulation of the memory objects in their list, deleting some,
 | |
| //  changing the compression engine of others, and clearing the marks
 | |
| //  of even more.  Finally, it creates the archive, then displays the
 | |
| //  list for your viewing pleasure.
 | |
| //
 | |
| //
 | |
| // REVISION HISTORY
 | |
| //
 | |
| //  February 1, 1996  2.0A  : Second release
 | |
| //
 | |
| 
 | |
| #include <iostream.h>
 | |
| #include <string.h>
 | |
| #include <stdio.h>
 | |
| #include <stdlib.h>
 | |
| #include <iomanip.h>
 | |
| #include <conio.h>
 | |
| 
 | |
| #include "arclib.h"
 | |
| #include "pkarc.h"
 | |
| #include "glarc.h"
 | |
| #include "glengn.h"
 | |
| #include "pkengn.h"
 | |
| #include "bargraph.h"
 | |
| #include "memstore.h"
 | |
| #include "copyengn.h"
 | |
| 
 | |
| main()
 | |
| {
 | |
|     cout << "Archive Library 2.0\nEX16CON.CPP\n\n";
 | |
|     cout << "This example is a grab-bag, designed to highlight a bunch of barely\n";
 | |
|     cout << "related functions.  So don't look for any sort of intelligence at\n";
 | |
|     cout << "work here, you won't find it.  The program first creates a whole\n";
 | |
|     cout << "bunch of ALMemory objects, initializing them with a bunch of fixed\n";
 | |
|     cout << "data so that they compress fairly well.  It then does a bunch of\n";
 | |
|     cout << "manipulation of the memory objects in their list, deleting some,\n";
 | |
|     cout << "changing the compression engine of others, and clearing the marks\n";
 | |
|     cout << "of even more.  Finally, it creates the archive, then displays the\n";
 | |
|     cout << "list for your viewing pleasure.\n\n";
 | |
|     getch();
 | |
| 
 | |
|     char temp[ 128 ];
 | |
|     ALBarGraph monitor( AL_MONITOR_JOB );
 | |
| 
 | |
| #if defined( ZIP )
 | |
|     ALPkArchive archive( "dos16.zip" );
 | |
| #else
 | |
|     ALGlArchive archive( "dos16.gal" );
 | |
| #endif
 | |
|     ALEntryList list( &monitor );
 | |
| //
 | |
| // The first step is to create 24 ALMemory objects.  Each one has the
 | |
| // contents of the temp buffer written out to it, with the temp buffer
 | |
| // being just a little different every time.  As each object is created,
 | |
| // I add it to the list, along with a new copy of the greenleaf engine.
 | |
| //
 | |
|     memset( temp, 'A', 128 );
 | |
|     for ( int i = 0 ; i < 24  ; i++ ) {
 | |
|         char name[ 20 ];
 | |
|         sprintf( name, "Buffer %02d", i );
 | |
|         ALStorage *obj = new ALMemory( name );
 | |
|         obj->Create();
 | |
|         memset( temp + i, i, i );
 | |
|         obj->WriteBuffer( (unsigned char *) temp, 128 );
 | |
|         obj->Close();
 | |
| #if defined( ZIP )
 | |
|         new ALEntry( list, obj, new ALPkCompressor, new ALPkDecompressor );
 | |
| #else
 | |
|         new ALEntry( list, obj, new ALGlCompressor, new ALGlDecompressor  );
 | |
| #endif
 | |
|     }
 | |
| //
 | |
| // Now for fun, I am going to delete every third entry in list
 | |
| //
 | |
|     ALEntry *entry = list.GetFirstEntry();
 | |
|     for ( ; entry != 0 ; ) {
 | |
|         ALEntry *next_entry = entry->GetNextEntry();
 | |
|         delete entry;
 | |
|         entry = next_entry->GetNextEntry();
 | |
|         if ( entry )
 | |
|             entry = entry->GetNextEntry();
 | |
|     }
 | |
| //
 | |
| // Now, for more fun, I am going to change the compression engine in every
 | |
| // third entry.
 | |
| //
 | |
|     entry = list.GetFirstEntry();
 | |
|     for ( ; entry != 0 ; ) {
 | |
|         if ( entry->mpCompressor->miCompressionType !=
 | |
| #if defined( ZIP )
 | |
|              AL_COMPRESSION_DEFLATE ) {
 | |
| #else
 | |
|              AL_COMPRESSION_GREENLEAF ) {
 | |
| #endif
 | |
|             cout << "Unknown engine type!\n";
 | |
|             exit( 1 );
 | |
|         }
 | |
|         delete entry->mpCompressor;
 | |
|         entry->mpCompressor = new ALCopyCompressor;
 | |
|         entry->SetComment( "No compression here" );
 | |
|         entry = entry->GetNextEntry();
 | |
|         if ( entry )
 | |
|             entry = entry->GetNextEntry();
 | |
|         if ( entry )
 | |
|             entry = entry->GetNextEntry();
 | |
|     }
 | |
| //
 | |
| // Now, for the last bit of fun, I unmark every other entry
 | |
| //
 | |
|     entry = list.GetFirstEntry();
 | |
|     for ( ; entry != 0 ; ) {
 | |
|         entry->ClearMark();
 | |
|         entry = entry->GetNextEntry();
 | |
|         if ( entry ) {
 | |
|             entry->SetMarkState( 1 );
 | |
|             entry = entry->GetNextEntry();
 | |
|         }
 | |
|     }
 | |
| //
 | |
| // Having done all that, it is time to create the archive, then print
 | |
| // out the list, along with the CRC and compression ratio for all
 | |
| // the entries.
 | |
| //
 | |
|     int status = archive.Create( list );
 | |
|     cout << "Archive status: " << archive.mStatus << endl;
 | |
|     cout << "\nList status:\n\n";
 | |
|     if ( status >= 0 ) {
 | |
|         for ( entry = list.GetFirstEntry() ;
 | |
|               entry ;
 | |
|               entry = entry->GetNextEntry() ) {
 | |
|             cout << entry->mpStorageObject->mName
 | |
|                  << " :  ";
 | |
|             if ( entry->GetMark() ) {
 | |
|                 cout << entry->CompressionRatio()
 | |
|                      << "%  ";
 | |
|                 (void) cout.width( 8 );
 | |
|                 cout << hex
 | |
|                      << entry->GetCrc32()
 | |
|                      << dec
 | |
|                      << "\n";
 | |
|             } else {
 | |
|                 cout << "Not marked\n";
 | |
|             }
 | |
|         }
 | |
|     }
 | |
|     cout << "\n";
 | |
|     cout << "List code:   " << (int) list.mStatus << "\n";
 | |
|     cout << "List string: " << list.mStatus.GetStatusString() << "\n";
 | |
|     cout << "List detail: " << list.mStatus.GetStatusDetail() << "\n";
 | |
|     return status;
 | |
| }
 |