?? rlep.cpp
字號:
// Created:11-20-98
// By Jeff Connelly
// RLEP - RLE Packer
#include "comprlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
// Returns the size of 'fp'
long file_length(FILE* fp)
{
long pos, ret;
pos = ftell(fp);
fseek(fp, 0, SEEK_END);
ret = ftell(fp);
fseek(fp, pos, SEEK_SET);
return ret;
}
const char* help =
"RLE Packer, packes files using RLE method\n"
"\tRLEP files...\n"
"Multible files may be specified. Output extension is .RLE\n"
"\n";
int main(int argc, char* argv[])
{
register int i;
FILE* in;
FILE* out;
char* infn;
char* outfn;
char* buf;
char* inbuf;
char c;
long inlen;
if (argc == 1)
{
printf(help);
exit (0);
}
// We could use file I/O, but memory I/O is faster
ComprLibMemIO::Set();
for (i = 1; i < argc; ++i)
{
// Copy 'fn' from 'argv[i]'
infn = xmalloc(strlen(argv[i]));
strcpy (infn, argv[i]);
printf ("\nPacking %s...\t\t", infn);
in = fopen(infn, "rb");
if (!in)
{
printf ("Cannot open %s", infn);
xfree(infn);
continue;
}
// Figure out the output filename, with .RLE
outfn = xmalloc(strlen(infn)); // Copy 'outfn' to
strcpy (outfn, infn); // 'infn' and allocate memory
if (!strchr(infn, '.')) // No extension, just tack on .RLE
strcat(outfn, ".RLE");
else // Replace the extension with .RLE
{
buf = strchr(infn, '.');
strcpy (buf, ".RLE");
}
if (__file_exists(outfn))
{
printf ("File already exists! [R]eplace, E[x]it, Re[n]ame, [S]kip");
c = toupper(getc(stdin));
if (c == 'X')
exit (2);
else if (c == 'S')
continue;
else if (c == 'N')
{
printf ("Name: ");
gets(outfn);
}
else if (c == 'R')
;
else
exit(2);
}
out = fopen(outfn, "wb");
// Load the file into memory
inlen = file_length(in);
inbuf = xmalloc(inlen);
fread (inbuf, inlen, 1, in);
// Set up ComprLib
ComprLibMemIO::source_ptr = inbuf;
ComprLibMemIO::dest_ptr = NULL;
ComprLibMemIO::source_len = inlen;
ComprLibMemIO::dest_len = 0;
rle1_encode(); // Encode it!
// Write the output buffer
fwrite (ComprLibMemIO::dest_ptr, 1, ComprLibMemIO::dest_len, out);
// Clean up all the stuff
xfree(inbuf);
xfree(ComprLibMemIO::dest_ptr);
xfree(infn);
fclose(in);
fclose(out);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -