aplibu.pas

来自「一些初级的网络编程」· PAS 代码 · 共 229 行

PAS
229
字号
unit aplibu;

(*
 * aPLib compression library  -  the smaller the better :)
 *
 * TMT Pascal interface to aPLib Delphi objects
 *
 * Copyright (c) 1998-2004 by Joergen Ibsen / Jibz
 * All Rights Reserved
 *
 * http://www.ibsensoftware.com/
 *
 * -> VPascal by Veit Kannegieser, 23.09.1998
 * -> TMT Pascal by Oleg Prokhorov
 *)

(* To enable aborting compression with Esc, define ESC_ABORT *)

interface

const
  aP_pack_continue=1;
  aP_pack_break   =0;

  aPLib_Error     =-1; (* indicates error compressing/decompressing *)

function aP_pack(var source;
                 var destination;
                 length:longint;
                 var workmem;
                 callback:pointer;
                 cbparam:pointer):longint;

function aP_workmem_size(inputsize:longint):longint;

function aP_max_packed_size(inputsize:longint):longint;

function aP_depack_asm(var source,destination):longint;

function aP_depack_asm_fast(var source,destination):longint;

function aP_depack_asm_safe(var source;
                            srclen:longint;
                            var destination;
                            dstlen:longint):longint;

function aP_crc32(var source;
                  length:longint):longint;

function aPsafe_pack(var source;
                     var destination;
                     length:longint;
                     var workmem;
                     callback:pointer;
                     cbparam:pointer):longint;

function aPsafe_check(var source):longint;

function aPsafe_get_orig_size(var source):longint;

function aPsafe_depack(var source;
                       srclen:longint;
                       var destination;
                       dstlen:longint):longint;

function cb0:longint;
function cb1:longint;

implementation

(*$IFDEF ESC_ABORT*)
uses crt;
(*$ENDIF ESC_ABORT*)

function _aP_pack:longint;external;
function _aP_workmem_size:longint;external;
function _aP_max_packed_size:longint;external;
function _aP_depack_asm:longint;external;
function _aP_depack_asm_fast:longint;external;
function _aP_depack_asm_safe:longint;external;
function _aP_crc32:longint;external;
function _aPsafe_pack:longint;external;
function _aPsafe_check:longint;external;
function _aPsafe_get_orig_size:longint;external;
function _aPsafe_depack:longint;external;

(*$l ..\..\lib\delphi\aplib.obj    *)
(*$l ..\..\lib\delphi\depack.obj   *)
(*$l ..\..\lib\delphi\depackf.obj  *)
(*$l ..\..\lib\delphi\depacks.obj  *)
(*$l ..\..\lib\delphi\crc32.obj    *)
(*$l ..\..\lib\delphi\spack.obj    *)
(*$l ..\..\lib\delphi\scheck.obj   *)
(*$l ..\..\lib\delphi\sgetsize.obj *)
(*$l ..\..\lib\delphi\sdepack.obj  *)

function aP_pack(var source;
                 var destination;
                 length:longint;
                 var workmem;
                 callback:pointer;
                 cbparam:pointer):longint;assembler;
  asm
      push cbparam
       push callback
        push workmem
         push length
          push destination
           push source
            call _aP_pack
  end;

function aP_workmem_size(inputsize:longint):longint;assembler;
  asm
     push inputsize
      call _aP_workmem_size
  end;

function aP_max_packed_size(inputsize:longint):longint;assembler;
  asm
     push inputsize
      call _aP_max_packed_size
  end;

function aP_depack_asm(var source,destination):longint;assembler;
  asm
     push destination
      push source
       call _aP_depack_asm
  end;

function aP_depack_asm_fast(var source,destination):longint;assembler;
  asm
     push destination
      push source
       call _aP_depack_asm_fast
  end;

function aP_depack_asm_safe(var source;
                            srclen:longint;
                            var destination;
                            dstlen:longint):longint;assembler;
  asm
     push dstlen
      push destination
       push srclen
        push source
         call _aP_depack_asm_safe
  end;

function aP_crc32(var source;
                  length:longint):longint;assembler;
  asm
     push length
      push source
       call _aP_crc32
  end;

function aPsafe_pack(var source;
                     var destination;
                     length:longint;
                     var workmem;
                     callback:pointer;
                     cbparam:pointer):longint;assembler;
  asm
      push cbparam
       push callback
        push workmem
         push length
          push destination
           push source
            call _aPsafe_pack
  end;

function aPsafe_check(var source):longint;assembler;
  asm
     push source
      call _aPsafe_check
  end;

function aPsafe_get_orig_size(var source):longint;assembler;
  asm
     push source
      call _aPsafe_get_orig_size
  end;

function aPsafe_depack(var source;
                       srclen:longint;
                       var destination;
                       dstlen:longint):longint;assembler;
  asm
     push dstlen
      push destination
       push srclen
        push source
         call _aPsafe_depack
  end;


(* callback samples for _aP_pack *)

function cb0:longint;assembler;
  asm
    mov eax,aP_pack_continue
  end;

function cb1_(w1,w2:longint):longint;
  begin
    write(w1:8,' -> ',w2:8,^m);
    cb1_:=aP_pack_continue;
    (*$IFDEF ESC_ABORT*)
    if keypressed then
      if readkey=#27 then
        cb1_:=aP_pack_break;
    (*$ENDIF ESC_ABORT*)
  end;

function cb1:longint;assembler;
  asm
    pushad
      push dword [ebp+0Ch]
        push dword [ ebp+10h]
          call cb1_
      mov [esp+1ch],eax (* POPAD restores EAX *)
    popad
  end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?