A C + + and Delphi to do the compression program

Source: Internet
Author: User
Tags define decompress file integer mail reset
{This is interface of C + + code.
C + + source code not included to this archive.
Look at the README. TXT file for more information. }

#ifndef __coding_h__
#define __coding_h__

#ifndef Coding_impex
#define CODING_IMPEX __declspec (dllimport)
#endif

Class Coding_impex Avldecode
{
Public
~avldecode ();
Avldecode ();

virtual int Readbuf
(void *buf,
Unsigned maxlen,
unsigned &rdlen
) = 0;

int get (void *buf, unsigned maxlen);
int get (void *buf, unsigned maxlen, unsigned &rdlen)
{return ((int) (Rdlen = Get (buf, MaxLen)) < 0)? rdlen:0;
}

void Reset ();

Private

????????? Private part not included???????????????????

};


Class Coding_impex Avlencode
{
Public
~avlencode ();
Avlencode ();

virtual int Writebuf
(void *buf,
Unsigned len
) = 0;


int put (void *buf, unsigned n);
void Reset ();

Private
?????????? Private Part not icluded?????????????

};

#endif//__coding_h__


Encode.pas
{$M 8192,120000,120000}
Uses avlcodes;

Const bufsize=60000;

var p:pointer;
F,f1:file;
s:string;
Buf:pointer;
Num:word;

{$F +}

Function WriteToFile (var buf; n:integer): integer;
var Num:word;
Begin
Blockwrite (F1,buf,n,num);
End;

{$F-}

Begin
If not getmemory then
Begin
Writeln (' Not enough memory in HEAP to compress file. ');
Halt
End;
S:=PARAMSTR (1);
Setencodeoutbuffer (@WriteToFile);
Assign (f,s);
{$I-}
If s<> ' then Reset (f,1);
{$I +}
if (ioresult<>0) or (s= ') then
Begin
Writeln;
Writeln (' The author of this Turbo-Pascal program and original C + + code is ');
Writeln (' Alexander Larkin (translated to Turbo Pascal-C + on 27/09/1999) ');
Writeln;
Writeln (' e-mail:avlarkin@writeme.com ');
Writeln (' internet:http://www.geocities.com/siliconvalley/6235/tpdl.htm ');
Writeln;
Writeln (' Usage:encode.exe InFile outfile [password] ');
Writeln;
Freememory;
Halt
End;
S:=PARAMSTR (2);
Assign (f1,s);
{$I-}
If s<> ' then ReWrite (f1,1);
{$I +}
if (ioresult<>0) or (s= ') then
Begin
Close (f);
Writeln (' Cannot create find file ' +s);
Freememory;
Halt
End;
SetPassword (PARAMSTR (3));
Getmem (buf,bufsize);
Repeat
Blockread (F,buf^,bufsize,num);
Encodeput (Buf^,num);
Until num<=0;
If Num<0 then Writeln (' cannot compress file. Do something wrong. ');
Encodereset;
Close (f);
Close (F1);
Freememory;
End.

Decode.pas
{$M 8192,120000,120000}
Uses avlcodes;

Const bufsize=60000;

var p:pointer;
F,f1:file;
s:string;
Buf:pointer;
Num:word;

{$F +}

Function ReadFromFile (var buf; n:integer var rdlen:integer): integer;
Begin
Blockread (F,buf,n,rdlen);
readfromfile:=0;
End;

{$F-}

Begin
If not getmemory then
Begin
Writeln (' Not enough memory in HEAP to decompress file. ');
Halt
End;
S:=PARAMSTR (1);
Setdecodeinbuffer (@ReadFromFile);
Assign (f,s);
{$I-}
If s<> ' then Reset (f,1);
{$I +}
if (ioresult<>0) or (s= ') then
Begin
Writeln;
Writeln (' The author of this Turbo-Pascal program and original C + + code is ');
Writeln (' Alexander Larkin (translated to Turbo Pascal-C + on 27/09/1999) ');
Writeln;
Writeln (' e-mail:avlarkin@writeme.com ');
Writeln (' internet:http://www.geocities.com/siliconvalley/6235/tpdl.htm ');
Writeln;
Writeln (' Usage:decode.exe InFile outfile [password] ');
Writeln;
Freememory;
Halt
End;
S:=PARAMSTR (2);
Assign (f1,s);
{$I-}
If s<> ' then ReWrite (f1,1);
{$I +}
if (ioresult<>0) or (s= ') then
Begin
Close (f);
Writeln (' Cannot create file ' +s);
Freememory;
Halt
End;
Getmem (buf,bufsize);
SetPassword (PARAMSTR (3));
Repeat
Num:=decodeget (buf^,bufsize);
If num<65535 then Blockwrite (f1,buf^,num,num);
Until (num=0) or (num=65535);
If num=65535 then Writeln (' error! Data corrupted. Cannot decompress file. ');
Close (f);
Close (F1);
Freememory;
End.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.