📄 encdec.cpp
字号:
// Created:10-31-98
// By Jeff Connelly
// The simplest program that uses ComprLib
// Compile: gcc encdec.cpp -o encdec.exe -lcompr
// Include the ComprLib header file
#include "comprlib.h"
// Other header files
#include <stdio.h>
int main (int argc, char* argv[])
{
if (argc != 4)
{
printf ("Encodes a file, a simple ComprLib example\n"
"\tSIMPLE source encoded decoded\n"
"SOURCE is encoded as ENCODED\n"
"ENCODED is is decoded as DECODED\n");
exit (0);
}
// I/O is accomplished by 4 function pointers: 'read_byte', 'write_byte',
// 'end_of_data', and 'stream_size'. These can be set directly or
// via the 'Set()' member function in 'ComprLibFileIO' or 'ComprLibMemIO'
// C++ classes.
ComprLibFileIO::Set(); // We are using file I/O
// Open the files
ComprLibFileIO::source_file = fopen(argv[1], "rb");
ComprLibFileIO::dest_file = fopen(argv[2], "wb");
// See if they were actually opened
if (!ComprLibFileIO::source_file || !ComprLibFileIO::dest_file)
{
printf ("Cannot open file(s)\n");
exit (1);
}
printf ("Encoding...\n");
// The meat of the program: encode the file. There are over 40 encoding,
// decoding, and other functions that can be used.
lzss_encode(); // LZSS -> Lempel-Ziv-Storer-Szymanski compression
// The files are not closed automatically, so do it now
fclose(ComprLibFileIO::source_file);
fclose(ComprLibFileIO::dest_file);
// Open the file pointers
ComprLibFileIO::source_file = fopen(argv[2], "rb");
ComprLibFileIO::dest_file = fopen(argv[3], "wb");
// Validate...
if (!ComprLibFileIO::source_file || !ComprLibFileIO::dest_file)
{
printf ("Cannot open file(s)\n");
exit (2);
}
// Decompress
printf ("Decoding...\n");
lzss_decode();
// Finally, close the files again
fclose(ComprLibFileIO::source_file);
fclose(ComprLibFileIO::dest_file);
// End of program!
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -