home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / packer / arc / arcpak / arcpak2.doc next >
Encoding:
Text File  |  1993-11-01  |  15.4 KB  |  360 lines

  1. unit ArcPak2;
  2. interface
  3. uses
  4.   {$IFDEF Windows}
  5.   WinDos
  6.   {$ELSE}
  7.   DOS
  8.   {$ENDIF}
  9. ;
  10.  
  11. type
  12. BigStr = array [1..65535] of char;
  13. BigStrPtr = ^BigStr;
  14.  
  15. Pak_point = ^Pak;
  16. Pak_Ext = record
  17.           Comment  : ^String;      { Remark (comments) }
  18.           Path     : ^String;      { Full Pathname }
  19.           Sec_Env  : ^String;      { Security Envelope, unknown structure }
  20.           Err_Corr : ^String;      { Error correction code, also unknown }
  21.      end;
  22. PakHead = record
  23.          Extend    : ^Pak_ext;
  24.          SDatime   : longint;
  25.   {$IFDEF Windows}
  26.          FDatime   : TDateTime;
  27.   {$ELSE}
  28.          FDatime   : DateTime;
  29.   {$ENDIF}
  30.     end;
  31. Pak = record
  32.           Marker  : byte;
  33.           CompVer : byte;       { Refers to const array PakCompVer }
  34.           Name    : ^string;
  35.           Size    : longint;    { compressed size }
  36.           Time    : word;
  37.           Date    : word;
  38.           CRC     : Integer;
  39.           Length  : longint;    { uncompressed size }
  40.           FilNumb : word;     { /* File Number to which the Pak extension revers */ }
  41.                                    { internal used only !}
  42.   {$IFDEF Windows}
  43.         FDatime   : TDateTime;
  44.   {$ELSE}
  45.         FDatime   : DateTime;
  46.   {$ENDIF}
  47.           NextPak : Pak_point;
  48.           Extend  : ^Pak_ext;     { pointer to next Pak-file, otherwise it's NIL }
  49.      end;
  50. Arc_point = ^Pak;
  51. Entr_ = record
  52.           Entry    : pointer;
  53.           Rel_mark : pointer;
  54.      end;
  55. ZCent_point = ^ZipCent;
  56. ZipEnd_point = ^ZipEnd;
  57. ZipLoc = record
  58.        Signa     : array[1..4] of char;
  59.        Vers      : word;
  60.        GenPur    : word;
  61.        CompVer   : word;
  62.        DaTime    : longint;
  63.        CRC       : longint;
  64.        Size      : longint;     { compressed size }
  65.        Length    : longint;     { uncompressed size }
  66.        NamLeng   : word;
  67.        ExtLeng   : word;
  68.        Name      : ^string;
  69.        ExtField  : ^string;
  70.   {$IFDEF Windows}
  71.        FDatime   : TDateTime;
  72.   {$ELSE}
  73.        FDatime   : DateTime;
  74.   {$ENDIF}
  75.     end;
  76. ZipCent = record
  77.        Signa     : array[1..4] of char;    { Always 'PK'+#1+#2 }
  78.        MadeVers  : word;         { Refers to const array VersionMade }
  79.        ExtVers   : word;         { Refers to const array VersionMade }
  80.        GenPur    : word;         { General purpose Bit-flag }
  81.        CompVer   : word;         { Refers to const array ZipCompVer }
  82.        DaTime    : longint;
  83.        CRC       : longint;
  84.        Size      : longint;     { compressed size }
  85.        Length    : longint;     { uncompressed size }
  86.        NamLeng   : word;        { Name length }
  87.        ExtLeng   : word;        { Extra field length }
  88.        ComtLeng  : word;        { Comment field length }
  89.        DiskNumb  : word;
  90.        IntAttr   : word;        { Internal file attributes }
  91.        ExteAttr  : Longint;     { External file attributes }
  92.        LocOffset : Longint;     { Relative offset of local file header }
  93.        Name      : ^string;
  94.        ExtField  : ^string;
  95.        Comment   : ^string;     { Comment }
  96.   {$IFDEF Windows}
  97.        FDatime   : TDateTime;
  98.   {$ELSE}
  99.        FDatime   : DateTime;
  100.   {$ENDIF}
  101.        NextZipl  : ZCent_point;  { pointer to next Zip-file, otherwise it's NIL }
  102.     end;
  103. ZipEnd = record
  104.        Signa         : array[1..4] of char;    { Always 'PK'+#5+#6 }
  105.        DiskNumb      : word;
  106.        DiskCentStart : word;  { Number of Disk with the start of central directory}
  107.        EnDiNumb      : word;  { total number of entries on this Disk }
  108.        EnToNumb      : word;  { total number of entries }
  109.        CentDirSize   : longint;  { size of the central directory }
  110.        OfCent        : longint;  { offset of the central directory from the first disk }
  111.        ZipComLeg     : word;     { Zip header comment field length }
  112.        ZipComt       : pointer;  { Zip header comment }
  113.   {$IFDEF Windows}
  114.        FDatime       : TDateTime;
  115.   {$ELSE}
  116.        FDatime       : DateTime;  { Date and Time of the Zip file }
  117.   {$ENDIF}
  118.     end;
  119. Lharc_point = ^Lharc;
  120. Lharc = record
  121.        HeadLen   : byte;           { Header length }
  122.        HeadSum   : byte;           { Header Checksum }
  123.        CompVer   : array[1..5] of char;   { Is either '-lh0-' or '-lh1-' }
  124.        Size      : longint;               { compressed size }
  125.        Length    : longint;               { uncompressed size }
  126.        Datime    : longint;
  127.        Atrb      : byte;
  128.        Level     : byte;
  129.        NamLeng   : byte;             { Name length, maximum 74 }
  130.        Name      : ^string;
  131.        CRC       : word;
  132.        Dos       : byte;
  133.        Extsize   : word;             { only for work, don't use this! }
  134.        Extkey    : byte;             { only for work, don't use this! }
  135.        PatLen    : byte;             { Path length, maximum 255 }
  136.        PatNam    : ^string;
  137.        FilLen    : byte;             { unknown usage, be careful!}
  138.        FilNam    : ^string;          { unknown usage, be careful!}
  139.        FilAtr    : word;             { unknown usage, be careful!}
  140.        FilCRC    : word;             { unknown usage, be careful!}
  141.        Attr      : word;
  142.   {$IFDEF Windows}
  143.        FDatime   : TDateTime;
  144.   {$ELSE}
  145.        FDatime   : DateTime;
  146.   {$ENDIF}
  147.        NextLzh   : Lharc_point;  { pointer to next lzh-file, otherwise it's NIL }
  148.     end;
  149. Arj_point = ^Arj;
  150. Arj = record
  151.       Head       : word;         { Header ID: 0xEA60 or 60000U }
  152.       BasHeadSiz : word;         { basic header size  }
  153.       FrsHeadSiz : byte;         { first header size  }
  154.       Vers       : byte;         { version number     }
  155.       MinVers    : byte;         { min. archive version to extract }
  156.       HostOS     : byte;         { operating system   }
  157.       Flags      : byte;         { Arj-Attribute: 0x01 Garbled,
  158.                                                   0x02 Reserved,
  159.                                                   0x04 Volume,
  160.                                                   0x08 Extfile,
  161.                                                   0x10 PathSym,
  162.                                                   0x20 Backup  }
  163.       CoMethod   : byte;         {0 stored, 1 compressed most ... 4 compressed fastest}
  164.       FlType     : byte;         {0 binary, 1 text, 2 comment, 3 directory, 4 volume }
  165.       Resv       : byte;         { reserved }
  166.       Datime     : longint;
  167.       Size       : longint;      { compressed size   }
  168.       Length     : longint;      { original size     }
  169.       CRC        : longint;      { original file CRC }
  170.       Entr       : word;         { entryname position in filename }
  171.       Attr       : word;         { file access mode  }
  172.       Data       : word;         { host data         }
  173.       ExtPos     : longint;      { extra data        }
  174.       Name       : ^string;      { filename          }
  175.       Comment    : ^BigStr;      { comment           }
  176.       HeadCRC    : longint;      { basic header CRC  }
  177.       _1stExtHSz  : word;         { 1st ext. heder size }
  178.       _1stExtH    : ^string;      { 1st ext. header   }
  179.       _1stExtHCRC : longint;      { 1st ext. header CRC }
  180.   {$IFDEF Windows}
  181.        FDatime   : TDateTime;
  182.   {$ELSE}
  183.        FDatime   : DateTime;     { date - time stamp }
  184.   {$ENDIF}
  185.       NamLeng    : word;         { Filename length }
  186.       ComtLeng   : word;         { Comment length }
  187.       NextArj    : Arj_point;    { pointer to next Arj-file, otherwise it's NIL }
  188.     end;
  189. GraphInfo = record
  190.       XRes    : word;
  191.       YRes    : word;
  192.       Colors  : longint;
  193.       Format  : ^string;
  194.       Comment : ^string;
  195.     end;
  196. const PVers = xxx;      { Version of ArcPak Unit}
  197.       PakCompVer  : array[0..11] of string[16] = ('End of File','Stored','Stored'
  198.                    ,'Packed','Squeezed','crunched','crunched','crunched',
  199.                    'Crunched','Squashed','Crushed','Distilled');
  200.       ZipCompVer  : array[0..9] of string[10] = ('Stored','Shrunk','Reduced1'
  201.                    ,'Reduced2','Reduced3','Reduced4','Imploded','*Token*','Deflate','*reserv*');
  202.       VersionMade : array[0..10] of string[18] = ('MS-Dos, OS/2 (FAT)','Amiga','VMS'
  203.                    ,'*NIX','VM/CMS','Atari-ST','OS/2 HPFS','MacIntosh'
  204.                    ,'Z-System','CP/M','unused');
  205.       Host_OS     : array[0..5] of string[6] = ('MSDOS','PRIMOS','UNIX','AMIGA','MACDOS','');
  206.  
  207. function GetGraph_Info(Name : string; var InfoBlock : GraphInfo) : integer;
  208.          { Get Info about Graphic Format }
  209.          { Return Codes:    Gif...   128 }
  210.          {                  PCX...   130 }
  211.          {                  LBM...   132 }
  212.          {                  BMP...   134 }
  213.          {        reserved  BMP/OS2      }
  214.          {                  ICO...       }
  215.          {        reserved  ICO/OS2      }
  216.  
  217. procedure GetAll_Zip(Name : string; var First : Entr_;
  218.                      var PCount: word; var EndOfCentZip : pointer);
  219.           { Get all files in a zipfile with comments, attrib., etc.}
  220.           { Name is the full name without wildcards of the zip-file }
  221.           { Where FirstEntry is a pointer to the first element in the list}
  222.           { and PCount is the number of Elements. EndOfCentZip is a pointer }
  223.           { to the type ZipCent (^ZipCent) }
  224.  
  225. {$IFNDEF OS2}         {*Not for OS/2 currently available*}
  226. procedure Release_ (var First : Entr_);
  227.           { Releases the memory marked in First.Entry, all memory }
  228.           { allocations after this will be freed !! }
  229. {$ENDIF}
  230.  
  231. procedure Dispose_Zip (var First : Entr_; var EndOfCentZip : pointer);
  232.                 { Disposes all groups of the zip file to which }
  233.                 { First.Entry and EndOfCentZip refers. The memory allocation }
  234.                 { of other groups will not be touched. }
  235.  
  236. procedure GetAll_Pak(Name : string; var First : Entr_;
  237.                      var PCount: word; var Head2 : pointer);
  238.                      { Head2 is a pointer to PakHead (^PakHead) }
  239.                      { Rest like above }
  240.  
  241. procedure Dispose_Pak (var First : Entr_;var Head2 : pointer);
  242.  
  243. procedure GetAll_Arc(Name : string; var First : Entr_;
  244.                      var PCount: word; var Head2 : pointer);
  245.  
  246. procedure Dispose_Arc (var First : Entr_;var Head2 : pointer);
  247.  
  248.  
  249. procedure GetAll_Lzh(AName : string; var First : Entr_;
  250.                      var PCount: word; var Head2 : pointer);
  251.  
  252. procedure Dispose_Lzh (var First : Entr_;var Head2 : pointer);
  253.  
  254. procedure GetAll_Arj(Name : string; var First : Entr_; var PCount: word);
  255.  
  256. procedure Dispose_Arj (var First : Entr_);
  257.  
  258. function IsArchiv(Name : string): byte;
  259.          { Checks file if it's an Arc(Pak), Zip or Lzh file }
  260.          { returns:  0  ... it's not an archiv (or unknown)
  261.                      1  ... Arc (Pak)
  262.                      2  ... Zip
  263.                      4  ... Lzh
  264.                      16 ... Arj      }
  265.  
  266. function Decide_Exe(Name : string): byte;
  267. {        Decide whether or not an Exe-file is a selfextracting arj,
  268.          arc, pak, zip, lzh archive:  0...None
  269.                                       1...Arc
  270.                                       2...Zip
  271.                                       3...Zip/2.0
  272.                                       4...Lzh
  273.                                       8...Pak
  274.                                      12...Arc?Pak
  275.                                      16...Arj
  276.                                      125... SomeOther  }
  277.  
  278. function TwoDig(Arg: word): string;
  279.          { Converts numeric value in a two digit string, used in DispAll_*}
  280.  
  281. function Ratio(Small : longint; Big : longint):real;
  282.          { Calculates the ratio of a compressed file, used in DispAll_*}
  283.  
  284. function HexW(W : Word) : string;
  285.          { Converts Number of type word in a 4-digit string}
  286.  
  287. function StUpCase(mixStr : string):string;
  288.          { Converts string to upper case, with international char.-set}
  289.  
  290. function HexL(L : LongInt) : string;
  291.          { Converts Number of type Longint in a 8-digit string}
  292.  
  293. function Atrib(Att : word):string;
  294.          { Calculates the Attributes, in a 5-Digit string don't handling }
  295.          { the volume- and directory-ID, used in DispAll_*}
  296.  
  297. function Atri2(Att : word):string;
  298.          { Calculates the Attributes, in a 4-Digit string don't handling }
  299.          { the volume- and directory-ID, used in DispAll_arj}
  300.  
  301. function CutYear(var Year : word) : word;
  302.          { Cuts the thousands and hundreds from a 4-Digit year, used in DispAll_*}
  303.  
  304. function ExpandName(Name : string):string;
  305.          { Inserts blank if extension is missing or less then 3 chars}
  306.  
  307. function Search(var Buffer; BufLength : Word;
  308.                 var Match; MatLength : Word) : Word;
  309.  
  310.  
  311. { /*****************  Revision History *******************/ }
  312. { 1.00 1st Version released                                 }
  313. { 1.02 fixed a small bug in DispAll_lzh                     }
  314. { 1.03 Checks if .ARC or .PAK is probably a compressed file }
  315. {      and make a small change in DispAll_Pak               }
  316. { 1.04 Fixed a small bug (division by zero) in function 'Ratio'}
  317. {      Make some small changes in DispAll_Zip and DispAll_Lzh  }
  318. {                                    (Similar to 1.03 change)  }
  319. { 1.54 (internal) linked lists realized for zip-files        }
  320. {      rewriten all zip procedures.                          }
  321. { 2.00 (internal) linked lists realized for pak-files,
  322.        rewriten all pak procedures, rewritten zip's procedures
  323.        one more time.                                        }
  324. { 2.30 (internal) realized linked lists for Arc's and PKArc's
  325.        with comments                                         }
  326. { 2.50 linked lists realized for lzh-files, DispAll-xxx moved to
  327.        another unit                                          }
  328. { 2.51 Fixed bug, of not closing file handle by zip files    }
  329. { 2.52 Adjust Filename if extension is missing or less then 3 chars.}
  330. { 2.53 ExpandName added to unit.                             }
  331. { 2.54 Fixed a major bug which occurs on some older .arc files      }
  332. {      ==> the machine hangs up!                             }
  333. { 2.55 Support added for file-testing. If it's (with none-standard  }
  334. {      extension) is an archiv.                              }
  335. {      Additional check by extended header in .PAK files     }
  336. { 2.56 Adding new kind of path storing in lzh files.         }
  337. {      And enhancing record for further usage.               }
  338. { 2.57 Adding handling of large ZipFile comment > 255 Bytes  }
  339. {      Changing record format of ZipEnd!                     }
  340. { 3.00 Adding handling of selfextracting files of PAK, ZIP,  }
  341. {      ARC and LZH (only EXE) files                          }
  342. { 3.01 Fixes Bug, which occurs by Lzh files made by Unix     }
  343. {      machines w/o extended Header                          }
  344. { 3.10 (internal) Added Graphic Format Info for Gif87a, Gif89a, PCX  }
  345. { 4.1  (internal) Added ARJ Support                          }
  346. { 4.2  Added Graphic Format Info for LBM, BMP                }
  347. { 4.3  Added PkZip 2.0 Support including selfextracting      }
  348. { 4.4  Some minor changes to support .TPW Units              }
  349. { 4.5  Several fixes, especially on Zip files                }
  350. { 4.6  Fixes Arj 2.41 self extracting recognition            }
  351. { 4.7  Several changes required for OS/2 porting             }
  352. {      Code is now _cleaner_                                 }
  353. { 4.8  Don't hang on corrupted Zip files                     }
  354. {      eg. if Pointer(First) = nil then writeln('corrupted');    }
  355. {      Fixed some currently unknown lzh behavior             }
  356. { /**********  Future enhancments ************/ }
  357. {  Display comments on Gif89a pictures }
  358. { /*******************************************/ }
  359.  
  360.